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@42335
|
156 |
to Rational.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 |
|
jan@42337
|
178 |
subsubsection {*get the numerator out of a fraction*}
|
jan@42338
|
179 |
text {*get numerator should also become a constant for the isabelle parser: *}
|
jan@42337
|
180 |
|
jan@42337
|
181 |
consts
|
jan@42337
|
182 |
get_numerator :: "real => real"
|
jan@42337
|
183 |
|
jan@42337
|
184 |
ML {*
|
jan@42337
|
185 |
fun eval_get_numerator (thmid:string) _
|
jan@42337
|
186 |
(t as Const ("Rational.get_numerator", _) $
|
jan@42338
|
187 |
(Const ("Rings.inverse_class.divide", _) $num
|
jan@42338
|
188 |
$denom )) thy =
|
jan@42337
|
189 |
SOME (mk_thmid thmid ""
|
jan@42338
|
190 |
(Print_Mode.setmp [] (Syntax.string_of_term (thy2ctxt thy)) num) "",
|
jan@42338
|
191 |
Trueprop $ (mk_equality (t, num)))
|
jan@42337
|
192 |
| eval_get_numerator _ _ _ _ = NONE;
|
jan@42337
|
193 |
|
jan@42337
|
194 |
*}
|
jan@42337
|
195 |
|
neuper@42279
|
196 |
subsection {*solve equation*}
|
neuper@42279
|
197 |
text {*this type of equation if too general for the present program*}
|
neuper@42279
|
198 |
ML {*
|
neuper@42279
|
199 |
"----------- Minisubplb/100-init-rootp (*OK*)bl.sml ---------------------";
|
neuper@42279
|
200 |
val denominator = parseNEW ctxt "z^^^2 - 1/4*z - 1/8 = 0";
|
neuper@42279
|
201 |
val fmz = ["equality (z^^^2 - 1/4*z - 1/8 = (0::real))", "solveFor z","solutions L"];
|
neuper@42279
|
202 |
val (dI',pI',mI') =("Isac", ["univariate","equation"], ["no_met"]);
|
neuper@42279
|
203 |
(* ^^^^^^^^^^^^^^^^^^^^^^ TODO: ISAC determines type of eq*)
|
neuper@42279
|
204 |
*}
|
neuper@42279
|
205 |
text {*Does the Equation Match the Specification ?*}
|
neuper@42279
|
206 |
ML {*
|
neuper@42279
|
207 |
match_pbl fmz (get_pbt ["univariate","equation"]);
|
neuper@42279
|
208 |
*}
|
neuper@42279
|
209 |
ML {*Context.theory_name thy = "Isac"(*==================================================*)*}
|
neuper@42279
|
210 |
|
neuper@42279
|
211 |
ML {*
|
neuper@42303
|
212 |
val denominator = parseNEW ctxt "-1 + -2 * z + 8 * z ^^^ 2 = 0";
|
neuper@42279
|
213 |
val fmz = (*specification*)
|
neuper@42303
|
214 |
["equality (-1 + -2 * z + 8 * z ^^^ 2 = (0::real))", (*equality*)
|
neuper@42279
|
215 |
"solveFor z", (*bound variable*)
|
neuper@42279
|
216 |
"solutions L"]; (*identifier for solution*)
|
jan@42300
|
217 |
|
neuper@42279
|
218 |
val (dI',pI',mI') =
|
neuper@42303
|
219 |
("Isac", ["abcFormula","degree_2","polynomial","univariate","equation"], ["no_met"]);
|
neuper@42279
|
220 |
*}
|
neuper@42279
|
221 |
text {*Does the Other Equation Match the Specification ?*}
|
neuper@42279
|
222 |
ML {*
|
neuper@42303
|
223 |
match_pbl fmz (get_pbt ["abcFormula","degree_2","polynomial","univariate","equation"]);
|
neuper@42279
|
224 |
*}
|
neuper@42279
|
225 |
text {*Solve Equation Stepwise*}
|
neuper@42279
|
226 |
ML {*
|
neuper@42303
|
227 |
*}
|
neuper@42303
|
228 |
ML {*
|
neuper@42279
|
229 |
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
|
neuper@42279
|
230 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
231 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
232 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
233 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
234 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
235 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
236 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
237 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
238 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
239 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
240 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
241 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt =..,Check_elementwise "Assumptions")*)
|
neuper@42279
|
242 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
243 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt; f2str f;
|
neuper@42303
|
244 |
(*[z = 1 / 2, z = -1 / 4]*)
|
neuper@42279
|
245 |
show_pt pt;
|
neuper@42279
|
246 |
val SOME f = parseNEW ctxt "[z=1/2, z=-1/4]";
|
neuper@42279
|
247 |
*}
|
neuper@42279
|
248 |
|
neuper@42279
|
249 |
subsection {*partial fraction decomposition*}
|
neuper@42279
|
250 |
subsubsection {*solution of the equation*}
|
neuper@42279
|
251 |
ML {*
|
neuper@42279
|
252 |
val SOME solutions = parseNEW ctxt "[z=1/2, z=-1/4]";
|
neuper@42279
|
253 |
term2str solutions;
|
neuper@42279
|
254 |
atomty solutions;
|
neuper@42279
|
255 |
*}
|
neuper@42279
|
256 |
|
neuper@42279
|
257 |
subsubsection {*get solutions out of list*}
|
neuper@42279
|
258 |
text {*in isac's CTP-based programming language: let$ $s_1 = NTH 1$ solutions; $s_2 = NTH 2...$*}
|
neuper@42279
|
259 |
ML {*
|
neuper@42279
|
260 |
val Const ("List.list.Cons", _) $ s_1 $ (Const ("List.list.Cons", _) $
|
neuper@42279
|
261 |
s_2 $ Const ("List.list.Nil", _)) = solutions;
|
neuper@42279
|
262 |
term2str s_1;
|
neuper@42279
|
263 |
term2str s_2;
|
neuper@42279
|
264 |
*}
|
neuper@42279
|
265 |
|
neuper@42279
|
266 |
ML {* (*Solutions as Denominator --> Denominator1 = z - Zeropoint1, Denominator2 = z-Zeropoint2,...*)
|
neuper@42279
|
267 |
val xx = HOLogic.dest_eq s_1;
|
neuper@42279
|
268 |
val s_1' = HOLogic.mk_binop "Groups.minus_class.minus" xx;
|
neuper@42279
|
269 |
val xx = HOLogic.dest_eq s_2;
|
neuper@42279
|
270 |
val s_2' = HOLogic.mk_binop "Groups.minus_class.minus" xx;
|
neuper@42279
|
271 |
term2str s_1';
|
neuper@42279
|
272 |
term2str s_2';
|
neuper@42279
|
273 |
*}
|
neuper@42335
|
274 |
text {* for the programming language a function
|
neuper@42335
|
275 |
collecting all the above manipulations is helpful*}
|
neuper@42335
|
276 |
ML {*
|
neuper@42335
|
277 |
fun mk_minus_1 T = Free("-1", T); (*TODO DELETE WITH numbers_to_string*)
|
neuper@42335
|
278 |
fun flip_sign t = (*TODO improve for use in factors_from_solution: -(-1) etc*)
|
neuper@42335
|
279 |
let val minus_1 = t |> type_of |> mk_minus_1
|
neuper@42335
|
280 |
in HOLogic.mk_binop "Groups.times_class.times" (minus_1, t) end;
|
neuper@42335
|
281 |
fun fac_from_sol s =
|
neuper@42335
|
282 |
let val (lhs, rhs) = HOLogic.dest_eq s
|
neuper@42335
|
283 |
in HOLogic.mk_binop "Groups.plus_class.plus" (lhs, flip_sign rhs) end;
|
neuper@42335
|
284 |
*}
|
neuper@42335
|
285 |
ML {*
|
neuper@42335
|
286 |
e_term
|
neuper@42335
|
287 |
*}
|
neuper@42335
|
288 |
ML {*
|
neuper@42335
|
289 |
fun mk_prod prod [] =
|
neuper@42335
|
290 |
if prod = e_term then error "mk_prod called with []" else prod
|
neuper@42335
|
291 |
| mk_prod prod (t :: []) =
|
neuper@42335
|
292 |
if prod = e_term then t else HOLogic.mk_binop "Groups.times_class.times" (prod, t)
|
neuper@42335
|
293 |
| mk_prod prod (t1 :: t2 :: ts) =
|
neuper@42335
|
294 |
if prod = e_term
|
neuper@42335
|
295 |
then
|
neuper@42335
|
296 |
let val p = HOLogic.mk_binop "Groups.times_class.times" (t1, t2)
|
neuper@42335
|
297 |
in mk_prod p ts end
|
neuper@42335
|
298 |
else
|
neuper@42335
|
299 |
let val p = HOLogic.mk_binop "Groups.times_class.times" (prod, t1)
|
neuper@42335
|
300 |
in mk_prod p (t2 :: ts) end
|
neuper@42335
|
301 |
*}
|
neuper@42335
|
302 |
ML {*
|
neuper@42335
|
303 |
*}
|
neuper@42335
|
304 |
ML {*
|
neuper@42335
|
305 |
(*probably keept these test in test/Tools/isac/...
|
neuper@42335
|
306 |
(*mk_prod e_term [];*)
|
neuper@42335
|
307 |
|
neuper@42335
|
308 |
val prod = mk_prod e_term [str2term "x + 123"];
|
neuper@42335
|
309 |
term2str prod = "x + 123";
|
neuper@42335
|
310 |
|
neuper@42335
|
311 |
val sol = str2term "[z = 1 / 2, z = -1 / 4]";
|
neuper@42335
|
312 |
val sols = HOLogic.dest_list sol;
|
neuper@42335
|
313 |
val facs = map fac_from_sol sols;
|
neuper@42335
|
314 |
val prod = mk_prod e_term facs;
|
neuper@42335
|
315 |
term2str prod = "(z + -1 * (1 / 2)) * (z + -1 * (-1 / 4))";
|
neuper@42335
|
316 |
|
neuper@42335
|
317 |
val prod = mk_prod e_term [str2term "x + 1", str2term "x + 2", str2term "x + 3"];
|
neuper@42335
|
318 |
term2str prod = "(x + 1) * (x + 2) * (x + 3)";
|
neuper@42335
|
319 |
*)
|
neuper@42335
|
320 |
|
neuper@42335
|
321 |
fun factors_from_solution sol =
|
neuper@42335
|
322 |
let val ts = HOLogic.dest_list sol
|
neuper@42335
|
323 |
in mk_prod e_term (map fac_from_sol ts) end;
|
neuper@42335
|
324 |
(*
|
neuper@42335
|
325 |
val sol = str2term "[z = 1 / 2, z = -1 / 4]";
|
neuper@42335
|
326 |
val fs = factors_from_solution sol;
|
neuper@42335
|
327 |
term2str fs = "(z + -1 * (1 / 2)) * (z + -1 * (-1 / 4))"
|
neuper@42335
|
328 |
*)
|
neuper@42335
|
329 |
*}
|
neuper@42335
|
330 |
text {* This function needs to be packed such that it can be evaluated by the Lucas-Interpreter:
|
neuper@42335
|
331 |
# shift these functions into the related Equation.thy
|
neuper@42335
|
332 |
# -- compare steps done with get_denominator above
|
neuper@42335
|
333 |
*}
|
neuper@42335
|
334 |
ML {*
|
neuper@42335
|
335 |
(*("factors_from_solution", ("Equation.factors_from_solution", eval_factors_from_solution ""))*)
|
neuper@42335
|
336 |
fun eval_factors_from_solution (thmid:string) _ t thy =
|
neuper@42335
|
337 |
(let val prod = factors_from_solution t
|
neuper@42335
|
338 |
in SOME (mk_thmid thmid ""
|
neuper@42335
|
339 |
(Print_Mode.setmp [] (Syntax.string_of_term (thy2ctxt thy)) prod) "",
|
neuper@42335
|
340 |
Trueprop $ (mk_equality (t, prod)))
|
neuper@42335
|
341 |
end)
|
neuper@42335
|
342 |
handle _ => NONE;
|
neuper@42335
|
343 |
*}
|
neuper@42279
|
344 |
|
neuper@42279
|
345 |
subsubsection {*build expression*}
|
neuper@42279
|
346 |
text {*in isac's CTP-based programming language: let s_1 = Take numerator / (s_1 * s_2)*}
|
neuper@42279
|
347 |
ML {*
|
neuper@42279
|
348 |
(*The Main Denominator is the multiplikation of the partial fraction denominators*)
|
neuper@42279
|
349 |
val denominator' = HOLogic.mk_binop "Groups.times_class.times" (s_1', s_2') ;
|
neuper@42279
|
350 |
val SOME numerator = parseNEW ctxt "3::real";
|
neuper@42279
|
351 |
|
neuper@42279
|
352 |
val expr' = HOLogic.mk_binop "Rings.inverse_class.divide" (numerator, denominator');
|
neuper@42279
|
353 |
term2str expr';
|
neuper@42279
|
354 |
*}
|
neuper@42279
|
355 |
|
neuper@42279
|
356 |
subsubsection {*Ansatz - create partial fractions out of our expression*}
|
neuper@42302
|
357 |
ML {*Context.theory_name thy = "Isac"*}
|
neuper@42279
|
358 |
|
neuper@42279
|
359 |
axiomatization where
|
neuper@42279
|
360 |
ansatz2: "n / (a*b) = A/a + B/(b::real)" and
|
neuper@42342
|
361 |
multiply_eq2: "((n::real) / (a*b) = A/a + B/b) = (a*b*(n / (a*b)) = a*b*(A/a + B/b))"
|
neuper@42279
|
362 |
|
neuper@42279
|
363 |
ML {*
|
neuper@42279
|
364 |
(*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
|
365 |
val SOME (t1,_) = rewrite_ @{theory Isac} e_rew_ord e_rls false @{thm ansatz2} expr';
|
neuper@42279
|
366 |
term2str t1; atomty t1;
|
neuper@42279
|
367 |
val eq1 = HOLogic.mk_eq (expr', t1);
|
neuper@42279
|
368 |
term2str eq1;
|
neuper@42279
|
369 |
*}
|
neuper@42279
|
370 |
ML {*
|
neuper@42279
|
371 |
(*eliminate the demoninators by multiplying the left and the right side with the main denominator*)
|
neuper@42279
|
372 |
val SOME (eq2,_) = rewrite_ @{theory Isac} e_rew_ord e_rls false @{thm multiply_eq2} eq1;
|
neuper@42279
|
373 |
term2str eq2;
|
neuper@42279
|
374 |
*}
|
neuper@42279
|
375 |
ML {*
|
neuper@42279
|
376 |
(*simplificatoin*)
|
neuper@42279
|
377 |
val SOME (eq3,_) = rewrite_set_ @{theory Isac} false norm_Rational eq2;
|
neuper@42279
|
378 |
term2str eq3; (*?A ?B not simplified*)
|
neuper@42279
|
379 |
*}
|
neuper@42279
|
380 |
ML {*
|
neuper@42279
|
381 |
val SOME fract1 =
|
neuper@42279
|
382 |
parseNEW ctxt "(z - 1 / 2) * (z - -1 / 4) * (A / (z - 1 / 2) + B / (z - -1 / 4))"; (*A B !*)
|
neuper@42279
|
383 |
val SOME (fract2,_) = rewrite_set_ @{theory Isac} false norm_Rational fract1;
|
neuper@42279
|
384 |
term2str fract2 = "(A + -2 * B + 4 * A * z + 4 * B * z) / 4";
|
neuper@42279
|
385 |
(*term2str fract2 = "A * (1 / 4 + z) + B * (-1 / 2 + z)" would be more traditional*)
|
neuper@42279
|
386 |
*}
|
neuper@42279
|
387 |
ML {*
|
neuper@42279
|
388 |
val (numerator, denominator) = HOLogic.dest_eq eq3;
|
neuper@42279
|
389 |
val eq3' = HOLogic.mk_eq (numerator, fract1); (*A B !*)
|
neuper@42279
|
390 |
term2str eq3';
|
neuper@42279
|
391 |
(*MANDATORY: simplify (and remove denominator) otherwise 3 = 0*)
|
neuper@42279
|
392 |
val SOME (eq3'' ,_) = rewrite_set_ @{theory Isac} false norm_Rational eq3';
|
neuper@42279
|
393 |
term2str eq3'';
|
neuper@42279
|
394 |
*}
|
neuper@42279
|
395 |
ML {*Context.theory_name thy = "Isac"(*==================================================*)*}
|
neuper@42279
|
396 |
|
neuper@42342
|
397 |
subsubsection {*Build a rule-set for ansatz*}
|
neuper@42342
|
398 |
ML {*
|
neuper@42342
|
399 |
val ansatz_rls = prep_rls(
|
neuper@42342
|
400 |
Rls {id = "ansatz_rls", preconds = [], rew_ord = ("dummy_ord",dummy_ord),
|
neuper@42342
|
401 |
erls = e_rls, srls = Erls, calc = [],
|
neuper@42342
|
402 |
rules =
|
neuper@42342
|
403 |
[Thm ("ansatz2",num_str @{thm ansatz2}),
|
neuper@42342
|
404 |
Thm ("multiply_eq2",num_str @{thm multiply_eq2})
|
neuper@42342
|
405 |
],
|
neuper@42342
|
406 |
scr = EmptyScr});
|
neuper@42342
|
407 |
*}
|
neuper@42342
|
408 |
ML {*
|
neuper@42342
|
409 |
val SOME (ttttt,_) = rewrite_set_ @{theory Isac} false ansatz_rls expr';
|
neuper@42342
|
410 |
term2str ttttt;
|
neuper@42342
|
411 |
*}
|
neuper@42342
|
412 |
|
neuper@42342
|
413 |
|
neuper@42279
|
414 |
subsubsection {*get first koeffizient*}
|
neuper@42279
|
415 |
|
neuper@42279
|
416 |
ML {*
|
neuper@42279
|
417 |
(*substitude z with the first zeropoint to get A*)
|
neuper@42279
|
418 |
val SOME (eq4_1,_) = rewrite_terms_ @{theory Isac} e_rew_ord e_rls [s_1] eq3'';
|
neuper@42279
|
419 |
term2str eq4_1;
|
neuper@42279
|
420 |
|
neuper@42279
|
421 |
val SOME (eq4_2,_) = rewrite_set_ @{theory Isac} false norm_Rational eq4_1;
|
neuper@42279
|
422 |
term2str eq4_2;
|
neuper@42279
|
423 |
|
neuper@42279
|
424 |
val fmz = ["equality (3 = 3 * A / (4::real))", "solveFor A","solutions L"];
|
neuper@42279
|
425 |
val (dI',pI',mI') =("Isac", ["univariate","equation"], ["no_met"]);
|
neuper@42279
|
426 |
(*solve the simple linear equilation for A TODO: return eq, not list of eq*)
|
neuper@42279
|
427 |
val (p,_,fa,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
|
neuper@42279
|
428 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
429 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
430 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
431 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
432 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
433 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
434 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
435 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
436 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
437 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
438 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
439 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
440 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
441 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
442 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
443 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
444 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
445 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
446 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
447 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
448 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
449 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
450 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
451 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
452 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
453 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
454 |
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
455 |
f2str fa;
|
neuper@42279
|
456 |
*}
|
neuper@42279
|
457 |
|
neuper@42279
|
458 |
subsubsection {*get second koeffizient*}
|
neuper@42279
|
459 |
ML {*thy*}
|
neuper@42279
|
460 |
|
neuper@42279
|
461 |
ML {*
|
neuper@42279
|
462 |
(*substitude z with the second zeropoint to get B*)
|
neuper@42279
|
463 |
val SOME (eq4b_1,_) = rewrite_terms_ @{theory Isac} e_rew_ord e_rls [s_2] eq3'';
|
neuper@42279
|
464 |
term2str eq4b_1;
|
neuper@42279
|
465 |
|
neuper@42279
|
466 |
val SOME (eq4b_2,_) = rewrite_set_ @{theory Isac} false norm_Rational eq4b_1;
|
neuper@42279
|
467 |
term2str eq4b_2;
|
neuper@42279
|
468 |
*}
|
neuper@42279
|
469 |
ML {*
|
neuper@42279
|
470 |
(*solve the simple linear equilation for B TODO: return eq, not list of eq*)
|
neuper@42279
|
471 |
val fmz = ["equality (3 = -3 * B / (4::real))", "solveFor B","solutions L"];
|
neuper@42279
|
472 |
val (dI',pI',mI') =("Isac", ["univariate","equation"], ["no_met"]);
|
neuper@42279
|
473 |
val (p,_,fb,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
|
neuper@42279
|
474 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
475 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
476 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
477 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
478 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
479 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
480 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
481 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
482 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
483 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
484 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
485 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
486 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
487 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
488 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
489 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
490 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
491 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
492 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
493 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
494 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
495 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
496 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
497 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
498 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
499 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
500 |
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
501 |
f2str fb;
|
neuper@42279
|
502 |
*}
|
neuper@42279
|
503 |
|
neuper@42279
|
504 |
ML {* (*check koeffizients*)
|
neuper@42279
|
505 |
if f2str fa = "[A = 4]" then () else error "part.fract. eq4_1";
|
neuper@42279
|
506 |
if f2str fb = "[B = -4]" then () else error "part.fract. eq4_1";
|
neuper@42279
|
507 |
*}
|
neuper@42279
|
508 |
|
neuper@42279
|
509 |
subsubsection {*substitute expression with solutions*}
|
neuper@42279
|
510 |
ML {*
|
neuper@42279
|
511 |
*}
|
neuper@42279
|
512 |
ML {*thy*}
|
neuper@42279
|
513 |
|
jan@42296
|
514 |
section {*Implement the Specification and the Method \label{spec-meth}*}
|
neuper@42279
|
515 |
text{*==============================================*}
|
neuper@42279
|
516 |
subsection{*Define the Field Descriptions for the specification*}
|
neuper@42279
|
517 |
consts
|
neuper@42279
|
518 |
filterExpression :: "bool => una"
|
neuper@42279
|
519 |
stepResponse :: "bool => una"
|
neuper@42279
|
520 |
|
neuper@42279
|
521 |
subsection{*Define the Specification*}
|
neuper@42279
|
522 |
ML {*
|
neuper@42279
|
523 |
store_pbt
|
neuper@42279
|
524 |
(prep_pbt thy "pbl_SP" [] e_pblID
|
neuper@42279
|
525 |
(["SignalProcessing"], [], e_rls, NONE, []));
|
neuper@42279
|
526 |
store_pbt
|
neuper@42279
|
527 |
(prep_pbt thy "pbl_SP_Ztrans" [] e_pblID
|
neuper@42279
|
528 |
(["Z_Transform","SignalProcessing"], [], e_rls, NONE, []));
|
neuper@42279
|
529 |
*}
|
neuper@42279
|
530 |
ML {*thy*}
|
neuper@42279
|
531 |
ML {*
|
neuper@42279
|
532 |
store_pbt
|
neuper@42279
|
533 |
(prep_pbt thy "pbl_SP_Ztrans_inv" [] e_pblID
|
neuper@42279
|
534 |
(["inverse", "Z_Transform", "SignalProcessing"],
|
neuper@42279
|
535 |
[("#Given" ,["filterExpression X_eq"]),
|
neuper@42279
|
536 |
("#Find" ,["stepResponse n_eq"])
|
neuper@42279
|
537 |
],
|
neuper@42279
|
538 |
append_rls "e_rls" e_rls [(*for preds in where_*)], NONE,
|
neuper@42279
|
539 |
[["SignalProcessing","Z_Transform","inverse"]]));
|
neuper@42279
|
540 |
|
neuper@42279
|
541 |
show_ptyps();
|
neuper@42279
|
542 |
get_pbt ["inverse","Z_Transform","SignalProcessing"];
|
neuper@42279
|
543 |
*}
|
neuper@42279
|
544 |
|
neuper@42279
|
545 |
subsection {*Define Name and Signature for the Method*}
|
neuper@42279
|
546 |
consts
|
neuper@42279
|
547 |
InverseZTransform :: "[bool, bool] => bool"
|
neuper@42279
|
548 |
("((Script InverseZTransform (_ =))// (_))" 9)
|
neuper@42279
|
549 |
|
neuper@42279
|
550 |
subsection {*Setup Parent Nodes in Hierarchy of Method*}
|
neuper@42279
|
551 |
ML {*
|
neuper@42279
|
552 |
store_met
|
neuper@42279
|
553 |
(prep_met thy "met_SP" [] e_metID
|
neuper@42279
|
554 |
(["SignalProcessing"], [],
|
neuper@42279
|
555 |
{rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls,
|
neuper@42279
|
556 |
crls = e_rls, nrls = e_rls}, "empty_script"));
|
neuper@42279
|
557 |
store_met
|
neuper@42279
|
558 |
(prep_met thy "met_SP_Ztrans" [] e_metID
|
neuper@42279
|
559 |
(["SignalProcessing", "Z_Transform"], [],
|
neuper@42279
|
560 |
{rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls,
|
neuper@42279
|
561 |
crls = e_rls, nrls = e_rls}, "empty_script"));
|
neuper@42279
|
562 |
*}
|
neuper@42279
|
563 |
ML {*
|
neuper@42279
|
564 |
store_met
|
neuper@42279
|
565 |
(prep_met thy "met_SP_Ztrans_inv" [] e_metID
|
neuper@42279
|
566 |
(["SignalProcessing", "Z_Transform", "inverse"],
|
neuper@42279
|
567 |
[("#Given" ,["filterExpression X_eq"]),
|
neuper@42279
|
568 |
("#Find" ,["stepResponse n_eq"])
|
neuper@42279
|
569 |
],
|
neuper@42279
|
570 |
{rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls,
|
neuper@42279
|
571 |
crls = e_rls, nrls = e_rls},
|
neuper@42279
|
572 |
"empty_script"
|
neuper@42279
|
573 |
));
|
neuper@42279
|
574 |
*}
|
neuper@42279
|
575 |
ML {*
|
neuper@42279
|
576 |
store_met
|
neuper@42279
|
577 |
(prep_met thy "met_SP_Ztrans_inv" [] e_metID
|
neuper@42279
|
578 |
(["SignalProcessing", "Z_Transform", "inverse"],
|
neuper@42279
|
579 |
[("#Given" ,["filterExpression X_eq"]),
|
neuper@42279
|
580 |
("#Find" ,["stepResponse n_eq"])
|
neuper@42279
|
581 |
],
|
neuper@42279
|
582 |
{rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls,
|
neuper@42279
|
583 |
crls = e_rls, nrls = e_rls},
|
neuper@42279
|
584 |
"Script InverseZTransform (Xeq::bool) =" ^
|
neuper@42279
|
585 |
" (let X = Take Xeq;" ^
|
neuper@42279
|
586 |
" X = Rewrite ruleZY False X" ^
|
neuper@42279
|
587 |
" in X)"
|
neuper@42279
|
588 |
));
|
jan@42299
|
589 |
*}
|
jan@42299
|
590 |
ML {*
|
neuper@42279
|
591 |
show_mets();
|
jan@42299
|
592 |
*}
|
jan@42299
|
593 |
ML {*
|
neuper@42279
|
594 |
get_met ["SignalProcessing","Z_Transform","inverse"];
|
neuper@42279
|
595 |
*}
|
neuper@42279
|
596 |
|
jan@42296
|
597 |
section {*Program in CTP-based language \label{prog-steps}*}
|
neuper@42279
|
598 |
text{*=================================*}
|
neuper@42279
|
599 |
subsection {*Stepwise extend Program*}
|
neuper@42279
|
600 |
ML {*
|
neuper@42279
|
601 |
val str =
|
neuper@42279
|
602 |
"Script InverseZTransform (Xeq::bool) =" ^
|
neuper@42279
|
603 |
" Xeq";
|
neuper@42279
|
604 |
*}
|
neuper@42279
|
605 |
ML {*
|
neuper@42279
|
606 |
val str =
|
neuper@42279
|
607 |
"Script InverseZTransform (Xeq::bool) =" ^ (*(1/z) instead of z ^^^ -1*)
|
neuper@42279
|
608 |
" (let X = Take Xeq;" ^
|
neuper@42279
|
609 |
" X' = Rewrite ruleZY False X;" ^ (*z * denominator*)
|
neuper@42279
|
610 |
" X' = (Rewrite_Set norm_Rational False) X'" ^ (*simplify*)
|
neuper@42279
|
611 |
" in X)";
|
neuper@42279
|
612 |
(*NONE*)
|
neuper@42279
|
613 |
"Script InverseZTransform (Xeq::bool) =" ^ (*(1/z) instead of z ^^^ -1*)
|
neuper@42279
|
614 |
" (let X = Take Xeq;" ^
|
neuper@42279
|
615 |
" X' = Rewrite ruleZY False X;" ^ (*z * denominator*)
|
neuper@42279
|
616 |
" X' = (Rewrite_Set norm_Rational False) X';" ^ (*simplify*)
|
neuper@42279
|
617 |
" X' = (SubProblem (Isac',[pqFormula,degree_2,polynomial,univariate,equation], [no_met]) " ^
|
neuper@42279
|
618 |
" [BOOL e_e, REAL v_v])" ^
|
neuper@42279
|
619 |
" in X)";
|
neuper@42279
|
620 |
*}
|
neuper@42279
|
621 |
ML {*
|
neuper@42279
|
622 |
val str =
|
neuper@42279
|
623 |
"Script InverseZTransform (Xeq::bool) =" ^ (*(1/z) instead of z ^^^ -1*)
|
neuper@42279
|
624 |
" (let X = Take Xeq;" ^
|
neuper@42279
|
625 |
" X' = Rewrite ruleZY False X;" ^ (*z * denominator*)
|
neuper@42279
|
626 |
" X' = (Rewrite_Set norm_Rational False) X';" ^ (*simplify*)
|
neuper@42279
|
627 |
" funterm = rhs X'" ^ (*drop X'= for equation solving*)
|
neuper@42279
|
628 |
" in X)";
|
neuper@42279
|
629 |
*}
|
neuper@42279
|
630 |
ML {*
|
neuper@42290
|
631 |
val str =
|
neuper@42290
|
632 |
"Script InverseZTransform (X_eq::bool) =" ^ (*(1/z) instead of z ^^^ -1*)
|
neuper@42290
|
633 |
" (let X = Take X_eq;" ^
|
neuper@42290
|
634 |
" X' = Rewrite ruleZY False X;" ^ (*z * denominator*)
|
neuper@42290
|
635 |
" X' = (Rewrite_Set norm_Rational False) X';" ^ (*simplify*)
|
jan@42298
|
636 |
" (X'_z::real) = lhs X';" ^
|
jan@42298
|
637 |
" (z::real) = argument_in X'_z;" ^
|
jan@42298
|
638 |
" (funterm::real) = rhs X';" ^ (*drop X' z = for equation solving*)
|
jan@42298
|
639 |
" (denom::real) = get_denominator funterm;" ^ (*get_denominator*)
|
jan@42298
|
640 |
" (equ::bool) = (denom = (0::real));" ^
|
neuper@42290
|
641 |
" (L_L::bool list) = " ^
|
neuper@42290
|
642 |
" (SubProblem (Test', " ^
|
neuper@42290
|
643 |
" [linear,univariate,equation,test]," ^
|
neuper@42290
|
644 |
" [Test,solve_linear]) " ^
|
neuper@42290
|
645 |
" [BOOL equ, REAL z]) " ^
|
neuper@42290
|
646 |
" in X)"
|
neuper@42290
|
647 |
;
|
neuper@42290
|
648 |
|
neuper@42279
|
649 |
parse thy str;
|
neuper@42279
|
650 |
val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
|
neuper@42279
|
651 |
atomty sc;
|
neuper@42279
|
652 |
|
neuper@42279
|
653 |
*}
|
jan@42300
|
654 |
|
jan@42300
|
655 |
text {*
|
jan@42300
|
656 |
This ruleset contains all functions that are in the script;
|
jan@42300
|
657 |
The evaluation of the functions is done by rewriting using this ruleset.
|
jan@42300
|
658 |
*}
|
jan@42300
|
659 |
|
neuper@42279
|
660 |
ML {*
|
neuper@42290
|
661 |
val srls = Rls {id="srls_InverseZTransform",
|
neuper@42290
|
662 |
preconds = [], rew_ord = ("termlessI",termlessI),
|
neuper@42290
|
663 |
erls = append_rls "erls_in_srls_InverseZTransform" e_rls
|
neuper@42290
|
664 |
[(*for asm in NTH_CONS ...*) Calc ("Orderings.ord_class.less",eval_equ "#less_"),
|
neuper@42290
|
665 |
(*2nd NTH_CONS pushes n+-1 into asms*) Calc("Groups.plus_class.plus", eval_binop "#add_")
|
neuper@42290
|
666 |
],
|
neuper@42290
|
667 |
srls = Erls, calc = [],
|
neuper@42290
|
668 |
rules =
|
neuper@42290
|
669 |
[Thm ("NTH_CONS",num_str @{thm NTH_CONS}),
|
neuper@42290
|
670 |
Calc("Groups.plus_class.plus", eval_binop "#add_"),
|
neuper@42290
|
671 |
Thm ("NTH_NIL",num_str @{thm NTH_NIL}),
|
neuper@42290
|
672 |
Calc("Tools.lhs", eval_lhs"eval_lhs_"), (*<=== ONLY USED*)
|
neuper@42290
|
673 |
Calc("Tools.rhs", eval_rhs"eval_rhs_"), (*<=== ONLY USED*)
|
jan@42300
|
674 |
Calc("Atools.argument'_in", eval_argument_in "Atools.argument'_in"),
|
neuper@42301
|
675 |
Calc("Rational.get_denominator",
|
jan@42338
|
676 |
eval_get_denominator "Rational.get_denominator"),
|
jan@42338
|
677 |
Calc("Rational.get_numerator",
|
jan@42338
|
678 |
eval_get_numerator "Rational.get_numerator")
|
neuper@42290
|
679 |
],
|
neuper@42290
|
680 |
scr = EmptyScr};
|
neuper@42279
|
681 |
*}
|
neuper@42279
|
682 |
|
neuper@42279
|
683 |
|
neuper@42279
|
684 |
subsection {*Store Final Version of Program for Execution*}
|
jan@42338
|
685 |
|
neuper@42279
|
686 |
ML {*
|
neuper@42279
|
687 |
store_met
|
neuper@42279
|
688 |
(prep_met thy "met_SP_Ztrans_inv" [] e_metID
|
neuper@42279
|
689 |
(["SignalProcessing", "Z_Transform", "inverse"],
|
neuper@42279
|
690 |
[("#Given" ,["filterExpression X_eq"]),
|
neuper@42279
|
691 |
("#Find" ,["stepResponse n_eq"])
|
neuper@42279
|
692 |
],
|
neuper@42290
|
693 |
{rew_ord'="tless_true", rls'= e_rls, calc = [], srls = srls,
|
neuper@42290
|
694 |
prls = e_rls,
|
neuper@42279
|
695 |
crls = e_rls, nrls = e_rls},
|
neuper@42289
|
696 |
"Script InverseZTransform (X_eq::bool) =" ^ (*(1/z) instead of z ^^^ -1*)
|
neuper@42289
|
697 |
" (let X = Take X_eq;" ^
|
neuper@42279
|
698 |
" X' = Rewrite ruleZY False X;" ^ (*z * denominator*)
|
neuper@42279
|
699 |
" X' = (Rewrite_Set norm_Rational False) X';" ^ (*simplify*)
|
jan@42298
|
700 |
" (X'_z::real) = lhs X';" ^ (**)
|
neuper@42303
|
701 |
" (zzz::real) = argument_in X'_z;" ^ (**)
|
jan@42298
|
702 |
" (funterm::real) = rhs X';" ^ (*drop X' z = for equation solving*)
|
jan@42298
|
703 |
" (denom::real) = get_denominator funterm;" ^ (*get_denominator*)
|
jan@42298
|
704 |
" (equ::bool) = (denom = (0::real));" ^
|
neuper@42303
|
705 |
|
neuper@42303
|
706 |
" (L_L::bool list) = (SubProblem (PolyEq'," ^
|
neuper@42315
|
707 |
" [abcFormula,degree_2,polynomial,univariate,equation],[no_met])" ^
|
jan@42339
|
708 |
" [BOOL equ, REAL zzz]); " ^
|
jan@42339
|
709 |
|
jan@42339
|
710 |
" (num::real) = get_numerator funterm; " ^ (*get_numerator*)
|
jan@42339
|
711 |
" (facs::real) = factors_from_solution L_L;" ^
|
jan@42339
|
712 |
|
jan@42339
|
713 |
" eq = Take (funterm = (num / facs));" ^
|
jan@42339
|
714 |
" eq = (Try (Rewrite_Set ansatz False)) eq" ^
|
jan@42339
|
715 |
|
jan@42338
|
716 |
" in X)"
|
neuper@42279
|
717 |
));
|
neuper@42279
|
718 |
*}
|
neuper@42279
|
719 |
|
jan@42338
|
720 |
|
neuper@42281
|
721 |
subsection {*Check the Program*}
|
neuper@42279
|
722 |
|
neuper@42281
|
723 |
subsubsection {*Check the formalization*}
|
neuper@42279
|
724 |
ML {*
|
neuper@42279
|
725 |
val fmz = ["filterExpression (X = 3 / (z - 1/4 + -1/8 * (1/(z::real))))",
|
neuper@42279
|
726 |
"stepResponse (x[n::real]::bool)"];
|
neuper@42279
|
727 |
val (dI,pI,mI) = ("Isac", ["inverse", "Z_Transform", "SignalProcessing"],
|
neuper@42279
|
728 |
["SignalProcessing","Z_Transform","inverse"]);
|
neuper@42281
|
729 |
|
neuper@42281
|
730 |
val ([(1, [1], "#Given", Const ("Inverse_Z_Transform.filterExpression", _),
|
neuper@42281
|
731 |
[Const ("HOL.eq", _) $ _ $ _]),
|
neuper@42281
|
732 |
(2, [1], "#Find", Const ("Inverse_Z_Transform.stepResponse", _),
|
neuper@42281
|
733 |
[Free ("x", _) $ _])],
|
neuper@42281
|
734 |
_) = prep_ori fmz thy ((#ppc o get_pbt) pI);
|
neuper@42281
|
735 |
*}
|
neuper@42290
|
736 |
ML {*
|
neuper@42290
|
737 |
val Script sc = (#scr o get_met) ["SignalProcessing","Z_Transform","inverse"];
|
neuper@42290
|
738 |
atomty sc;
|
neuper@42290
|
739 |
*}
|
neuper@42281
|
740 |
|
neuper@42281
|
741 |
subsubsection {*Stepwise check the program*}
|
neuper@42281
|
742 |
ML {*
|
neuper@42302
|
743 |
trace_rewrite := false;
|
neuper@42306
|
744 |
trace_script := false; print_depth 9;
|
neuper@42281
|
745 |
val fmz = ["filterExpression (X z = 3 / (z - 1/4 + -1/8 * (1/(z::real))))",
|
neuper@42281
|
746 |
"stepResponse (x[n::real]::bool)"];
|
neuper@42281
|
747 |
val (dI,pI,mI) = ("Isac", ["inverse", "Z_Transform", "SignalProcessing"],
|
neuper@42281
|
748 |
["SignalProcessing","Z_Transform","inverse"]);
|
neuper@42310
|
749 |
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI,pI,mI))];
|
neuper@42310
|
750 |
*}
|
neuper@42310
|
751 |
ML {*
|
neuper@42303
|
752 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Add_Given";
|
neuper@42303
|
753 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Add_Find";
|
neuper@42303
|
754 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Specify_Theory";
|
neuper@42303
|
755 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Specify_Problem";
|
neuper@42303
|
756 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Specify_Method";
|
jan@42296
|
757 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Apply_Method";
|
jan@42297
|
758 |
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
|
759 |
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
|
760 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = SubProblem";
|
jan@42300
|
761 |
*}
|
neuper@42305
|
762 |
text {* Instead of nxt = Subproblem above we had Empty_Tac; the search for the reason
|
neuper@42305
|
763 |
considered the following points:
|
neuper@42303
|
764 |
# what shows show_pt pt; ...
|
neuper@42303
|
765 |
(([2], Res), ?X' z = 24 / (-1 + -2 * z + 8 * z ^^^ 2))] ..calculation ok,
|
neuper@42303
|
766 |
but no "next" step found: should be "nxt = Subproblem" ?!?
|
neuper@42303
|
767 |
# what shows trace_script := true; we read bottom up ...
|
neuper@42303
|
768 |
@@@ next leaf 'SubProbfrom
|
neuper@42303
|
769 |
(PolyEq', [abcFormula, degree_2, polynomial, univariate, equation],
|
neuper@42303
|
770 |
no_meth)
|
neuper@42303
|
771 |
[BOOL equ, REAL z]' ---> STac 'SubProblem
|
neuper@42303
|
772 |
(PolyEq', [abcFormula, degree_2, polynomial, univariate, equation],
|
neuper@42303
|
773 |
no_meth)
|
neuper@42303
|
774 |
[BOOL (-1 + -2 * z + 8 * z ^^^ 2 = 0), REAL z]'
|
neuper@42305
|
775 |
... and see the SubProblem with correct arguments from searching next step
|
neuper@42305
|
776 |
(program text !!!--->!!! STac (script tactic) with arguments evaluated.)
|
neuper@42310
|
777 |
# do we have the right Script ...difference in the argumentsdifference in the arguments
|
neuper@42303
|
778 |
val Script s = (#scr o get_met) ["SignalProcessing","Z_Transform","inverse"];
|
neuper@42303
|
779 |
writeln (term2str s);
|
neuper@42310
|
780 |
... shows the right script.difference in the arguments
|
neuper@42305
|
781 |
# test --- why helpless here ? --- shows: replace no_meth by [no_meth] in Script
|
neuper@42301
|
782 |
*}
|
neuper@42315
|
783 |
|
neuper@42301
|
784 |
ML {*
|
neuper@42315
|
785 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Model_Problem";
|
neuper@42306
|
786 |
*}
|
neuper@42306
|
787 |
text {* Instead of nxt = Model_Problem above we had Empty_Tac; the search for the reason
|
neuper@42310
|
788 |
considered the following points:difference in the arguments
|
neuper@42306
|
789 |
# comparison with subsection { *solve equation* }: there solving this equation works,
|
neuper@42315
|
790 |
so there must be some difference in the arguments of the Subproblem:
|
neuper@42315
|
791 |
RIGHT: we had [no_meth] instead of [no_met] ;-))
|
neuper@42305
|
792 |
*}
|
neuper@42305
|
793 |
ML {*
|
neuper@42315
|
794 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Add_Given equality (-1 + -2 * z + 8 * z ^^^ 2 = 0)";
|
neuper@42315
|
795 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Add_Given solveFor z";
|
neuper@42315
|
796 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Add_Find solutions z_i";
|
neuper@42315
|
797 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Specify_Theory Isac";
|
neuper@42301
|
798 |
*}
|
neuper@42315
|
799 |
text {* We had "nxt = Empty_Tac instead Specify_Theory;
|
neuper@42315
|
800 |
the search for the reason considered the following points:
|
neuper@42302
|
801 |
# was there an error message ? NO --ok
|
neuper@42302
|
802 |
# has "nxt = Add_Find" been inserted in pt: get_obj g_pbl pt (fst p); YES --ok
|
neuper@42302
|
803 |
# what is the returned "formula": print_depth 999; f; print_depth 999; --
|
neuper@42302
|
804 |
{Find = [Correct "solutions z_i"], With = [],
|
neuper@42302
|
805 |
Given = [Correct "equality (-1 + -2 * z + 8 * z ^^^ 2 = 0)", Correct "solveFor z"],
|
neuper@42302
|
806 |
Where = [False "matches (z = 0) (-1 + -2 * z + 8 * z ^^^ 2 = 0) |\n
|
neuper@42302
|
807 |
matches (?b * z = 0) (-1 + -2 * z + 8 * z ^^^ 2 = 0) |\n
|
neuper@42302
|
808 |
matches (?a + z = 0) (-1 + -2 * z + 8 * z ^^^ 2 = 0) |\n
|
neuper@42302
|
809 |
matches (?a + ?b * z = 0) (-1 + -2 * z + 8 * z ^^^ 2 = 0)"],
|
neuper@42302
|
810 |
Relate = []}
|
neuper@42302
|
811 |
-- the only False is the reason: the Where (the precondition) is False for good reasons:
|
neuper@42302
|
812 |
the precondition seems to check for linear equations, not for the one we want to solve!
|
neuper@42302
|
813 |
Removed this error by correcting the Script
|
neuper@42302
|
814 |
from SubProblem (PolyEq', [linear,univariate,equation,test], [Test,solve_linear]
|
neuper@42302
|
815 |
to SubProblem (PolyEq', [abcFormula,degree_2,polynomial,univariate,equation],
|
neuper@42303
|
816 |
[PolyEq,solve_d2_polyeq_abc_equation]
|
neuper@42302
|
817 |
You find the appropriate type of equation at
|
neuper@42302
|
818 |
http://www.ist.tugraz.at/projects/isac/www/kbase/pbl/index_pbl.html
|
neuper@42302
|
819 |
and the respective method in Knowledge/PolyEq.thy at the respective store_pbt.
|
neuper@42302
|
820 |
Or you leave the selection of the appropriate type to isac as done in the final Script ;-))
|
neuper@42302
|
821 |
*}
|
neuper@42302
|
822 |
ML {*
|
neuper@42315
|
823 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Specify_Problem [abcFormula,...";
|
neuper@42315
|
824 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Specify_Method [PolyEq,solve_d2_polyeq_abc_equation";
|
neuper@42315
|
825 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Apply_Method [PolyEq,solve_d2_polyeq_abc_equation";
|
neuper@42315
|
826 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Rewrite_Set_Inst ([(bdv, z)], d2_polyeq_abcFormula_simplify";
|
neuper@42289
|
827 |
show_pt pt;
|
neuper@42279
|
828 |
*}
|
neuper@42279
|
829 |
ML {*
|
neuper@42335
|
830 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@42279
|
831 |
*}
|
neuper@42279
|
832 |
ML {*
|
neuper@42335
|
833 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@42335
|
834 |
*}
|
neuper@42335
|
835 |
ML {*
|
neuper@42335
|
836 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@42335
|
837 |
*}
|
neuper@42335
|
838 |
ML {*
|
neuper@42335
|
839 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@42335
|
840 |
*}
|
neuper@42335
|
841 |
ML {*
|
neuper@42335
|
842 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@42335
|
843 |
*}
|
jan@42339
|
844 |
|
jan@42339
|
845 |
ML {*
|
jan@42339
|
846 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
jan@42339
|
847 |
*}
|
jan@42339
|
848 |
|
jan@42339
|
849 |
ML {*
|
jan@42339
|
850 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
jan@42339
|
851 |
*}
|
jan@42339
|
852 |
|
neuper@42335
|
853 |
ML {*
|
neuper@42335
|
854 |
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
|
neuper@42335
|
855 |
show_pt pt;
|
neuper@42279
|
856 |
*}
|
neuper@42279
|
857 |
ML {*
|
neuper@42279
|
858 |
*}
|
neuper@42279
|
859 |
|
neuper@42279
|
860 |
section {*Write Tests for Crucial Details*}
|
neuper@42279
|
861 |
text{*===================================*}
|
neuper@42279
|
862 |
ML {*
|
neuper@42279
|
863 |
*}
|
neuper@42279
|
864 |
|
neuper@42279
|
865 |
section {*Integrate Program into Knowledge*}
|
neuper@42279
|
866 |
ML {*
|
neuper@42290
|
867 |
@{theory Isac}
|
neuper@42279
|
868 |
*}
|
neuper@42279
|
869 |
|
neuper@42279
|
870 |
end
|
neuper@42279
|
871 |
|