cleanup, naming: 'KEStore_Elems' in Tests now 'Test_KEStore_Elems', 'store_pbts' now 'add_pbts'
1 (* Title: Test_Z_Transform
3 (c) copyright due to lincense terms.
4 12345678901234567890123456789012345678901234567890123456789012345678901234567890
5 10 20 30 40 50 60 70 80
8 theory Inverse_Z_Transform imports PolyEq DiffApp Partial_Fractions begin
11 rule1: "1 = \<delta>[n]" and
12 rule2: "|| z || > 1 ==> z / (z - 1) = u [n]" and
13 rule3: "|| z || < 1 ==> z / (z - 1) = -u [-n - 1]" and
14 rule4: "c * (z / (z - \<alpha>)) = c * \<alpha>^^^n * u [n]" and
15 rule5: "|| z || < || \<alpha> || ==> z / (z - \<alpha>) = -(\<alpha>^^^n) * u [-n - 1]" and
16 rule6: "|| z || > 1 ==> z/(z - 1)^^^2 = n * u [n]" (*and
17 rule42: "(a * (z/(z-b)) + c * (z/(z-d))) = (a * b^^^n * u [n] + c * d^^^n * u [n])"*)
20 ruleZY: "(X z = a / b) = (X' z = a / (z * b))" and
21 ruleYZ: "(a/b + c/d) = (a*(z/b) + c*(z/d))"
23 subsection{*Define the Field Descriptions for the specification*}
25 filterExpression :: "bool => una"
26 stepResponse :: "bool => una"
30 val inverse_z = prep_rls(
31 Rls {id = "inverse_z", preconds = [], rew_ord = ("dummy_ord",dummy_ord),
32 erls = Erls, srls = Erls, calc = [], errpatts = [],
35 Thm ("rule4",num_str @{thm rule4})
41 text {*store the rule set for math engine*}
43 setup {* KEStore_Elems.add_rlss [("inverse_z", (Context.theory_name @{theory}, inverse_z))] *}
45 subsection{*Define the Specification*}
50 (prep_pbt thy "pbl_SP" [] e_pblID
51 (["SignalProcessing"], [], e_rls, NONE, []));
53 (prep_pbt thy "pbl_SP_Ztrans" [] e_pblID
54 (["Z_Transform","SignalProcessing"], [], e_rls, NONE, []));
56 (prep_pbt thy "pbl_SP_Ztrans_inv" [] e_pblID
57 (["Inverse", "Z_Transform", "SignalProcessing"],
58 (*^ capital letter breaks coding standard
59 because "inverse" = Const ("Rings.inverse_class.inverse", ..*)
60 [("#Given" ,["filterExpression (X_eq::bool)"]),
61 ("#Find" ,["stepResponse (n_eq::bool)"])
63 append_rls "e_rls" e_rls [(*for preds in where_*)], NONE,
64 [["SignalProcessing","Z_Transform","Inverse"]]));
68 (prep_pbt thy "pbl_SP_Ztrans_inv" [] e_pblID
69 (["Inverse", "Z_Transform", "SignalProcessing"],
70 [("#Given" ,["filterExpression X_eq"]),
71 ("#Find" ,["stepResponse n_eq"])
73 append_rls "e_rls" e_rls [(*for preds in where_*)], NONE,
74 [["SignalProcessing","Z_Transform","Inverse"]]));
76 setup {* KEStore_Elems.add_pbts
77 [(prep_pbt thy "pbl_SP" [] e_pblID (["SignalProcessing"], [], e_rls, NONE, [])),
78 (prep_pbt thy "pbl_SP_Ztrans" [] e_pblID
79 (["Z_Transform","SignalProcessing"], [], e_rls, NONE, [])),
80 (prep_pbt thy "pbl_SP_Ztrans_inv" [] e_pblID
81 (["Inverse", "Z_Transform", "SignalProcessing"],
82 (*^ capital letter breaks coding standard
83 because "inverse" = Const ("Rings.inverse_class.inverse", ..*)
84 [("#Given" ,["filterExpression (X_eq::bool)"]),
85 ("#Find" ,["stepResponse (n_eq::bool)"])],
86 append_rls "e_rls" e_rls [(*for preds in where_*)], NONE,
87 [["SignalProcessing","Z_Transform","Inverse"]])),
88 (prep_pbt thy "pbl_SP_Ztrans_inv" [] e_pblID
89 (["Inverse", "Z_Transform", "SignalProcessing"],
90 [("#Given" ,["filterExpression X_eq"]),
91 ("#Find" ,["stepResponse n_eq"])],
92 append_rls "e_rls" e_rls [(*for preds in where_*)], NONE,
93 [["SignalProcessing","Z_Transform","Inverse"]]))] *}
95 subsection {*Define Name and Signature for the Method*}
97 InverseZTransform :: "[bool, bool] => bool"
98 ("((Script InverseZTransform (_ =))// (_))" 9)
100 subsection {*Setup Parent Nodes in Hierarchy of Method*}
103 (prep_met thy "met_SP" [] e_metID
104 (["SignalProcessing"], [],
105 {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls,
106 crls = e_rls, errpats = [], nrls = e_rls}, "empty_script"));
108 (prep_met thy "met_SP_Ztrans" [] e_metID
109 (["SignalProcessing", "Z_Transform"], [],
110 {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls,
111 crls = e_rls, errpats = [], nrls = e_rls}, "empty_script"));
112 val thy = @{theory}; (*latest version of thy required*)
114 (prep_met thy "met_SP_Ztrans_inv" [] e_metID
115 (["SignalProcessing", "Z_Transform", "Inverse"],
116 [("#Given" ,["filterExpression (X_eq::bool)"]),
117 ("#Find" ,["stepResponse (n_eq::bool)"])
119 {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls,
120 crls = e_rls, errpats = [], nrls = e_rls},
121 "Script InverseZTransform (X_eq::bool) =" ^ (*(1/z) instead of z ^^^ -1*)
122 " (let X = Take X_eq;" ^
123 " X' = Rewrite ruleZY False X;" ^ (*z * denominator*)
124 " X' = (Rewrite_Set norm_Rational False) X';" ^ (*simplify*)
125 " funterm = Take (rhs X');" ^ (*drop X' z = for equation solving*)
126 " denom = (Rewrite_Set partial_fraction False) funterm;" ^ (*get_denominator*)
127 " equ = (denom = (0::real));" ^
128 " fun_arg = Take (lhs X');" ^
129 " arg = (Rewrite_Set partial_fraction False) X';" ^ (*get_argument TODO*)
130 " (L_L::bool list) = " ^
131 " (SubProblem (Test', " ^
132 " [LINEAR,univariate,equation,test]," ^
133 " [Test,solve_linear]) " ^
134 " [BOOL equ, REAL z]) " ^
140 prep_met thy "met_SP_Ztrans_inv" [] e_metID
141 (["SignalProcessing",
145 ("#Given" ,["filterExpression X_eq"]),
146 ("#Find" ,["stepResponse n_eq"])
149 rew_ord'="tless_true",
150 rls'= e_rls, calc = [],
151 srls = srls_partial_fraction,
153 crls = e_rls, errpats = [], nrls = e_rls
155 "Script InverseZTransform (X_eq::bool) = "^
156 (*(1/z) instead of z ^^^ -1*)
157 "(let X = Take X_eq; "^
158 " X' = Rewrite ruleZY False X; "^
160 " (num_orig::real) = get_numerator (rhs X'); "^
161 " X' = (Rewrite_Set norm_Rational False) X'; "^
163 " (X'_z::real) = lhs X'; "^
164 " (zzz::real) = argument_in X'_z; "^
165 " (funterm::real) = rhs X'; "^
166 (*drop X' z = for equation solving*)
167 " (denom::real) = get_denominator funterm; "^
169 " (num::real) = get_numerator funterm; "^
171 " (equ::bool) = (denom = (0::real)); "^
172 " (L_L::bool list) = (SubProblem (PolyEq', "^
173 " [abcFormula,degree_2,polynomial,univariate,equation], "^
175 " [BOOL equ, REAL zzz]); "^
176 " (facs::real) = factors_from_solution L_L; "^
177 " (eql::real) = Take (num_orig / facs); "^
179 " (eqr::real) = (Try (Rewrite_Set ansatz_rls False)) eql; "^
181 " (eq::bool) = Take (eql = eqr); "^
182 (*Maybe possible to use HOLogic.mk_eq ??*)
183 " eq = (Try (Rewrite_Set equival_trans False)) eq; "^
185 " eq = drop_questionmarks eq; "^
186 " (z1::real) = (rhs (NTH 1 L_L)); "^
188 * prepare equation for a - eq_a
189 * therefor substitute z with solution 1 - z1
191 " (z2::real) = (rhs (NTH 2 L_L)); "^
193 " (eq_a::bool) = Take eq; "^
194 " eq_a = (Substitute [zzz=z1]) eq; "^
195 " eq_a = (Rewrite_Set norm_Rational False) eq_a; "^
196 " (sol_a::bool list) = "^
197 " (SubProblem (Isac', "^
198 " [univariate,equation],[no_met]) "^
199 " [BOOL eq_a, REAL (A::real)]); "^
200 " (a::real) = (rhs(NTH 1 sol_a)); "^
202 " (eq_b::bool) = Take eq; "^
203 " eq_b = (Substitute [zzz=z2]) eq_b; "^
204 " eq_b = (Rewrite_Set norm_Rational False) eq_b; "^
205 " (sol_b::bool list) = "^
206 " (SubProblem (Isac', "^
207 " [univariate,equation],[no_met]) "^
208 " [BOOL eq_b, REAL (B::real)]); "^
209 " (b::real) = (rhs(NTH 1 sol_b)); "^
211 " eqr = drop_questionmarks eqr; "^
212 " (pbz::real) = Take eqr; "^
213 " pbz = ((Substitute [A=a, B=b]) pbz); "^
215 " pbz = Rewrite ruleYZ False pbz; "^
216 " pbz = drop_questionmarks pbz; "^
218 " (X_z::bool) = Take (X_z = pbz); "^
219 " (n_eq::bool) = (Rewrite_Set inverse_z False) X_z; "^
220 " n_eq = drop_questionmarks n_eq "^
225 store_met (prep_met thy "met_SP_Ztrans_inv_sub" [] e_metID
226 (["SignalProcessing", "Z_Transform", "Inverse_sub"],
227 [("#Given" ,["filterExpression X_eq"]),
228 ("#Find" ,["stepResponse n_eq"])],
229 {rew_ord'="tless_true",
230 rls'= e_rls, calc = [],
231 srls = Rls {id="srls_partial_fraction",
233 rew_ord = ("termlessI",termlessI),
234 erls = append_rls "erls_in_srls_partial_fraction" e_rls
235 [(*for asm in NTH_CONS ...*)
236 Calc ("Orderings.ord_class.less",eval_equ "#less_"),
237 (*2nd NTH_CONS pushes n+-1 into asms*)
238 Calc("Groups.plus_class.plus", eval_binop "#add_")],
239 srls = Erls, calc = [], errpatts = [],
241 Thm ("NTH_CONS",num_str @{thm NTH_CONS}),
242 Calc("Groups.plus_class.plus", eval_binop "#add_"),
243 Thm ("NTH_NIL",num_str @{thm NTH_NIL}),
244 Calc("Tools.lhs", eval_lhs "eval_lhs_"),
245 Calc("Tools.rhs", eval_rhs"eval_rhs_"),
246 Calc("Atools.argument'_in", eval_argument_in "Atools.argument'_in"),
247 Calc("Rational.get_denominator", eval_get_denominator "#get_denominator"),
248 Calc("Rational.get_numerator", eval_get_numerator "#get_numerator"),
249 Calc("Partial_Fractions.factors_from_solution",
250 eval_factors_from_solution "#factors_from_solution"),
251 Calc("Partial_Fractions.drop_questionmarks", eval_drop_questionmarks "#drop_?")],
253 prls = e_rls, crls = e_rls, errpats = [], nrls = norm_Rational},
254 "Script InverseZTransform (X_eq::bool) = "^(*([], Frm), Problem (Isac, [Inverse, Z_Transform, SignalProcessing])*)
255 "(let X = Take X_eq; "^(*([1], Frm), X z = 3 / (z - 1 / 4 + -1 / 8 * (1 / z))*)
256 " X' = Rewrite ruleZY False X; "^(*([1], Res), ?X' z = 3 / (z * (z - 1 / 4 + -1 / 8 * (1 / z)))*)
257 " (X'_z::real) = lhs X'; "^(* ?X' z*)
258 " (zzz::real) = argument_in X'_z; "^(* z *)
259 " (funterm::real) = rhs X'; "^(* 3 / (z * (z - 1 / 4 + -1 / 8 * (1 / z)))*)
261 " (pbz::real) = (SubProblem (Isac', "^(**)
262 " [partial_fraction,rational,simplification], "^
263 " [simplification,of_rationals,to_partial_fraction]) "^
264 " [REAL funterm, REAL zzz]); "^(*([2], Res), 4 / (z - 1 / 2) + -4 / (z - -1 / 4)*)
266 " (pbz_eq::bool) = Take (X'_z = pbz); "^(*([3], Frm), ?X' z = 4 / (z - 1 / 2) + -4 / (z - -1 / 4)*)
267 " pbz_eq = Rewrite ruleYZ False pbz_eq; "^(*([3], Res), ?X' z = 4 * (?z / (z - 1 / 2)) + -4 * (?z / (z - -1 / 4))*)
268 " pbz_eq = drop_questionmarks pbz_eq; "^(* 4 * (z / (z - 1 / 2)) + -4 * (z / (z - -1 / 4))*)
269 " (X_zeq::bool) = Take (X_z = rhs pbz_eq); "^(*([4], Frm), X_z = 4 * (z / (z - 1 / 2)) + -4 * (z / (z - -1 / 4))*)
270 " n_eq = (Rewrite_Set inverse_z False) X_zeq; "^(*([4], Res), X_z = 4 * (1 / 2) ^^^ ?n * ?u [?n] + -4 * (-1 / 4) ^^^ ?n * ?u [?n]*)
271 " n_eq = drop_questionmarks n_eq "^(* X_z = 4 * (1 / 2) ^^^ n * u [n] + -4 * (-1 / 4) ^^^ n * u [n]*)
272 "in n_eq)" (*([], Res), X_z = 4 * (1 / 2) ^^^ n * u [n] + -4 * (-1 / 4) ^^^ n * u [n]*)