774 In our special case of Signal Processing and the rules defined in |
776 In our special case of Signal Processing and the rules defined in |
775 Example~\ref{eg:ruledef} we have to apply rule~1 first of all to transform all |
777 Example~\ref{eg:ruledef} we have to apply rule~1 first of all to transform all |
776 constants. After this step has been done it no mather which rule fit's next. |
778 constants. After this step has been done it no mather which rule fit's next. |
777 |
779 |
778 \subsection{Preparation of ML-Functions}\label{funs} |
780 \subsection{Preparation of ML-Functions}\label{funs} |
779 |
781 The prototype's Lucas-Interpreter uses the {\sisac}-rewrite-engine for |
780 \paragraph{Explicit Problems} require explicit methods to solve them, and within |
782 all kinds of evaluation. Some functionality required in programming, |
781 this methods we have some explicit steps to do. This steps can be unique for |
783 however, cannot be accomplished by rewriting. So the prototype has a |
782 a special problem or refindable in other problems. No mather what case, such |
784 mechanism to call ML-functions during rewriting, and the programmer has |
783 steps often require some technical functions behind. For the solving process |
785 to use this mechanism. |
784 of the Inverse Z Transformation and the corresponding partial fraction it was |
786 |
785 neccessary to build helping functions like \texttt{get\_denominator}, |
787 In the running example's program on p.\pageref{s:impl} the lines {\rm |
786 \texttt{get\_numerator} or \texttt{argument\_in}. First two functions help us |
788 05} and {\rm 06} contain such functions; we go into the details with |
787 to filter the denominator or numerator out of a fraction, last one helps us to |
789 \textit{argument\_in X\_z;}. This function fetches the argument from a |
788 get to know the bound variable in a equation. |
790 function application: Line {\rm 03} in the example calculation on |
789 \par |
791 p.\pageref{exp-calc} is created by line {\rm 06} of the example |
790 By taking \texttt{get\_denominator} as an example, we want to explain how to |
792 program on p.\pageref{s:impl} where the program's environment assigns |
791 implement new functions into the existing system and how we can later use them |
793 the value \textit{X z} to the variable \textit{X\_z}; so the function |
792 in our program. |
794 shall extract the argument \textit{z}. |
793 |
795 |
794 \subsubsection{Find a place to Store the Function} |
796 \medskip In order to be recognised as a function constant in the |
795 |
797 program source the function needs to be declared in a theory, here in |
796 The whole system builds up on a well defined structure of Knowledge. This |
798 \textit{Build\_Inverse\_Z\_Transform.thy}; then it can be parsed in |
797 Knowledge sets up at the Path: |
799 the context \textit{ctxt} of that theory: |
798 \begin{center}\ttfamily src/Tools/isac/Knowledge\normalfont\end{center} |
800 {\footnotesize |
799 For implementing the Function \texttt{get\_denominator} (which let us extract |
|
800 the denominator out of a fraction) we have choosen the Theory (file) |
|
801 \texttt{Rational.thy}. |
|
802 |
|
803 \subsubsection{Write down the new Function} |
|
804 |
|
805 In upper Theory we now define the new function and its purpose: |
|
806 \begin{verbatim} |
801 \begin{verbatim} |
807 get_denominator :: "real => real" |
802 consts |
808 \end{verbatim} |
803 argument'_in :: "real => real" ("argument'_in _" 10) |
809 This command tells the machine that a function with the name |
804 |
810 \texttt{get\_denominator} exists which gets a real expression as argument and |
805 ML {* val SOME t = parse ctxt "argument_in (X z)"; *} |
811 returns once again a real expression. Now we are able to implement the function |
806 |
812 itself, upcoming example now shows the implementation of |
807 val t = Const ("Build_Inverse_Z_Transform.argument'_in", "RealDef.real ⇒ RealDef.real") |
813 \texttt{get\_denominator}. |
808 $ (Free ("X", "RealDef.real ⇒ RealDef.real") $ Free ("z", "RealDef.real")): term |
814 |
809 \end{verbatim}} |
815 %\begin{example} |
810 |
816 \label{eg:getdenom} |
811 \noindent Parsing produces a term \texttt{t} in internal |
817 \begin{verbatim} |
812 representation, consisting of \texttt{Const ("argument'\_in", type)} |
818 |
813 and the two variables \texttt{Free ("X", type)} and \texttt{Free ("z", |
819 01 (* |
814 type)}, \texttt{\$} is the term constructor. The function body below is |
820 02 *("get_denominator", |
815 implemented directly in ML, i.e in an \texttt{ML \{* *\}} block; the |
821 03 * ("Rational.get_denominator", eval_get_denominator "")) |
816 function definition provides a unique prefix \texttt{eval\_} to the |
822 04 *) |
817 function name: |
823 05 fun eval_get_denominator (thmid:string) _ |
818 |
824 06 (t as Const ("Rational.get_denominator", _) $ |
819 {\footnotesize |
825 07 (Const ("Rings.inverse_class.divide", _) $num |
|
826 08 $denom)) thy = |
|
827 09 SOME (mk_thmid thmid "" |
|
828 10 (Print_Mode.setmp [] |
|
829 11 (Syntax.string_of_term (thy2ctxt thy)) denom) "", |
|
830 12 Trueprop $ (mk_equality (t, denom))) |
|
831 13 | eval_get_denominator _ _ _ _ = NONE;\end{verbatim} |
|
832 %\end{example} |
|
833 |
|
834 Line \texttt{07} and \texttt{08} are describing the mode of operation the best - |
|
835 there is a fraction\\ (\ttfamily Rings.inverse\_class.divide\normalfont) |
|
836 splittet |
|
837 into its two parts (\texttt{\$num \$denom}). The lines before are additionals |
|
838 commands for declaring the function and the lines after are modeling and |
|
839 returning a real variable out of \texttt{\$denom}. |
|
840 |
|
841 \subsubsection{Add a test for the new Function} |
|
842 |
|
843 \paragraph{Everytime when adding} a new function it is essential also to add |
|
844 a test for it. Tests for all functions are sorted in the same structure as the |
|
845 knowledge it self and can be found up from the path: |
|
846 \begin{center}\ttfamily test/Tools/isac/Knowledge\normalfont\end{center} |
|
847 This tests are nothing very special, as a first prototype the functionallity |
|
848 of a function can be checked by evaluating the result of a simple expression |
|
849 passed to the function. Example~\ref{eg:getdenomtest} shows the test for our |
|
850 \textit{just} created function \texttt{get\_denominator}. |
|
851 |
|
852 %\begin{example} |
|
853 \label{eg:getdenomtest} |
|
854 \begin{verbatim} |
820 \begin{verbatim} |
855 |
821 ML {* |
856 01 val thy = @{theory Isac}; |
822 fun eval_argument_in _ |
857 02 val t = term_of (the (parse thy "get_denominator ((a +x)/b)")); |
823 "Build_Inverse_Z_Transform.argument'_in" |
858 03 val SOME (_, t') = eval_get_denominator "" 0 t thy; |
824 (t as (Const ("Build_Inverse_Z_Transform.argument'_in", _) $ (f $ arg))) _ = |
859 04 if term2str t' = "get_denominator ((a + x) / b) = b" then () |
825 if is_Free arg (*could be something to be simplified before*) |
860 05 else error "get_denominator ((a + x) / b) = b" \end{verbatim} |
826 then SOME (term2str t ^ " = " ^ term2str arg, Trueprop $ (mk_equality (t, arg))) |
861 %\end{example} |
827 else NONE |
862 |
828 | eval_argument_in _ _ _ _ = NONE; |
863 \begin{description} |
829 *} |
864 \item[01] checks if the proofer set up on our {\sisac{}} System. |
830 \end{verbatim}} |
865 \item[02] passes a simple expression (fraction) to our suddenly created |
831 |
866 function. |
832 \noindent The function body creates either creates \texttt{NONE} |
867 \item[04] checks if the resulting variable is the correct one (in this case |
833 telling the rewrite-engine to search for the next redex, or creates an |
868 ``b'' the denominator) and returns. |
834 ad-hoc theorem for rewriting, thus the programmer needs to adopt many |
869 \item[05] handels the error case and reports that the function is not able to |
835 technicalities of Isabelle, for instance, the \textit{Trueprop} |
870 solve the given problem. |
836 constant. |
871 \end{description} |
837 |
|
838 \bigskip This sub-task particularly sheds light on basic issues in the |
|
839 design of a programming language, the integration of diffent language |
|
840 layers, the layer of Isabelle/Isar and Isabelle/ML. |
|
841 |
|
842 Another point of improvement for the prototype is the rewrite-engine: The |
|
843 program on p.\pageref{s:impl} would not allow to contract the two lines {\rm 05} |
|
844 and {\rm 06} to |
|
845 |
|
846 {\small\it\label{s:impl} |
|
847 \begin{tabbing} |
|
848 123l\=123\=123\=123\=123\=123\=123\=((x\=123\=(x \=123\=123\=\kill |
|
849 \>{\rm 05/6}\>\>\> (z::real) = argument\_in (lhs X\_eq) ; |
|
850 \end{tabbing}} |
|
851 |
|
852 \noindent because nested function calls would require creating redexes |
|
853 inside-out; however, the prototype's rewrite-engine only works top down |
|
854 from the root of a term down to the leaves. |
|
855 |
|
856 How all these ugly technicalities are to be checked in the prototype is |
|
857 shown in \S\ref{flow-prep} below. |
|
858 |
|
859 % \paragraph{Explicit Problems} require explicit methods to solve them, and within |
|
860 % this methods we have some explicit steps to do. This steps can be unique for |
|
861 % a special problem or refindable in other problems. No mather what case, such |
|
862 % steps often require some technical functions behind. For the solving process |
|
863 % of the Inverse Z Transformation and the corresponding partial fraction it was |
|
864 % neccessary to build helping functions like \texttt{get\_denominator}, |
|
865 % \texttt{get\_numerator} or \texttt{argument\_in}. First two functions help us |
|
866 % to filter the denominator or numerator out of a fraction, last one helps us to |
|
867 % get to know the bound variable in a equation. |
|
868 % \par |
|
869 % By taking \texttt{get\_denominator} as an example, we want to explain how to |
|
870 % implement new functions into the existing system and how we can later use them |
|
871 % in our program. |
|
872 % |
|
873 % \subsubsection{Find a place to Store the Function} |
|
874 % |
|
875 % The whole system builds up on a well defined structure of Knowledge. This |
|
876 % Knowledge sets up at the Path: |
|
877 % \begin{center}\ttfamily src/Tools/isac/Knowledge\normalfont\end{center} |
|
878 % For implementing the Function \texttt{get\_denominator} (which let us extract |
|
879 % the denominator out of a fraction) we have choosen the Theory (file) |
|
880 % \texttt{Rational.thy}. |
|
881 % |
|
882 % \subsubsection{Write down the new Function} |
|
883 % |
|
884 % In upper Theory we now define the new function and its purpose: |
|
885 % \begin{verbatim} |
|
886 % get_denominator :: "real => real" |
|
887 % \end{verbatim} |
|
888 % This command tells the machine that a function with the name |
|
889 % \texttt{get\_denominator} exists which gets a real expression as argument and |
|
890 % returns once again a real expression. Now we are able to implement the function |
|
891 % itself, upcoming example now shows the implementation of |
|
892 % \texttt{get\_denominator}. |
|
893 % |
|
894 % %\begin{example} |
|
895 % \label{eg:getdenom} |
|
896 % \begin{verbatim} |
|
897 % |
|
898 % 01 (* |
|
899 % 02 *("get_denominator", |
|
900 % 03 * ("Rational.get_denominator", eval_get_denominator "")) |
|
901 % 04 *) |
|
902 % 05 fun eval_get_denominator (thmid:string) _ |
|
903 % 06 (t as Const ("Rational.get_denominator", _) $ |
|
904 % 07 (Const ("Rings.inverse_class.divide", _) $num |
|
905 % 08 $denom)) thy = |
|
906 % 09 SOME (mk_thmid thmid "" |
|
907 % 10 (Print_Mode.setmp [] |
|
908 % 11 (Syntax.string_of_term (thy2ctxt thy)) denom) "", |
|
909 % 12 Trueprop $ (mk_equality (t, denom))) |
|
910 % 13 | eval_get_denominator _ _ _ _ = NONE;\end{verbatim} |
|
911 % %\end{example} |
|
912 % |
|
913 % Line \texttt{07} and \texttt{08} are describing the mode of operation the best - |
|
914 % there is a fraction\\ (\ttfamily Rings.inverse\_class.divide\normalfont) |
|
915 % splittet |
|
916 % into its two parts (\texttt{\$num \$denom}). The lines before are additionals |
|
917 % commands for declaring the function and the lines after are modeling and |
|
918 % returning a real variable out of \texttt{\$denom}. |
|
919 % |
|
920 % \subsubsection{Add a test for the new Function} |
|
921 % |
|
922 % \paragraph{Everytime when adding} a new function it is essential also to add |
|
923 % a test for it. Tests for all functions are sorted in the same structure as the |
|
924 % knowledge it self and can be found up from the path: |
|
925 % \begin{center}\ttfamily test/Tools/isac/Knowledge\normalfont\end{center} |
|
926 % This tests are nothing very special, as a first prototype the functionallity |
|
927 % of a function can be checked by evaluating the result of a simple expression |
|
928 % passed to the function. Example~\ref{eg:getdenomtest} shows the test for our |
|
929 % \textit{just} created function \texttt{get\_denominator}. |
|
930 % |
|
931 % %\begin{example} |
|
932 % \label{eg:getdenomtest} |
|
933 % \begin{verbatim} |
|
934 % |
|
935 % 01 val thy = @{theory Isac}; |
|
936 % 02 val t = term_of (the (parse thy "get_denominator ((a +x)/b)")); |
|
937 % 03 val SOME (_, t') = eval_get_denominator "" 0 t thy; |
|
938 % 04 if term2str t' = "get_denominator ((a + x) / b) = b" then () |
|
939 % 05 else error "get_denominator ((a + x) / b) = b" \end{verbatim} |
|
940 % %\end{example} |
|
941 % |
|
942 % \begin{description} |
|
943 % \item[01] checks if the proofer set up on our {\sisac{}} System. |
|
944 % \item[02] passes a simple expression (fraction) to our suddenly created |
|
945 % function. |
|
946 % \item[04] checks if the resulting variable is the correct one (in this case |
|
947 % ``b'' the denominator) and returns. |
|
948 % \item[05] handels the error case and reports that the function is not able to |
|
949 % solve the given problem. |
|
950 % \end{description} |
872 |
951 |
873 \subsection{Specification of the Problem}\label{spec} |
952 \subsection{Specification of the Problem}\label{spec} |
874 %WN <--> \chapter 7 der Thesis |
953 %WN <--> \chapter 7 der Thesis |
875 %WN die Argumentation unten sollte sich NUR auf Verifikation beziehen.. |
954 %WN die Argumentation unten sollte sich NUR auf Verifikation beziehen.. |
876 |
955 |