funpack: release sequence-relation between method's itm list and partial_function's arg list
Note: this release is required by additional formal arguments,
which capture new variables on rhs of partial_function.
1 (* Title: Test_Z_Transform
3 (c) copyright due to lincense terms.
6 theory Inverse_Z_Transform imports PolyEq DiffApp Partial_Fractions begin
9 rule1: "1 = \<delta>[n]" and
10 rule2: "|| z || > 1 ==> z / (z - 1) = u [n]" and
11 rule3: "|| z || < 1 ==> z / (z - 1) = -u [-n - 1]" and
12 rule4: "c * (z / (z - \<alpha>)) = c * \<alpha>^^^n * u [n]" and
13 rule5: "|| z || < || \<alpha> || ==> z / (z - \<alpha>) = -(\<alpha>^^^n) * u [-n - 1]" and
14 rule6: "|| z || > 1 ==> z/(z - 1)^^^2 = n * u [n]" (*and
15 rule42: "(a * (z/(z-b)) + c * (z/(z-d))) = (a * b^^^n * u [n] + c * d^^^n * u [n])"*)
18 (*ruleZY: "(X z = a / b) = (d_d z X = a / (z * b))" ..looks better, but types are flawed*)
19 ruleZY: "(X z = a / b) = (X' z = a / (z * b))" and
20 ruleYZ: "a / (z - b) + c / (z - d) = a * (z / (z - b)) + c * (z / (z - d))" and
21 ruleYZa: "(a / b + c / d) = (a * (z / b) + c * (z / d))" \<comment> \<open>that is what students learn\<close>
23 subsection\<open>Define the Field Descriptions for the specification\<close>
25 filterExpression :: "bool => una"
26 stepResponse :: "bool => una"
29 val inverse_z = prep_rls'(
30 Rule.Rls {id = "inverse_z", preconds = [], rew_ord = ("dummy_ord",Rule.dummy_ord),
31 erls = Rule.Erls, srls = Rule.Erls, calc = [], errpatts = [],
34 Rule.Thm ("rule4", @{thm rule4})
36 scr = Rule.EmptyScr});
40 text \<open>store the rule set for math engine\<close>
42 setup \<open>KEStore_Elems.add_rlss [("inverse_z", (Context.theory_name @{theory}, inverse_z))]\<close>
44 subsection\<open>Define the Specification\<close>
48 setup \<open>KEStore_Elems.add_pbts
49 [(Specify.prep_pbt thy "pbl_SP" [] Celem.e_pblID (["SignalProcessing"], [], Rule.e_rls, NONE, [])),
50 (Specify.prep_pbt thy "pbl_SP_Ztrans" [] Celem.e_pblID
51 (["Z_Transform","SignalProcessing"], [], Rule.e_rls, NONE, [])),
52 (Specify.prep_pbt thy "pbl_SP_Ztrans_inv" [] Celem.e_pblID
53 (["Inverse", "Z_Transform", "SignalProcessing"],
54 [("#Given" ,["filterExpression X_eq"]),
55 ("#Find" ,["stepResponse n_eq"])],
56 Rule.append_rls "e_rls" Rule.e_rls [(*for preds in where_*)], NONE,
57 [["SignalProcessing","Z_Transform","Inverse"]])),
58 (Specify.prep_pbt thy "pbl_SP_Ztrans_inv_sub" [] Celem.e_pblID
59 (["Inverse_sub", "Z_Transform", "SignalProcessing"],
60 [("#Given" ,["filterExpression X_eq"]),
61 ("#Find" ,["stepResponse n_eq"])],
62 Rule.append_rls "e_rls" Rule.e_rls [(*for preds in where_*)], NONE,
63 [["SignalProcessing","Z_Transform","Inverse_sub"]]))]\<close>
65 subsection \<open>Define Name and Signature for the Method\<close>
67 InverseZTransform1 :: "[bool, bool] => bool"
68 ("((Script InverseZTransform1 (_ =))// (_))" 9)
69 InverseZTransform2 :: "[bool, real, bool] => bool"
70 ("((Script InverseZTransform2 (_ _ =))// (_))" 9)
72 subsection \<open>Setup Parent Nodes in Hierarchy of Method\<close>
73 ML \<open>val thy = @{theory}; (*latest version of thy required*)\<close>
74 setup \<open>KEStore_Elems.add_mets
75 [Specify.prep_met thy "met_SP" [] Celem.e_metID
76 (["SignalProcessing"], [],
77 {rew_ord'="tless_true", rls'= Rule.e_rls, calc = [], srls = Rule.e_rls, prls = Rule.e_rls, crls = Rule.e_rls,
78 errpats = [], nrls = Rule.e_rls}, "empty_script"),
79 Specify.prep_met thy "met_SP_Ztrans" [] Celem.e_metID
80 (["SignalProcessing", "Z_Transform"], [],
81 {rew_ord'="tless_true", rls'= Rule.e_rls, calc = [], srls = Rule.e_rls, prls = Rule.e_rls, crls = Rule.e_rls,
82 errpats = [], nrls = Rule.e_rls}, "empty_script")]
85 partial_function (tailrec) inverse_ztransform :: "bool \<Rightarrow> bool"
87 "inverse_ztransform X_eq = \<comment> \<open>(1/z) instead of z ^^^ -1\<close>
89 X' = Rewrite ''ruleZY'' False X; \<comment> \<open>z * denominator\<close>
90 X' = (Rewrite_Set ''norm_Rational'' False) X'; \<comment> \<open>simplify\<close>
91 funterm = Take (rhs X'); \<comment> \<open>drop X' z = for equation solving\<close>
92 denom = (Rewrite_Set ''partial_fraction'' False) funterm; \<comment> \<open>get_denominator\<close>
93 equ = (denom = (0::real));
94 fun_arg = Take (lhs X');
95 arg = (Rewrite_Set ''partial_fraction'' False) X'; \<comment> \<open>get_argument TODO\<close>
96 L_L = SubProblem (''Test'', [''LINEAR'',''univariate'',''equation'',''test''],
97 [''Test'',''solve_linear'']) [BOOL equ, REAL z]
100 setup \<open>KEStore_Elems.add_mets
101 [Specify.prep_met thy "met_SP_Ztrans_inv" [] Celem.e_metID
102 (["SignalProcessing", "Z_Transform", "Inverse"],
103 [("#Given" ,["filterExpression (X_eq::bool)"]),
104 ("#Find" ,["stepResponse (n_eq::bool)"])],
105 {rew_ord'="tless_true", rls'= Rule.e_rls, calc = [], srls = Rule.e_rls, prls = Rule.e_rls, crls = Rule.e_rls,
106 errpats = [], nrls = Rule.e_rls},
107 "Script InverseZTransform1 (X_eq::bool) =" ^ (*(1/z) instead of z ^^^ -1*)
108 " (let X = Take X_eq;" ^
109 " X' = Rewrite ''ruleZY'' False X;" ^ (*z * denominator*)
110 " X' = (Rewrite_Set ''norm_Rational'' False) X';" ^ (*simplify*)
111 " funterm = Take (rhs X');" ^ (*drop X' z = for equation solving*)
112 " denom = (Rewrite_Set ''partial_fraction'' False) funterm;" ^ (*get_denominator*)
113 " equ = (denom = (0::real));" ^
114 " fun_arg = Take (lhs X');" ^
115 " arg = (Rewrite_Set ''partial_fraction'' False) X';" ^ (*get_argument TODO*)
116 " (L_L::bool list) = " ^
117 " (SubProblem (''Test'', " ^
118 " [''LINEAR'',''univariate'',''equation'',''test'']," ^
119 " [''Test'',''solve_linear'']) " ^
120 " [BOOL equ, REAL z]) " ^
125 partial_function (tailrec) inverse_ztransform2 :: "bool \<Rightarrow> real \<Rightarrow> bool"
127 "inverse_ztransform2 X_eq X_z =
129 X' = Rewrite ''ruleZY'' False X;
131 zzz = argument_in X'_z;
133 pbz = SubProblem (''Isac'',
134 [''partial_fraction'',''rational'',''simplification''],
135 [''simplification'',''of_rationals'',''to_partial_fraction''])
136 [REAL funterm, REAL zzz];
137 pbz_eq = Take (X'_z = pbz);
138 pbz_eq = Rewrite ''ruleYZ'' False pbz_eq;
139 X_zeq = Take (X_z = rhs pbz_eq);
140 n_eq = (Rewrite_Set ''inverse_z'' False) X_zeq
143 setup \<open>KEStore_Elems.add_mets
144 [Specify.prep_met thy "met_SP_Ztrans_inv_sub" [] Celem.e_metID
145 (["SignalProcessing", "Z_Transform", "Inverse_sub"],
146 [("#Given" ,["filterExpression X_eq", "boundVariable X_z"]),
147 ("#Find" ,["stepResponse n_eq"])],
148 {rew_ord'="tless_true", rls'= Rule.e_rls, calc = [],
149 srls = Rule.Rls {id="srls_partial_fraction",
150 preconds = [], rew_ord = ("termlessI",termlessI),
151 erls = Rule.append_rls "erls_in_srls_partial_fraction" Rule.e_rls
152 [(*for asm in NTH_CONS ...*)
153 Rule.Calc ("Orderings.ord_class.less",eval_equ "#less_"),
154 (*2nd NTH_CONS pushes n+-1 into asms*)
155 Rule.Calc("Groups.plus_class.plus", eval_binop "#add_")],
156 srls = Rule.Erls, calc = [], errpatts = [],
157 rules = [Rule.Thm ("NTH_CONS", @{thm NTH_CONS}),
158 Rule.Calc ("Groups.plus_class.plus", eval_binop "#add_"),
159 Rule.Thm ("NTH_NIL", @{thm NTH_NIL}),
160 Rule.Calc ("Tools.lhs", Tools.eval_lhs "eval_lhs_"),
161 Rule.Calc ("Tools.rhs", Tools.eval_rhs"eval_rhs_"),
162 Rule.Calc ("Atools.argument'_in", eval_argument_in "Atools.argument'_in"),
163 Rule.Calc ("Rational.get_denominator", eval_get_denominator "#get_denominator"),
164 Rule.Calc ("Rational.get_numerator", eval_get_numerator "#get_numerator"),
165 Rule.Calc ("Partial_Fractions.factors_from_solution",
166 eval_factors_from_solution "#factors_from_solution")
167 ], scr = Rule.EmptyScr},
168 prls = Rule.e_rls, crls = Rule.e_rls, errpats = [], nrls = norm_Rational},
169 " Script InverseZTransform2 (X_eq::bool) (X_z::real) = "^ (*([], Frm), Problem (Isac, [Inverse, Z_Transform, SignalProcessing])*)
170 " (let X = Take X_eq; "^ (*([1], Frm), X z = 3 / (z - 1 / 4 + -1 / 8 * (1 / z))*)
171 " X' = Rewrite ''ruleZY'' False X; "^ (*([1], Res), ?X' z = 3 / (z * (z - 1 / 4 + -1 / 8 * (1 / z)))*)
172 " (X'_z::real) = lhs X'; "^ (* ?X' z*)
173 " (zzz::real) = argument_in X'_z; "^ (* z *)
174 " (funterm::real) = rhs X'; "^ (* 3 / (z * (z - 1 / 4 + -1 / 8 * (1 / z)))*)
175 " (pbz::real) = (SubProblem (''Isac'', "^ (*([2], Res), 4 / (z - 1 / 2) + -4 / (z - -1 / 4)*)
176 " [''partial_fraction'',''rational'',''simplification''], "^
177 " [''simplification'',''of_rationals'',''to_partial_fraction'']) "^
178 " [REAL funterm, REAL zzz]); "^
179 " (pbz_eq::bool) = Take (X'_z = pbz); "^ (*([3], Frm), ?X' z = 4 / (z - 1 / 2) + -4 / (z - -1 / 4)*)
180 " pbz_eq = Rewrite ''ruleYZ'' False pbz_eq; "^ (*([3], Res), ?X' z = 4 * (?z / (z - 1 / 2)) + -4 * (?z / (z - -1 / 4))*)
181 " (X_zeq::bool) = Take (X_z = rhs pbz_eq); "^ (*([4], Frm), X_z = 4 * (z / (z - 1 / 2)) + -4 * (z / (z - -1 / 4))*)
182 " 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]*)
183 " in n_eq) ")](* X_z = 4 * (1 / 2) ^^^ n * u [n] + -4 * (-1 / 4) ^^^ n * u [n]*)