ad 967c8a1eb6b1 (7): removed all code concerned with 'ptyps = Unsynchronized.ref'
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*}
49 setup {* KEStore_Elems.add_pbts
50 [(prep_pbt thy "pbl_SP" [] e_pblID (["SignalProcessing"], [], e_rls, NONE, [])),
51 (prep_pbt thy "pbl_SP_Ztrans" [] e_pblID
52 (["Z_Transform","SignalProcessing"], [], e_rls, NONE, [])),
53 (prep_pbt thy "pbl_SP_Ztrans_inv" [] 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 append_rls "e_rls" e_rls [(*for preds in where_*)], NONE,
60 [["SignalProcessing","Z_Transform","Inverse"]])),
61 (prep_pbt thy "pbl_SP_Ztrans_inv" [] e_pblID
62 (["Inverse", "Z_Transform", "SignalProcessing"],
63 [("#Given" ,["filterExpression X_eq"]),
64 ("#Find" ,["stepResponse n_eq"])],
65 append_rls "e_rls" e_rls [(*for preds in where_*)], NONE,
66 [["SignalProcessing","Z_Transform","Inverse"]]))] *}
68 subsection {*Define Name and Signature for the Method*}
70 InverseZTransform :: "[bool, bool] => bool"
71 ("((Script InverseZTransform (_ =))// (_))" 9)
73 subsection {*Setup Parent Nodes in Hierarchy of Method*}
76 (prep_met thy "met_SP" [] e_metID
77 (["SignalProcessing"], [],
78 {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls,
79 crls = e_rls, errpats = [], nrls = e_rls}, "empty_script"));
81 (prep_met thy "met_SP_Ztrans" [] e_metID
82 (["SignalProcessing", "Z_Transform"], [],
83 {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls,
84 crls = e_rls, errpats = [], nrls = e_rls}, "empty_script"));
85 val thy = @{theory}; (*latest version of thy required*)
87 (prep_met thy "met_SP_Ztrans_inv" [] e_metID
88 (["SignalProcessing", "Z_Transform", "Inverse"],
89 [("#Given" ,["filterExpression (X_eq::bool)"]),
90 ("#Find" ,["stepResponse (n_eq::bool)"])
92 {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls,
93 crls = e_rls, errpats = [], nrls = e_rls},
94 "Script InverseZTransform (X_eq::bool) =" ^ (*(1/z) instead of z ^^^ -1*)
95 " (let X = Take X_eq;" ^
96 " X' = Rewrite ruleZY False X;" ^ (*z * denominator*)
97 " X' = (Rewrite_Set norm_Rational False) X';" ^ (*simplify*)
98 " funterm = Take (rhs X');" ^ (*drop X' z = for equation solving*)
99 " denom = (Rewrite_Set partial_fraction False) funterm;" ^ (*get_denominator*)
100 " equ = (denom = (0::real));" ^
101 " fun_arg = Take (lhs X');" ^
102 " arg = (Rewrite_Set partial_fraction False) X';" ^ (*get_argument TODO*)
103 " (L_L::bool list) = " ^
104 " (SubProblem (Test', " ^
105 " [LINEAR,univariate,equation,test]," ^
106 " [Test,solve_linear]) " ^
107 " [BOOL equ, REAL z]) " ^
113 prep_met thy "met_SP_Ztrans_inv" [] e_metID
114 (["SignalProcessing",
118 ("#Given" ,["filterExpression X_eq"]),
119 ("#Find" ,["stepResponse n_eq"])
122 rew_ord'="tless_true",
123 rls'= e_rls, calc = [],
124 srls = srls_partial_fraction,
126 crls = e_rls, errpats = [], nrls = e_rls
128 "Script InverseZTransform (X_eq::bool) = "^
129 (*(1/z) instead of z ^^^ -1*)
130 "(let X = Take X_eq; "^
131 " X' = Rewrite ruleZY False X; "^
133 " (num_orig::real) = get_numerator (rhs X'); "^
134 " X' = (Rewrite_Set norm_Rational False) X'; "^
136 " (X'_z::real) = lhs X'; "^
137 " (zzz::real) = argument_in X'_z; "^
138 " (funterm::real) = rhs X'; "^
139 (*drop X' z = for equation solving*)
140 " (denom::real) = get_denominator funterm; "^
142 " (num::real) = get_numerator funterm; "^
144 " (equ::bool) = (denom = (0::real)); "^
145 " (L_L::bool list) = (SubProblem (PolyEq', "^
146 " [abcFormula,degree_2,polynomial,univariate,equation], "^
148 " [BOOL equ, REAL zzz]); "^
149 " (facs::real) = factors_from_solution L_L; "^
150 " (eql::real) = Take (num_orig / facs); "^
152 " (eqr::real) = (Try (Rewrite_Set ansatz_rls False)) eql; "^
154 " (eq::bool) = Take (eql = eqr); "^
155 (*Maybe possible to use HOLogic.mk_eq ??*)
156 " eq = (Try (Rewrite_Set equival_trans False)) eq; "^
158 " eq = drop_questionmarks eq; "^
159 " (z1::real) = (rhs (NTH 1 L_L)); "^
161 * prepare equation for a - eq_a
162 * therefor substitute z with solution 1 - z1
164 " (z2::real) = (rhs (NTH 2 L_L)); "^
166 " (eq_a::bool) = Take eq; "^
167 " eq_a = (Substitute [zzz=z1]) eq; "^
168 " eq_a = (Rewrite_Set norm_Rational False) eq_a; "^
169 " (sol_a::bool list) = "^
170 " (SubProblem (Isac', "^
171 " [univariate,equation],[no_met]) "^
172 " [BOOL eq_a, REAL (A::real)]); "^
173 " (a::real) = (rhs(NTH 1 sol_a)); "^
175 " (eq_b::bool) = Take eq; "^
176 " eq_b = (Substitute [zzz=z2]) eq_b; "^
177 " eq_b = (Rewrite_Set norm_Rational False) eq_b; "^
178 " (sol_b::bool list) = "^
179 " (SubProblem (Isac', "^
180 " [univariate,equation],[no_met]) "^
181 " [BOOL eq_b, REAL (B::real)]); "^
182 " (b::real) = (rhs(NTH 1 sol_b)); "^
184 " eqr = drop_questionmarks eqr; "^
185 " (pbz::real) = Take eqr; "^
186 " pbz = ((Substitute [A=a, B=b]) pbz); "^
188 " pbz = Rewrite ruleYZ False pbz; "^
189 " pbz = drop_questionmarks pbz; "^
191 " (X_z::bool) = Take (X_z = pbz); "^
192 " (n_eq::bool) = (Rewrite_Set inverse_z False) X_z; "^
193 " n_eq = drop_questionmarks n_eq "^
198 store_met (prep_met thy "met_SP_Ztrans_inv_sub" [] e_metID
199 (["SignalProcessing", "Z_Transform", "Inverse_sub"],
200 [("#Given" ,["filterExpression X_eq"]),
201 ("#Find" ,["stepResponse n_eq"])],
202 {rew_ord'="tless_true",
203 rls'= e_rls, calc = [],
204 srls = Rls {id="srls_partial_fraction",
206 rew_ord = ("termlessI",termlessI),
207 erls = append_rls "erls_in_srls_partial_fraction" e_rls
208 [(*for asm in NTH_CONS ...*)
209 Calc ("Orderings.ord_class.less",eval_equ "#less_"),
210 (*2nd NTH_CONS pushes n+-1 into asms*)
211 Calc("Groups.plus_class.plus", eval_binop "#add_")],
212 srls = Erls, calc = [], errpatts = [],
214 Thm ("NTH_CONS",num_str @{thm NTH_CONS}),
215 Calc("Groups.plus_class.plus", eval_binop "#add_"),
216 Thm ("NTH_NIL",num_str @{thm NTH_NIL}),
217 Calc("Tools.lhs", eval_lhs "eval_lhs_"),
218 Calc("Tools.rhs", eval_rhs"eval_rhs_"),
219 Calc("Atools.argument'_in", eval_argument_in "Atools.argument'_in"),
220 Calc("Rational.get_denominator", eval_get_denominator "#get_denominator"),
221 Calc("Rational.get_numerator", eval_get_numerator "#get_numerator"),
222 Calc("Partial_Fractions.factors_from_solution",
223 eval_factors_from_solution "#factors_from_solution"),
224 Calc("Partial_Fractions.drop_questionmarks", eval_drop_questionmarks "#drop_?")],
226 prls = e_rls, crls = e_rls, errpats = [], nrls = norm_Rational},
227 "Script InverseZTransform (X_eq::bool) = "^(*([], Frm), Problem (Isac, [Inverse, Z_Transform, SignalProcessing])*)
228 "(let X = Take X_eq; "^(*([1], Frm), X z = 3 / (z - 1 / 4 + -1 / 8 * (1 / z))*)
229 " X' = Rewrite ruleZY False X; "^(*([1], Res), ?X' z = 3 / (z * (z - 1 / 4 + -1 / 8 * (1 / z)))*)
230 " (X'_z::real) = lhs X'; "^(* ?X' z*)
231 " (zzz::real) = argument_in X'_z; "^(* z *)
232 " (funterm::real) = rhs X'; "^(* 3 / (z * (z - 1 / 4 + -1 / 8 * (1 / z)))*)
234 " (pbz::real) = (SubProblem (Isac', "^(**)
235 " [partial_fraction,rational,simplification], "^
236 " [simplification,of_rationals,to_partial_fraction]) "^
237 " [REAL funterm, REAL zzz]); "^(*([2], Res), 4 / (z - 1 / 2) + -4 / (z - -1 / 4)*)
239 " (pbz_eq::bool) = Take (X'_z = pbz); "^(*([3], Frm), ?X' z = 4 / (z - 1 / 2) + -4 / (z - -1 / 4)*)
240 " pbz_eq = Rewrite ruleYZ False pbz_eq; "^(*([3], Res), ?X' z = 4 * (?z / (z - 1 / 2)) + -4 * (?z / (z - -1 / 4))*)
241 " pbz_eq = drop_questionmarks pbz_eq; "^(* 4 * (z / (z - 1 / 2)) + -4 * (z / (z - -1 / 4))*)
242 " (X_zeq::bool) = Take (X_z = rhs pbz_eq); "^(*([4], Frm), X_z = 4 * (z / (z - 1 / 2)) + -4 * (z / (z - -1 / 4))*)
243 " 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]*)
244 " n_eq = drop_questionmarks n_eq "^(* X_z = 4 * (1 / 2) ^^^ n * u [n] + -4 * (-1 / 4) ^^^ n * u [n]*)
245 "in n_eq)" (*([], Res), X_z = 4 * (1 / 2) ^^^ n * u [n] + -4 * (-1 / 4) ^^^ n * u [n]*)