test/Tools/isac/ADDTESTS/course/SignalProcess/Build_Inverse_Z_Transform.thy
changeset 59472 3e904f8ec16c
parent 59465 b33dc41f4350
child 59476 863c3629ad24
equal deleted inserted replaced
59471:f2b3681fafb9 59472:3e904f8ec16c
     5 
     5 
     6 theory Build_Inverse_Z_Transform imports Isac.Inverse_Z_Transform
     6 theory Build_Inverse_Z_Transform imports Isac.Inverse_Z_Transform
     7   
     7   
     8 begin
     8 begin
     9 
     9 
    10 text{* We stepwise build \ttfamily Inverse\_Z\_Transform.thy \normalfont as an 
    10 text\<open>We stepwise build \ttfamily Inverse\_Z\_Transform.thy \normalfont as an 
    11   exercise. Because Subsection~\ref{sec:stepcheck} requires 
    11   exercise. Because Subsection~\ref{sec:stepcheck} requires 
    12   \ttfamily Inverse\_Z\_Transform.thy \normalfont as a subtheory of \ttfamily 
    12   \ttfamily Inverse\_Z\_Transform.thy \normalfont as a subtheory of \ttfamily 
    13   Isac.thy\normalfont, the setup has been changed from \ttfamily theory 
    13   Isac.thy\normalfont, the setup has been changed from \ttfamily theory 
    14   Inverse\_Z\_Transform imports Isac \normalfont to the above one.
    14   Inverse\_Z\_Transform imports Isac \normalfont to the above one.
    15   \par \noindent
    15   \par \noindent
    18   \end{center}
    18   \end{center}
    19   Here in this theory there are the internal names twice, for instance we have
    19   Here in this theory there are the internal names twice, for instance we have
    20   \ttfamily (Thm.derivation\_name @{thm rule1} = 
    20   \ttfamily (Thm.derivation\_name @{thm rule1} = 
    21   "Build\_Inverse\_Z\_Transform.rule1") = true; \normalfont
    21   "Build\_Inverse\_Z\_Transform.rule1") = true; \normalfont
    22   but actually in us will be \ttfamily Inverse\_Z\_Transform.rule1 \normalfont
    22   but actually in us will be \ttfamily Inverse\_Z\_Transform.rule1 \normalfont
    23 *}
    23 \<close>
    24 
    24 
    25 section {*Trials towards the Z-Transform\label{sec:trials}*}
    25 section \<open>Trials towards the Z-Transform\label{sec:trials}\<close>
    26 
    26 
    27 ML {*val thy = @{theory};*}
    27 ML \<open>val thy = @{theory};\<close>
    28 
    28 
    29 subsection {*Notations and Terms*}
    29 subsection \<open>Notations and Terms\<close>
    30 text{*\noindent Try which notations we are able to use.*}
    30 text\<open>\noindent Try which notations we are able to use.\<close>
    31 ML {*
    31 ML \<open>
    32   @{term "1 < || z ||"};
    32   @{term "1 < || z ||"};
    33   @{term "z / (z - 1)"};
    33   @{term "z / (z - 1)"};
    34   @{term "-u -n - 1"};
    34   @{term "-u -n - 1"};
    35   @{term "-u [-n - 1]"}; (*[ ] denotes lists !!!*)
    35   @{term "-u [-n - 1]"}; (*[ ] denotes lists !!!*)
    36   @{term "z /(z - 1) = -u [-n - 1]"};
    36   @{term "z /(z - 1) = -u [-n - 1]"};
    37   @{term "1 < || z || ==> z / (z - 1) = -u [-n - 1]"};
    37   @{term "1 < || z || ==> z / (z - 1) = -u [-n - 1]"};
    38   term2str @{term "1 < || z || ==> z / (z - 1) = -u [-n - 1]"};
    38   term2str @{term "1 < || z || ==> z / (z - 1) = -u [-n - 1]"};
    39 *}
    39 \<close>
    40 text{*\noindent Try which symbols we are able to use and how we generate them.*}
    40 text\<open>\noindent Try which symbols we are able to use and how we generate them.\<close>
    41 ML {*
    41 ML \<open>
    42   (*alpha -->  "</alpha>" *)
    42   (*alpha -->  "</alpha>" *)
    43   @{term "\<alpha> "};
    43   @{term "\<alpha> "};
    44   @{term "\<delta> "};
    44   @{term "\<delta> "};
    45   @{term "\<phi> "};
    45   @{term "\<phi> "};
    46   @{term "\<rho> "};
    46   @{term "\<rho> "};
    47   term2str @{term "\<rho> "};
    47   term2str @{term "\<rho> "};
    48 *}
    48 \<close>
    49 
    49 
    50 subsection {*Rules*}
    50 subsection \<open>Rules\<close>
    51 (*axiomatization "z / (z - 1) = -u [-n - 1]"
    51 (*axiomatization "z / (z - 1) = -u [-n - 1]"
    52   Illegal variable name: "z / (z - 1) = -u [-n - 1]" *)
    52   Illegal variable name: "z / (z - 1) = -u [-n - 1]" *)
    53 (*definition     "z / (z - 1) = -u [-n - 1]"
    53 (*definition     "z / (z - 1) = -u [-n - 1]"
    54   Bad head of lhs: existing constant "op /"*)
    54   Bad head of lhs: existing constant "op /"*)
    55 axiomatization where 
    55 axiomatization where 
    58   rule3: "|| z || < 1 ==> z / (z - 1) = -u [-n - 1]" and 
    58   rule3: "|| z || < 1 ==> z / (z - 1) = -u [-n - 1]" and 
    59   rule4: "|| z || > || \<alpha> || ==> z / (z - \<alpha>) = \<alpha>^^^n * u [n]" and
    59   rule4: "|| z || > || \<alpha> || ==> z / (z - \<alpha>) = \<alpha>^^^n * u [n]" and
    60   rule5: "|| z || < || \<alpha> || ==> z / (z - \<alpha>) = -(\<alpha>^^^n) * u [-n - 1]" and
    60   rule5: "|| z || < || \<alpha> || ==> z / (z - \<alpha>) = -(\<alpha>^^^n) * u [-n - 1]" and
    61   rule6: "|| z || > 1 ==> z/(z - 1)^^^2 = n * u [n]"
    61   rule6: "|| z || > 1 ==> z/(z - 1)^^^2 = n * u [n]"
    62 
    62 
    63 text{*\noindent Check the rules for their correct notation. 
    63 text\<open>\noindent Check the rules for their correct notation. 
    64       (See the machine output.)*}
    64       (See the machine output.)\<close>
    65 ML {*
    65 ML \<open>
    66   @{thm rule1};
    66   @{thm rule1};
    67   @{thm rule2};
    67   @{thm rule2};
    68   @{thm rule3};
    68   @{thm rule3};
    69   @{thm rule4};
    69   @{thm rule4};
    70 *}
    70 \<close>
    71 
    71 
    72 subsection {*Apply Rules*}
    72 subsection \<open>Apply Rules\<close>
    73 text{*\noindent We try to apply the rules to a given expression.*}
    73 text\<open>\noindent We try to apply the rules to a given expression.\<close>
    74 
    74 
    75 ML {*
    75 ML \<open>
    76   val inverse_Z = append_rls "inverse_Z" e_rls
    76   val inverse_Z = append_rls "inverse_Z" e_rls
    77     [ Thm  ("rule3",TermC.num_str @{thm rule3}),
    77     [ Thm  ("rule3",TermC.num_str @{thm rule3}),
    78       Thm  ("rule4",TermC.num_str @{thm rule4}),
    78       Thm  ("rule4",TermC.num_str @{thm rule4}),
    79       Thm  ("rule1",TermC.num_str @{thm rule1})   
    79       Thm  ("rule1",TermC.num_str @{thm rule1})   
    80     ];
    80     ];
    84   term2str t' = "z / (z - ?\<delta> [?n]) + z / (z - \<alpha>) + ?\<delta> [?n]";
    84   term2str t' = "z / (z - ?\<delta> [?n]) + z / (z - \<alpha>) + ?\<delta> [?n]";
    85   (*
    85   (*
    86    * Attention rule1 is applied before the expression is 
    86    * Attention rule1 is applied before the expression is 
    87    * checked for rule4 which would be correct!!!
    87    * checked for rule4 which would be correct!!!
    88    *)
    88    *)
    89 *}
    89 \<close>
    90 
    90 
    91 ML {* val (thy, ro, er) = (@{theory}, tless_true, eval_rls); *}
    91 ML \<open>val (thy, ro, er) = (@{theory}, tless_true, eval_rls);\<close>
    92 ML {*
    92 ML \<open>
    93   val SOME (t, asm1) = 
    93   val SOME (t, asm1) = 
    94     Rewrite.rewrite_ thy ro er true (TermC.num_str @{thm rule3}) t;
    94     Rewrite.rewrite_ thy ro er true (TermC.num_str @{thm rule3}) t;
    95   term2str t = "- ?u [- ?n - 1] + z / (z - \<alpha>) + 1";
    95   term2str t = "- ?u [- ?n - 1] + z / (z - \<alpha>) + 1";
    96   (*- real *)
    96   (*- real *)
    97   term2str t;
    97   term2str t;
   105   val SOME (t, asm3) = 
   105   val SOME (t, asm3) = 
   106     Rewrite.rewrite_ thy ro er true (TermC.num_str @{thm rule1}) t;
   106     Rewrite.rewrite_ thy ro er true (TermC.num_str @{thm rule1}) t;
   107   term2str t = "- ?u [- ?n - 1] + \<alpha> ^^^ ?n * ?u [?n] + ?\<delta> [?n]";
   107   term2str t = "- ?u [- ?n - 1] + \<alpha> ^^^ ?n * ?u [?n] + ?\<delta> [?n]";
   108   (*- real *)
   108   (*- real *)
   109   term2str t;
   109   term2str t;
   110 *}
   110 \<close>
   111 ML {* terms2str (asm1 @ asm2 @ asm3); *}
   111 ML \<open>terms2str (asm1 @ asm2 @ asm3);\<close>
   112 
   112 
   113 section{*Prepare Steps for TP-based programming Language\label{sec:prepstep}*}
   113 section\<open>Prepare Steps for TP-based programming Language\label{sec:prepstep}\<close>
   114 text{*
   114 text\<open>
   115       \par \noindent The following sections are challenging with the CTP-based 
   115       \par \noindent The following sections are challenging with the CTP-based 
   116       possibilities of building the program. The goal is realized in 
   116       possibilities of building the program. The goal is realized in 
   117       Section~\ref{spec-meth} and Section~\ref{prog-steps}.
   117       Section~\ref{spec-meth} and Section~\ref{prog-steps}.
   118       \par The reader is advised to jump between the subsequent subsections and 
   118       \par The reader is advised to jump between the subsequent subsections and 
   119       the respective steps in Section~\ref{prog-steps}. By comparing 
   119       the respective steps in Section~\ref{prog-steps}. By comparing 
   120       Section~\ref{sec:calc:ztrans} the calculation can be comprehended step 
   120       Section~\ref{sec:calc:ztrans} the calculation can be comprehended step 
   121       by step.
   121       by step.
   122 *}
   122 \<close>
   123 
   123 
   124 subsection {*Prepare Expression\label{prep-expr}*}
   124 subsection \<open>Prepare Expression\label{prep-expr}\<close>
   125 text{*\noindent We try two different notations and check which of them 
   125 text\<open>\noindent We try two different notations and check which of them 
   126        Isabelle can handle best.*}
   126        Isabelle can handle best.\<close>
   127 ML {*
   127 ML \<open>
   128   val ctxt = Proof_Context.init_global @{theory};
   128   val ctxt = Proof_Context.init_global @{theory};
   129   val ctxt = Stool.declare_constraints' [@{term "z::real"}] ctxt;
   129   val ctxt = Stool.declare_constraints' [@{term "z::real"}] ctxt;
   130 
   130 
   131   val SOME fun1 = 
   131   val SOME fun1 = 
   132     TermC.parseNEW ctxt "X z = 3 / (z - 1/4 + -1/8 * z ^^^ -1)"; term2str fun1;
   132     TermC.parseNEW ctxt "X z = 3 / (z - 1/4 + -1/8 * z ^^^ -1)"; term2str fun1;
   133   val SOME fun1' = 
   133   val SOME fun1' = 
   134     TermC.parseNEW ctxt "X z = 3 / (z - 1/4 + -1/8 * (1/z))"; term2str fun1';
   134     TermC.parseNEW ctxt "X z = 3 / (z - 1/4 + -1/8 * (1/z))"; term2str fun1';
   135 *}
   135 \<close>
   136 
   136 
   137 subsubsection {*Prepare Numerator and Denominator*}
   137 subsubsection \<open>Prepare Numerator and Denominator\<close>
   138 text{*\noindent The partial fraction decomposition is only possible if we
   138 text\<open>\noindent The partial fraction decomposition is only possible if we
   139        get the bound variable out of the numerator. Therefor we divide
   139        get the bound variable out of the numerator. Therefor we divide
   140        the expression by $z$. Follow up the Calculation at 
   140        the expression by $z$. Follow up the Calculation at 
   141        Section~\ref{sec:calc:ztrans} line number 02.*}
   141        Section~\ref{sec:calc:ztrans} line number 02.\<close>
   142 
   142 
   143 axiomatization where
   143 axiomatization where
   144   ruleZY: "(X z = a / b) = (X' z = a / (z * b))"
   144   ruleZY: "(X z = a / b) = (X' z = a / (z * b))"
   145 
   145 
   146 ML {*
   146 ML \<open>
   147   val (thy, ro, er) = (@{theory}, tless_true, eval_rls);
   147   val (thy, ro, er) = (@{theory}, tless_true, eval_rls);
   148   val SOME (fun2, asm1) = 
   148   val SOME (fun2, asm1) = 
   149     Rewrite.rewrite_ thy ro er true  @{thm ruleZY} fun1; term2str fun2;
   149     Rewrite.rewrite_ thy ro er true  @{thm ruleZY} fun1; term2str fun2;
   150   val SOME (fun2', asm1) = 
   150   val SOME (fun2', asm1) = 
   151     Rewrite.rewrite_ thy ro er true  @{thm ruleZY} fun1'; term2str fun2';
   151     Rewrite.rewrite_ thy ro er true  @{thm ruleZY} fun1'; term2str fun2';
   161     Rewrite.rewrite_set_ @{theory} false norm_Rational fun2';
   161     Rewrite.rewrite_set_ @{theory} false norm_Rational fun2';
   162   term2str fun3';
   162   term2str fun3';
   163   (*
   163   (*
   164    * OK - workaround!
   164    * OK - workaround!
   165    *)
   165    *)
   166 *}
   166 \<close>
   167 
   167 
   168 subsubsection {*Get the Argument of the Expression X'*}
   168 subsubsection \<open>Get the Argument of the Expression X'\<close>
   169 text{*\noindent We use \texttt{grep} for finding possibilities how we can
   169 text\<open>\noindent We use \texttt{grep} for finding possibilities how we can
   170        extract the bound variable in the expression. \ttfamily Atools.thy, 
   170        extract the bound variable in the expression. \ttfamily Atools.thy, 
   171        Tools.thy \normalfont contain general utilities: \ttfamily 
   171        Tools.thy \normalfont contain general utilities: \ttfamily 
   172        eval\_argument\_in, eval\_rhs, eval\_lhs,\ldots \normalfont
   172        eval\_argument\_in, eval\_rhs, eval\_lhs,\ldots \normalfont
   173        \ttfamily grep -r "fun eva\_" * \normalfont shows all functions 
   173        \ttfamily grep -r "fun eva\_" * \normalfont shows all functions 
   174        witch can be used in a script. Lookup this files how to build 
   174        witch can be used in a script. Lookup this files how to build 
   175        and handle such functions.
   175        and handle such functions.
   176        \par The next section shows how to introduce such a function.
   176        \par The next section shows how to introduce such a function.
   177 *}
   177 \<close>
   178 
   178 
   179 subsubsection{*Decompose the Given Term Into lhs and rhs*}
   179 subsubsection\<open>Decompose the Given Term Into lhs and rhs\<close>
   180 ML {*
   180 ML \<open>
   181   val (_, expr) = HOLogic.dest_eq fun3'; term2str expr;
   181   val (_, expr) = HOLogic.dest_eq fun3'; term2str expr;
   182   val (_, denom) = 
   182   val (_, denom) = 
   183     HOLogic.dest_bin "Rings.divide_class.divide" (type_of expr) expr;
   183     HOLogic.dest_bin "Rings.divide_class.divide" (type_of expr) expr;
   184   term2str denom = "-1 + -2 * z + 8 * z ^^^ 2";
   184   term2str denom = "-1 + -2 * z + 8 * z ^^^ 2";
   185 *}
   185 \<close>
   186 
   186 
   187 text{*\noindent We have rhs\footnote{Note: lhs means \em Left Hand Side
   187 text\<open>\noindent We have rhs\footnote{Note: lhs means \em Left Hand Side
   188       \normalfont and rhs means \em Right Hand Side \normalfont and indicates
   188       \normalfont and rhs means \em Right Hand Side \normalfont and indicates
   189       the left or the right part of an equation.} in the Script language, but
   189       the left or the right part of an equation.} in the Script language, but
   190       we need a function which gets the denominator of a fraction.*}
   190       we need a function which gets the denominator of a fraction.\<close>
   191 
   191 
   192 subsubsection{*Get the Denominator and Numerator out of a Fraction*}
   192 subsubsection\<open>Get the Denominator and Numerator out of a Fraction\<close>
   193 text{*\noindent The self written functions in e.g. \texttt{get\_denominator}
   193 text\<open>\noindent The self written functions in e.g. \texttt{get\_denominator}
   194        should become a constant for the Isabelle parser:*}
   194        should become a constant for the Isabelle parser:\<close>
   195 
   195 
   196 consts
   196 consts
   197   get_denominator :: "real => real"
   197   get_denominator :: "real => real"
   198   get_numerator :: "real => real"
   198   get_numerator :: "real => real"
   199 
   199 
   200 text {*\noindent With the above definition we run into problems when we parse
   200 text \<open>\noindent With the above definition we run into problems when we parse
   201         the Script \texttt{InverseZTransform}. This leads to \em ambiguous
   201         the Script \texttt{InverseZTransform}. This leads to \em ambiguous
   202         parse trees. \normalfont We avoid this by moving the definition
   202         parse trees. \normalfont We avoid this by moving the definition
   203         to \ttfamily Rational.thy \normalfont and re-building {\sisac}.
   203         to \ttfamily Rational.thy \normalfont and re-building {\sisac}.
   204         \par \noindent ATTENTION: From now on \ttfamily 
   204         \par \noindent ATTENTION: From now on \ttfamily 
   205         Build\_Inverse\_Z\_Transform \normalfont mimics a build from scratch;
   205         Build\_Inverse\_Z\_Transform \normalfont mimics a build from scratch;
   206         it only works due to re-building {\sisac} several times (indicated 
   206         it only works due to re-building {\sisac} several times (indicated 
   207         explicitly).
   207         explicitly).
   208 *}
   208 \<close>
   209 
   209 
   210 ML {*
   210 ML \<open>
   211 (*
   211 (*
   212  *("get_denominator",
   212  *("get_denominator",
   213  *  ("Rational.get_denominator", eval_get_denominator ""))
   213  *  ("Rational.get_denominator", eval_get_denominator ""))
   214  *)
   214  *)
   215 fun eval_get_denominator (thmid:string) _ 
   215 fun eval_get_denominator (thmid:string) _ 
   217               (Const ("Rings.divide_class.divide", _) $num 
   217               (Const ("Rings.divide_class.divide", _) $num 
   218                 $denom)) thy = 
   218                 $denom)) thy = 
   219         SOME (TermC.mk_thmid thmid (term_to_string''' thy denom) "", 
   219         SOME (TermC.mk_thmid thmid (term_to_string''' thy denom) "", 
   220 	        HOLogic.Trueprop $ (TermC.mk_equality (t, denom)))
   220 	        HOLogic.Trueprop $ (TermC.mk_equality (t, denom)))
   221   | eval_get_denominator _ _ _ _ = NONE; 
   221   | eval_get_denominator _ _ _ _ = NONE; 
   222 *}
   222 \<close>
   223 text {*\noindent For the tests of \ttfamily eval\_get\_denominator \normalfont
   223 text \<open>\noindent For the tests of \ttfamily eval\_get\_denominator \normalfont
   224         see \ttfamily test/Knowledge/rational.sml\normalfont*}
   224         see \ttfamily test/Knowledge/rational.sml\normalfont\<close>
   225 
   225 
   226 text {*\noindent \ttfamily get\_numerator \normalfont should also become a
   226 text \<open>\noindent \ttfamily get\_numerator \normalfont should also become a
   227         constant for the Isabelle parser, follow up the \texttt{const}
   227         constant for the Isabelle parser, follow up the \texttt{const}
   228         declaration above.*}
   228         declaration above.\<close>
   229 
   229 
   230 ML {*
   230 ML \<open>
   231 (*
   231 (*
   232  *("get_numerator",
   232  *("get_numerator",
   233  *  ("Rational.get_numerator", eval_get_numerator ""))
   233  *  ("Rational.get_numerator", eval_get_numerator ""))
   234  *)
   234  *)
   235 fun eval_get_numerator (thmid:string) _ 
   235 fun eval_get_numerator (thmid:string) _ 
   237               (Const ("Rings.divide_class.divide", _) $num
   237               (Const ("Rings.divide_class.divide", _) $num
   238                 $denom )) thy = 
   238                 $denom )) thy = 
   239         SOME (TermC.mk_thmid thmid (term_to_string''' thy num) "", 
   239         SOME (TermC.mk_thmid thmid (term_to_string''' thy num) "", 
   240 	        HOLogic.Trueprop $ (TermC.mk_equality (t, num)))
   240 	        HOLogic.Trueprop $ (TermC.mk_equality (t, num)))
   241   | eval_get_numerator _ _ _ _ = NONE; 
   241   | eval_get_numerator _ _ _ _ = NONE; 
   242 *}
   242 \<close>
   243 
   243 
   244 text {*\noindent We discovered several problems by implementing the 
   244 text \<open>\noindent We discovered several problems by implementing the 
   245        \ttfamily get\_numerator \normalfont function. Remember when 
   245        \ttfamily get\_numerator \normalfont function. Remember when 
   246        putting new functions to {\sisac}, put them in a thy file and rebuild 
   246        putting new functions to {\sisac}, put them in a thy file and rebuild 
   247        {\sisac}, also put them in the ruleset for the script!*}
   247        {\sisac}, also put them in the ruleset for the script!\<close>
   248 
   248 
   249 subsection {*Solve Equation\label{sec:solveq}*}
   249 subsection \<open>Solve Equation\label{sec:solveq}\<close>
   250 text {*\noindent We have to find the zeros of the term, therefor we use our
   250 text \<open>\noindent We have to find the zeros of the term, therefor we use our
   251        \ttfamily get\_denominator \normalfont function from the step before
   251        \ttfamily get\_denominator \normalfont function from the step before
   252        and try to solve the second order equation. (Follow up the Calculation
   252        and try to solve the second order equation. (Follow up the Calculation
   253        in Section~\ref{sec:calc:ztrans} Subproblem 2) Note: This type of
   253        in Section~\ref{sec:calc:ztrans} Subproblem 2) Note: This type of
   254        equation is too general for the present program.
   254        equation is too general for the present program.
   255        \par We know that this equation can be categorized as \em univariate
   255        \par We know that this equation can be categorized as \em univariate
   256        equation \normalfont and solved with the functions {\sisac} provides
   256        equation \normalfont and solved with the functions {\sisac} provides
   257        for this equation type. Later on {\sisac} should determine the type
   257        for this equation type. Later on {\sisac} should determine the type
   258        of the given equation self.*}
   258        of the given equation self.\<close>
   259 ML {*
   259 ML \<open>
   260   val denominator = TermC.parseNEW ctxt "z^^^2 - 1/4*z - 1/8 = 0";
   260   val denominator = TermC.parseNEW ctxt "z^^^2 - 1/4*z - 1/8 = 0";
   261   val fmz = ["equality (z^^^2 - 1/4*z - 1/8 = (0::real))",
   261   val fmz = ["equality (z^^^2 - 1/4*z - 1/8 = (0::real))",
   262              "solveFor z",
   262              "solveFor z",
   263              "solutions L"];
   263              "solutions L"];
   264   val (dI',pI',mI') =("Isac", ["univariate","equation"], ["no_met"]);
   264   val (dI',pI',mI') =("Isac", ["univariate","equation"], ["no_met"]);
   265 *}
   265 \<close>
   266 text {*\noindent Check if the given equation matches the specification of this
   266 text \<open>\noindent Check if the given equation matches the specification of this
   267         equation type.*}
   267         equation type.\<close>
   268 ML {*
   268 ML \<open>
   269   Specify.match_pbl fmz (Specify.get_pbt ["univariate","equation"]);
   269   Specify.match_pbl fmz (Specify.get_pbt ["univariate","equation"]);
   270 *}
   270 \<close>
   271 
   271 
   272 text{*\noindent We switch up to the {\sisac} Context and try to solve the 
   272 text\<open>\noindent We switch up to the {\sisac} Context and try to solve the 
   273        equation with a more specific type definition.*}
   273        equation with a more specific type definition.\<close>
   274 
   274 
   275 ML {*
   275 ML \<open>
   276   Context.theory_name thy = "Isac";
   276   Context.theory_name thy = "Isac";
   277   val denominator = TermC.parseNEW ctxt "-1 + -2 * z + 8 * z ^^^ 2 = 0";
   277   val denominator = TermC.parseNEW ctxt "-1 + -2 * z + 8 * z ^^^ 2 = 0";
   278   val fmz =                                             (*specification*)
   278   val fmz =                                             (*specification*)
   279     ["equality (-1 + -2 * z + 8 * z ^^^ 2 = (0::real))",(*equality*)
   279     ["equality (-1 + -2 * z + 8 * z ^^^ 2 = (0::real))",(*equality*)
   280      "solveFor z",                                      (*bound variable*)
   280      "solveFor z",                                      (*bound variable*)
   282                                                           solution*)
   282                                                           solution*)
   283   val (dI',pI',mI') =
   283   val (dI',pI',mI') =
   284     ("Isac", 
   284     ("Isac", 
   285       ["abcFormula","degree_2","polynomial","univariate","equation"],
   285       ["abcFormula","degree_2","polynomial","univariate","equation"],
   286       ["no_met"]);
   286       ["no_met"]);
   287 *}
   287 \<close>
   288 
   288 
   289 text {*\noindent Check if the (other) given equation matches the 
   289 text \<open>\noindent Check if the (other) given equation matches the 
   290         specification of this equation type.*}
   290         specification of this equation type.\<close>
   291         
   291         
   292 ML {*
   292 ML \<open>
   293   Specify.match_pbl fmz (Specify.get_pbt
   293   Specify.match_pbl fmz (Specify.get_pbt
   294     ["abcFormula","degree_2","polynomial","univariate","equation"]);
   294     ["abcFormula","degree_2","polynomial","univariate","equation"]);
   295 *}
   295 \<close>
   296 
   296 
   297 text {*\noindent We stepwise solve the equation. This is done by the
   297 text \<open>\noindent We stepwise solve the equation. This is done by the
   298         use of a so called calc tree seen downwards.*}
   298         use of a so called calc tree seen downwards.\<close>
   299 
   299 
   300 ML {*
   300 ML \<open>
   301   val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
   301   val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
   302   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   302   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   303   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   303   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   304   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   304   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   305   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   305   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   319   (*
   319   (*
   320    * [z = 1 / 2, z = -1 / 4]
   320    * [z = 1 / 2, z = -1 / 4]
   321    *)
   321    *)
   322   Chead.show_pt pt; 
   322   Chead.show_pt pt; 
   323   val SOME f = parseNEW ctxt "[z=1/2, z=-1/4]";
   323   val SOME f = parseNEW ctxt "[z=1/2, z=-1/4]";
   324 *}
   324 \<close>
   325 
   325 
   326 subsection {*Partial Fraction Decomposition\label{sec:pbz}*}
   326 subsection \<open>Partial Fraction Decomposition\label{sec:pbz}\<close>
   327 text{*\noindent We go on with the decomposition of our expression. Follow up the
   327 text\<open>\noindent We go on with the decomposition of our expression. Follow up the
   328        Calculation in Section~\ref{sec:calc:ztrans} Step~3 and later on
   328        Calculation in Section~\ref{sec:calc:ztrans} Step~3 and later on
   329        Subproblem~1.*}
   329        Subproblem~1.\<close>
   330 subsubsection {*Solutions of the Equation*}
   330 subsubsection \<open>Solutions of the Equation\<close>
   331 text{*\noindent We get the solutions of the before solved equation in a list.*}
   331 text\<open>\noindent We get the solutions of the before solved equation in a list.\<close>
   332 
   332 
   333 ML {*
   333 ML \<open>
   334   val SOME solutions = parseNEW ctxt "[z=1/2, z=-1/4]";
   334   val SOME solutions = parseNEW ctxt "[z=1/2, z=-1/4]";
   335   term2str solutions;
   335   term2str solutions;
   336   atomty solutions;
   336   atomty solutions;
   337 *}
   337 \<close>
   338 
   338 
   339 subsubsection {*Get Solutions out of a List*}
   339 subsubsection \<open>Get Solutions out of a List\<close>
   340 text {*\noindent In {\sisac}'s TP-based programming language: 
   340 text \<open>\noindent In {\sisac}'s TP-based programming language: 
   341 \begin{verbatim}
   341 \begin{verbatim}
   342   let $ $ s_1 = NTH 1 $ solutions; $ s_2 = NTH 2... $
   342   let $ $ s_1 = NTH 1 $ solutions; $ s_2 = NTH 2... $
   343 \end{verbatim}
   343 \end{verbatim}
   344        can be useful.
   344        can be useful.
   345        *}
   345 \<close>
   346 
   346 
   347 ML {*
   347 ML \<open>
   348   val Const ("List.list.Cons", _) $ s_1 $ (Const ("List.list.Cons", _)
   348   val Const ("List.list.Cons", _) $ s_1 $ (Const ("List.list.Cons", _)
   349         $ s_2 $ Const ("List.list.Nil", _)) = solutions;
   349         $ s_2 $ Const ("List.list.Nil", _)) = solutions;
   350   term2str s_1;
   350   term2str s_1;
   351   term2str s_2;
   351   term2str s_2;
   352 *}
   352 \<close>
   353 
   353 
   354 text{*\noindent The ansatz for the \em Partial Fraction Decomposition \normalfont
   354 text\<open>\noindent The ansatz for the \em Partial Fraction Decomposition \normalfont
   355       requires to get the denominators of the partial fractions out of the 
   355       requires to get the denominators of the partial fractions out of the 
   356       Solutions as:
   356       Solutions as:
   357       \begin{itemize}
   357       \begin{itemize}
   358         \item $Denominator_{1}=z-Zeropoint_{1}$
   358         \item $Denominator_{1}=z-Zeropoint_{1}$
   359         \item $Denominator_{2}=z-Zeropoint_{2}$
   359         \item $Denominator_{2}=z-Zeropoint_{2}$
   360         \item \ldots
   360         \item \ldots
   361       \end{itemize}
   361       \end{itemize}
   362 *}
   362 \<close>
   363       
   363       
   364 ML {*
   364 ML \<open>
   365   val xx = HOLogic.dest_eq s_1;
   365   val xx = HOLogic.dest_eq s_1;
   366   val s_1' = HOLogic.mk_binop "Groups.minus_class.minus" xx;
   366   val s_1' = HOLogic.mk_binop "Groups.minus_class.minus" xx;
   367   val xx = HOLogic.dest_eq s_2;
   367   val xx = HOLogic.dest_eq s_2;
   368   val s_2' = HOLogic.mk_binop "Groups.minus_class.minus" xx;
   368   val s_2' = HOLogic.mk_binop "Groups.minus_class.minus" xx;
   369   term2str s_1';
   369   term2str s_1';
   370   term2str s_2';
   370   term2str s_2';
   371 *}
   371 \<close>
   372 
   372 
   373 text {*\noindent For the programming language a function collecting all the 
   373 text \<open>\noindent For the programming language a function collecting all the 
   374         above manipulations is helpful.*}
   374         above manipulations is helpful.\<close>
   375 
   375 
   376 ML {*
   376 ML \<open>
   377   fun fac_from_sol s =
   377   fun fac_from_sol s =
   378     let val (lhs, rhs) = HOLogic.dest_eq s
   378     let val (lhs, rhs) = HOLogic.dest_eq s
   379     in HOLogic.mk_binop "Groups.minus_class.minus" (lhs, rhs) end;
   379     in HOLogic.mk_binop "Groups.minus_class.minus" (lhs, rhs) end;
   380 *}
   380 \<close>
   381 
   381 
   382 ML {*
   382 ML \<open>
   383   fun mk_prod prod [] =
   383   fun mk_prod prod [] =
   384         if prod = e_term
   384         if prod = e_term
   385         then error "mk_prod called with []" 
   385         then error "mk_prod called with []" 
   386         else prod
   386         else prod
   387     | mk_prod prod (t :: []) =
   387     | mk_prod prod (t :: []) =
   396              in mk_prod p ts end 
   396              in mk_prod p ts end 
   397           else 
   397           else 
   398              let val p =
   398              let val p =
   399                HOLogic.mk_binop "Groups.times_class.times" (prod, t1)
   399                HOLogic.mk_binop "Groups.times_class.times" (prod, t1)
   400              in mk_prod p (t2 :: ts) end 
   400              in mk_prod p (t2 :: ts) end 
   401 *}
   401 \<close>
   402 (* ML {* 
   402 (* ML {* 
   403 probably keep these test in test/Tools/isac/...
   403 probably keep these test in test/Tools/isac/...
   404 (*mk_prod e_term [];*)
   404 (*mk_prod e_term [];*)
   405 
   405 
   406 val prod = mk_prod e_term [str2term "x + 123"]; 
   406 val prod = mk_prod e_term [str2term "x + 123"]; 
   414 
   414 
   415 val prod = 
   415 val prod = 
   416   mk_prod e_term [str2term "x + 1", str2term "x + 2", str2term "x + 3"]; 
   416   mk_prod e_term [str2term "x + 1", str2term "x + 2", str2term "x + 3"]; 
   417 term2str prod = "(x + 1) * (x + 2) * (x + 3)";
   417 term2str prod = "(x + 1) * (x + 2) * (x + 3)";
   418 *} *)
   418 *} *)
   419 ML {*
   419 ML \<open>
   420   fun factors_from_solution sol = 
   420   fun factors_from_solution sol = 
   421     let val ts = HOLogic.dest_list sol
   421     let val ts = HOLogic.dest_list sol
   422     in mk_prod e_term (map fac_from_sol ts) end;
   422     in mk_prod e_term (map fac_from_sol ts) end;
   423 *}
   423 \<close>
   424 (* ML {*
   424 (* ML {*
   425 val sol = str2term "[z = 1 / 2, z = -1 / 4]";
   425 val sol = str2term "[z = 1 / 2, z = -1 / 4]";
   426 val fs = factors_from_solution sol;
   426 val fs = factors_from_solution sol;
   427 term2str fs = "(z + -1 * (1 / 2)) * (z + -1 * (-1 / 4))"
   427 term2str fs = "(z + -1 * (1 / 2)) * (z + -1 * (-1 / 4))"
   428 *} *)
   428 *} *)
   429 text {*\noindent This function needs to be packed such that it can be evaluated
   429 text \<open>\noindent This function needs to be packed such that it can be evaluated
   430         by the Lucas-Interpreter. Therefor we moved the function to the
   430         by the Lucas-Interpreter. Therefor we moved the function to the
   431         corresponding \ttfamily Equation.thy \normalfont in our case
   431         corresponding \ttfamily Equation.thy \normalfont in our case
   432         \ttfamily PartialFractions.thy \normalfont. The necessary steps
   432         \ttfamily PartialFractions.thy \normalfont. The necessary steps
   433         are quit the same as we have done with \ttfamily get\_denominator 
   433         are quit the same as we have done with \ttfamily get\_denominator 
   434         \normalfont before.*}
   434         \normalfont before.\<close>
   435 ML {*
   435 ML \<open>
   436   (*("factors_from_solution",
   436   (*("factors_from_solution",
   437     ("Partial_Fractions.factors_from_solution",
   437     ("Partial_Fractions.factors_from_solution",
   438       eval_factors_from_solution ""))*)
   438       eval_factors_from_solution ""))*)
   439       
   439       
   440   fun eval_factors_from_solution (thmid:string) _
   440   fun eval_factors_from_solution (thmid:string) _
   443                    in SOME (mk_thmid thmid "" (term_to_string''' thy prod) "",
   443                    in SOME (mk_thmid thmid "" (term_to_string''' thy prod) "",
   444                          Trueprop $ (mk_equality (t, prod)))
   444                          Trueprop $ (mk_equality (t, prod)))
   445                 end)
   445                 end)
   446                handle _ => NONE)
   446                handle _ => NONE)
   447    | eval_factors_from_solution _ _ _ _ = NONE;
   447    | eval_factors_from_solution _ _ _ _ = NONE;
   448 *}
   448 \<close>
   449 
   449 
   450 text {*\noindent The tracing output of the calc tree after applying this
   450 text \<open>\noindent The tracing output of the calc tree after applying this
   451        function was:
   451        function was:
   452 \begin{verbatim}
   452 \begin{verbatim}
   453   24 / factors_from_solution [z = 1/ 2, z = -1 / 4])]
   453   24 / factors_from_solution [z = 1/ 2, z = -1 / 4])]
   454 \end{verbatim}
   454 \end{verbatim}
   455        and the next step:
   455        and the next step:
   457   val nxt = ("Empty_Tac", ...): tac'_)
   457   val nxt = ("Empty_Tac", ...): tac'_)
   458 \end{verbatim}
   458 \end{verbatim}
   459        These observations indicate, that the Lucas-Interpreter (LIP) 
   459        These observations indicate, that the Lucas-Interpreter (LIP) 
   460        does not know how to evaluate \ttfamily factors\_from\_solution
   460        does not know how to evaluate \ttfamily factors\_from\_solution
   461        \normalfont, so we knew that there is something wrong or missing.
   461        \normalfont, so we knew that there is something wrong or missing.
   462        *}
   462 \<close>
   463        
   463        
   464 text{*\noindent First we isolate the difficulty in the program as follows:
   464 text\<open>\noindent First we isolate the difficulty in the program as follows:
   465 \begin{verbatim}      
   465 \begin{verbatim}      
   466   " (L_L::bool list) = (SubProblem (PolyEq',      " ^
   466   " (L_L::bool list) = (SubProblem (PolyEq',      " ^
   467   "   [abcFormula, degree_2, polynomial,          " ^
   467   "   [abcFormula, degree_2, polynomial,          " ^
   468   "    univariate,equation],                      " ^
   468   "    univariate,equation],                      " ^
   469   "   [no_met])                                   " ^
   469   "   [no_met])                                   " ^
   567 \begin{verbatim}
   567 \begin{verbatim}
   568   val thy = @{theory "Inverse_Z_Transform"};
   568   val thy = @{theory "Inverse_Z_Transform"};
   569 \end{verbatim}
   569 \end{verbatim}
   570 
   570 
   571       After rebuilding {\sisac} again it worked.
   571       After rebuilding {\sisac} again it worked.
   572 *}
   572 \<close>
   573 
   573 
   574 subsubsection {*Build Expression*}
   574 subsubsection \<open>Build Expression\<close>
   575 text {*\noindent In {\sisac}'s TP-based programming language we can build
   575 text \<open>\noindent In {\sisac}'s TP-based programming language we can build
   576        expressions by:\\
   576        expressions by:\\
   577        \ttfamily let s\_1 = Take numerator / (s\_1 * s\_2) \normalfont*}
   577        \ttfamily let s\_1 = Take numerator / (s\_1 * s\_2) \normalfont\<close>
   578        
   578        
   579 ML {*
   579 ML \<open>
   580   (*
   580   (*
   581    * The main denominator is the multiplication of the denominators of
   581    * The main denominator is the multiplication of the denominators of
   582    * all partial fractions.
   582    * all partial fractions.
   583    *)
   583    *)
   584    
   584    
   587   val SOME numerator = parseNEW ctxt "3::real";
   587   val SOME numerator = parseNEW ctxt "3::real";
   588 
   588 
   589   val expr' = HOLogic.mk_binop
   589   val expr' = HOLogic.mk_binop
   590     "Rings.divide_class.divide" (numerator, denominator');
   590     "Rings.divide_class.divide" (numerator, denominator');
   591   term2str expr';
   591   term2str expr';
   592 *}
   592 \<close>
   593 
   593 
   594 subsubsection {*Apply the Partial Fraction Decomposion Ansatz*}
   594 subsubsection \<open>Apply the Partial Fraction Decomposion Ansatz\<close>
   595 
   595 
   596 text{*\noindent We use the Ansatz of the Partial Fraction Decomposition for our
   596 text\<open>\noindent We use the Ansatz of the Partial Fraction Decomposition for our
   597       expression 2nd order. Follow up the calculation in 
   597       expression 2nd order. Follow up the calculation in 
   598       Section~\ref{sec:calc:ztrans} Step~03.*}
   598       Section~\ref{sec:calc:ztrans} Step~03.\<close>
   599 
   599 
   600 ML {*Context.theory_name thy = "Isac"*}
   600 ML \<open>Context.theory_name thy = "Isac"\<close>
   601 
   601 
   602 text{*\noindent We define two axiomatization, the first one is the main ansatz,
   602 text\<open>\noindent We define two axiomatization, the first one is the main ansatz,
   603       the next one is just an equivalent transformation of the resulting
   603       the next one is just an equivalent transformation of the resulting
   604       equation. Both axiomatizations were moved to \ttfamily
   604       equation. Both axiomatizations were moved to \ttfamily
   605       Partial\_Fractions.thy \normalfont and got their own rulesets. In later
   605       Partial\_Fractions.thy \normalfont and got their own rulesets. In later
   606       programs it is possible to use the rulesets and the machine will find
   606       programs it is possible to use the rulesets and the machine will find
   607       the correct ansatz and equivalent transformation itself.*}
   607       the correct ansatz and equivalent transformation itself.\<close>
   608 
   608 
   609 axiomatization where
   609 axiomatization where
   610   ansatz_2nd_order: "n / (a*b) = A/a + B/b" and
   610   ansatz_2nd_order: "n / (a*b) = A/a + B/b" and
   611   equival_trans_2nd_order: "(n/(a*b) = A/a + B/b) = (n = A*b + B*a)"
   611   equival_trans_2nd_order: "(n/(a*b) = A/a + B/b) = (n = A*b + B*a)"
   612 
   612 
   613 text{*\noindent We use our \ttfamily ansatz\_2nd\_order \normalfont to rewrite
   613 text\<open>\noindent We use our \ttfamily ansatz\_2nd\_order \normalfont to rewrite
   614        our expression and get an equation with our expression on the left
   614        our expression and get an equation with our expression on the left
   615        and the partial fractions of it on the right hand side.*}
   615        and the partial fractions of it on the right hand side.\<close>
   616   
   616   
   617 ML {*
   617 ML \<open>
   618   val SOME (t1,_) = 
   618   val SOME (t1,_) = 
   619     rewrite_ @{theory} e_rew_ord e_rls false 
   619     rewrite_ @{theory} e_rew_ord e_rls false 
   620              @{thm ansatz_2nd_order} expr';
   620              @{thm ansatz_2nd_order} expr';
   621   term2str t1; atomty t1;
   621   term2str t1; atomty t1;
   622   val eq1 = HOLogic.mk_eq (expr', t1);
   622   val eq1 = HOLogic.mk_eq (expr', t1);
   623   term2str eq1;
   623   term2str eq1;
   624 *}
   624 \<close>
   625 
   625 
   626 text{*\noindent Eliminate the denominators by multiplying the left and the
   626 text\<open>\noindent Eliminate the denominators by multiplying the left and the
   627       right hand side of the equation with the main denominator. This is an
   627       right hand side of the equation with the main denominator. This is an
   628       simple equivalent transformation. Later on we use an own ruleset
   628       simple equivalent transformation. Later on we use an own ruleset
   629       defined in \ttfamily Partial\_Fractions.thy \normalfont for doing this.
   629       defined in \ttfamily Partial\_Fractions.thy \normalfont for doing this.
   630       Follow up the calculation in Section~\ref{sec:calc:ztrans} Step~04.*}
   630       Follow up the calculation in Section~\ref{sec:calc:ztrans} Step~04.\<close>
   631 
   631 
   632 ML {*
   632 ML \<open>
   633   val SOME (eq2,_) = 
   633   val SOME (eq2,_) = 
   634     rewrite_ @{theory} e_rew_ord e_rls false 
   634     rewrite_ @{theory} e_rew_ord e_rls false 
   635              @{thm equival_trans_2nd_order} eq1;
   635              @{thm equival_trans_2nd_order} eq1;
   636   term2str eq2;
   636   term2str eq2;
   637 *}
   637 \<close>
   638 
   638 
   639 text{*\noindent We use the existing ruleset \ttfamily norm\_Rational \normalfont 
   639 text\<open>\noindent We use the existing ruleset \ttfamily norm\_Rational \normalfont 
   640      for simplifications on expressions.*}
   640      for simplifications on expressions.\<close>
   641 
   641 
   642 ML {*
   642 ML \<open>
   643   val SOME (eq3,_) = rewrite_set_ @{theory} false norm_Rational eq2;
   643   val SOME (eq3,_) = rewrite_set_ @{theory} false norm_Rational eq2;
   644   term2str eq3;
   644   term2str eq3;
   645   (*
   645   (*
   646    * ?A ?B not simplified
   646    * ?A ?B not simplified
   647    *)
   647    *)
   648 *}
   648 \<close>
   649 
   649 
   650 text{*\noindent In Example~\ref{eg:gap} of my thesis I'm describing a problem about
   650 text\<open>\noindent In Example~\ref{eg:gap} of my thesis I'm describing a problem about
   651       simplifications. The problem that we would like to have only a specific degree
   651       simplifications. The problem that we would like to have only a specific degree
   652       of simplification occurs right here, in the next step.*}
   652       of simplification occurs right here, in the next step.\<close>
   653 
   653 
   654 ML {*
   654 ML \<open>
   655   trace_rewrite := false;
   655   trace_rewrite := false;
   656   val SOME fract1 =
   656   val SOME fract1 =
   657     parseNEW ctxt "(z - 1/2)*(z - -1/4) * (A/(z - 1/2) + B/(z - -1/4))";
   657     parseNEW ctxt "(z - 1/2)*(z - -1/4) * (A/(z - 1/2) + B/(z - -1/4))";
   658   (*
   658   (*
   659    * A B !
   659    * A B !
   663   term2str fract2 = "(A + -2 * B + 4 * A * z + 4 * B * z) / 4";
   663   term2str fract2 = "(A + -2 * B + 4 * A * z + 4 * B * z) / 4";
   664   (*
   664   (*
   665    * term2str fract2 = "A * (1 / 4 + z) + B * (-1 / 2 + z)" 
   665    * term2str fract2 = "A * (1 / 4 + z) + B * (-1 / 2 + z)" 
   666    * would be more traditional...
   666    * would be more traditional...
   667    *)
   667    *)
   668 *}
   668 \<close>
   669 
   669 
   670 text{*\noindent We walk around this problem by generating our new equation first.*}
   670 text\<open>\noindent We walk around this problem by generating our new equation first.\<close>
   671 
   671 
   672 ML {*
   672 ML \<open>
   673   val (numerator, denominator) = HOLogic.dest_eq eq3;
   673   val (numerator, denominator) = HOLogic.dest_eq eq3;
   674   val eq3' = HOLogic.mk_eq (numerator, fract1);
   674   val eq3' = HOLogic.mk_eq (numerator, fract1);
   675   (*
   675   (*
   676    * A B !
   676    * A B !
   677    *)
   677    *)
   680    * MANDATORY: simplify (and remove denominator) otherwise 3 = 0
   680    * MANDATORY: simplify (and remove denominator) otherwise 3 = 0
   681    *)
   681    *)
   682   val SOME (eq3'' ,_) = 
   682   val SOME (eq3'' ,_) = 
   683     rewrite_set_ @{theory} false norm_Rational eq3';
   683     rewrite_set_ @{theory} false norm_Rational eq3';
   684   term2str eq3'';
   684   term2str eq3'';
   685 *}
   685 \<close>
   686 
   686 
   687 text{*\noindent Still working at {\sisac}\ldots*}
   687 text\<open>\noindent Still working at {\sisac}\ldots\<close>
   688 
   688 
   689 ML {* Context.theory_name thy = "Isac" *}
   689 ML \<open>Context.theory_name thy = "Isac"\<close>
   690 
   690 
   691 subsubsection {*Build a Rule-Set for the Ansatz*}
   691 subsubsection \<open>Build a Rule-Set for the Ansatz\<close>
   692 text {*\noindent The \emph{ansatz} rules violate the principle that each
   692 text \<open>\noindent The \emph{ansatz} rules violate the principle that each
   693        variable on the right-hand-side must also occur on the
   693        variable on the right-hand-side must also occur on the
   694        left-hand-side of the rule: A, B, etc. don't do that. Thus the
   694        left-hand-side of the rule: A, B, etc. don't do that. Thus the
   695        rewriter marks these variables with question marks: ?A, ?B, etc.
   695        rewriter marks these variables with question marks: ?A, ?B, etc.
   696        These question marks can be dropped by \ttfamily fun
   696        These question marks can be dropped by \ttfamily fun
   697        drop\_questionmarks\normalfont.*}
   697        drop\_questionmarks\normalfont.\<close>
   698        
   698        
   699 ML {*
   699 ML \<open>
   700   val ansatz_rls = prep_rls @{theory} (
   700   val ansatz_rls = prep_rls @{theory} (
   701     Rls {id = "ansatz_rls", preconds = [], rew_ord = ("dummy_ord",dummy_ord),
   701     Rls {id = "ansatz_rls", preconds = [], rew_ord = ("dummy_ord",dummy_ord),
   702       erls = e_rls, srls = Erls, calc = [], errpatts = [],
   702       erls = e_rls, srls = Erls, calc = [], errpatts = [],
   703       rules = [
   703       rules = [
   704         Thm ("ansatz_2nd_order",num_str @{thm ansatz_2nd_order}),
   704         Thm ("ansatz_2nd_order",num_str @{thm ansatz_2nd_order}),
   705         Thm ("equival_trans_2nd_order",num_str @{thm equival_trans_2nd_order})
   705         Thm ("equival_trans_2nd_order",num_str @{thm equival_trans_2nd_order})
   706               ], 
   706               ], 
   707       scr = EmptyScr});
   707       scr = EmptyScr});
   708 *}
   708 \<close>
   709 
   709 
   710 text{*\noindent We apply the ruleset\ldots*}
   710 text\<open>\noindent We apply the ruleset\ldots\<close>
   711 
   711 
   712 ML {*
   712 ML \<open>
   713   val SOME (ttttt,_) = 
   713   val SOME (ttttt,_) = 
   714     rewrite_set_ @{theory} false ansatz_rls expr';
   714     rewrite_set_ @{theory} false ansatz_rls expr';
   715 *}
   715 \<close>
   716 
   716 
   717 text{*\noindent And check the output\ldots*}
   717 text\<open>\noindent And check the output\ldots\<close>
   718 
   718 
   719 ML {*
   719 ML \<open>
   720   term2str expr' = "3 / ((z - 1 / 2) * (z - -1 / 4))";
   720   term2str expr' = "3 / ((z - 1 / 2) * (z - -1 / 4))";
   721   term2str ttttt = "?A / (z - 1 / 2) + ?B / (z - -1 / 4)";
   721   term2str ttttt = "?A / (z - 1 / 2) + ?B / (z - -1 / 4)";
   722 *}
   722 \<close>
   723 
   723 
   724 subsubsection {*Get the First Coefficient*}
   724 subsubsection \<open>Get the First Coefficient\<close>
   725 
   725 
   726 text{*\noindent Now it's up to get the two coefficients A and B, which will be
   726 text\<open>\noindent Now it's up to get the two coefficients A and B, which will be
   727       the numerators of our partial fractions. Continue following up the 
   727       the numerators of our partial fractions. Continue following up the 
   728       Calculation in Section~\ref{sec:calc:ztrans} Subproblem~1.*}
   728       Calculation in Section~\ref{sec:calc:ztrans} Subproblem~1.\<close>
   729       
   729       
   730 text{*\noindent To get the first coefficient we substitute $z$ with the first
   730 text\<open>\noindent To get the first coefficient we substitute $z$ with the first
   731       zero-point we determined in Section~\ref{sec:solveq}.*}
   731       zero-point we determined in Section~\ref{sec:solveq}.\<close>
   732 
   732 
   733 ML {*
   733 ML \<open>
   734   val SOME (eq4_1,_) =
   734   val SOME (eq4_1,_) =
   735     rewrite_terms_ @{theory} e_rew_ord e_rls [s_1] eq3'';
   735     rewrite_terms_ @{theory} e_rew_ord e_rls [s_1] eq3'';
   736   term2str eq4_1;
   736   term2str eq4_1;
   737   val SOME (eq4_2,_) =
   737   val SOME (eq4_2,_) =
   738     rewrite_set_ @{theory} false norm_Rational eq4_1;
   738     rewrite_set_ @{theory} false norm_Rational eq4_1;
   796     (*Check_Postcond ["normalise","polynomial",
   796     (*Check_Postcond ["normalise","polynomial",
   797                       "univariate","equation"]*)
   797                       "univariate","equation"]*)
   798   val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
   798   val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
   799     (*End_Proof'*)
   799     (*End_Proof'*)
   800   f2str fa;
   800   f2str fa;
   801 *}
   801 \<close>
   802 
   802 
   803 subsubsection {*Get Second Coefficient*}
   803 subsubsection \<open>Get Second Coefficient\<close>
   804 
   804 
   805 text{*\noindent With the use of \texttt{thy} we check which theories the 
   805 text\<open>\noindent With the use of \texttt{thy} we check which theories the 
   806       interpreter knows.*}
   806       interpreter knows.\<close>
   807 
   807 
   808 ML {*thy*}
   808 ML \<open>thy\<close>
   809 
   809 
   810 text{*\noindent To get the second coefficient we substitute $z$ with the second
   810 text\<open>\noindent To get the second coefficient we substitute $z$ with the second
   811       zero-point we determined in Section~\ref{sec:solveq}.*}
   811       zero-point we determined in Section~\ref{sec:solveq}.\<close>
   812 
   812 
   813 ML {*
   813 ML \<open>
   814   val SOME (eq4b_1,_) =
   814   val SOME (eq4b_1,_) =
   815     rewrite_terms_ @{theory} e_rew_ord e_rls [s_2] eq3'';
   815     rewrite_terms_ @{theory} e_rew_ord e_rls [s_2] eq3'';
   816   term2str eq4b_1;
   816   term2str eq4b_1;
   817   val SOME (eq4b_2,_) =
   817   val SOME (eq4b_2,_) =
   818     rewrite_set_ @{theory} false norm_Rational eq4b_1;
   818     rewrite_set_ @{theory} false norm_Rational eq4b_1;
   847   val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
   847   val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
   848   val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
   848   val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
   849   val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
   849   val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
   850   val (p,_,fb,nxt,_,pt) = me nxt p [] pt; 
   850   val (p,_,fb,nxt,_,pt) = me nxt p [] pt; 
   851   f2str fb;
   851   f2str fb;
   852 *}
   852 \<close>
   853 
   853 
   854 text{*\noindent We compare our results with the pre calculated upshot.*}
   854 text\<open>\noindent We compare our results with the pre calculated upshot.\<close>
   855 
   855 
   856 ML {*
   856 ML \<open>
   857   if f2str fa = "[A = 4]" then () else error "part.fract. eq4_1";
   857   if f2str fa = "[A = 4]" then () else error "part.fract. eq4_1";
   858   if f2str fb = "[B = -4]" then () else error "part.fract. eq4_1";
   858   if f2str fb = "[B = -4]" then () else error "part.fract. eq4_1";
   859 *}
   859 \<close>
   860 
   860 
   861 section {*Implement the Specification and the Method \label{spec-meth}*}
   861 section \<open>Implement the Specification and the Method \label{spec-meth}\<close>
   862 
   862 
   863 text{*\noindent Now everything we need for solving the problem has been
   863 text\<open>\noindent Now everything we need for solving the problem has been
   864       tested out. We now start by creating new nodes for our methods and
   864       tested out. We now start by creating new nodes for our methods and
   865       further on our new program in the interpreter.*}
   865       further on our new program in the interpreter.\<close>
   866 
   866 
   867 subsection{*Define the Field Descriptions for the 
   867 subsection\<open>Define the Field Descriptions for the 
   868             Specification\label{sec:deffdes}*}
   868             Specification\label{sec:deffdes}\<close>
   869 
   869 
   870 text{*\noindent We define the fields \em filterExpression \normalfont and
   870 text\<open>\noindent We define the fields \em filterExpression \normalfont and
   871       \em stepResponse \normalfont both as equations, they represent the in- and
   871       \em stepResponse \normalfont both as equations, they represent the in- and
   872       output of the program.*}
   872       output of the program.\<close>
   873 
   873 
   874 consts
   874 consts
   875   filterExpression  :: "bool => una"
   875   filterExpression  :: "bool => una"
   876   stepResponse      :: "bool => una"
   876   stepResponse      :: "bool => una"
   877 
   877 
   878 subsection{*Define the Specification*}
   878 subsection\<open>Define the Specification\<close>
   879 
   879 
   880 text{*\noindent The next step is defining the specifications as nodes in the
   880 text\<open>\noindent The next step is defining the specifications as nodes in the
   881       designated part. We have to create the hierarchy node by node and start
   881       designated part. We have to create the hierarchy node by node and start
   882       with \em SignalProcessing \normalfont and go on by creating the node
   882       with \em SignalProcessing \normalfont and go on by creating the node
   883       \em Z\_Transform\normalfont.*}
   883       \em Z\_Transform\normalfont.\<close>
   884 
   884 
   885 setup {* KEStore_Elems.add_pbts
   885 setup \<open>KEStore_Elems.add_pbts
   886   [prep_pbt thy "pbl_SP" [] e_pblID (["SignalProcessing"], [], e_rls, NONE, []),
   886   [prep_pbt thy "pbl_SP" [] e_pblID (["SignalProcessing"], [], e_rls, NONE, []),
   887     prep_pbt thy "pbl_SP_Ztrans" [] e_pblID
   887     prep_pbt thy "pbl_SP_Ztrans" [] e_pblID
   888       (["Z_Transform","SignalProcessing"], [], e_rls, NONE, [])] *}
   888       (["Z_Transform","SignalProcessing"], [], e_rls, NONE, [])]\<close>
   889 
   889 
   890 text{*\noindent For the suddenly created node we have to define the input
   890 text\<open>\noindent For the suddenly created node we have to define the input
   891        and output parameters. We already prepared their definition in
   891        and output parameters. We already prepared their definition in
   892        Section~\ref{sec:deffdes}.*}
   892        Section~\ref{sec:deffdes}.\<close>
   893 
   893 
   894 setup {* KEStore_Elems.add_pbts
   894 setup \<open>KEStore_Elems.add_pbts
   895   [prep_pbt thy "pbl_SP_Ztrans_inv" [] e_pblID
   895   [prep_pbt thy "pbl_SP_Ztrans_inv" [] e_pblID
   896       (["Inverse", "Z_Transform", "SignalProcessing"],
   896       (["Inverse", "Z_Transform", "SignalProcessing"],
   897         [("#Given", ["filterExpression X_eq"]),
   897         [("#Given", ["filterExpression X_eq"]),
   898           ("#Find", ["stepResponse n_eq"])],
   898           ("#Find", ["stepResponse n_eq"])],
   899         append_rls "e_rls" e_rls [(*for preds in where_*)],
   899         append_rls "e_rls" e_rls [(*for preds in where_*)],
   900         NONE,
   900         NONE,
   901         [["SignalProcessing","Z_Transform","Inverse"]])] *}
   901         [["SignalProcessing","Z_Transform","Inverse"]])]\<close>
   902 ML {*
   902 ML \<open>
   903   show_ptyps ();
   903   show_ptyps ();
   904   get_pbt ["Inverse","Z_Transform","SignalProcessing"];
   904   get_pbt ["Inverse","Z_Transform","SignalProcessing"];
   905 *}
   905 \<close>
   906 
   906 
   907 subsection {*Define Name and Signature for the Method*}
   907 subsection \<open>Define Name and Signature for the Method\<close>
   908 
   908 
   909 text{*\noindent As a next step we store the definition of our new method as a
   909 text\<open>\noindent As a next step we store the definition of our new method as a
   910       constant for the interpreter.*}
   910       constant for the interpreter.\<close>
   911 
   911 
   912 consts
   912 consts
   913   InverseZTransform :: "[bool, bool] => bool"
   913   InverseZTransform :: "[bool, bool] => bool"
   914     ("((Script InverseZTransform (_ =))// (_))" 9)
   914     ("((Script InverseZTransform (_ =))// (_))" 9)
   915 
   915 
   916 subsection {*Setup Parent Nodes in Hierarchy of Method\label{sec:cparentnode}*}
   916 subsection \<open>Setup Parent Nodes in Hierarchy of Method\label{sec:cparentnode}\<close>
   917 
   917 
   918 text{*\noindent Again we have to generate the nodes step by step, first the
   918 text\<open>\noindent Again we have to generate the nodes step by step, first the
   919       parent node and then the originally \em Z\_Transformation 
   919       parent node and then the originally \em Z\_Transformation 
   920       \normalfont node. We have to define both nodes first with an empty script
   920       \normalfont node. We have to define both nodes first with an empty script
   921       as content.*}
   921       as content.\<close>
   922 
   922 
   923 setup {* KEStore_Elems.add_mets
   923 setup \<open>KEStore_Elems.add_mets
   924   [prep_met thy "met_SP" [] e_metID
   924   [prep_met thy "met_SP" [] e_metID
   925       (["SignalProcessing"], [],
   925       (["SignalProcessing"], [],
   926         {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls, crls = e_rls,
   926         {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls, crls = e_rls,
   927           errpats = [], nrls = e_rls},
   927           errpats = [], nrls = e_rls},
   928         "empty_script"),
   928         "empty_script"),
   929     prep_met thy "met_SP_Ztrans" [] e_metID
   929     prep_met thy "met_SP_Ztrans" [] e_metID
   930       (["SignalProcessing", "Z_Transform"], [],
   930       (["SignalProcessing", "Z_Transform"], [],
   931         {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls, crls = e_rls,
   931         {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls, crls = e_rls,
   932           errpats = [], nrls = e_rls},
   932           errpats = [], nrls = e_rls},
   933         "empty_script")]
   933         "empty_script")]
   934 *}
   934 \<close>
   935 
   935 
   936 text{*\noindent After we generated both nodes, we can fill the containing
   936 text\<open>\noindent After we generated both nodes, we can fill the containing
   937       script we want to implement later. First we define the specifications
   937       script we want to implement later. First we define the specifications
   938       of the script in e.g. the in- and output.*}
   938       of the script in e.g. the in- and output.\<close>
   939 
   939 
   940 setup {* KEStore_Elems.add_mets
   940 setup \<open>KEStore_Elems.add_mets
   941   [prep_met thy "met_SP_Ztrans_inv" [] e_metID
   941   [prep_met thy "met_SP_Ztrans_inv" [] e_metID
   942       (["SignalProcessing", "Z_Transform", "Inverse"], 
   942       (["SignalProcessing", "Z_Transform", "Inverse"], 
   943         [("#Given" ,["filterExpression X_eq"]), ("#Find"  ,["stepResponse n_eq"])],
   943         [("#Given" ,["filterExpression X_eq"]), ("#Find"  ,["stepResponse n_eq"])],
   944         {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls, crls = e_rls,
   944         {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls, crls = e_rls,
   945           errpats = [], nrls = e_rls},
   945           errpats = [], nrls = e_rls},
   946         "empty_script")]
   946         "empty_script")]
   947 *}
   947 \<close>
   948 
   948 
   949 text{*\noindent After we stored the definition we can start implementing the
   949 text\<open>\noindent After we stored the definition we can start implementing the
   950       script itself. As a first try we define only three rows containing one
   950       script itself. As a first try we define only three rows containing one
   951       simple operation.*}
   951       simple operation.\<close>
   952 
   952 
   953 setup {* KEStore_Elems.add_mets
   953 setup \<open>KEStore_Elems.add_mets
   954   [prep_met thy "met_SP_Ztrans_inv" [] e_metID
   954   [prep_met thy "met_SP_Ztrans_inv" [] e_metID
   955       (["SignalProcessing", "Z_Transform", "Inverse"], 
   955       (["SignalProcessing", "Z_Transform", "Inverse"], 
   956         [("#Given" ,["filterExpression X_eq"]), ("#Find"  ,["stepResponse n_eq"])],
   956         [("#Given" ,["filterExpression X_eq"]), ("#Find"  ,["stepResponse n_eq"])],
   957         {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls, crls = e_rls,
   957         {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls, crls = e_rls,
   958           errpats = [], nrls = e_rls},
   958           errpats = [], nrls = e_rls},
   959         "Script InverseZTransform (Xeq::bool) =" ^
   959         "Script InverseZTransform (Xeq::bool) =" ^
   960           " (let X = Take Xeq;" ^
   960           " (let X = Take Xeq;" ^
   961           "      X = Rewrite ruleZY False X" ^
   961           "      X = Rewrite ruleZY False X" ^
   962           "  in X)")]
   962           "  in X)")]
   963 *}
   963 \<close>
   964 
   964 
   965 text{*\noindent Check if the method has been stored correctly\ldots*}
   965 text\<open>\noindent Check if the method has been stored correctly\ldots\<close>
   966 
   966 
   967 ML {*
   967 ML \<open>
   968   show_mets(); 
   968   show_mets(); 
   969 *}
   969 \<close>
   970 
   970 
   971 text{*\noindent If yes we can get the method by stepping backwards through
   971 text\<open>\noindent If yes we can get the method by stepping backwards through
   972       the hierarchy.*}
   972       the hierarchy.\<close>
   973 
   973 
   974 ML {*
   974 ML \<open>
   975   get_met ["SignalProcessing","Z_Transform","Inverse"];
   975   get_met ["SignalProcessing","Z_Transform","Inverse"];
   976 *}
   976 \<close>
   977 
   977 
   978 section {*Program in TP-based language \label{prog-steps}*}
   978 section \<open>Program in TP-based language \label{prog-steps}\<close>
   979 
   979 
   980 text{*\noindent We start stepwise expanding our program. The script is a
   980 text\<open>\noindent We start stepwise expanding our program. The script is a
   981       simple string containing several manipulation instructions.
   981       simple string containing several manipulation instructions.
   982       \par The first script we try contains no instruction, we only test if
   982       \par The first script we try contains no instruction, we only test if
   983       building scripts that way work.*}
   983       building scripts that way work.\<close>
   984 
   984 
   985 subsection {*Stepwise Extend the Program*}
   985 subsection \<open>Stepwise Extend the Program\<close>
   986 ML {*
   986 ML \<open>
   987   val str = 
   987   val str = 
   988     "Script InverseZTransform (Xeq::bool) =                          "^
   988     "Script InverseZTransform (Xeq::bool) =                          "^
   989     " Xeq";
   989     " Xeq";
   990 *}
   990 \<close>
   991 
   991 
   992 text{*\noindent Next we put some instructions in the script and try if we are
   992 text\<open>\noindent Next we put some instructions in the script and try if we are
   993       able to solve our first equation.*}
   993       able to solve our first equation.\<close>
   994 
   994 
   995 ML {*
   995 ML \<open>
   996   val str = 
   996   val str = 
   997     "Script InverseZTransform (Xeq::bool) =                          "^
   997     "Script InverseZTransform (Xeq::bool) =                          "^
   998     (*
   998     (*
   999      * 1/z) instead of z ^^^ -1
   999      * 1/z) instead of z ^^^ -1
  1000      *)
  1000      *)
  1027     "      X' = (SubProblem (Isac',[pqFormula,degree_2,              "^
  1027     "      X' = (SubProblem (Isac',[pqFormula,degree_2,              "^
  1028     "                               polynomial,univariate,equation], "^
  1028     "                               polynomial,univariate,equation], "^
  1029     "                              [no_met])                         "^
  1029     "                              [no_met])                         "^
  1030     "                              [BOOL e_e, REAL v_v])             "^
  1030     "                              [BOOL e_e, REAL v_v])             "^
  1031     "            in X)";
  1031     "            in X)";
  1032 *}
  1032 \<close>
  1033 
  1033 
  1034 text{*\noindent To solve the equation it is necessary to drop the left hand
  1034 text\<open>\noindent To solve the equation it is necessary to drop the left hand
  1035       side, now we only need the denominator of the right hand side. The first
  1035       side, now we only need the denominator of the right hand side. The first
  1036       equation solves the zeros of our expression.*}
  1036       equation solves the zeros of our expression.\<close>
  1037 
  1037 
  1038 ML {*
  1038 ML \<open>
  1039   val str = 
  1039   val str = 
  1040     "Script InverseZTransform (Xeq::bool) =                          "^
  1040     "Script InverseZTransform (Xeq::bool) =                          "^
  1041     " (let X = Take Xeq;                                             "^
  1041     " (let X = Take Xeq;                                             "^
  1042     "      X' = Rewrite ruleZY False X;                              "^
  1042     "      X' = Rewrite ruleZY False X;                              "^
  1043     "      X' = (Rewrite_Set norm_Rational False) X';                "^
  1043     "      X' = (Rewrite_Set norm_Rational False) X';                "^
  1044     "      funterm = rhs X'                                          "^
  1044     "      funterm = rhs X'                                          "^
  1045     (*
  1045     (*
  1046      * drop X'= for equation solving
  1046      * drop X'= for equation solving
  1047      *)
  1047      *)
  1048     "  in X)";
  1048     "  in X)";
  1049 *}
  1049 \<close>
  1050 
  1050 
  1051 text{*\noindent As mentioned above, we need the denominator of the right hand
  1051 text\<open>\noindent As mentioned above, we need the denominator of the right hand
  1052       side. The equation itself consists of this denominator and tries to find
  1052       side. The equation itself consists of this denominator and tries to find
  1053       a $z$ for this the denominator is equal to zero.*}
  1053       a $z$ for this the denominator is equal to zero.\<close>
  1054 
  1054 
  1055 ML {*
  1055 ML \<open>
  1056   val str = 
  1056   val str = 
  1057     "Script InverseZTransform (X_eq::bool) =                         "^
  1057     "Script InverseZTransform (X_eq::bool) =                         "^
  1058     " (let X = Take X_eq;                                            "^
  1058     " (let X = Take X_eq;                                            "^
  1059     "      X' = Rewrite ruleZY False X;                              "^
  1059     "      X' = Rewrite ruleZY False X;                              "^
  1060     "      X' = (Rewrite_Set norm_Rational False) X';                "^
  1060     "      X' = (Rewrite_Set norm_Rational False) X';                "^
  1074     "  in X)";
  1074     "  in X)";
  1075 
  1075 
  1076   parse thy str;
  1076   parse thy str;
  1077   val sc = (inst_abs o Thm.term_of o the o (parse thy)) str;
  1077   val sc = (inst_abs o Thm.term_of o the o (parse thy)) str;
  1078   atomty sc;
  1078   atomty sc;
  1079 *}
  1079 \<close>
  1080 
  1080 
  1081 text {*\noindent This ruleset contains all functions that are in the script; 
  1081 text \<open>\noindent This ruleset contains all functions that are in the script; 
  1082        The evaluation of the functions is done by rewriting using this ruleset.*}
  1082        The evaluation of the functions is done by rewriting using this ruleset.\<close>
  1083 
  1083 
  1084 ML {*
  1084 ML \<open>
  1085   val srls = 
  1085   val srls = 
  1086     Rls {id="srls_InverseZTransform", 
  1086     Rls {id="srls_InverseZTransform", 
  1087          preconds = [],
  1087          preconds = [],
  1088          rew_ord = ("termlessI",termlessI),
  1088          rew_ord = ("termlessI",termlessI),
  1089          erls = append_rls "erls_in_srls_InverseZTransform" e_rls
  1089          erls = append_rls "erls_in_srls_InverseZTransform" e_rls
  1111                          "#factors_from_solution"),
  1111                          "#factors_from_solution"),
  1112                   Calc("Partial_Fractions.drop_questionmarks",
  1112                   Calc("Partial_Fractions.drop_questionmarks",
  1113                        eval_drop_questionmarks "#drop_?")
  1113                        eval_drop_questionmarks "#drop_?")
  1114                  ],
  1114                  ],
  1115          scr = EmptyScr};
  1115          scr = EmptyScr};
  1116 *}
  1116 \<close>
  1117 
  1117 
  1118 
  1118 
  1119 subsection {*Store Final Version of Program for Execution*}
  1119 subsection \<open>Store Final Version of Program for Execution\<close>
  1120 
  1120 
  1121 text{*\noindent After we also tested how to write scripts and run them,
  1121 text\<open>\noindent After we also tested how to write scripts and run them,
  1122       we start creating the final version of our script and store it into
  1122       we start creating the final version of our script and store it into
  1123       the method for which we created a node in Section~\ref{sec:cparentnode}
  1123       the method for which we created a node in Section~\ref{sec:cparentnode}
  1124       Note that we also did this stepwise, but we didn't kept every
  1124       Note that we also did this stepwise, but we didn't kept every
  1125       subversion.*}
  1125       subversion.\<close>
  1126 
  1126 
  1127 setup {* KEStore_Elems.add_mets
  1127 setup \<open>KEStore_Elems.add_mets
  1128   [prep_met thy "met_SP_Ztrans_inv" [] e_metID
  1128   [prep_met thy "met_SP_Ztrans_inv" [] e_metID
  1129       (["SignalProcessing", "Z_Transform", "Inverse"], 
  1129       (["SignalProcessing", "Z_Transform", "Inverse"], 
  1130         [("#Given" ,["filterExpression X_eq"]), ("#Find"  ,["stepResponse n_eq"])],
  1130         [("#Given" ,["filterExpression X_eq"]), ("#Find"  ,["stepResponse n_eq"])],
  1131         {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = srls, prls = e_rls, crls = e_rls,
  1131         {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = srls, prls = e_rls, crls = e_rls,
  1132           errpats = [], nrls = e_rls},
  1132           errpats = [], nrls = e_rls},
  1195 
  1195 
  1196           "      (X_z::bool) = Take (X_z = pbz);                          "^
  1196           "      (X_z::bool) = Take (X_z = pbz);                          "^
  1197           "      (n_eq::bool) = (Rewrite_Set inverse_z False) X_z;        "^
  1197           "      (n_eq::bool) = (Rewrite_Set inverse_z False) X_z;        "^
  1198           "      n_eq = drop_questionmarks n_eq                           "^
  1198           "      n_eq = drop_questionmarks n_eq                           "^
  1199           "in n_eq)")]
  1199           "in n_eq)")]
  1200 *}
  1200 \<close>
  1201 
  1201 
  1202 
  1202 
  1203 subsection {*Check the Program*}
  1203 subsection \<open>Check the Program\<close>
  1204 text{*\noindent When the script is ready we can start checking our work.*}
  1204 text\<open>\noindent When the script is ready we can start checking our work.\<close>
  1205 subsubsection {*Check the Formalization*}
  1205 subsubsection \<open>Check the Formalization\<close>
  1206 text{*\noindent First we want to check the formalization of the in and
  1206 text\<open>\noindent First we want to check the formalization of the in and
  1207        output of our program.*}
  1207        output of our program.\<close>
  1208 
  1208 
  1209 ML {*
  1209 ML \<open>
  1210   val fmz = 
  1210   val fmz = 
  1211     ["filterExpression (X  = 3 / (z - 1/4 + -1/8 * (1/(z::real))))",
  1211     ["filterExpression (X  = 3 / (z - 1/4 + -1/8 * (1/(z::real))))",
  1212      "stepResponse (x[n::real]::bool)"];
  1212      "stepResponse (x[n::real]::bool)"];
  1213   val (dI,pI,mI) = 
  1213   val (dI,pI,mI) = 
  1214     ("Isac", ["Inverse", "Z_Transform", "SignalProcessing"], 
  1214     ("Isac", ["Inverse", "Z_Transform", "SignalProcessing"], 
  1235   val Prog sc 
  1235   val Prog sc 
  1236     = (#scr o get_met) ["SignalProcessing",
  1236     = (#scr o get_met) ["SignalProcessing",
  1237                         "Z_Transform",
  1237                         "Z_Transform",
  1238                         "Inverse"];
  1238                         "Inverse"];
  1239   atomty sc;
  1239   atomty sc;
  1240 *}
  1240 \<close>
  1241 
  1241 
  1242 subsubsection {*Stepwise Check the Program\label{sec:stepcheck}*}
  1242 subsubsection \<open>Stepwise Check the Program\label{sec:stepcheck}\<close>
  1243 text{*\noindent We start to stepwise execute our new program in a calculation
  1243 text\<open>\noindent We start to stepwise execute our new program in a calculation
  1244       tree and check if every node implements that what we have wanted.*}
  1244       tree and check if every node implements that what we have wanted.\<close>
  1245       
  1245       
  1246 ML {*
  1246 ML \<open>
  1247   trace_rewrite := false; (*true*)
  1247   trace_rewrite := false; (*true*)
  1248   trace_script := false; (*true*)
  1248   trace_script := false; (*true*)
  1249   print_depth 9;
  1249   print_depth 9;
  1250   
  1250   
  1251   val fmz =
  1251   val fmz =
  1279     "Rewrite_Set norm_Rational";
  1279     "Rewrite_Set norm_Rational";
  1280     " --> X' z = 3 / (z * (z - 1 / 4 + -1 / 8 * (1 / z)))";
  1280     " --> X' z = 3 / (z * (z - 1 / 4 + -1 / 8 * (1 / z)))";
  1281   val (p,_,f,nxt,_,pt) = me nxt p [] pt; 
  1281   val (p,_,f,nxt,_,pt) = me nxt p [] pt; 
  1282     "SubProblem";
  1282     "SubProblem";
  1283   print_depth 3;
  1283   print_depth 3;
  1284 *}
  1284 \<close>
  1285 
  1285 
  1286 text {*\noindent Instead of \ttfamily nxt = Subproblem \normalfont above we had
  1286 text \<open>\noindent Instead of \ttfamily nxt = Subproblem \normalfont above we had
  1287        \ttfamily Empty\_Tac; \normalfont the search for the reason considered
  1287        \ttfamily Empty\_Tac; \normalfont the search for the reason considered
  1288        the following points:\begin{itemize}
  1288        the following points:\begin{itemize}
  1289        \item What shows \ttfamily show\_pt pt;\normalfont\ldots?
  1289        \item What shows \ttfamily show\_pt pt;\normalfont\ldots?
  1290 \begin{verbatim}(([2], Res), ?X' z = 24 / (-1 + -2 * z + 8 * z ^^^ 2))]\end{verbatim}
  1290 \begin{verbatim}(([2], Res), ?X' z = 24 / (-1 + -2 * z + 8 * z ^^^ 2))]\end{verbatim}
  1291          The calculation is ok but no \ttfamily next \normalfont step found:
  1291          The calculation is ok but no \ttfamily next \normalfont step found:
  1316          \end{verbatim}
  1316          \end{verbatim}
  1317          \ldots shows the right script. Difference in the arguments.
  1317          \ldots shows the right script. Difference in the arguments.
  1318      \item Test --- Why helpless here ? --- shows: \ttfamily replace
  1318      \item Test --- Why helpless here ? --- shows: \ttfamily replace
  1319          no\_meth by [no\_meth] \normalfont in Script
  1319          no\_meth by [no\_meth] \normalfont in Script
  1320      \end{itemize}
  1320      \end{itemize}
  1321 *}
  1321 \<close>
  1322 
  1322 
  1323 ML {*
  1323 ML \<open>
  1324   val (p,_,f,nxt,_,pt) = me nxt p [] pt; 
  1324   val (p,_,f,nxt,_,pt) = me nxt p [] pt; 
  1325     (*Model_Problem";*)
  1325     (*Model_Problem";*)
  1326 *}
  1326 \<close>
  1327 
  1327 
  1328 text {*\noindent Instead of \ttfamily nxt = Model\_Problem \normalfont above
  1328 text \<open>\noindent Instead of \ttfamily nxt = Model\_Problem \normalfont above
  1329        we had \ttfamily Empty\_Tac; \normalfont the search for the reason 
  1329        we had \ttfamily Empty\_Tac; \normalfont the search for the reason 
  1330        considered the following points:\begin{itemize}
  1330        considered the following points:\begin{itemize}
  1331        \item Difference in the arguments
  1331        \item Difference in the arguments
  1332        \item Comparison with Subsection~\ref{sec:solveq}: There solving this
  1332        \item Comparison with Subsection~\ref{sec:solveq}: There solving this
  1333          equation works, so there must be some difference in the arguments
  1333          equation works, so there must be some difference in the arguments
  1334          of the Subproblem: RIGHT: we had \ttfamily [no\_meth] \normalfont
  1334          of the Subproblem: RIGHT: we had \ttfamily [no\_meth] \normalfont
  1335          instead of \ttfamily [no\_met] \normalfont ;-)
  1335          instead of \ttfamily [no\_met] \normalfont ;-)
  1336        \end{itemize}*}
  1336        \end{itemize}\<close>
  1337 
  1337 
  1338 ML {*
  1338 ML \<open>
  1339   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1339   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1340     (*Add_Given equality (-1 + -2 * z + 8 * z ^^^ 2 = 0)";*)
  1340     (*Add_Given equality (-1 + -2 * z + 8 * z ^^^ 2 = 0)";*)
  1341   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1341   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1342     (*Add_Given solveFor z";*)
  1342     (*Add_Given solveFor z";*)
  1343   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1343   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1344     (*Add_Find solutions z_i";*)
  1344     (*Add_Find solutions z_i";*)
  1345   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1345   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1346     (*Specify_Theory Isac";*)
  1346     (*Specify_Theory Isac";*)
  1347 *}
  1347 \<close>
  1348 
  1348 
  1349 text {*\noindent We had \ttfamily nxt = Empty\_Tac instead Specify\_Theory;
  1349 text \<open>\noindent We had \ttfamily nxt = Empty\_Tac instead Specify\_Theory;
  1350        \normalfont The search for the reason considered the following points:
  1350        \normalfont The search for the reason considered the following points:
  1351        \begin{itemize}
  1351        \begin{itemize}
  1352        \item Was there an error message? NO -- ok
  1352        \item Was there an error message? NO -- ok
  1353        \item Has \ttfamily nxt = Add\_Find \normalfont been inserted in pt:\\
  1353        \item Has \ttfamily nxt = Add\_Find \normalfont been inserted in pt:\\
  1354          \ttfamily get\_obj g\_pbl pt (fst p);\normalfont? YES -- ok
  1354          \ttfamily get\_obj g\_pbl pt (fst p);\normalfont? YES -- ok
  1378           {http://www.ist.tugraz.at/projects/isac/www/kbase/pbl/index\_pbl.html}
  1378           {http://www.ist.tugraz.at/projects/isac/www/kbase/pbl/index\_pbl.html}
  1379                                }
  1379                                }
  1380      And the respective method in \ttfamily Knowledge/PolyEq.thy \normalfont
  1380      And the respective method in \ttfamily Knowledge/PolyEq.thy \normalfont
  1381      at the respective \ttfamily store\_pbt. \normalfont Or you leave the
  1381      at the respective \ttfamily store\_pbt. \normalfont Or you leave the
  1382      selection of the appropriate type to isac as done in the final Script ;-))
  1382      selection of the appropriate type to isac as done in the final Script ;-))
  1383   \end{itemize}*}
  1383   \end{itemize}\<close>
  1384   
  1384   
  1385 ML {*
  1385 ML \<open>
  1386   val (p,_,f,nxt,_,pt) = me nxt p [] pt; 
  1386   val (p,_,f,nxt,_,pt) = me nxt p [] pt; 
  1387     (*Specify_Problem [abcFormula,...";*)
  1387     (*Specify_Problem [abcFormula,...";*)
  1388   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1388   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1389     (*Specify_Method [PolyEq,solve_d2_polyeq_abc_equation";*)
  1389     (*Specify_Method [PolyEq,solve_d2_polyeq_abc_equation";*)
  1390   val (p,_,f,nxt,_,pt) = me nxt p [] pt; 
  1390   val (p,_,f,nxt,_,pt) = me nxt p [] pt; 
  1471   val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*([11], Res) Take*)
  1471   val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*([11], Res) Take*)
  1472   val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*([12], Frm) Substitute*)
  1472   val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*([12], Frm) Substitute*)
  1473   val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*([12], Res) Rewrite*)
  1473   val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*([12], Res) Rewrite*)
  1474   val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*([13], Res) Take*)
  1474   val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*([13], Res) Take*)
  1475   val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*([14], Frm) Empty_Tac*)
  1475   val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*([14], Frm) Empty_Tac*)
  1476 *}
  1476 \<close>
  1477 ML {*
  1477 ML \<open>
  1478   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1478   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1479 *}
  1479 \<close>
  1480 ML {*
  1480 ML \<open>
  1481   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1481   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1482 *}
  1482 \<close>
  1483 ML {*
  1483 ML \<open>
  1484   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1484   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1485 *}
  1485 \<close>
  1486 ML {*
  1486 ML \<open>
  1487   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1487   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1488 *}
  1488 \<close>
  1489 ML {*
  1489 ML \<open>
  1490   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1490   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1491 *}
  1491 \<close>
  1492 ML {*
  1492 ML \<open>
  1493   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1493   val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1494 *}
  1494 \<close>
  1495 
  1495 
  1496 ML {*
  1496 ML \<open>
  1497 trace_script := true;
  1497 trace_script := true;
  1498 *}
  1498 \<close>
  1499 ML {*
  1499 ML \<open>
  1500 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1500 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
  1501 *}
  1501 \<close>
  1502 ML {*
  1502 ML \<open>
  1503 Chead.show_pt pt;
  1503 Chead.show_pt pt;
  1504 *}
  1504 \<close>
  1505 ML {*
  1505 ML \<open>
  1506 *} 
  1506 \<close> 
  1507 ML {*
  1507 ML \<open>
  1508 *} 
  1508 \<close> 
  1509 ML {*
  1509 ML \<open>
  1510 *} 
  1510 \<close> 
  1511 ML {*
  1511 ML \<open>
  1512 *} 
  1512 \<close> 
  1513 ML {*
  1513 ML \<open>
  1514 *} 
  1514 \<close> 
  1515 ML {*
  1515 ML \<open>
  1516 *} 
  1516 \<close> 
  1517 
  1517 
  1518 text{*\noindent As a last step we check the tracing output of the last calc
  1518 text\<open>\noindent As a last step we check the tracing output of the last calc
  1519       tree instruction and compare it with the pre-calculated result.*}
  1519       tree instruction and compare it with the pre-calculated result.\<close>
  1520 
  1520 
  1521 section {* Improve and Transfer into Knowledge *}
  1521 section \<open>Improve and Transfer into Knowledge\<close>
  1522 text {*
  1522 text \<open>
  1523   We want to improve the very long program \ttfamily InverseZTransform
  1523   We want to improve the very long program \ttfamily InverseZTransform
  1524   \normalfont by modularisation: partial fraction decomposition shall
  1524   \normalfont by modularisation: partial fraction decomposition shall
  1525   become a sub-problem.
  1525   become a sub-problem.
  1526 
  1526 
  1527   We could transfer all knowledge in \ttfamily Build\_Inverse\_Z\_Transform.thy 
  1527   We could transfer all knowledge in \ttfamily Build\_Inverse\_Z\_Transform.thy 
  1536   \noindent (how this still can be improved see \ttfamily Partial\_Fractions.thy\normalfont),
  1536   \noindent (how this still can be improved see \ttfamily Partial\_Fractions.thy\normalfont),
  1537   and re-use all stuff prepared in \ttfamily Build\_Inverse\_Z\_Transform.thy:
  1537   and re-use all stuff prepared in \ttfamily Build\_Inverse\_Z\_Transform.thy:
  1538   \normalfont The knowledge will be transferred to \ttfamily src/../Partial\_Fractions.thy 
  1538   \normalfont The knowledge will be transferred to \ttfamily src/../Partial\_Fractions.thy 
  1539   \normalfont and the respective tests to:
  1539   \normalfont and the respective tests to:
  1540   \begin{center}\ttfamily test/../sartial\_fractions.sml\normalfont\end{center}
  1540   \begin{center}\ttfamily test/../sartial\_fractions.sml\normalfont\end{center}
  1541 *}
  1541 \<close>
  1542 
  1542 
  1543 subsection {* Transfer to Partial\_Fractions.thy *}
  1543 subsection \<open>Transfer to Partial\_Fractions.thy\<close>
  1544 text {*
  1544 text \<open>
  1545   First we transfer both, knowledge and tests into:
  1545   First we transfer both, knowledge and tests into:
  1546   \begin{center}\ttfamily src/../Partial\_Fractions.thy\normalfont\end{center}
  1546   \begin{center}\ttfamily src/../Partial\_Fractions.thy\normalfont\end{center}
  1547   in order to immediately have the test results.
  1547   in order to immediately have the test results.
  1548 
  1548 
  1549   We copy \ttfamily factors\_from\_solution, drop\_questionmarks,\\
  1549   We copy \ttfamily factors\_from\_solution, drop\_questionmarks,\\
  1557   \normalfont\\ to\\ 
  1557   \normalfont\\ to\\ 
  1558   (2) \ttfamily Partial\_Fractions.thy store\_met\ldots "met\_SP\_Ztrans\_inv" 
  1558   (2) \ttfamily Partial\_Fractions.thy store\_met\ldots "met\_SP\_Ztrans\_inv" 
  1559   \normalfont\\ and cut out the respective part from the program. First we ensure that
  1559   \normalfont\\ and cut out the respective part from the program. First we ensure that
  1560   the string is correct. When we insert the string into (2)
  1560   the string is correct. When we insert the string into (2)
  1561   \ttfamily store\_met .. "met\_partial\_fraction" \normalfont --- and get an error.
  1561   \ttfamily store\_met .. "met\_partial\_fraction" \normalfont --- and get an error.
  1562 *}
  1562 \<close>
  1563 
  1563 
  1564 subsubsection {* 'Programming' in ISAC's TP-based Language *}
  1564 subsubsection \<open>'Programming' in ISAC's TP-based Language\<close>
  1565 text {* 
  1565 text \<open>
  1566   At the present state writing programs in {\sisac} is particularly cumbersome.
  1566   At the present state writing programs in {\sisac} is particularly cumbersome.
  1567   So we give hints how to cope with the many obstacles. Below we describe the
  1567   So we give hints how to cope with the many obstacles. Below we describe the
  1568   steps we did in making (2) run.
  1568   steps we did in making (2) run.
  1569   
  1569   
  1570   \begin{enumerate}
  1570   \begin{enumerate}
  1602         of the program. Evaluation is done by the Lucas-Interpreter, which works
  1602         of the program. Evaluation is done by the Lucas-Interpreter, which works
  1603         using the knowledge in theory Isac; so we have to re-build Isac. And the
  1603         using the knowledge in theory Isac; so we have to re-build Isac. And the
  1604         test are performed simplest in a file which is loaded with Isac.
  1604         test are performed simplest in a file which is loaded with Isac.
  1605         See \ttfamily tests/../partial\_fractions.sml \normalfont.
  1605         See \ttfamily tests/../partial\_fractions.sml \normalfont.
  1606   \end{enumerate}
  1606   \end{enumerate}
  1607 *}
  1607 \<close>
  1608 
  1608 
  1609 subsection {* Transfer to Inverse\_Z\_Transform.thy *}
  1609 subsection \<open>Transfer to Inverse\_Z\_Transform.thy\<close>
  1610 text {*
  1610 text \<open>
  1611   It was not possible to complete this task, because we ran out of time.
  1611   It was not possible to complete this task, because we ran out of time.
  1612 *}
  1612 \<close>
  1613 
  1613 
  1614 
  1614 
  1615 end
  1615 end
  1616 
  1616