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\<open>Define the Field Descriptions for the specification\<close>
25 filterExpression :: "bool => una"
26 stepResponse :: "bool => una"
30 val inverse_z = prep_rls'(
31 Rule.Rls {id = "inverse_z", preconds = [], rew_ord = ("dummy_ord",Rule.dummy_ord),
32 erls = Rule.Erls, srls = Rule.Erls, calc = [], errpatts = [],
35 Rule.Thm ("rule4", @{thm rule4})
37 scr = Rule.EmptyScr});
41 text \<open>store the rule set for math engine\<close>
43 setup \<open>KEStore_Elems.add_rlss [("inverse_z", (Context.theory_name @{theory}, inverse_z))]\<close>
45 subsection\<open>Define the Specification\<close>
49 setup \<open>KEStore_Elems.add_pbts
50 [(Specify.prep_pbt thy "pbl_SP" [] Celem.e_pblID (["SignalProcessing"], [], Rule.e_rls, NONE, [])),
51 (Specify.prep_pbt thy "pbl_SP_Ztrans" [] Celem.e_pblID
52 (["Z_Transform","SignalProcessing"], [], Rule.e_rls, NONE, [])),
53 (Specify.prep_pbt thy "pbl_SP_Ztrans_inv" [] Celem.e_pblID
54 (["Inverse", "Z_Transform", "SignalProcessing"],
55 (*^ capital letter breaks coding standard
56 because "inverse" = Const ("Rings.inverse_class.inverse", ..*)
57 [("#Given" ,["filterExpression (X_eq::bool)"]),
58 ("#Find" ,["stepResponse (n_eq::bool)"])],
59 Rule.append_rls "e_rls" Rule.e_rls [(*for preds in where_*)], NONE,
60 [["SignalProcessing","Z_Transform","Inverse"]])),
61 (Specify.prep_pbt thy "pbl_SP_Ztrans_inv" [] Celem.e_pblID
62 (["Inverse", "Z_Transform", "SignalProcessing"],
63 [("#Given" ,["filterExpression X_eq"]),
64 ("#Find" ,["stepResponse n_eq"])],
65 Rule.append_rls "e_rls" Rule.e_rls [(*for preds in where_*)], NONE,
66 [["SignalProcessing","Z_Transform","Inverse"]]))]\<close>
68 subsection \<open>Define Name and Signature for the Method\<close>
70 InverseZTransform :: "[bool, bool] => bool"
71 ("((Script InverseZTransform (_ =))// (_))" 9)
73 subsection \<open>Setup Parent Nodes in Hierarchy of Method\<close>
74 ML \<open>val thy = @{theory}; (*latest version of thy required*)\<close>
75 setup \<open>KEStore_Elems.add_mets
76 [Specify.prep_met thy "met_SP" [] Celem.e_metID
77 (["SignalProcessing"], [],
78 {rew_ord'="tless_true", rls'= Rule.e_rls, calc = [], srls = Rule.e_rls, prls = Rule.e_rls, crls = Rule.e_rls,
79 errpats = [], nrls = Rule.e_rls}, "empty_script"),
80 Specify.prep_met thy "met_SP_Ztrans" [] Celem.e_metID
81 (["SignalProcessing", "Z_Transform"], [],
82 {rew_ord'="tless_true", rls'= Rule.e_rls, calc = [], srls = Rule.e_rls, prls = Rule.e_rls, crls = Rule.e_rls,
83 errpats = [], nrls = Rule.e_rls}, "empty_script"),
84 Specify.prep_met thy "met_SP_Ztrans_inv" [] Celem.e_metID
85 (["SignalProcessing", "Z_Transform", "Inverse"],
86 [("#Given" ,["filterExpression (X_eq::bool)"]),
87 ("#Find" ,["stepResponse (n_eq::bool)"])],
88 {rew_ord'="tless_true", rls'= Rule.e_rls, calc = [], srls = Rule.e_rls, prls = Rule.e_rls, crls = Rule.e_rls,
89 errpats = [], nrls = Rule.e_rls},
90 "Script InverseZTransform (X_eq::bool) =" ^ (*(1/z) instead of z ^^^ -1*)
91 " (let X = Take X_eq;" ^
92 " X' = Rewrite ruleZY False X;" ^ (*z * denominator*)
93 " X' = (Rewrite_Set norm_Rational False) X';" ^ (*simplify*)
94 " funterm = Take (rhs X');" ^ (*drop X' z = for equation solving*)
95 " denom = (Rewrite_Set partial_fraction False) funterm;" ^ (*get_denominator*)
96 " equ = (denom = (0::real));" ^
97 " fun_arg = Take (lhs X');" ^
98 " arg = (Rewrite_Set partial_fraction False) X';" ^ (*get_argument TODO*)
99 " (L_L::bool list) = " ^
100 " (SubProblem (Test', " ^
101 " [LINEAR,univariate,equation,test]," ^
102 " [Test,solve_linear]) " ^
103 " [BOOL equ, REAL z]) " ^
105 Specify.prep_met thy "met_SP_Ztrans_inv" [] Celem.e_metID
106 (["SignalProcessing", "Z_Transform", "Inverse"],
107 [("#Given" ,["filterExpression X_eq"]),
108 ("#Find" ,["stepResponse n_eq"])],
109 {rew_ord'="tless_true", rls'= Rule.e_rls, calc = [], srls = srls_partial_fraction, prls = Rule.e_rls,
110 crls = Rule.e_rls, errpats = [], nrls = Rule.e_rls},
111 "Script InverseZTransform (X_eq::bool) = "^
112 (*(1/z) instead of z ^^^ -1*)
113 "(let X = Take X_eq; "^
114 " X' = Rewrite ruleZY False X; "^
116 " (num_orig::real) = get_numerator (rhs X'); "^
117 " X' = (Rewrite_Set norm_Rational False) X'; "^
119 " (X'_z::real) = lhs X'; "^
120 " (zzz::real) = argument_in X'_z; "^
121 " (funterm::real) = rhs X'; "^
122 (*drop X' z = for equation solving*)
123 " (denom::real) = get_denominator funterm; "^
125 " (num::real) = get_numerator funterm; "^
127 " (equ::bool) = (denom = (0::real)); "^
128 " (L_L::bool list) = (SubProblem (PolyEq', "^
129 " [abcFormula,degree_2,polynomial,univariate,equation], "^
131 " [BOOL equ, REAL zzz]); "^
132 " (facs::real) = factors_from_solution L_L; "^
133 " (eql::real) = Take (num_orig / facs); "^
135 " (eqr::real) = (Try (Rewrite_Set ansatz_rls False)) eql; "^
137 " (eq::bool) = Take (eql = eqr); "^
138 (*Maybe possible to use HOLogic.mk_eq ??*)
139 " eq = (Try (Rewrite_Set equival_trans False)) eq; "^
141 " eq = drop_questionmarks eq; "^
142 " (z1::real) = (rhs (NTH 1 L_L)); "^
144 * prepare equation for a - eq_a
145 * therefor substitute z with solution 1 - z1
147 " (z2::real) = (rhs (NTH 2 L_L)); "^
149 " (eq_a::bool) = Take eq; "^
150 " eq_a = (Substitute [zzz=z1]) eq; "^
151 " eq_a = (Rewrite_Set norm_Rational False) eq_a; "^
152 " (sol_a::bool list) = "^
153 " (SubProblem (Isac', "^
154 " [univariate,equation],[no_met]) "^
155 " [BOOL eq_a, REAL (A::real)]); "^
156 " (a::real) = (rhs(NTH 1 sol_a)); "^
158 " (eq_b::bool) = Take eq; "^
159 " eq_b = (Substitute [zzz=z2]) eq_b; "^
160 " eq_b = (Rewrite_Set norm_Rational False) eq_b; "^
161 " (sol_b::bool list) = "^
162 " (SubProblem (Isac', "^
163 " [univariate,equation],[no_met]) "^
164 " [BOOL eq_b, REAL (B::real)]); "^
165 " (b::real) = (rhs(NTH 1 sol_b)); "^
167 " eqr = drop_questionmarks eqr; "^
168 " (pbz::real) = Take eqr; "^
169 " pbz = ((Substitute [A=a, B=b]) pbz); "^
171 " pbz = Rewrite ruleYZ False pbz; "^
172 " pbz = drop_questionmarks pbz; "^
174 " (X_z::bool) = Take (X_z = pbz); "^
175 " (n_eq::bool) = (Rewrite_Set inverse_z False) X_z; "^
176 " n_eq = drop_questionmarks n_eq "^
178 Specify.prep_met thy "met_SP_Ztrans_inv_sub" [] Celem.e_metID
179 (["SignalProcessing", "Z_Transform", "Inverse_sub"],
180 [("#Given" ,["filterExpression X_eq"]),
181 ("#Find" ,["stepResponse n_eq"])],
182 {rew_ord'="tless_true", rls'= Rule.e_rls, calc = [],
183 srls = Rule.Rls {id="srls_partial_fraction",
184 preconds = [], rew_ord = ("termlessI",termlessI),
185 erls = Rule.append_rls "erls_in_srls_partial_fraction" Rule.e_rls
186 [(*for asm in NTH_CONS ...*)
187 Rule.Calc ("Orderings.ord_class.less",eval_equ "#less_"),
188 (*2nd NTH_CONS pushes n+-1 into asms*)
189 Rule.Calc("Groups.plus_class.plus", eval_binop "#add_")],
190 srls = Rule.Erls, calc = [], errpatts = [],
191 rules = [Rule.Thm ("NTH_CONS", @{thm NTH_CONS}),
192 Rule.Calc ("Groups.plus_class.plus", eval_binop "#add_"),
193 Rule.Thm ("NTH_NIL", @{thm NTH_NIL}),
194 Rule.Calc ("Tools.lhs", eval_lhs "eval_lhs_"),
195 Rule.Calc ("Tools.rhs", eval_rhs"eval_rhs_"),
196 Rule.Calc ("Atools.argument'_in", eval_argument_in "Atools.argument'_in"),
197 Rule.Calc ("Rational.get_denominator", eval_get_denominator "#get_denominator"),
198 Rule.Calc ("Rational.get_numerator", eval_get_numerator "#get_numerator"),
199 Rule.Calc ("Partial_Fractions.factors_from_solution",
200 eval_factors_from_solution "#factors_from_solution"),
201 Rule.Calc("Partial_Fractions.drop_questionmarks", eval_drop_questionmarks "#drop_?")],
202 scr = Rule.EmptyScr},
203 prls = Rule.e_rls, crls = Rule.e_rls, errpats = [], nrls = norm_Rational},
204 (*([], Frm), Problem (Isac, [Inverse, Z_Transform, SignalProcessing])*)
205 "Script InverseZTransform (X_eq::bool) = "^
206 (*([1], Frm), X z = 3 / (z - 1 / 4 + -1 / 8 * (1 / z))*)
207 "(let X = Take X_eq; "^
208 (*([1], Res), ?X' z = 3 / (z * (z - 1 / 4 + -1 / 8 * (1 / z)))*)
209 " X' = Rewrite ruleZY False X; "^
211 " (X'_z::real) = lhs X'; "^
213 " (zzz::real) = argument_in X'_z; "^
214 (* 3 / (z * (z - 1 / 4 + -1 / 8 * (1 / z)))*)
215 " (funterm::real) = rhs X'; "^
217 " (pbz::real) = (SubProblem (Isac', "^
218 " [partial_fraction,rational,simplification], "^
219 " [simplification,of_rationals,to_partial_fraction]) "^
220 (*([2], Res), 4 / (z - 1 / 2) + -4 / (z - -1 / 4)*)
221 " [REAL funterm, REAL zzz]); "^
223 (*([3], Frm), ?X' z = 4 / (z - 1 / 2) + -4 / (z - -1 / 4)*)
224 " (pbz_eq::bool) = Take (X'_z = pbz); "^
225 (*([3], Res), ?X' z = 4 * (?z / (z - 1 / 2)) + -4 * (?z / (z - -1 / 4))*)
226 " pbz_eq = Rewrite ruleYZ False pbz_eq; "^
227 (* 4 * (z / (z - 1 / 2)) + -4 * (z / (z - -1 / 4))*)
228 " pbz_eq = drop_questionmarks pbz_eq; "^
229 (*([4], Frm), X_z = 4 * (z / (z - 1 / 2)) + -4 * (z / (z - -1 / 4))*)
230 " (X_zeq::bool) = Take (X_z = rhs pbz_eq); "^
231 (*([4], Res), X_z = 4 * (1 / 2) ^^^ ?n * ?u [?n] + -4 * (-1 / 4) ^^^ ?n * ?u [?n]*)
232 " n_eq = (Rewrite_Set inverse_z False) X_zeq; "^
233 (* X_z = 4 * (1 / 2) ^^^ n * u [n] + -4 * (-1 / 4) ^^^ n * u [n]*)
234 " n_eq = drop_questionmarks n_eq "^
235 (*([], Res), X_z = 4 * (1 / 2) ^^^ n * u [n] + -4 * (-1 / 4) ^^^ n * u [n]*)