doc-src/isac/jrocnik/eJMT-paper/jrocnik_eJMT.tex
author Walther Neuper <neuper@ist.tugraz.at>
Wed, 12 Sep 2012 21:14:15 +0200
changeset 42504 fea5b11e1646
parent 42503 67921e3c60ff
child 42506 480aee713e3d
permissions -rwxr-xr-x
jrocnik: reworked up to \sect.3.5

... except \sect.3.2 under construction by jrocnik
jan@42463
     1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
jan@42463
     2
% Electronic Journal of Mathematics and Technology (eJMT) %
jan@42463
     3
% style sheet for LaTeX.  Please do not modify sections   %
jan@42463
     4
% or commands marked 'eJMT'.                              %
jan@42463
     5
%                                                         %
jan@42463
     6
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
jan@42463
     7
%                                                         %
jan@42463
     8
% eJMT commands                                           %
jan@42463
     9
%                                                         %
jan@42463
    10
\documentclass[12pt,a4paper]{article}%                    %
jan@42463
    11
\usepackage{times}                                        %
jan@42463
    12
\usepackage{amsfonts,amsmath,amssymb}                     %
jan@42463
    13
\usepackage[a4paper]{geometry}                            %
jan@42463
    14
\usepackage{fancyhdr}                                     %
jan@42463
    15
\usepackage{color}                                        %
jan@42463
    16
\usepackage[pdftex]{hyperref} % see note below            %
jan@42463
    17
\usepackage{graphicx}%                                    %
jan@42463
    18
\hypersetup{                                              %
jan@42463
    19
    a4paper,                                              %
jan@42463
    20
    breaklinks                                            %
jan@42463
    21
}                                                         %
jan@42463
    22
%                                                         %
jan@42463
    23
\newtheorem{theorem}{Theorem}                             %
jan@42463
    24
\newtheorem{acknowledgement}[theorem]{Acknowledgement}    %
jan@42463
    25
\newtheorem{algorithm}[theorem]{Algorithm}                %
jan@42463
    26
\newtheorem{axiom}[theorem]{Axiom}                        %
jan@42463
    27
\newtheorem{case}[theorem]{Case}                          %
jan@42463
    28
\newtheorem{claim}[theorem]{Claim}                        %
jan@42463
    29
\newtheorem{conclusion}[theorem]{Conclusion}              %
jan@42463
    30
\newtheorem{condition}[theorem]{Condition}                %
jan@42463
    31
\newtheorem{conjecture}[theorem]{Conjecture}              %
jan@42463
    32
\newtheorem{corollary}[theorem]{Corollary}                %
jan@42463
    33
\newtheorem{criterion}[theorem]{Criterion}                %
jan@42463
    34
\newtheorem{definition}[theorem]{Definition}              %
jan@42463
    35
\newtheorem{example}[theorem]{Example}                    %
jan@42463
    36
\newtheorem{exercise}[theorem]{Exercise}                  %
jan@42463
    37
\newtheorem{lemma}[theorem]{Lemma}                        %
jan@42463
    38
\newtheorem{notation}[theorem]{Notation}                  %
jan@42463
    39
\newtheorem{problem}[theorem]{Problem}                    %
jan@42463
    40
\newtheorem{proposition}[theorem]{Proposition}            %
jan@42463
    41
\newtheorem{remark}[theorem]{Remark}                      %
jan@42463
    42
\newtheorem{solution}[theorem]{Solution}                  %
jan@42463
    43
\newtheorem{summary}[theorem]{Summary}                    %
jan@42463
    44
\newenvironment{proof}[1][Proof]{\noindent\textbf{#1.} }  %
jan@42463
    45
{\ \rule{0.5em}{0.5em}}                                   %
jan@42463
    46
%                                                         %
jan@42463
    47
% eJMT page dimensions                                    %
jan@42463
    48
%                                                         %
jan@42463
    49
\geometry{left=2cm,right=2cm,top=3.2cm,bottom=4cm}        %
jan@42463
    50
%                                                         %
jan@42463
    51
% eJMT header & footer                                    %
jan@42463
    52
%                                                         %
jan@42463
    53
\newcounter{ejmtFirstpage}                                %
jan@42463
    54
\setcounter{ejmtFirstpage}{1}                             %
jan@42463
    55
\pagestyle{empty}                                         %
jan@42463
    56
\setlength{\headheight}{14pt}                             %
jan@42463
    57
\geometry{left=2cm,right=2cm,top=3.2cm,bottom=4cm}        %
jan@42463
    58
\pagestyle{fancyplain}                                    %
jan@42463
    59
\fancyhf{}                                                %
jan@42463
    60
\fancyhead[c]{\small The Electronic Journal of Mathematics%
jan@42463
    61
\ and Technology, Volume 1, Number 1, ISSN 1933-2823}     %
jan@42463
    62
\cfoot{%                                                  %
jan@42463
    63
  \ifnum\value{ejmtFirstpage}=0%                          %
jan@42463
    64
    {\vtop to\hsize{\hrule\vskip .2cm\thepage}}%          %
jan@42463
    65
  \else\setcounter{ejmtFirstpage}{0}\fi%                  %
jan@42463
    66
}                                                         %
jan@42463
    67
%                                                         %
jan@42463
    68
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
jan@42463
    69
%
jan@42463
    70
% Please place your own definitions here
jan@42463
    71
%
jan@42463
    72
\def\isac{${\cal I}\mkern-2mu{\cal S}\mkern-5mu{\cal AC}$}
jan@42463
    73
\def\sisac{\footnotesize${\cal I}\mkern-2mu{\cal S}\mkern-5mu{\cal AC}$}
jan@42463
    74
jan@42463
    75
\usepackage{color}
jan@42463
    76
\definecolor{lgray}{RGB}{238,238,238}
jan@42463
    77
jan@42463
    78
%
jan@42463
    79
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
jan@42463
    80
%                                                         %
jan@42463
    81
% How to use hyperref                                     %
jan@42463
    82
% -------------------                                     %
jan@42463
    83
%                                                         %
jan@42463
    84
% Probably the only way you will need to use the hyperref %
jan@42463
    85
% package is as follows.  To make some text, say          %
jan@42463
    86
% "My Text Link", into a link to the URL                  %
jan@42463
    87
% http://something.somewhere.com/mystuff, use             %
jan@42463
    88
%                                                         %
jan@42463
    89
% \href{http://something.somewhere.com/mystuff}{My Text Link}
jan@42463
    90
%                                                         %
jan@42463
    91
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
jan@42463
    92
%
jan@42463
    93
\begin{document}
jan@42463
    94
%
jan@42463
    95
% document title
jan@42463
    96
%
neuper@42464
    97
\title{Trials with TP-based Programming
neuper@42464
    98
\\
neuper@42464
    99
for Interactive Course Material}%
jan@42463
   100
%
jan@42463
   101
% Single author.  Please supply at least your name,
jan@42463
   102
% email address, and affiliation here.
jan@42463
   103
%
jan@42463
   104
\author{\begin{tabular}{c}
jan@42463
   105
\textit{Jan Ro\v{c}nik} \\
jan@42463
   106
jan.rocnik@student.tugraz.at \\
jan@42463
   107
IST, SPSC\\
neuper@42464
   108
Graz University of Technologie\\
jan@42463
   109
Austria\end{tabular}
jan@42463
   110
}%
jan@42463
   111
%
jan@42463
   112
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
jan@42463
   113
%                                                         %
jan@42463
   114
% eJMT commands - do not change these                     %
jan@42463
   115
%                                                         %
jan@42463
   116
\date{}                                                   %
jan@42463
   117
\maketitle                                                %
jan@42463
   118
%                                                         %
jan@42463
   119
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
jan@42463
   120
%
jan@42463
   121
% abstract
jan@42463
   122
%
jan@42463
   123
\begin{abstract}
jan@42463
   124
jan@42463
   125
Traditional course material in engineering disciplines lacks an
jan@42463
   126
important component, interactive support for step-wise problem
neuper@42464
   127
solving. Theorem-Proving (TP) technology is appropriate for one part
jan@42463
   128
of such support, in checking user-input. For the other part of such
jan@42463
   129
support, guiding the learner towards a solution, another kind of
jan@42463
   130
technology is required. %TODO ... connect to prototype ...
jan@42463
   131
neuper@42504
   132
Both kinds of support can be acchieved by so-called
neuper@42504
   133
Lucas-Interpretation which combines deduction and computation and, for
neuper@42504
   134
the latter, uses a novel kind of programming language. This language
neuper@42504
   135
is based on (Computer) Theorem Proving (TP), thus called a ``TP-based
neuper@42504
   136
programming language''.
jan@42463
   137
neuper@42504
   138
This paper is the experience report of the first ``application
neuper@42504
   139
programmer'' using this language, the experience gained from a
neuper@42504
   140
prototype of the programming language and of it's interpreter.
neuper@42504
   141
neuper@42504
   142
The report concludes with a positive proof of concept, states
neuper@42504
   143
insuggicient usability of the prototype and captures the requirements
neuper@42504
   144
for further development of both, the programming language and the
neuper@42504
   145
interpreter.
jan@42463
   146
%
jan@42463
   147
\end{abstract}%
jan@42463
   148
%
jan@42463
   149
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
jan@42463
   150
%                                                         %
jan@42463
   151
% eJMT command                                            %
jan@42463
   152
%                                                         %
jan@42463
   153
\thispagestyle{fancy}                                     %
jan@42463
   154
%                                                         %
jan@42463
   155
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
jan@42463
   156
%
jan@42463
   157
% Please use the following to indicate sections, subsections,
jan@42463
   158
% etc.  Please also use \subsubsection{...}, \paragraph{...}
jan@42463
   159
% and \subparagraph{...} as necessary.
jan@42463
   160
%
jan@42463
   161
neuper@42464
   162
\section{Introduction}\label{intro}
jan@42463
   163
jan@42466
   164
% \paragraph{Didactics of mathematics} 
jan@42466
   165
%WN: wenn man in einem high-quality paper von 'didactics' spricht, 
jan@42466
   166
%WN muss man am state-of-the-art ankn"upfen -- siehe
jan@42466
   167
%WN W.Neuper, On the Emergence of TP-based Educational Math Assistants
neuper@42464
   168
% faces a specific issue, a gap
neuper@42464
   169
% between (1) introduction of math concepts and skills and (2)
neuper@42464
   170
% application of these concepts and skills, which usually are separated
neuper@42464
   171
% into different units in curricula (for good reasons). For instance,
neuper@42464
   172
% (1) teaching partial fraction decomposition is separated from (2)
neuper@42464
   173
% application for inverse Z-transform in signal processing.
neuper@42464
   174
% 
neuper@42464
   175
% \par This gap is an obstacle for applying math as an fundamental
neuper@42464
   176
% thinking technology in engineering: In (1) motivation is lacking
neuper@42464
   177
% because the question ``What is this stuff good for?'' cannot be
neuper@42464
   178
% treated sufficiently, and in (2) the ``stuff'' is not available to
neuper@42464
   179
% students in higher semesters as widespread experience shows.
neuper@42464
   180
% 
neuper@42464
   181
% \paragraph{Motivation} taken by this didactic issue on the one hand,
neuper@42464
   182
% and ongoing research and development on a novel kind of educational
neuper@42464
   183
% mathematics assistant at Graz University of
neuper@42464
   184
% Technology~\footnote{http://www.ist.tugraz.at/isac/} promising to
neuper@42464
   185
% scope with this issue on the other hand, several institutes are
neuper@42464
   186
% planning to join their expertise: the Institute for Information
neuper@42464
   187
% Systems and Computer Media (IICM), the Institute for Software
neuper@42464
   188
% Technology (IST), the Institutes for Mathematics, the Institute for
neuper@42464
   189
% Signal Processing and Speech Communication (SPSC), the Institute for
neuper@42464
   190
% Structural Analysis and the Institute of Electrical Measurement and
neuper@42464
   191
% Measurement Signal Processing.
jan@42466
   192
%WN diese Information ist f"ur das Paper zu spezielle, zu aktuell 
jan@42466
   193
%WN und damit zu verg"anglich.
neuper@42464
   194
% \par This thesis is the first attempt to tackle the above mentioned
neuper@42464
   195
% issue, it focuses on Telematics, because these specific studies focus
neuper@42464
   196
% on mathematics in \emph{STEOP}, the introductory orientation phase in
neuper@42464
   197
% Austria. \emph{STEOP} is considered an opportunity to investigate the
neuper@42464
   198
% impact of {\sisac}'s prototype on the issue and others.
neuper@42464
   199
% 
jan@42466
   200
jan@42502
   201
Traditional course material in engineering disciplines lacks an
neuper@42464
   202
important component, interactive support for step-wise problem
neuper@42464
   203
solving. Theorem-Proving (TP) technology can provide such support by
neuper@42464
   204
specific services. An important part of such services is called
neuper@42464
   205
``next-step-guidance'', generated by a specific kind of ``TP-based
neuper@42464
   206
programming language''. In the
neuper@42464
   207
{\sisac}-project~\footnote{http://www.ist.tugraz.at/projects/isac/} such
neuper@42464
   208
a language is prototyped in line with~\cite{plmms10} and built upon
neuper@42464
   209
the theorem prover
neuper@42464
   210
Isabelle~\cite{Nipkow-Paulson-Wenzel:2002}\footnote{http://isabelle.in.tum.de/}.
neuper@42464
   211
The TP services are coordinated by a specific interpreter for the
neuper@42464
   212
programming language, called
neuper@42464
   213
Lucas-Interpreter~\cite{wn:lucas-interp-12}. The language and the
neuper@42464
   214
interpreter will be briefly re-introduced in order to make the paper
neuper@42464
   215
self-contained.
jan@42463
   216
neuper@42504
   217
The main part of the paper is an account of first experiences
neuper@42464
   218
with programming in this TP-based language. The experience was gained
neuper@42464
   219
in a case study by the author. The author was considered an ideal
neuper@42464
   220
candidate for this study for the following reasons: as a student in
neuper@42464
   221
Telematics (computer science with focus on Signal Processing) he had
neuper@42464
   222
general knowledge in programming as well as specific domain knowledge
neuper@42504
   223
in Signal Processing; and he was {\em not} involved in the development of
neuper@42464
   224
{\sisac}'s programming language and interpeter, thus a novice to the
neuper@42464
   225
language.
jan@42463
   226
neuper@42504
   227
The goal of the case study was (1) some TP-based programs for
neuper@42464
   228
interactive course material for a specific ``Adavanced Signal
neuper@42464
   229
Processing Lab'' in a higher semester, (2) respective program
neuper@42464
   230
development with as little advice from the {\sisac}-team and (3) records
neuper@42464
   231
and comments for the main steps of development in an Isabelle theory;
neuper@42464
   232
this theory should provide guidelines for future programmers. An
neuper@42464
   233
excerpt from this theory is the main part of this paper.
jan@42466
   234
\par
jan@42466
   235
The paper will use the problem in Fig.\ref{fig-interactive} as a
jan@42463
   236
running example:
jan@42463
   237
\begin{figure} [htb]
jan@42463
   238
\begin{center}
neuper@42468
   239
\includegraphics[width=140mm]{fig/isac-Ztrans-math-3}
neuper@42468
   240
%\includegraphics[width=140mm]{fig/isac-Ztrans-math}
jan@42463
   241
\caption{Step-wise problem solving guided by the TP-based program}
jan@42463
   242
\label{fig-interactive}
jan@42463
   243
\end{center}
jan@42463
   244
\end{figure}
jan@42466
   245
jan@42502
   246
The problem is from the domain of Signal Processing and requests to
neuper@42504
   247
determine the inverse ${\cal Z}$-transform for a given term. Fig.\ref{fig-interactive}
neuper@42464
   248
also shows the beginning of the interactive construction of a solution
neuper@42464
   249
for the problem. This construction is done in the right window named
neuper@42464
   250
``Worksheet''.
jan@42466
   251
\par
neuper@42464
   252
User-interaction on the Worksheet is {\em checked} and {\em guided} by
neuper@42464
   253
TP services:
neuper@42464
   254
\begin{enumerate}
neuper@42464
   255
\item Formulas input by the user are {\em checked} by TP: such a
neuper@42464
   256
formula establishes a proof situation --- the prover has to derive the
neuper@42464
   257
formula from the logical context. The context is built up from the
neuper@42464
   258
formal specification of the problem (here hidden from the user) by the
neuper@42464
   259
Lucas-Interpreter.
neuper@42464
   260
\item If the user gets stuck, the program developed below in this
neuper@42504
   261
paper ``knows the next step'' and Lucas-Interpretation provides services
neuper@42504
   262
featuring so-called ``next-step-guidance''; this is out of scope of this
neuper@42464
   263
paper and can be studied in~\cite{gdaroczy-EP-13}.
neuper@42464
   264
\end{enumerate} It should be noted that the programmer using the
neuper@42464
   265
TP-based language is not concerned with interaction at all; we will
neuper@42464
   266
see that the program contains neither input-statements nor
neuper@42504
   267
output-statements. Rather, interaction is handled by the interpreter
neuper@42504
   268
pf the language.
neuper@42504
   269
neuper@42504
   270
So there is a clear separation of concerns: Dialogues are adapted by
neuper@42504
   271
dialogue authors (in Java-based tools), using TP services provided by
neuper@42504
   272
Lucas-Interpretation. The latter acts on programs developed by
neuper@42504
   273
mathematics-authors (in Isabelle/ML); their task is concern of this
neuper@42464
   274
paper.
jan@42466
   275
jan@42466
   276
\paragraph{The paper is structed} as follows: The introduction
neuper@42464
   277
\S\ref{intro} is followed by a brief re-introduction of the TP-based
neuper@42464
   278
programming language in \S\ref{PL}, which extends the executable
neuper@42464
   279
fragment of Isabelle's language (\S\ref{PL-isab}) by tactics which
neuper@42464
   280
play a specific role in Lucas-Interpretation and in providing the TP
neuper@42504
   281
services (\S\ref{PL-tacs}). The main part \S\ref{trial} describes
neuper@42464
   282
the main steps in developing the program for the running example:
neuper@42464
   283
prepare domain knowledge, implement the formal specification of the
neuper@42504
   284
problem, prepare the environment for the interpreter, implement the
neuper@42504
   285
program in \S\ref{isabisac} to \S\ref{progr} respectively. 
neuper@42504
   286
The workflow of programming, debugging and testing is
neuper@42464
   287
described in \S\ref{workflow}. The conclusion \S\ref{conclusion} will
neuper@42464
   288
give directions identified for future development. 
neuper@42464
   289
jan@42463
   290
jan@42463
   291
\section{\isac's Prototype for a Programming Language}\label{PL} 
neuper@42504
   292
The prototype of the language and of the Lucas-Interpreter are briefly
neuper@42504
   293
described from the point of view of a programmer. The language extends
neuper@42504
   294
the executable fragment in the language of the theorem prover
neuper@42504
   295
Isabelle~\cite{Nipkow-Paulson-Wenzel:2002}\footnote{http://isabelle.in.tum.de/}.
jan@42463
   296
jan@42463
   297
\subsection{The Executable Fragment of Isabelle's Language}\label{PL-isab}
jan@42463
   298
The executable fragment consists of data-type and function
jan@42463
   299
definitions.  It's usability even suggests that fragment for
jan@42463
   300
introductory courses \cite{nipkow-prog-prove}. HOL is a typed logic
jan@42463
   301
whose type system resembles that of functional programming
jan@42463
   302
languages. Thus there are
jan@42463
   303
\begin{description}
jan@42463
   304
\item[base types,] in particular \textit{bool}, the type of truth
jan@42463
   305
values, \textit{nat}, \textit{int}, \textit{complex}, and the types of
jan@42463
   306
natural, integer and complex numbers respectively in mathematics.
jan@42463
   307
\item[type constructors] allow to define arbitrary types, from
jan@42463
   308
\textit{set}, \textit{list} to advanced data-structures like
jan@42463
   309
\textit{trees}, red-black-trees etc.
jan@42463
   310
\item[function types,] denoted by $\Rightarrow$.
jan@42463
   311
\item[type variables,] denoted by $^\prime a, ^\prime b$ etc, provide
jan@42463
   312
type polymorphism. Isabelle automatically computes the type of each
jan@42463
   313
variable in a term by use of Hindley-Milner type inference
jan@42463
   314
\cite{pl:hind97,Milner-78}.
jan@42463
   315
\end{description}
jan@42463
   316
jan@42463
   317
\textbf{Terms} are formed as in functional programming by applying
jan@42463
   318
functions to arguments. If $f$ is a function of type
jan@42463
   319
$\tau_1\Rightarrow \tau_2$ and $t$ is a term of type $\tau_1$ then
jan@42463
   320
$f\;t$ is a term of type~$\tau_2$. $t\;::\;\tau$ means that term $t$
jan@42463
   321
has type $\tau$. There are many predefined infix symbols like $+$ and
jan@42463
   322
$\leq$ most of which are overloaded for various types.
jan@42463
   323
jan@42463
   324
HOL also supports some basic constructs from functional programming:
jan@42463
   325
{\it\label{isabelle-stmts}
jan@42463
   326
\begin{tabbing} 123\=\kill
jan@42463
   327
\>$( \; {\tt if} \; b \; {\tt then} \; t_1 \; {\tt else} \; t_2 \;)$\\
jan@42463
   328
\>$( \; {\tt let} \; x=t \; {\tt in} \; u \; )$\\
jan@42463
   329
\>$( \; {\tt case} \; t \; {\tt of} \; {\it pat}_1
jan@42463
   330
  \Rightarrow t_1 \; |\dots| \; {\it pat}_n\Rightarrow t_n \; )$
jan@42463
   331
\end{tabbing} }
neuper@42482
   332
\noindent The running example's program uses some of these elements
neuper@42482
   333
(marked by {\tt tt-font} on p.\pageref{s:impl}): for instance {\tt
neuper@42482
   334
let}\dots{\tt in} in lines {\rm 02} \dots {\rm 13}. In fact, the whole program
neuper@42482
   335
is an Isabelle term with specific function constants like {\tt
neuper@42482
   336
program}, {\tt Take}, {\tt Rewrite}, {\tt Subproblem} and {\tt
neuper@42482
   337
Rewrite\_Set} in lines {\rm 01, 03. 04, 07, 10} and {\rm 11, 12}
neuper@42482
   338
respectively.
jan@42463
   339
jan@42463
   340
% Terms may also contain $\lambda$-abstractions. For example, $\lambda
jan@42463
   341
% x. \; x$ is the identity function.
jan@42463
   342
neuper@42467
   343
%JR warum auskommentiert? WN2...
neuper@42467
   344
%WN2 weil ein Punkt wie dieser in weiteren Zusammenh"angen innerhalb
neuper@42467
   345
%WN2 des Papers auftauchen m"usste; nachdem ich einen solchen
neuper@42467
   346
%WN2 Zusammenhang _noch_ nicht sehe, habe ich den Punkt _noch_ nicht
neuper@42467
   347
%WN2 gel"oscht.
neuper@42467
   348
%WN2 Wenn der Punkt nicht weiter gebraucht wird, nimmt er nur wertvollen
neuper@42467
   349
%WN2 Platz f"ur Anderes weg.
jan@42466
   350
neuper@42464
   351
\textbf{Formulae} are terms of type \textit{bool}. There are the basic
jan@42463
   352
constants \textit{True} and \textit{False} and the usual logical
jan@42463
   353
connectives (in decreasing order of precedence): $\neg, \land, \lor,
jan@42463
   354
\rightarrow$.
jan@42463
   355
neuper@42464
   356
\textbf{Equality} is available in the form of the infix function $=$
neuper@42464
   357
of type $a \Rightarrow a \Rightarrow {\it bool}$. It also works for
neuper@42464
   358
formulas, where it means ``if and only if''.
jan@42463
   359
jan@42463
   360
\textbf{Quantifiers} are written $\forall x. \; P$ and $\exists x. \;
jan@42463
   361
P$.  Quantifiers lead to non-executable functions, so functions do not
jan@42463
   362
always correspond to programs, for instance, if comprising \\$(
jan@42463
   363
\;{\it if} \; \exists x.\;P \; {\it then} \; e_1 \; {\it else} \; e_2
jan@42463
   364
\;)$.
jan@42463
   365
jan@42463
   366
\subsection{\isac's Tactics for Lucas-Interpretation}\label{PL-tacs}
jan@42463
   367
The prototype extends Isabelle's language by specific statements
neuper@42464
   368
called tactics~\footnote{{\sisac}'s tactics are different from
jan@42463
   369
Isabelle's tactics: the former concern steps in a calculation, the
neuper@42504
   370
latter concern proofs.}  and tacticals. For the programmer these
jan@42463
   371
statements are functions with the following signatures:
jan@42463
   372
jan@42463
   373
\begin{description}
jan@42463
   374
\item[Rewrite:] ${\it theorem}\Rightarrow{\it term}\Rightarrow{\it
jan@42463
   375
term} * {\it term}\;{\it list}$:
jan@42463
   376
this tactic appplies {\it theorem} to a {\it term} yielding a {\it
jan@42463
   377
term} and a {\it term list}, the list are assumptions generated by
jan@42463
   378
conditional rewriting. For instance, the {\it theorem}
jan@42463
   379
$b\not=0\land c\not=0\Rightarrow\frac{a\cdot c}{b\cdot c}=\frac{a}{b}$
jan@42463
   380
applied to the {\it term} $\frac{2\cdot x}{3\cdot x}$ yields
jan@42463
   381
$(\frac{2}{3}, [x\not=0])$.
jan@42463
   382
jan@42463
   383
\item[Rewrite\_Set:] ${\it ruleset}\Rightarrow{\it
jan@42463
   384
term}\Rightarrow{\it term} * {\it term}\;{\it list}$:
jan@42463
   385
this tactic appplies {\it ruleset} to a {\it term}; {\it ruleset} is
jan@42463
   386
a confluent and terminating term rewrite system, in general. If
jan@42463
   387
none of the rules ({\it theorem}s) is applicable on interpretation
jan@42463
   388
of this tactic, an exception is thrown.
jan@42463
   389
jan@42463
   390
% \item[Rewrite\_Inst:] ${\it substitution}\Rightarrow{\it
jan@42463
   391
% theorem}\Rightarrow{\it term}\Rightarrow{\it term} * {\it term}\;{\it
jan@42463
   392
% list}$:
jan@42463
   393
% 
jan@42463
   394
% \item[Rewrite\_Set\_Inst:] ${\it substitution}\Rightarrow{\it
jan@42463
   395
% ruleset}\Rightarrow{\it term}\Rightarrow{\it term} * {\it term}\;{\it
jan@42463
   396
% list}$:
jan@42463
   397
neuper@42504
   398
%SPACEvvv
jan@42463
   399
\item[Substitute:] ${\it substitution}\Rightarrow{\it
neuper@42482
   400
term}\Rightarrow{\it term}$: allows to access sub-terms.
neuper@42504
   401
%SPACE^^^
jan@42463
   402
jan@42463
   403
\item[Take:] ${\it term}\Rightarrow{\it term}$:
jan@42463
   404
this tactic has no effect in the program; but it creates a side-effect
jan@42463
   405
by Lucas-Interpretation (see below) and writes {\it term} to the
jan@42463
   406
Worksheet.
jan@42463
   407
jan@42463
   408
\item[Subproblem:] ${\it theory} * {\it specification} * {\it
jan@42463
   409
method}\Rightarrow{\it argument}\;{\it list}\Rightarrow{\it term}$:
neuper@42482
   410
this tactic is a generalisation of a function call: it takes an
neuper@42482
   411
\textit{argument list} as usual, and additionally a triple consisting
neuper@42482
   412
of an Isabelle \textit{theory}, an implicit \textit{specification} of the
neuper@42482
   413
program and a \textit{method} containing data for Lucas-Interpretation,
neuper@42482
   414
last not least a program (as an explicit specification)~\footnote{In
neuper@42482
   415
interactive tutoring these three items can be determined explicitly
neuper@42482
   416
by the user.}.
jan@42463
   417
\end{description}
jan@42463
   418
The tactics play a specific role in
jan@42463
   419
Lucas-Interpretation~\cite{wn:lucas-interp-12}: they are treated as
neuper@42482
   420
break-points where, as a side-effect, a line is added to a calculation
neuper@42483
   421
as a protocol for proceeding towards a solution in step-wise problem
neuper@42483
   422
solving. At the same points Lucas-Interpretation serves interactive
neuper@42504
   423
tutoring and hands over control to the user. The user is free to
neuper@42483
   424
investigate underlying knowledge, applicable theorems, etc.  And the
neuper@42483
   425
user can proceed constructing a solution by input of a tactic to be
neuper@42483
   426
applied or by input of a formula; in the latter case the
jan@42463
   427
Lucas-Interpreter has built up a logical context (initialised with the
jan@42463
   428
precondition of the formal specification) such that Isabelle can
jan@42463
   429
derive the formula from this context --- or give feedback, that no
jan@42463
   430
derivation can be found.
jan@42463
   431
neuper@42496
   432
\subsection{Tacticals as Control Flow Statements}
jan@42463
   433
The flow of control in a program can be determined by {\tt if then else}
jan@42463
   434
and {\tt case of} as mentioned on p.\pageref{isabelle-stmts} and also
jan@42463
   435
by additional tacticals:
jan@42463
   436
\begin{description}
jan@42463
   437
\item[Repeat:] ${\it tactic}\Rightarrow{\it term}\Rightarrow{\it
jan@42463
   438
term}$: iterates over tactics which take a {\it term} as argument as
neuper@42482
   439
long as a tactic is applicable (for instance, {\tt Rewrite\_Set} might
jan@42463
   440
not be applicable).
jan@42463
   441
jan@42463
   442
\item[Try:] ${\it tactic}\Rightarrow{\it term}\Rightarrow{\it term}$:
jan@42463
   443
if {\it tactic} is applicable, then it is applied to {\it term},
neuper@42483
   444
otherwise {\it term} is passed on without changes.
jan@42463
   445
jan@42463
   446
\item[Or:] ${\it tactic}\Rightarrow{\it tactic}\Rightarrow{\it
neuper@42483
   447
term}\Rightarrow{\it term}$: If the first {\it tactic} is applicable,
neuper@42483
   448
it is applied to the first {\it term} yielding another {\it term},
neuper@42483
   449
otherwise the second {\it tactic} is applied; if none is applicable an
neuper@42483
   450
exception is raised.
jan@42463
   451
jan@42463
   452
\item[@@:] ${\it tactic}\Rightarrow{\it tactic}\Rightarrow{\it
neuper@42483
   453
term}\Rightarrow{\it term}$: applies the first {\it tactic} to the
neuper@42483
   454
first {\it term} yielding an intermediate term (not appearing in the
neuper@42483
   455
signature) to which the second {\it tactic} is applied.
jan@42463
   456
jan@42463
   457
\item[While:] ${\it term::bool}\Rightarrow{\it tactic}\Rightarrow{\it
neuper@42483
   458
term}\Rightarrow{\it term}$: if the first {\it term} is true, then the
neuper@42483
   459
{\it tactic} is applied to the first {\it term} yielding an
neuper@42483
   460
intermediate term (not appearing in the signature); the intermediate
neuper@42483
   461
term is added to the environment the first {\it term} is evaluated in
neuper@42483
   462
etc as long as the first {\it term} is true.
jan@42463
   463
\end{description}
neuper@42483
   464
The tacticals are not treated as break-points by Lucas-Interpretation
neuper@42504
   465
and thus do neither contribute to the calculation nor to interaction.
jan@42463
   466
neuper@42498
   467
\section{Concepts and Tasks in TP-based Programming}\label{trial}
neuper@42498
   468
%\section{Development of a Program on Trial}
neuper@42498
   469
neuper@42498
   470
This section presents all the concepts involved in TP-based
neuper@42498
   471
programming and all the tasks to be accomplished by programmers. The
neuper@42504
   472
presentation uses the running example from
neuper@42498
   473
Fig.\ref{fig-interactive} on p.\pageref{fig-interactive}.
jan@42466
   474
jan@42466
   475
\subsection{Mechanization of Math --- Domain Engineering}\label{isabisac}
jan@42466
   476
neuper@42467
   477
%WN was Fachleute unter obigem Titel interessiert findet sich
jan@42466
   478
%WN unterhalb des auskommentierten Textes.
jan@42466
   479
jan@42466
   480
%WN der Text unten spricht Benutzer-Aspekte anund ist nicht speziell
jan@42466
   481
%WN auf Computer-Mathematiker fokussiert.
neuper@42464
   482
% \paragraph{As mentioned in the introduction,} a prototype of an
neuper@42464
   483
% educational math assistant called
neuper@42464
   484
% {{\sisac}}\footnote{{{\sisac}}=\textbf{Isa}belle for
neuper@42464
   485
% \textbf{C}alculations, see http://www.ist.tugraz.at/isac/.} bridges
neuper@42464
   486
% the gap between (1) introducation and (2) application of mathematics:
neuper@42464
   487
% {{\sisac}} is based on Computer Theorem Proving (TP), a technology which
neuper@42464
   488
% requires each fact and each action justified by formal logic, so
neuper@42464
   489
% {{{\sisac}{}}} makes justifications transparent to students in
neuper@42464
   490
% interactive step-wise problem solving. By that way {{\sisac}} already
neuper@42464
   491
% can serve both:
neuper@42464
   492
% \begin{enumerate}
neuper@42464
   493
%   \item Introduction of math stuff (in e.g. partial fraction
neuper@42464
   494
% decomposition) by stepwise explaining and exercising respective
neuper@42464
   495
% symbolic calculations with ``next step guidance (NSG)'' and rigorously
neuper@42464
   496
% checking steps freely input by students --- this also in context with
neuper@42464
   497
% advanced applications (where the stuff to be taught in higher
neuper@42464
   498
% semesters can be skimmed through by NSG), and
neuper@42464
   499
%   \item Application of math stuff in advanced engineering courses
neuper@42464
   500
% (e.g. problems to be solved by inverse Z-transform in a Signal
neuper@42464
   501
% Processing Lab) and now without much ado about basic math techniques
neuper@42464
   502
% (like partial fraction decomposition): ``next step guidance'' supports
neuper@42464
   503
% students in independently (re-)adopting such techniques.
neuper@42464
   504
% \end{enumerate} 
neuper@42464
   505
% Before the question is answers, how {{\sisac}}
neuper@42464
   506
% accomplishes this task from a technical point of view, some remarks on
neuper@42464
   507
% the state-of-the-art is given, therefor follow up Section~\ref{emas}.
neuper@42464
   508
% 
neuper@42464
   509
% \subsection{Educational Mathematics Assistants (EMAs)}\label{emas}
neuper@42464
   510
% 
jan@42466
   511
% \paragraph{Educational software in mathematics} is, if at all, based
jan@42466
   512
% on Computer Algebra Systems (CAS, for instance), Dynamic Geometry
jan@42466
   513
% Systems (DGS, for instance \footnote{GeoGebra http://www.geogebra.org}
jan@42466
   514
% \footnote{Cinderella http://www.cinderella.de/}\footnote{GCLC
jan@42466
   515
% http://poincare.matf.bg.ac.rs/~janicic/gclc/}) or spread-sheets. These
jan@42466
   516
% base technologies are used to program math lessons and sometimes even
jan@42466
   517
% exercises. The latter are cumbersome: the steps towards a solution of
jan@42466
   518
% such an interactive exercise need to be provided with feedback, where
jan@42466
   519
% at each step a wide variety of possible input has to be foreseen by
jan@42466
   520
% the programmer - so such interactive exercises either require high
neuper@42464
   521
% development efforts or the exercises constrain possible inputs.
neuper@42464
   522
% 
jan@42466
   523
% \subparagraph{A new generation} of educational math assistants (EMAs)
jan@42466
   524
% is emerging presently, which is based on Theorem Proving (TP). TP, for
jan@42466
   525
% instance Isabelle and Coq, is a technology which requires each fact
jan@42466
   526
% and each action justified by formal logic. Pushed by demands for
jan@42466
   527
% \textit{proven} correctness of safety-critical software TP advances
jan@42466
   528
% into software engineering; from these advancements computer
jan@42466
   529
% mathematics benefits in general, and math education in particular. Two
neuper@42464
   530
% features of TP are immediately beneficial for learning:
neuper@42464
   531
% 
jan@42466
   532
% \paragraph{TP have knowledge in human readable format,} that is in
jan@42466
   533
% standard predicate calculus. TP following the LCF-tradition have that
jan@42466
   534
% knowledge down to the basic definitions of set, equality,
jan@42466
   535
% etc~\footnote{http://isabelle.in.tum.de/dist/library/HOL/HOL.html};
jan@42466
   536
% following the typical deductive development of math, natural numbers
jan@42466
   537
% are defined and their properties
jan@42466
   538
% proven~\footnote{http://isabelle.in.tum.de/dist/library/HOL/Number\_Theory/Primes.html},
jan@42466
   539
% etc. Present knowledge mechanized in TP exceeds high-school
jan@42466
   540
% mathematics by far, however by knowledge required in software
neuper@42464
   541
% technology, and not in other engineering sciences.
neuper@42464
   542
% 
jan@42466
   543
% \paragraph{TP can model the whole problem solving process} in
jan@42466
   544
% mathematical problem solving {\em within} a coherent logical
jan@42466
   545
% framework. This is already being done by three projects, by
neuper@42464
   546
% Ralph-Johan Back, by ActiveMath and by Carnegie Mellon Tutor.
neuper@42464
   547
% \par
jan@42466
   548
% Having the whole problem solving process within a logical coherent
jan@42466
   549
% system, such a design guarantees correctness of intermediate steps and
jan@42466
   550
% of the result (which seems essential for math software); and the
jan@42466
   551
% second advantage is that TP provides a wealth of theories which can be
jan@42466
   552
% exploited for mechanizing other features essential for educational
neuper@42464
   553
% software.
neuper@42464
   554
% 
neuper@42464
   555
% \subsubsection{Generation of User Guidance in EMAs}\label{user-guid}
neuper@42464
   556
% 
jan@42466
   557
% One essential feature for educational software is feedback to user
neuper@42464
   558
% input and assistance in coming to a solution.
neuper@42464
   559
% 
jan@42466
   560
% \paragraph{Checking user input} by ATP during stepwise problem solving
jan@42466
   561
% is being accomplished by the three projects mentioned above
jan@42466
   562
% exclusively. They model the whole problem solving process as mentioned
jan@42466
   563
% above, so all what happens between formalized assumptions (or formal
jan@42466
   564
% specification) and goal (or fulfilled postcondition) can be
jan@42466
   565
% mechanized. Such mechanization promises to greatly extend the scope of
neuper@42464
   566
% educational software in stepwise problem solving.
neuper@42464
   567
% 
jan@42466
   568
% \paragraph{NSG (Next step guidance)} comprises the system's ability to
jan@42466
   569
% propose a next step; this is a challenge for TP: either a radical
jan@42466
   570
% restriction of the search space by restriction to very specific
jan@42466
   571
% problem classes is required, or much care and effort is required in
jan@42466
   572
% designing possible variants in the process of problem solving
neuper@42464
   573
% \cite{proof-strategies-11}.
neuper@42464
   574
% \par
jan@42466
   575
% Another approach is restricted to problem solving in engineering
jan@42466
   576
% domains, where a problem is specified by input, precondition, output
jan@42466
   577
% and postcondition, and where the postcondition is proven by ATP behind
jan@42466
   578
% the scenes: Here the possible variants in the process of problem
jan@42466
   579
% solving are provided with feedback {\em automatically}, if the problem
jan@42466
   580
% is described in a TP-based programing language: \cite{plmms10} the
jan@42466
   581
% programmer only describes the math algorithm without caring about
jan@42466
   582
% interaction (the respective program is functional and even has no
jan@42466
   583
% input or output statements!); interaction is generated as a
jan@42466
   584
% side-effect by the interpreter --- an efficient separation of concern
jan@42466
   585
% between math programmers and dialog designers promising application
neuper@42464
   586
% all over engineering disciplines.
neuper@42464
   587
% 
neuper@42464
   588
% 
neuper@42464
   589
% \subsubsection{Math Authoring in Isabelle/ISAC\label{math-auth}}
jan@42466
   590
% Authoring new mathematics knowledge in {{\sisac}} can be compared with
jan@42466
   591
% ``application programing'' of engineering problems; most of such
jan@42466
   592
% programing uses CAS-based programing languages (CAS = Computer Algebra
neuper@42464
   593
% Systems; e.g. Mathematica's or Maple's programing language).
neuper@42464
   594
% 
jan@42466
   595
% \paragraph{A novel type of TP-based language} is used by {{\sisac}{}}
jan@42466
   596
% \cite{plmms10} for describing how to construct a solution to an
jan@42466
   597
% engineering problem and for calling equation solvers, integration,
jan@42466
   598
% etc~\footnote{Implementation of CAS-like functionality in TP is not
jan@42466
   599
% primarily concerned with efficiency, but with a didactic question:
jan@42466
   600
% What to decide for: for high-brow algorithms at the state-of-the-art
jan@42466
   601
% or for elementary algorithms comprehensible for students?} within TP;
jan@42466
   602
% TP can ensure ``systems that never make a mistake'' \cite{casproto} -
neuper@42464
   603
% are impossible for CAS which have no logics underlying.
neuper@42464
   604
% 
jan@42466
   605
% \subparagraph{Authoring is perfect} by writing such TP based programs;
jan@42466
   606
% the application programmer is not concerned with interaction or with
jan@42466
   607
% user guidance: this is concern of a novel kind of program interpreter
jan@42466
   608
% called Lucas-Interpreter. This interpreter hands over control to a
jan@42466
   609
% dialog component at each step of calculation (like a debugger at
jan@42466
   610
% breakpoints) and calls automated TP to check user input following
neuper@42464
   611
% personalized strategies according to a feedback module.
neuper@42464
   612
% \par
jan@42466
   613
% However ``application programing with TP'' is not done with writing a
jan@42466
   614
% program: according to the principles of TP, each step must be
jan@42466
   615
% justified. Such justifications are given by theorems. So all steps
jan@42466
   616
% must be related to some theorem, if there is no such theorem it must
jan@42466
   617
% be added to the existing knowledge, which is organized in so-called
jan@42466
   618
% \textbf{theories} in Isabelle. A theorem must be proven; fortunately
jan@42466
   619
% Isabelle comprises a mechanism (called ``axiomatization''), which
jan@42466
   620
% allows to omit proofs. Such a theorem is shown in
neuper@42464
   621
% Example~\ref{eg:neuper1}.
jan@42466
   622
neuper@42498
   623
The running example requires to determine the inverse $\cal
jan@42466
   624
Z$-transform for a class of functions. The domain of Signal Processing
jan@42466
   625
is accustomed to specific notation for the resulting functions, which
neuper@42504
   626
are absolutely summable and are called step-response: $u[n]$, where $u$ is the
jan@42466
   627
function, $n$ is the argument and the brackets indicate that the
neuper@42504
   628
arguments are discrete. Surprisingly, Isabelle accepts the rules for
jan@42466
   629
${\cal Z}^{-1}$ in this traditional notation~\footnote{Isabelle
jan@42466
   630
experts might be particularly surprised, that the brackets do not
jan@42466
   631
cause errors in typing (as lists).}:
neuper@42464
   632
%\vbox{
neuper@42464
   633
% \begin{example}
jan@42463
   634
  \label{eg:neuper1}
jan@42463
   635
  {\small\begin{tabbing}
jan@42463
   636
  123\=123\=123\=123\=\kill
jan@42463
   637
  \hfill \\
jan@42463
   638
  \>axiomatization where \\
neuper@42464
   639
  \>\>  rule1: ``${\cal Z}^{-1}\;1 = \delta [n]$'' and\\
neuper@42464
   640
  \>\>  rule2: ``$\vert\vert z \vert\vert > 1 \Rightarrow {\cal Z}^{-1}\;z / (z - 1) = u [n]$'' and\\
jan@42466
   641
  \>\>  rule3: ``$\vert\vert$ z $\vert\vert$ < 1 ==> z / (z - 1) = -u [-n - 1]'' and \\
jan@42466
   642
%TODO
jan@42466
   643
  \>\>  rule4: ``$\vert\vert$ z $\vert\vert$ > $\vert\vert$ $\alpha$ $\vert\vert$ ==> z / (z - $\alpha$) = $\alpha^n$ $\cdot$ u [n]'' and\\
jan@42466
   644
%TODO
jan@42466
   645
  \>\>  rule5: ``$\vert\vert$ z $\vert\vert$ < $\vert\vert$ $\alpha$ $\vert\vert$ ==> z / (z - $\alpha$) = -($\alpha^n$) $\cdot$ u [-n - 1]'' and\\
jan@42466
   646
%TODO
jan@42466
   647
  \>\>  rule6: ``$\vert\vert$ z $\vert\vert$ > 1 ==> z/(z - 1)$^2$ = n $\cdot$ u [n]''\\
jan@42466
   648
%TODO
jan@42463
   649
  \end{tabbing}
jan@42463
   650
  }
neuper@42464
   651
% \end{example}
jan@42466
   652
%}
jan@42466
   653
These 6 rules can be used as conditional rewrite rules, depending on
jan@42466
   654
the respective convergence radius. Satisfaction from accordance with traditional notation
jan@42466
   655
contrasts with the above word {\em axiomatization}: As TP-based, the
jan@42466
   656
programming language expects these rules as {\em proved} theorems, and
jan@42466
   657
not as axioms implemented in the above brute force manner; otherwise
jan@42466
   658
all the verification efforts envisaged (like proof of the
jan@42466
   659
post-condition, see below) would be meaningless.
jan@42466
   660
jan@42466
   661
Isabelle provides a large body of knowledge, rigorously proven from
jan@42466
   662
the basic axioms of mathematics~\footnote{This way of rigorously
jan@42466
   663
deriving all knowledge from first principles is called the
neuper@42504
   664
LCF-paradigm in TP.}. In the case of the ${\cal Z}$-Transform the most advanced
jan@42466
   665
knowledge can be found in the theoris on Multivariate
jan@42466
   666
Analysis~\footnote{http://isabelle.in.tum.de/dist/library/HOL/HOL-Multivariate\_Analysis}. However,
jan@42466
   667
building up knowledge such that a proof for the above rules would be
jan@42466
   668
reasonably short and easily comprehensible, still requires lots of
jan@42466
   669
work (and is definitely out of scope of our case study).
jan@42466
   670
neuper@42487
   671
At the state-of-the-art in mechanization of knowledge in engineering
neuper@42487
   672
sciences, the process does not stop with the mechanization of
neuper@42487
   673
mathematics traditionally used in these sciences. Rather, ``Formal
neuper@42487
   674
Methods''~\cite{ fm-03} are expected to proceed to formal and explicit
neuper@42487
   675
description of physical items.  Signal Processing, for instance is
neuper@42487
   676
concerned with physical devices for signal acquisition and
neuper@42487
   677
reconstruction, which involve measuring a physical signal, storing it,
neuper@42487
   678
and possibly later rebuilding the original signal or an approximation
neuper@42487
   679
thereof. For digital systems, this typically includes sampling and
neuper@42487
   680
quantization; devices for signal compression, including audio
neuper@42487
   681
compression, image compression, and video compression, etc.  ``Domain
neuper@42487
   682
engineering''\cite{db:dom-eng} is concerned with {\em specification}
neuper@42487
   683
of these devices' components and features; this part in the process of
neuper@42487
   684
mechanization is only at the beginning in domains like Signal
neuper@42487
   685
Processing.
jan@42466
   686
neuper@42487
   687
TP-based programming, concern of this paper, is determined to
neuper@42504
   688
add ``algorithmic knowledge'' to the mechanised body of knowledge.
neuper@42504
   689
% in Fig.\ref{fig:mathuni} on
neuper@42504
   690
% p.\pageref{fig:mathuni}.  As we shall see below, TP-based programming
neuper@42504
   691
% starts with a formal {\em specification} of the problem to be solved.
neuper@42504
   692
% \begin{figure}
neuper@42504
   693
%   \begin{center}
neuper@42504
   694
%     \includegraphics[width=110mm]{../../fig/jrocnik/math-universe-small}
neuper@42504
   695
%     \caption{The three-dimensional universe of mathematics knowledge}
neuper@42504
   696
%     \label{fig:mathuni}
neuper@42504
   697
%   \end{center}
neuper@42504
   698
% \end{figure}
neuper@42504
   699
% The language for both axes is defined in the axis at the bottom, deductive
neuper@42504
   700
% knowledge, in {\sisac} represented by Isabelle's theories.
jan@42466
   701
jan@42466
   702
\subsection{Preparation of Simplifiers for the Program}\label{simp}
jan@42469
   703
neuper@42503
   704
If it is clear how the later calculation should look like
neuper@42503
   705
%WN3 ... Allgem.<-->Konkret ist gut: aber hier ist 'calculation'
neuper@42503
   706
%WN3 zu weit weg: der Satz geh"ort bestenfalls gleich an den
neuper@42503
   707
%WN3 Anfang von \sect.3
neuper@42503
   708
%WN3 
neuper@42503
   709
%WN3 Im Folgenden sind einige Ungenauigkeiten:
neuper@42503
   710
 and when
neuper@42503
   711
which mathematic rule 
neuper@42503
   712
%WN3 rewrite-rule oder theorem ! Ein Paper enth"alt viele Begriffe
neuper@42503
   713
%WN3 und man versucht, die Anzahl so gering wie m"oglich zu halten
neuper@42503
   714
%WN3 und die verbleibenden so pr"azise zu definieren wie m"oglich;
neuper@42503
   715
%WN3 das Vermeiden von Wiederholungen muss mit anderen Mitteln erfolgen,
neuper@42503
   716
%WN3 als dieselbe Sache mit verschiedenen Namen zu benennen;
neuper@42503
   717
%WN3 das gilt insbesonders f"ur technische Begriffe wie oben
neuper@42503
   718
should be applied, it can be started to find ways of
neuper@42503
   719
simplifications. 
neuper@42503
   720
%WN3 ... zu allgemein. Das Folgende w"urde durch einen Verweis in
neuper@42503
   721
%WN3 das Programm auf S.12 gewinnen.
neuper@42503
   722
This includes in e.g. the simplification of reational 
jan@42489
   723
expressions or also rewrites of an expession.
jan@42502
   724
\par
neuper@42503
   725
%WN3 das Folgende habe ich aus dem Beispielprogramm auf S.12
neuper@42503
   726
%WN3 gestrichen, weil es aus prinzipiellen Gr"unden unsch"on ist.
neuper@42503
   727
%WN3 Und es ist so kompliziert dass es mehr Platz zum Erkl"aren
neuper@42503
   728
%WN3 braucht, als es wert ist ...
jan@42502
   729
Obligate is the use of the function \texttt{drop\_questionmarks} 
jan@42489
   730
which excludes irrelevant symbols out of the expression. (Irrelevant symbols may 
jan@42489
   731
be result out of the system during the calculation. The function has to be
jan@42489
   732
applied for two reasons. First two make every placeholder in a expression 
jan@42489
   733
useable as a constant and second to provide a better view at the frontend.) 
jan@42502
   734
\par
neuper@42503
   735
%WN3 Da kommt eine ganze Reihe von Ungenauigkeiten:
neuper@42503
   736
Most rewrites are represented through rulesets
neuper@42503
   737
%WN3 ... das ist schlicht falsch:
neuper@42503
   738
%WN3 _alle_ rewrites werden durch rule-sets erzeugt (per definition
neuper@42503
   739
%WN3 dieser W"orter).
neuper@42503
   740
 this
jan@42489
   741
rulesets tell the machine which terms have to be rewritten into which
neuper@42503
   742
representation. 
neuper@42503
   743
%WN3 ... ist ein besonders "uberzeugendes Beispiel von Allgem.<-->Konkret:
neuper@42503
   744
%WN3 so allgemein, wie es hier steht, ist es
neuper@42503
   745
%WN3 # f"ur einen Fachmann klar und nicht ganz fachgem"ass formuliert
neuper@42503
   746
%WN3   (a rule-set rewrites a certain term into another with certain properties)
neuper@42503
   747
%WN3 # f"ur einen Nicht-Fachmann trotz allem unverst"andlich.
neuper@42503
   748
%WN3 
neuper@42503
   749
%WN3 Wenn schon allgemeine S"atze, dann unmittelbar auf das Beispiel
neuper@42503
   750
%WN3 unten verweisen,
neuper@42503
   751
%WN3 oder besser: den Satz dorthin schreiben, wo er unmittelbar vom
neuper@42503
   752
%WN3 Beispiel gefolgt wird.
neuper@42503
   753
In the upcoming programm a rewrite can be applied only in using
jan@42489
   754
such rulesets on existing terms.
neuper@42503
   755
%WN3 Du willst wohl soetwas sagen wie ...
neuper@42503
   756
%WN3 rewriting is the main concept to step-wise create and transform 
neuper@42503
   757
%WN3 formulas in order to proceed towards a solution of a problem
neuper@42503
   758
%WN3 ...?
jan@42489
   759
\paragraph{The core} of our implemented problem is the Z-Transformation
neuper@42503
   760
%WN3 ^^^^^ ist nicht gut: was soll THE CORE vermitteln, wenn man die
neuper@42503
   761
%WN3 Seite "uberfliegt ? Dass hier das Zentrum Deiner Arbeit liegt ?
neuper@42503
   762
%WN3 
neuper@42503
   763
%WN3 Das Folgende ist eine allgemeine Design-"Uberlegung, die entweder
neuper@42503
   764
%WN3 vorne zur Einf"uhrung des Beispiels geh"ort,
neuper@42503
   765
%WN3 oder zur konkreten L"osung durch die Rechnung auf S.15/16.
jan@42489
   766
(remember the description of the running example, introduced by
jan@42489
   767
Fig.\ref{fig-interactive} on p.\pageref{fig-interactive}) due the fact that the
jan@42489
   768
transformation itself would require higher math which isn't yet avaible in our system we decided to choose the way like it is applied in labratory and problem classes at our university - by applying transformation rules (collected in
jan@42489
   769
transformation tables).
jan@42502
   770
\par
neuper@42503
   771
%WN3 Zum Folgenden: 'axiomatization' ist schon in 3.1. angesprochen:
neuper@42503
   772
%WN3 entweder dort erg"anzen, wenn's wichtig ist, oder weglassen.
jan@42502
   773
Rules, in {\sisac{}}'s programming language can be designed by the use of
jan@42502
   774
axiomatization. In this axiomatization we declare how a term has to look like
jan@42502
   775
(left side) to be rewritten into another form (right side). Every line of this 
jan@42502
   776
axiomatizations starts with the name of the rule.
neuper@42503
   777
%WN3 Die folgenden Zeilen nehmen Platz weg: von hier auf S.6 verweisen
jan@42494
   778
%\begin{example}
jan@42502
   779
{\footnotesize
jan@42489
   780
  \label{eg:ruledef}
jan@42502
   781
%  \hfill\\
jan@42489
   782
  \begin{verbatim}
jan@42489
   783
  axiomatization where
jan@42489
   784
    rule1: ``1 = $\delta$[n]'' and
jan@42489
   785
    rule2: ``|| z || > 1 ==> z / (z - 1) = u [n]'' and
neuper@42503
   786
    rule3: ``|| z || < 1 ==> z / (z - 1) = -u [-n - 1]''
neuper@42503
   787
\end{verbatim}
jan@42494
   788
%\end{example}
jan@42502
   789
}
jan@42502
   790
jan@42502
   791
Rules can be summarized in a ruleset (collection of rules) and afterwards tried to be applied to a given expression as puttet over in following code.
neuper@42503
   792
%WN3 ... ist schon mehrmals gesagt worden. 1-mal pr"azise sagen gen"ugt.
neuper@42503
   793
%WN3 
neuper@42503
   794
%WN3 mit dem append_rls unten verbirgst Du die ganze Komplexit"at von
neuper@42503
   795
%WN3 rule-sets --- ich w"urde diese hier ausbreiten, damit man die
neuper@42503
   796
%WN3 Schwierigkeit von TP-based programming ermessen kann.
neuper@42503
   797
%WN3 Eine Erkl"arung wie in 3.4 und 3.5 braucht viel Platz, der sich
neuper@42503
   798
%WN3 meines Erachtens mehr auszahlt als die allgemeinen S"atze 
neuper@42503
   799
%WN3 am Ende von 3.2 auf S.8.
neuper@42503
   800
%WN3 
neuper@42503
   801
%WN3 mache ein 'grep -r "and rls";
neuper@42503
   802
%WN3 auch in Build_Inverse_Z_Transform.thy hast Du 'Rls'
jan@42475
   803
jan@42494
   804
%\begin{example}
jan@42502
   805
%  \hfill\\
jan@42489
   806
  \label{eg:ruleapp}
jan@42489
   807
  \begin{enumerate}
jan@42502
   808
jan@42489
   809
  \item Store rules in ruleset:
jan@42502
   810
  {\footnotesize\begin{verbatim}
jan@42489
   811
  val inverse_Z = append_rls "inverse_Z" e_rls
jan@42489
   812
    [ Thm ("rule1",num_str @{thm rule1}),
jan@42489
   813
      Thm ("rule2",num_str @{thm rule2}),
jan@42489
   814
      Thm ("rule3",num_str @{thm rule3})
jan@42502
   815
    ];\end{verbatim}}
jan@42502
   816
jan@42489
   817
  \item Define exression:
jan@42502
   818
  {\footnotesize\begin{verbatim}
jan@42502
   819
  val sample_term = str2term "z/(z-1)+z/(z-</delta>)+1";\end{verbatim}}
neuper@42503
   820
%WN3 vergleiche bitte obige Zeile mit den letzten 3 Zeilen aus S.8,
neuper@42503
   821
%WN3 diese entsprechen dem g"angigen functional-programming Stil.
neuper@42503
   822
%WN3 
neuper@42503
   823
%WN3 Super w"ar's, wenn Du hier schon die interne Darstellung von
neuper@42503
   824
%WN3 Isabelle Termen zeigen k"onntest, dann w"urde ich den entsprechenden Teil
neuper@42503
   825
%WN3 am Ende von S.8 und Anfang S.9 (erste 2.1 Zeilen) l"oschen.
jan@42502
   826
jan@42489
   827
  \item Apply ruleset:
jan@42502
   828
  {\footnotesize\begin{verbatim}
jan@42489
   829
  val SOME (sample_term', asm) = 
jan@42502
   830
    rewrite_set_ thy true inverse_Z sample_term;\end{verbatim}}
jan@42502
   831
jan@42489
   832
  \end{enumerate}
jan@42494
   833
%\end{example}
jan@42489
   834
 
neuper@42503
   835
%WN3 Wie oben gesagt, die folgenden allgemeinen S"atze scheinen
neuper@42503
   836
%WN3 weniger wert als eine konkrete Beschreibung der rls-Struktur.
neuper@42503
   837
%WN3 
neuper@42503
   838
%WN3 Ich nehme an, wir l"oschen das Folgende
neuper@42503
   839
%WN3 und ich spare mir Kommentare (ausser Du hast noch Zeit/Energie
neuper@42503
   840
%WN3 daf"ur und fragst extra nach).
jan@42489
   841
The use of rulesets makes it much easier to develop our designated applications,
jan@42489
   842
but the programmer has to be careful and patient. When applying rulesets
jan@42489
   843
two important issues have to be mentionend:
jan@42502
   844
\begin{enumerate}
jan@42502
   845
\item How often the rules have to be applied? In case of
jan@42489
   846
transformations it is quite clear that we use them once but other fields
jan@42489
   847
reuqire to apply rules until a special condition is reached (e.g.
jan@42489
   848
a simplification is finished when there is nothing to be done left).
jan@42502
   849
\item The order in which rules are applied often takes a big effect
jan@42489
   850
and has to be evaluated for each purpose once again.
jan@42502
   851
\end{enumerate}
jan@42502
   852
In the special case of Signal Processing the rules defined in the
jan@42502
   853
Example upwards have to be applied in a dedicated order to transform all 
jan@42502
   854
constants first of all. After this first transformation step has been done it no 
jan@42502
   855
mather which rule fit's next.
neuper@42503
   856
%WN3 Beim Paper-Schreiben ist mir aufgefallen, dass eine Konstante ZZ_1
neuper@42503
   857
%WN3 (f"ur ${\cal Z}^{-1}$) die eben beschriebenen Probleme gel"ost
neuper@42503
   858
%WN3 h"atte: auf S.6 in rule1, auf S.12 in line 10 und in der Rechnung S.16
neuper@42503
   859
%WN3 hab' ich die Konstante schon eingef"uhrt.
neuper@42503
   860
%WN3 
neuper@42503
   861
%WN3 Bite bei der rewrite_set_ demo oben bitte schummeln !
jan@42469
   862
jan@42466
   863
\subsection{Preparation of ML-Functions}\label{funs}
neuper@42504
   864
Some functionality required in programming, cannot be accomplished by
neuper@42504
   865
rewriting. So the prototype has a mechanism to call functions within
neuper@42504
   866
the rewrite-engine: certain redexes in Isabelle terms call these
neuper@42504
   867
functions written in SML~\cite{pl:milner97}, the implementation {\em
neuper@42504
   868
and} meta-language of Isabelle. The programmer has to use this
neuper@42504
   869
mechanism.
jan@42469
   870
neuper@42498
   871
In the running example's program on p.\pageref{s:impl} the lines {\rm
neuper@42498
   872
05} and {\rm 06} contain such functions; we go into the details with
neuper@42498
   873
\textit{argument\_in X\_z;}. This function fetches the argument from a
neuper@42498
   874
function application: Line {\rm 03} in the example calculation on
neuper@42498
   875
p.\pageref{exp-calc} is created by line {\rm 06} of the example
neuper@42498
   876
program on p.\pageref{s:impl} where the program's environment assigns
neuper@42498
   877
the value \textit{X z} to the variable \textit{X\_z}; so the function
neuper@42498
   878
shall extract the argument \textit{z}.
jan@42469
   879
neuper@42498
   880
\medskip In order to be recognised as a function constant in the
neuper@42499
   881
program source the constant needs to be declared in a theory, here in
neuper@42498
   882
\textit{Build\_Inverse\_Z\_Transform.thy}; then it can be parsed in
neuper@42498
   883
the context \textit{ctxt} of that theory:
neuper@42504
   884
neuper@42498
   885
{\footnotesize
neuper@42498
   886
\begin{verbatim}
neuper@42498
   887
   consts
neuper@42504
   888
     argument'_in :: "real => real" ("argument'_in _" 10)
neuper@42498
   889
   
neuper@42498
   890
   ML {* val SOME t = parse ctxt "argument_in (X z)"; *}
neuper@42498
   891
   val t = Const ("Build_Inverse_Z_Transform.argument'_in", "RealDef.real ⇒ RealDef.real") 
neuper@42498
   892
             $ (Free ("X", "RealDef.real ⇒ RealDef.real") $ Free ("z", "RealDef.real")): term
neuper@42498
   893
\end{verbatim}}
jan@42469
   894
neuper@42498
   895
\noindent Parsing produces a term \texttt{t} in internal
neuper@42504
   896
representation~\footnote{The attentive reader realizes the 
neuper@42499
   897
differences between interal and extermal representation even in the
neuper@42499
   898
strings, i.e \texttt{'\_}}, consisting of \texttt{Const
neuper@42499
   899
("argument'\_in", type)} and the two variables \texttt{Free ("X",
neuper@42499
   900
type)} and \texttt{Free ("z", type)}, \texttt{\$} is the term
neuper@42504
   901
constructor. The function body below is implemented directly in SML,
neuper@42499
   902
i.e in an \texttt{ML \{* *\}} block; the function definition provides
neuper@42499
   903
a unique prefix \texttt{eval\_} to the function name:
jan@42473
   904
neuper@42498
   905
{\footnotesize
jan@42470
   906
\begin{verbatim}
neuper@42498
   907
   ML {*
neuper@42498
   908
     fun eval_argument_in _ 
neuper@42498
   909
       "Build_Inverse_Z_Transform.argument'_in" 
neuper@42498
   910
       (t as (Const ("Build_Inverse_Z_Transform.argument'_in", _) $ (f $ arg))) _ =
neuper@42498
   911
         if is_Free arg (*could be something to be simplified before*)
neuper@42498
   912
         then SOME (term2str t ^ " = " ^ term2str arg, Trueprop $ (mk_equality (t, arg)))
neuper@42498
   913
         else NONE
neuper@42498
   914
     | eval_argument_in _ _ _ _ = NONE;
neuper@42498
   915
   *}
neuper@42498
   916
\end{verbatim}}
jan@42469
   917
neuper@42498
   918
\noindent The function body creates either creates \texttt{NONE}
neuper@42498
   919
telling the rewrite-engine to search for the next redex, or creates an
neuper@42498
   920
ad-hoc theorem for rewriting, thus the programmer needs to adopt many
neuper@42498
   921
technicalities of Isabelle, for instance, the \textit{Trueprop}
neuper@42498
   922
constant.
jan@42469
   923
neuper@42498
   924
\bigskip This sub-task particularly sheds light on basic issues in the
neuper@42498
   925
design of a programming language, the integration of diffent language
neuper@42498
   926
layers, the layer of Isabelle/Isar and Isabelle/ML.
jan@42469
   927
neuper@42498
   928
Another point of improvement for the prototype is the rewrite-engine: The
neuper@42498
   929
program on p.\pageref{s:impl} would not allow to contract the two lines {\rm 05}
neuper@42498
   930
and {\rm 06} to
jan@42469
   931
neuper@42498
   932
{\small\it\label{s:impl}
neuper@42498
   933
\begin{tabbing}
neuper@42498
   934
123l\=123\=123\=123\=123\=123\=123\=((x\=123\=(x \=123\=123\=\kill
neuper@42498
   935
\>{\rm 05/6}\>\>\>  (z::real) = argument\_in (lhs X\_eq) ;
neuper@42498
   936
\end{tabbing}}
jan@42469
   937
neuper@42498
   938
\noindent because nested function calls would require creating redexes
neuper@42498
   939
inside-out; however, the prototype's rewrite-engine only works top down
neuper@42498
   940
from the root of a term down to the leaves.
jan@42469
   941
neuper@42504
   942
How all these technicalities are to be checked in the prototype is 
neuper@42498
   943
shown in \S\ref{flow-prep} below.
jan@42473
   944
neuper@42498
   945
% \paragraph{Explicit Problems} require explicit methods to solve them, and within
neuper@42498
   946
% this methods we have some explicit steps to do. This steps can be unique for
neuper@42498
   947
% a special problem or refindable in other problems. No mather what case, such
neuper@42498
   948
% steps often require some technical functions behind. For the solving process
neuper@42498
   949
% of the Inverse Z Transformation and the corresponding partial fraction it was
neuper@42498
   950
% neccessary to build helping functions like \texttt{get\_denominator},
neuper@42498
   951
% \texttt{get\_numerator} or \texttt{argument\_in}. First two functions help us
neuper@42498
   952
% to filter the denominator or numerator out of a fraction, last one helps us to
neuper@42498
   953
% get to know the bound variable in a equation.
neuper@42498
   954
% \par
neuper@42498
   955
% By taking \texttt{get\_denominator} as an example, we want to explain how to 
neuper@42498
   956
% implement new functions into the existing system and how we can later use them
neuper@42498
   957
% in our program.
neuper@42498
   958
% 
neuper@42498
   959
% \subsubsection{Find a place to Store the Function}
neuper@42498
   960
% 
neuper@42498
   961
% The whole system builds up on a well defined structure of Knowledge. This
neuper@42498
   962
% Knowledge sets up at the Path:
neuper@42498
   963
% \begin{center}\ttfamily src/Tools/isac/Knowledge\normalfont\end{center}
neuper@42498
   964
% For implementing the Function \texttt{get\_denominator} (which let us extract
neuper@42498
   965
% the denominator out of a fraction) we have choosen the Theory (file)
neuper@42498
   966
% \texttt{Rational.thy}.
neuper@42498
   967
% 
neuper@42498
   968
% \subsubsection{Write down the new Function}
neuper@42498
   969
% 
neuper@42498
   970
% In upper Theory we now define the new function and its purpose:
neuper@42498
   971
% \begin{verbatim}
neuper@42498
   972
%   get_denominator :: "real => real"
neuper@42498
   973
% \end{verbatim}
neuper@42498
   974
% This command tells the machine that a function with the name
neuper@42498
   975
% \texttt{get\_denominator} exists which gets a real expression as argument and
neuper@42498
   976
% returns once again a real expression. Now we are able to implement the function
neuper@42498
   977
% itself, upcoming example now shows the implementation of
neuper@42498
   978
% \texttt{get\_denominator}.
neuper@42498
   979
% 
neuper@42498
   980
% %\begin{example}
neuper@42498
   981
%   \label{eg:getdenom}
neuper@42498
   982
%   \begin{verbatim}
neuper@42498
   983
% 
neuper@42498
   984
% 01  (*
neuper@42498
   985
% 02   *("get_denominator",
neuper@42498
   986
% 03   *  ("Rational.get_denominator", eval_get_denominator ""))
neuper@42498
   987
% 04   *)
neuper@42498
   988
% 05  fun eval_get_denominator (thmid:string) _ 
neuper@42498
   989
% 06            (t as Const ("Rational.get_denominator", _) $
neuper@42498
   990
% 07                (Const ("Rings.inverse_class.divide", _) $num 
neuper@42498
   991
% 08                  $denom)) thy = 
neuper@42498
   992
% 09          SOME (mk_thmid thmid "" 
neuper@42498
   993
% 10              (Print_Mode.setmp [] 
neuper@42498
   994
% 11                (Syntax.string_of_term (thy2ctxt thy)) denom) "", 
neuper@42498
   995
% 12              Trueprop $ (mk_equality (t, denom)))
neuper@42498
   996
% 13    | eval_get_denominator _ _ _ _ = NONE;\end{verbatim}
neuper@42498
   997
% %\end{example}
neuper@42498
   998
% 
neuper@42498
   999
% Line \texttt{07} and \texttt{08} are describing the mode of operation the best -
neuper@42498
  1000
% there is a fraction\\ (\ttfamily Rings.inverse\_class.divide\normalfont) 
neuper@42498
  1001
% splittet
neuper@42498
  1002
% into its two parts (\texttt{\$num \$denom}). The lines before are additionals
neuper@42498
  1003
% commands for declaring the function and the lines after are modeling and 
neuper@42498
  1004
% returning a real variable out of \texttt{\$denom}.
neuper@42498
  1005
% 
neuper@42498
  1006
% \subsubsection{Add a test for the new Function}
neuper@42498
  1007
% 
neuper@42498
  1008
% \paragraph{Everytime when adding} a new function it is essential also to add
neuper@42498
  1009
% a test for it. Tests for all functions are sorted in the same structure as the
neuper@42498
  1010
% knowledge it self and can be found up from the path:
neuper@42498
  1011
% \begin{center}\ttfamily test/Tools/isac/Knowledge\normalfont\end{center}
neuper@42498
  1012
% This tests are nothing very special, as a first prototype the functionallity
neuper@42498
  1013
% of a function can be checked by evaluating the result of a simple expression
neuper@42498
  1014
% passed to the function. Example~\ref{eg:getdenomtest} shows the test for our
neuper@42498
  1015
% \textit{just} created function \texttt{get\_denominator}.
neuper@42498
  1016
% 
neuper@42498
  1017
% %\begin{example}
neuper@42498
  1018
% \label{eg:getdenomtest}
neuper@42498
  1019
% \begin{verbatim}
neuper@42498
  1020
% 
neuper@42498
  1021
% 01 val thy = @{theory Isac};
neuper@42498
  1022
% 02 val t = term_of (the (parse thy "get_denominator ((a +x)/b)"));
neuper@42498
  1023
% 03 val SOME (_, t') = eval_get_denominator "" 0 t thy;
neuper@42498
  1024
% 04 if term2str t' = "get_denominator ((a + x) / b) = b" then ()
neuper@42498
  1025
% 05 else error "get_denominator ((a + x) / b) = b" \end{verbatim}
neuper@42498
  1026
% %\end{example}
neuper@42498
  1027
% 
neuper@42498
  1028
% \begin{description}
neuper@42498
  1029
% \item[01] checks if the proofer set up on our {\sisac{}} System.
neuper@42498
  1030
% \item[02] passes a simple expression (fraction) to our suddenly created
neuper@42498
  1031
%           function.
neuper@42498
  1032
% \item[04] checks if the resulting variable is the correct one (in this case
neuper@42498
  1033
%           ``b'' the denominator) and returns.
neuper@42498
  1034
% \item[05] handels the error case and reports that the function is not able to
neuper@42498
  1035
%           solve the given problem.
neuper@42498
  1036
% \end{description}
jan@42469
  1037
jan@42491
  1038
\subsection{Specification of the Problem}\label{spec}
jan@42491
  1039
%WN <--> \chapter 7 der Thesis
jan@42491
  1040
%WN die Argumentation unten sollte sich NUR auf Verifikation beziehen..
jan@42491
  1041
neuper@42504
  1042
Mechanical treatment requires to translate a textual problem
neuper@42504
  1043
description like in Fig.\ref{fig-interactive} on
neuper@42504
  1044
p.\pageref{fig-interactive} into a {\em formal} specification. The
neuper@42504
  1045
formal specification of the running example could look like is this:
jan@42491
  1046
jan@42491
  1047
%WN Hier brauchen wir die Spezifikation des 'running example' ...
jan@42491
  1048
%JR Habe input, output und precond vom Beispiel eingefügt brauche aber Hilfe bei
jan@42491
  1049
%JR der post condition - die existiert für uns ja eigentlich nicht aka
jan@42491
  1050
%JR haben sie bis jetzt nicht beachtet WN...
jan@42491
  1051
%WN2 Mein Vorschlag ist, das TODO zu lassen und deutlich zu kommentieren.
jan@42491
  1052
%JR2 done
jan@42491
  1053
neuper@42504
  1054
\label{eg:neuper2}
neuper@42504
  1055
{\small\begin{tabbing}
neuper@42504
  1056
  123\=123\=postcond \=: \= $\forall \,A^\prime\, u^\prime \,v^\prime.\,$\=\kill
neuper@42504
  1057
  %\hfill \\
neuper@42504
  1058
  \>Specification:\\
neuper@42504
  1059
  \>  \>input    \>: ${\it filterExpression} \;\;X\;z=\frac{3}{z-\frac{1}{4}+-\frac{1}{8}*\frac{1}{z}}$\\
neuper@42504
  1060
  \>\>precond  \>: $\frac{3}{z-\frac{1}{4}+-\frac{1}{8}*\frac{1}{z}}\;\; {\it continuous\_on}\; \mathbb{R}-\{\frac{1}{2}, \frac{-1}{4}\}$ \\
neuper@42504
  1061
  \>\>output   \>: stepResponse $x[n]$ \\
neuper@42504
  1062
  \>\>postcond \>: TODO
neuper@42504
  1063
\end{tabbing}}
jan@42491
  1064
jan@42500
  1065
%JR wie besprochen, kein remark, keine begründung, nur simples "nicht behandelt"
jan@42500
  1066
jan@42500
  1067
% \begin{remark}
jan@42500
  1068
%    Defining the postcondition requires a high amount mathematical 
jan@42500
  1069
%    knowledge, the difficult part in our case is not to set up this condition 
jan@42500
  1070
%    nor it is more to define it in a way the interpreter is able to handle it. 
jan@42500
  1071
%    Due the fact that implementing that mechanisms is quite the same amount as 
jan@42500
  1072
%    creating the programm itself, it is not avaible in our prototype.
jan@42500
  1073
%    \label{rm:postcond}
jan@42500
  1074
% \end{remark}
jan@42491
  1075
neuper@42504
  1076
The implementation of the formal specification in the present
neuper@42504
  1077
prototype, still bar-bones without support for authoring, is done
neuper@42504
  1078
like that:
jan@42491
  1079
%WN Kopie von Inverse_Z_Transform.thy, leicht versch"onert:
neuper@42504
  1080
jan@42491
  1081
{\footnotesize\label{exp-spec}
jan@42491
  1082
\begin{verbatim}
neuper@42504
  1083
   00 ML {*
jan@42491
  1084
   01  store_specification
jan@42491
  1085
   02    (prepare_specification
neuper@42504
  1086
   03      "pbl_SP_Ztrans_inv"
neuper@42504
  1087
   04      ["Jan Rocnik"]
jan@42491
  1088
   05      thy
jan@42491
  1089
   06      ( ["Inverse", "Z_Transform", "SignalProcessing"],
jan@42491
  1090
   07        [ ("#Given", ["filterExpression X_eq"]),
neuper@42504
  1091
   08          ("#Pre"  , ["(rhs X_eq) is_continuous_in R\{1/2, -1/4}"]),
jan@42494
  1092
   09          ("#Find" , ["stepResponse n_eq"]),
jan@42491
  1093
   10          ("#Post" , [" TODO "])],
jan@42491
  1094
   11        append_rls Erls [Calc ("Atools.is_continuous", eval_is_continuous)], 
jan@42491
  1095
   12        NONE, 
jan@42491
  1096
   13        [["SignalProcessing","Z_Transform","Inverse"]]));
neuper@42504
  1097
   14 *}
jan@42491
  1098
\end{verbatim}}
neuper@42504
  1099
jan@42491
  1100
Although the above details are partly very technical, we explain them
jan@42491
  1101
in order to document some intricacies of TP-based programming in the
jan@42491
  1102
present state of the {\sisac} prototype:
jan@42491
  1103
\begin{description}
jan@42491
  1104
\item[01..02]\textit{store\_specification:} stores the result of the
jan@42491
  1105
function \textit{prep\_specification} in a global reference
jan@42491
  1106
\textit{Unsynchronized.ref}, which causes principal conflicts with
jan@42491
  1107
Isabelle's asyncronous document model~\cite{Wenzel-11:doc-orient} and
jan@42491
  1108
parallel execution~\cite{Makarius-09:parall-proof} and is under
jan@42491
  1109
reconstruction already.
jan@42491
  1110
neuper@42504
  1111
\textit{prep\_specification:} translates the specification to an internal format
jan@42491
  1112
which allows efficient processing; see for instance line {\rm 07}
jan@42491
  1113
below.
neuper@42504
  1114
\item[03..04] are a unique identifier for the specification within {\sisac}
neuper@42504
  1115
and the ``mathematics author'' holding the copy-rights.
jan@42491
  1116
\item[05] is the Isabelle \textit{theory} required to parse the
jan@42491
  1117
specification in lines {\rm 07..10}.
jan@42491
  1118
\item[06] is a key into the tree of all specifications as presented to
jan@42491
  1119
the user (where some branches might be hidden by the dialog
jan@42491
  1120
component).
jan@42491
  1121
\item[07..10] are the specification with input, pre-condition, output
jan@42491
  1122
and post-condition respectively; the post-condition is not handled in
neuper@42504
  1123
the prototype presently.
neuper@42504
  1124
\item[11] creates a rule-set (abbreviated \textit{rls} in
jan@42491
  1125
{\sisac}) which evaluates the pre-condition for the actual input data.
neuper@42504
  1126
Only if the evaluation yields \textit{True}, a program can be started.
jan@42491
  1127
\item[12]\textit{NONE:} could be \textit{SOME ``solve ...''} for a
jan@42491
  1128
problem associated to a function from Computer Algebra (like an
jan@42491
  1129
equation solver) which is not the case here.
neuper@42504
  1130
\item[13] is a list of methods solving the specified problem (here
neuper@42504
  1131
only one list item) represented analogously to {\rm 06}.
jan@42491
  1132
\end{description}
jan@42491
  1133
jan@42491
  1134
jan@42491
  1135
%WN die folgenden Erkl"arungen finden sich durch "grep -r 'datatype pbt' *"
jan@42491
  1136
%WN ...
jan@42491
  1137
%  type pbt = 
jan@42491
  1138
%     {guh  : guh,         (*unique within this isac-knowledge*)
jan@42491
  1139
%      mathauthors: string list, (*copyright*)
jan@42491
  1140
%      init  : pblID,      (*to start refinement with*)
jan@42491
  1141
%      thy   : theory,     (* which allows to compile that pbt
jan@42491
  1142
%			  TODO: search generalized for subthy (ref.p.69*)
jan@42491
  1143
%      (*^^^ WN050912 NOT used during application of the problem,
jan@42491
  1144
%       because applied terms may be from 'subthy' as well as from super;
jan@42491
  1145
%       thus we take 'maxthy'; see match_ags !*)
jan@42491
  1146
%      cas   : term option,(*'CAS-command'*)
jan@42491
  1147
%      prls  : rls,        (* for preds in where_*)
jan@42491
  1148
%      where_: term list,  (* where - predicates*)
jan@42491
  1149
%      ppc   : pat list,
jan@42491
  1150
%      (*this is the model-pattern; 
jan@42491
  1151
%       it contains "#Given","#Where","#Find","#Relate"-patterns
jan@42491
  1152
%       for constraints on identifiers see "fun cpy_nam"*)
jan@42491
  1153
%      met   : metID list}; (* methods solving the pbt*)
jan@42491
  1154
%
jan@42491
  1155
%WN weil dieser Code sehr unaufger"aumt ist, habe ich die Erkl"arungen
jan@42491
  1156
%WN oben selbst geschrieben.
jan@42491
  1157
jan@42491
  1158
jan@42491
  1159
jan@42491
  1160
jan@42491
  1161
%WN das w"urde ich in \sec\label{progr} verschieben und
jan@42491
  1162
%WN das SubProblem partial fractions zum Erkl"aren verwenden.
jan@42491
  1163
% Such a specification is checked before the execution of a program is
jan@42491
  1164
% started, the same applies for sub-programs. In the following example
jan@42491
  1165
% (Example~\ref{eg:subprob}) shows the call of such a subproblem:
jan@42491
  1166
% 
jan@42491
  1167
% \vbox{
jan@42491
  1168
%   \begin{example}
jan@42491
  1169
%   \label{eg:subprob}
jan@42491
  1170
%   \hfill \\
jan@42491
  1171
%   {\ttfamily \begin{tabbing}
jan@42491
  1172
%   ``(L\_L::bool list) = (\=SubProblem (\=Test','' \\
jan@42491
  1173
%   ``\>\>[linear,univariate,equation,test],'' \\
jan@42491
  1174
%   ``\>\>[Test,solve\_linear])'' \\
jan@42491
  1175
%   ``\>[BOOL equ, REAL z])'' \\
jan@42491
  1176
%   \end{tabbing}
jan@42491
  1177
%   }
jan@42491
  1178
%   {\small\textit{
jan@42491
  1179
%     \noindent If a program requires a result which has to be
jan@42491
  1180
% calculated first we can use a subproblem to do so. In our specific
jan@42491
  1181
% case we wanted to calculate the zeros of a fraction and used a
jan@42491
  1182
% subproblem to calculate the zeros of the denominator polynom.
jan@42491
  1183
%     }}
jan@42491
  1184
%   \end{example}
jan@42491
  1185
% }
jan@42491
  1186
jan@42491
  1187
\subsection{Implementation of the Method}\label{meth}
neuper@42504
  1188
A method collects all data required to interpret a certain program by
neuper@42504
  1189
Lucas-Interpretation. The \texttt{program} from p.\pageref{s:impl} of
neuper@42504
  1190
the running example is embedded in the following method:
neuper@42504
  1191
%The methods represent the different ways a problem can be solved. This can
neuper@42504
  1192
%include mathematical tactics as well as tactics taught in different courses.
neuper@42504
  1193
%Declaring the Method itself gives us the possibilities to describe the way of 
neuper@42504
  1194
%calculation in deep, as well we get the oppertunities to build in different
neuper@42504
  1195
%rulesets.
jan@42491
  1196
jan@42502
  1197
{\footnotesize
jan@42491
  1198
\begin{verbatim}
neuper@42504
  1199
   00 ML {*
neuper@42504
  1200
   01  store_method
neuper@42504
  1201
   02    (prep_method
neuper@42504
  1202
   03      "SP_InverseZTransformation_classic" 
neuper@42504
  1203
   04      ["Jan Rocnik"]
neuper@42504
  1204
   05      thy 
neuper@42504
  1205
   06      (["SignalProcessing", "Z_Transform", "Inverse"], 
neuper@42504
  1206
   07       [("#Given" ,["filterExpression (X_eq::bool)"]),
neuper@42504
  1207
   08        ("#Pre"  , ["(rhs X_eq) is_continuous_in R\{1/2, -1/4}"]),
neuper@42504
  1208
   09        ("#Find"  ,["stepResponse (n_eq::bool)"])],
neuper@42504
  1209
   10       {rew_ord = tless_true, rls  = rls, 
neuper@42504
  1210
   11        srls = srls, calc = [],
neuper@42504
  1211
   12        prls = prls, crls = crls,
neuper@42504
  1212
   13        nrls = nrls,
neuper@42504
  1213
   14        errpats = []},
neuper@42504
  1214
   15        program));
neuper@42504
  1215
   16 *}
neuper@42504
  1216
\end{verbatim}}
jan@42494
  1217
neuper@42504
  1218
\noindent The above code stores the whole structure analogously to a
neuper@42504
  1219
specification,
neuper@42504
  1220
\begin{description}
neuper@42504
  1221
\item[01..06] are identical to those for the example specification on
neuper@42504
  1222
p.\pageref{exp-spec}.
jan@42494
  1223
neuper@42504
  1224
\item[07..09] show something looking like the specification; this is a
neuper@42504
  1225
{\em guard}: as long as not all \texttt{Given} items are present and
neuper@42504
  1226
the \texttt{Pre}-conditions is not true, interpretation of the program
neuper@42504
  1227
is not started.
neuper@42504
  1228
neuper@42504
  1229
\item[01..09]
neuper@42504
  1230
neuper@42504
  1231
\item[01..09]
neuper@42504
  1232
neuper@42504
  1233
\item[01..09]
neuper@42504
  1234
neuper@42504
  1235
\item[01..09]
jan@42494
  1236
\end{description}
jan@42491
  1237
neuper@42504
  1238
neuper@42504
  1239
.\\.\\.\\
neuper@42504
  1240
neuper@42504
  1241
% is again very technical and goes hard in detail. Unfortunataly
neuper@42504
  1242
% most declerations are not essential for a basic programm but leads us to a huge
neuper@42504
  1243
% range of powerful possibilities.
neuper@42504
  1244
% 
neuper@42504
  1245
% \begin{description}
neuper@42504
  1246
% \item[01..02] stores the method with the given name into the system under a global
neuper@42504
  1247
% reference.
neuper@42504
  1248
% \item[03] specifies the topic within which context the method can be found.
neuper@42504
  1249
% \item[04..05] as the requirements for different methods can be deviant we 
neuper@42504
  1250
% declare what is \emph{given} and and what to \emph{find} for this specific method.
neuper@42504
  1251
% The code again helds on the topic of the case studie, where the inverse 
neuper@42504
  1252
% z-transformation does a switch between a term describing a electrical filter into
neuper@42504
  1253
% its step response. Also the datatype has to be declared (bool - due the fact that 
neuper@42504
  1254
% we handle equations).
neuper@42504
  1255
% \item[06] \emph{rewrite order} is the order of this rls (ruleset), where one 
neuper@42504
  1256
% theorem of it is used for rewriting one single step.
neuper@42504
  1257
% \item[07] \texttt{rls} is the currently used ruleset for this method. This set
neuper@42504
  1258
% has already been defined before.
neuper@42504
  1259
% \item[08] we would have the possiblitiy to add this method to a predefined tree of
neuper@42504
  1260
% calculations, i.eg. if it would be a sub of a bigger problem, here we leave it
neuper@42504
  1261
% independend.
neuper@42504
  1262
% \item[09] The \emph{source ruleset}, can be used to evaluate list expressions in 
neuper@42504
  1263
% the source.
neuper@42504
  1264
% \item[10] \emph{predicates ruleset} can be used to indicates predicates within 
neuper@42504
  1265
% model patterns.
neuper@42504
  1266
% \item[11] The \emph{check ruleset} summarizes rules for checking formulas 
neuper@42504
  1267
% elementwise.
neuper@42504
  1268
% \item[12] \emph{error patterns} which are expected in this kind of method can be
neuper@42504
  1269
% pre-specified to recognize them during the method.
neuper@42504
  1270
% \item[13] finally the \emph{canonical ruleset}, declares the canonical simplifier 
neuper@42504
  1271
% of the specific method.
neuper@42504
  1272
% \item[14] for this code snipset we don't specify the programm itself and keep it 
neuper@42504
  1273
% empty. Follow up \S\ref{progr} for informations on how to implement this
neuper@42504
  1274
% \textit{main} part.
neuper@42504
  1275
% \end{description}
neuper@42504
  1276
neuper@42478
  1277
\subsection{Implementation of the TP-based Program}\label{progr} 
neuper@42480
  1278
So finally all the prerequisites are described and the very topic can
neuper@42480
  1279
be addressed. The program below comes back to the running example: it
neuper@42480
  1280
computes a solution for the problem from Fig.\ref{fig-interactive} on
neuper@42480
  1281
p.\pageref{fig-interactive}. The reader is reminded of
neuper@42480
  1282
\S\ref{PL-isab}, the introduction of the programming language:
jan@42502
  1283
jan@42502
  1284
{\footnotesize\it\label{s:impl}
neuper@42482
  1285
\begin{tabbing}
neuper@42478
  1286
123l\=123\=123\=123\=123\=123\=123\=((x\=123\=(x \=123\=123\=\kill
neuper@42504
  1287
\>        \>ML \{*
neuper@42480
  1288
\>{\rm 00}\>val program =\\
neuper@42480
  1289
\>{\rm 01}\>  "{\tt Program} InverseZTransform (X\_eq::bool) =   \\
neuper@42482
  1290
\>{\rm 02}\>\>  {\tt let}                                       \\
neuper@42468
  1291
\>{\rm 03}\>\>\>  X\_eq = {\tt Take} X\_eq ;   \\
neuper@42468
  1292
\>{\rm 04}\>\>\>  X\_eq = {\tt Rewrite} ruleZY X\_eq ; \\
neuper@42468
  1293
\>{\rm 05}\>\>\>  (X\_z::real) = lhs X\_eq ;       \\ %no inside-out evaluation
neuper@42468
  1294
\>{\rm 06}\>\>\>  (z::real) = argument\_in X\_z; \\
neuper@42468
  1295
\>{\rm 07}\>\>\>  (part\_frac::real) = {\tt SubProblem} \\
neuper@42478
  1296
\>{\rm 08}\>\>\>\>\>\>\>\>  ( Isac, [partial\_fraction, rational, simplification], [] )\\
neuper@42478
  1297
%\>{\rm 10}\>\>\>\>\>\>\>\>\>  [simplification, of\_rationals, to\_partial\_fraction] ) \\
neuper@42478
  1298
\>{\rm 09}\>\>\>\>\>\>\>\>  [ (rhs X\_eq)::real, z::real ]; \\
neuper@42478
  1299
\>{\rm 10}\>\>\>  (X'\_eq::bool) = {\tt Take} ((X'::real =$>$ bool) z = ZZ\_1 part\_frac) ; \\
neuper@42478
  1300
\>{\rm 11}\>\>\>  X'\_eq = (({\tt Rewrite\_Set} ruleYZ) @@   \\
neuper@42478
  1301
\>{\rm 12}\>\>\>\>\>  $\;\;$ ({\tt Rewrite\_Set} inverse\_z)) X'\_eq \\
neuper@42482
  1302
\>{\rm 13}\>\>  {\tt in } \\
neuper@42504
  1303
\>{\rm 14}\>\>\>  X'\_eq"\\
neuper@42504
  1304
\>        \>*\}
neuper@42478
  1305
\end{tabbing}}
neuper@42468
  1306
% ORIGINAL FROM Inverse_Z_Transform.thy
neuper@42468
  1307
% "Script InverseZTransform (X_eq::bool) =            "^(*([], Frm), Problem (Isac, [Inverse, Z_Transform, SignalProcessing])*)
neuper@42468
  1308
% "(let X = Take X_eq;                                "^(*([1], Frm), X z = 3 / (z - 1 / 4 + -1 / 8 * (1 / z))*)
neuper@42468
  1309
% "  X' = Rewrite ruleZY False X;                     "^(*([1], Res), ?X' z = 3 / (z * (z - 1 / 4 + -1 / 8 * (1 / z)))*)
neuper@42468
  1310
% "  (X'_z::real) = lhs X';                           "^(*            ?X' z*)
neuper@42468
  1311
% "  (zzz::real) = argument_in X'_z;                  "^(*            z *)
neuper@42468
  1312
% "  (funterm::real) = rhs X';                        "^(*            3 / (z * (z - 1 / 4 + -1 / 8 * (1 / z)))*)
neuper@42468
  1313
%
neuper@42468
  1314
% "  (pbz::real) = (SubProblem (Isac',                "^(**)
neuper@42468
  1315
% "    [partial_fraction,rational,simplification],    "^
neuper@42468
  1316
% "    [simplification,of_rationals,to_partial_fraction]) "^
neuper@42468
  1317
% "    [REAL funterm, REAL zzz]);                     "^(*([2], Res), 4 / (z - 1 / 2) + -4 / (z - -1 / 4)*)
neuper@42468
  1318
%
neuper@42468
  1319
% "  (pbz_eq::bool) = Take (X'_z = pbz);              "^(*([3], Frm), ?X' z = 4 / (z - 1 / 2) + -4 / (z - -1 / 4)*)
neuper@42468
  1320
% "  pbz_eq = Rewrite ruleYZ False pbz_eq;            "^(*([3], Res), ?X' z = 4 * (?z / (z - 1 / 2)) + -4 * (?z / (z - -1 / 4))*)
neuper@42468
  1321
% "  pbz_eq = drop_questionmarks pbz_eq;              "^(*               4 * (z / (z - 1 / 2)) + -4 * (z / (z - -1 / 4))*)
neuper@42468
  1322
% "  (X_zeq::bool) = Take (X_z = rhs pbz_eq);         "^(*([4], Frm), X_z = 4 * (z / (z - 1 / 2)) + -4 * (z / (z - -1 / 4))*)
neuper@42468
  1323
% "  n_eq = (Rewrite_Set inverse_z False) X_zeq;      "^(*([4], Res), X_z = 4 * (1 / 2) ^^^ ?n * ?u [?n] + -4 * (-1 / 4) ^^^ ?n * ?u [?n]*)
neuper@42468
  1324
% "  n_eq = drop_questionmarks n_eq                   "^(*            X_z = 4 * (1 / 2) ^^^ n * u [n] + -4 * (-1 / 4) ^^^ n * u [n]*)
neuper@42468
  1325
% "in n_eq)"                                            (*([], Res), X_z = 4 * (1 / 2) ^^^ n * u [n] + -4 * (-1 / 4) ^^^ n * u [n]*)
neuper@42480
  1326
The program is represented as a string and part of the method in
neuper@42480
  1327
\S\ref{meth}.  As mentioned in \S\ref{PL} the program is purely
neuper@42480
  1328
functional and lacks any input statements and output statements. So
neuper@42480
  1329
the steps of calculation towards a solution (and interactive tutoring
neuper@42480
  1330
in step-wise problem solving) are created as a side-effect by
neuper@42480
  1331
Lucas-Interpretation.  The side-effects are triggered by the tactics
neuper@42482
  1332
\texttt{Take}, \texttt{Rewrite}, \texttt{SubProblem} and
neuper@42482
  1333
\texttt{Rewrite\_Set} in the above lines {\rm 03, 04, 07, 10, 11} and
neuper@42480
  1334
{\rm 12} respectively. These tactics produce the lines in the
neuper@42480
  1335
calculation on p.\pageref{flow-impl}.
neuper@42478
  1336
neuper@42480
  1337
The above lines {\rm 05, 06} do not contain a tactics, so they do not
neuper@42480
  1338
immediately contribute to the calculation on p.\pageref{flow-impl};
neuper@42482
  1339
rather, they compute actual arguments for the \texttt{SubProblem} in
neuper@42480
  1340
line {\rm 09}~\footnote{The tactics also are break-points for the
neuper@42480
  1341
interpreter, where control is handed over to the user in interactive
neuper@42482
  1342
tutoring.}. Line {\rm 11} contains tactical \textit{@@}.
neuper@42480
  1343
neuper@42480
  1344
\medskip The above program also indicates the dominant role of interactive
neuper@42478
  1345
selection of knowledge in the three-dimensional universe of
neuper@42478
  1346
mathematics as depicted in Fig.\ref{fig:mathuni} on
neuper@42482
  1347
p.\pageref{fig:mathuni}, The \texttt{SubProblem} in the above lines
neuper@42478
  1348
{\rm 07..09} is more than a function call with the actual arguments
neuper@42478
  1349
\textit{[ (rhs X\_eq)::real, z::real ]}. The programmer has to determine
neuper@42478
  1350
three items:
neuper@42480
  1351
neuper@42478
  1352
\begin{enumerate}
neuper@42478
  1353
\item the theory, in the example \textit{Isac} because different
neuper@42478
  1354
methods can be selected in Pt.3 below, which are defined in different
neuper@42478
  1355
theories with \textit{Isac} collecting them.
neuper@42480
  1356
\item the specification identified by \textit{[partial\_fraction,
neuper@42480
  1357
rational, simplification]} in the tree of specifications; this
neuper@42480
  1358
specification is analogous to the specification of the main program
neuper@42480
  1359
described in \S\ref{spec}; the problem is to find a ``partial fraction
neuper@42480
  1360
decomposition'' for a univariate rational polynomial.
neuper@42480
  1361
\item the method in the above example is \textit{[ ]}, i.e. empty,
neuper@42480
  1362
which supposes the interpreter to select one of the methods predefined
neuper@42480
  1363
in the specification, for instance in line {\rm 13} in the running
neuper@42480
  1364
example's specification on p.\pageref{exp-spec}~\footnote{The freedom
neuper@42480
  1365
(or obligation) for selection carries over to the student in
neuper@42480
  1366
interactive tutoring.}.
neuper@42478
  1367
\end{enumerate}
neuper@42478
  1368
neuper@42480
  1369
The program code, above presented as a string, is parsed by Isabelle's
neuper@42480
  1370
parser --- the program is an Isabelle term. This fact is expected to
neuper@42480
  1371
simplify verification tasks in the future; on the other hand, this
neuper@42480
  1372
fact causes troubles in error detectetion which are discussed as part
neuper@42480
  1373
of the workflow in the subsequent section.
neuper@42467
  1374
jan@42463
  1375
\section{Workflow of Programming in the Prototype}\label{workflow}
neuper@42498
  1376
The new prover IDE Isabelle/jEdit~\cite{makar-jedit-12} is a great
neuper@42498
  1377
step forward for interactive theory and proof development. The
neuper@42498
  1378
{\sisac}-prototype re-uses this IDE as a programming environment.  The
neuper@42498
  1379
experiences from this re-use show, that the essential components are
neuper@42498
  1380
available from Isabelle/jEdit. However, additional tools and features
neuper@42498
  1381
are required to acchieve acceptable usability.
neuper@42498
  1382
neuper@42498
  1383
So notable experiences are reported here, also as a requirement
neuper@42498
  1384
capture for further development of TP-based languages and respective
neuper@42498
  1385
IDEs.
neuper@42468
  1386
jan@42466
  1387
\subsection{Preparations and Trials}\label{flow-prep}
neuper@42499
  1388
The many sub-tasks to be accomplished {\em before} the first line of
neuper@42499
  1389
program code can be written and tested suggest an approach which
neuper@42499
  1390
step-wise establishes the prerequisites. The case study underlying
neuper@42499
  1391
this paper~\cite{jrocnik-bakk} documents the approach in a separate
neuper@42499
  1392
Isabelle theory,
neuper@42499
  1393
\textit{Build\_Inverse\_Z\_Transform.thy}~\footnote{http://www.ist.tugraz.at/projects/isac/publ/Build\_Inverse\_Z\_Transform.thy}. Part
neuper@42499
  1394
II in the study comprises this theory, \LaTeX ed from the theory by
neuper@42499
  1395
use of Isabelle's document preparation system. This paper resembles
neuper@42499
  1396
the approach in \S\ref{isabisac} to \S\ref{meth}, which in actual
neuper@42499
  1397
implementation work involves several iterations.
neuper@42498
  1398
neuper@42499
  1399
\bigskip For instance, only the last step, implementing the program
neuper@42499
  1400
described in \S\ref{meth}, reveals details required. Let us assume,
neuper@42499
  1401
this is the ML-function \textit{argument\_in} required in line {\rm 06}
neuper@42499
  1402
of the example program on p.\pageref{s:impl}; how this function needs
neuper@42499
  1403
to be implemented in the prototype has been discussed in \S\ref{funs}
neuper@42499
  1404
already.
neuper@42498
  1405
neuper@42499
  1406
Now let us assume, that calling this function from the program code
neuper@42499
  1407
does not work; so testing this function is required in order to find out
neuper@42499
  1408
the reason: type errors, a missing entry of the function somewhere or
neuper@42499
  1409
even more nasty technicalities \dots
neuper@42498
  1410
neuper@42499
  1411
{\footnotesize
neuper@42482
  1412
\begin{verbatim}
neuper@42482
  1413
   ML {*
neuper@42499
  1414
     val SOME t = parseNEW ctxt "argument_in (X (z::real))";
neuper@42499
  1415
     val SOME (str, t') = eval_argument_in "" 
neuper@42499
  1416
       "Build_Inverse_Z_Transform.argument'_in" t 0;
neuper@42482
  1417
   *}
neuper@42499
  1418
   ML {*
neuper@42499
  1419
     term2str t';
neuper@42499
  1420
   *}
neuper@42499
  1421
   val it = "(argument_in X z) = z": string
neuper@42482
  1422
\end{verbatim}}
neuper@42499
  1423
neuper@42499
  1424
\noindent So, this works: we get an ad-hoc theorem, which used in
neuper@42499
  1425
rewriting would reduce \texttt{argument\_in X z} to \texttt{z}. Now we check this
neuper@42499
  1426
reduction and create a rule-set \texttt{rls} for that purpose:
neuper@42499
  1427
neuper@42499
  1428
{\footnotesize
neuper@42482
  1429
\begin{verbatim}
neuper@42482
  1430
   ML {*
neuper@42499
  1431
     val rls = append_rls "test" e_rls 
neuper@42499
  1432
       [Calc ("Build_Inverse_Z_Transform.argument'_in", eval_argument_in "")]
neuper@42482
  1433
   *}
neuper@42499
  1434
   ML {*
neuper@42499
  1435
     val SOME (t', asm) = rewrite_set_ @{theory} rls t;
neuper@42499
  1436
   *}
neuper@42499
  1437
   val t' = Free ("z", "RealDef.real"): term
neuper@42499
  1438
   val asm = []: term list
neuper@42482
  1439
\end{verbatim}}
neuper@42499
  1440
neuper@42499
  1441
\noindent The resulting term \texttt{t'} is \texttt{Free ("z",
neuper@42499
  1442
"RealDef.real")}, i.e the variable \texttt{z}, so all is
neuper@42499
  1443
perfect. Probably we have forgotten to store this function correctly~?
neuper@42499
  1444
We review the respective \texttt{calclist} (again an
neuper@42499
  1445
\textit{Unsynchronized.ref} to be removed in order to adjust to
neuper@42499
  1446
IsabelleIsar's asyncronous document model):
neuper@42499
  1447
neuper@42499
  1448
{\footnotesize
neuper@42499
  1449
\begin{verbatim}
neuper@42499
  1450
   calclist:= overwritel (! calclist, 
neuper@42499
  1451
    [("argument_in",("Build_Inverse_Z_Transform.argument'_in", eval_argument_in "")),
neuper@42499
  1452
     ...
neuper@42499
  1453
     ]);
neuper@42499
  1454
\end{verbatim}}
neuper@42499
  1455
neuper@42499
  1456
\noindent The entry is perfect. So what is the reason~? Ah, probably there
neuper@42499
  1457
is something messed up with the many rule-sets in the method, see \S\ref{meth} ---
neuper@42499
  1458
right, the function \texttt{argument\_in} is not contained in the respective
neuper@42499
  1459
rule-set \textit{srls} \dots this just as an example of the intricacies in
neuper@42499
  1460
debugging a program in the present state of the prototype.
neuper@42499
  1461
neuper@42499
  1462
\subsection{Implementation in Isabelle/{\isac}}\label{flow-impl}
neuper@42499
  1463
Given all the prerequisites from \S\ref{isabisac} to \S\ref{meth},
neuper@42499
  1464
usually developed within several iterations, the program can be
neuper@42499
  1465
assembled; on p.\pageref{s:impl} there is the complete program of the
neuper@42499
  1466
running example.
neuper@42499
  1467
neuper@42499
  1468
The completion of this program required efforts for several weeks
neuper@42499
  1469
(after some months of familiarisation with {\sisac}), caused by the
neuper@42499
  1470
abundance of intricacies indicated above. Also writing the program is
neuper@42499
  1471
not pleasant, given Isabelle/Isar/ without add-ons for
neuper@42499
  1472
programming. Already writing and parsing a few lines of program code
neuper@42499
  1473
is a challenge: the program is an Isabelle term; Isabelle's parser,
neuper@42499
  1474
however, is not meant for huge terms like the program of the running
neuper@42499
  1475
example. So reading out the specific error (usually type errors) from
neuper@42499
  1476
Isabelle's message is difficult.
neuper@42499
  1477
neuper@42499
  1478
\medskip Testing the evaluation of the program has to rely on very
neuper@42499
  1479
simple tools. Step-wise execution is modelled by a function
neuper@42499
  1480
\texttt{me}, short for mathematics-engine~\footnote{The interface used
neuper@42499
  1481
by the fron-end which created the calculation on
neuper@42499
  1482
p.\pageref{fig-interactive} is different from this function}:
neuper@42499
  1483
%the following is a simplification of the actual function 
neuper@42499
  1484
neuper@42499
  1485
{\footnotesize
neuper@42499
  1486
\begin{verbatim}
neuper@42499
  1487
   ML {* me; *}
neuper@42499
  1488
   val it = tac -> ctree * pos -> mout * tac * ctree * pos
neuper@42499
  1489
\end{verbatim}} 
neuper@42499
  1490
neuper@42499
  1491
\noindent This function takes as arguments a tactic \texttt{tac} which
neuper@42499
  1492
determines the next step, the step applied to the interpreter-state
neuper@42499
  1493
\texttt{ctree * pos} as last argument taken. The interpreter-state is
neuper@42499
  1494
a pair of a tree \texttt{ctree} representing the calculation created
neuper@42499
  1495
(see the example below) and a position \texttt{pos} in the
neuper@42499
  1496
calculation. The function delivers a quadrupel, beginning with the new
neuper@42499
  1497
formula \texttt{mout} and the next tactic followed by the new
neuper@42499
  1498
interpreter-state.
neuper@42499
  1499
neuper@42499
  1500
This function allows to stepwise check the program:
neuper@42499
  1501
neuper@42499
  1502
{\footnotesize
neuper@42482
  1503
\begin{verbatim}
neuper@42482
  1504
   ML {*
neuper@42499
  1505
     val fmz =
neuper@42499
  1506
       ["filterExpression (X z = 3 / ((z::real) + 1/10 - 1/50*(1/z)))",
neuper@42499
  1507
        "stepResponse (x[n::real]::bool)"];     
neuper@42499
  1508
     val (dI,pI,mI) =
neuper@42499
  1509
       ("Isac", 
neuper@42499
  1510
        ["Inverse", "Z_Transform", "SignalProcessing"], 
neuper@42499
  1511
        ["SignalProcessing","Z_Transform","Inverse"]);
neuper@42499
  1512
                
neuper@42499
  1513
     val (mout, tac, ctree, pos)  = CalcTreeTEST [(fmz, (dI, pI, mI))];
neuper@42499
  1514
     val (mout, tac, ctree, pos)  = me tac (ctree, pos);
neuper@42499
  1515
     val (mout, tac, ctree, pos)  = me tac (ctree, pos);
neuper@42499
  1516
     val (mout, tac, ctree, pos)  = me tac (ctree, pos);
neuper@42499
  1517
     ...
neuper@42499
  1518
\end{verbatim}} 
neuper@42481
  1519
neuper@42499
  1520
\noindent Several douzens of calls for \texttt{me} are required to
neuper@42499
  1521
create the lines in the calculation below (including the sub-problems
neuper@42499
  1522
not shown). When an error occurs, the reason might be located
neuper@42499
  1523
many steps before: if evaluation by rewriting, as done by the prototype,
neuper@42499
  1524
fails, then first nothing happens --- the effects come later and
neuper@42499
  1525
cause unpleasant checks.
neuper@42481
  1526
neuper@42499
  1527
The checks comprise watching the rewrite-engine for many different
neuper@42499
  1528
kinds of rule-sets (see \S\ref{meth}), the interpreter-state, in
neuper@42499
  1529
particular the environment and the context at the states position ---
neuper@42499
  1530
all checks have to rely on simple functions accessing the
neuper@42499
  1531
\texttt{ctree}. So getting the calculation below (which resembles the
neuper@42499
  1532
calculation in Fig.\ref{fig-interactive} on p.\pageref{fig-interactive})
neuper@42499
  1533
finished successfully is a relief:
jan@42469
  1534
neuper@42498
  1535
{\small\it\label{exp-calc}
neuper@42468
  1536
\begin{tabbing}
neuper@42468
  1537
123l\=123\=123\=123\=123\=123\=123\=123\=123\=123\=123\=123\=\kill
neuper@42468
  1538
\>{\rm 01}\> $\bullet$  \> {\tt Problem } (Inverse\_Z\_Transform, [Inverse, Z\_Transform, SignalProcessing])       \`\\
neuper@42468
  1539
\>{\rm 02}\>\> $\vdash\;\;X z = \frac{3}{z - \frac{1}{4} - \frac{1}{8} \cdot z^{-1}}$       \`{\footnotesize {\tt Take} X\_eq}\\
neuper@42468
  1540
\>{\rm 03}\>\> $X z = \frac{3}{z + \frac{-1}{4} + \frac{-1}{8} \cdot \frac{1}{z}}$          \`{\footnotesize {\tt Rewrite} ruleZY X\_eq}\\
neuper@42468
  1541
\>{\rm 04}\>\> $\bullet$\> {\tt Problem } [partial\_fraction,rational,simplification]        \`{\footnotesize {\tt SubProblem} \dots}\\
neuper@42468
  1542
\>{\rm 05}\>\>\>  $\vdash\;\;\frac{3}{z + \frac{-1}{4} + \frac{-1}{8} \cdot \frac{1}{z}}=$    \`- - -\\
neuper@42468
  1543
\>{\rm 06}\>\>\>  $\frac{24}{-1 + -2 \cdot z + 8 \cdot z^2}$                                   \`- - -\\
neuper@42468
  1544
\>{\rm 07}\>\>\>  $\bullet$\> solve ($-1 + -2 \cdot z + 8 \cdot z^2,\;z$ )                      \`- - -\\
neuper@42468
  1545
\>{\rm 08}\>\>\>\>   $\vdash$ \> $\frac{3}{z + \frac{-1}{4} + \frac{-1}{8} \cdot \frac{1}{z}}=0$ \`- - -\\
neuper@42468
  1546
\>{\rm 09}\>\>\>\>   $z = \frac{2+\sqrt{-4+8}}{16}\;\lor\;z = \frac{2-\sqrt{-4+8}}{16}$           \`- - -\\
neuper@42468
  1547
\>{\rm 10}\>\>\>\>   $z = \frac{1}{2}\;\lor\;z =$ \_\_\_                                           \`- - -\\
neuper@42468
  1548
\>        \>\>\>\>   \_\_\_                                                                        \`- - -\\
neuper@42468
  1549
\>{\rm 11}\>\> \dots\> $\frac{4}{z - \frac{1}{2}} + \frac{-4}{z - \frac{-1}{4}}$                   \`\\
neuper@42468
  1550
\>{\rm 12}\>\> $X^\prime z = {\cal Z}^{-1} (\frac{4}{z - \frac{1}{2}} + \frac{-4}{z - \frac{-1}{4}})$ \`{\footnotesize {\tt Take} ((X'::real =$>$ bool) z = ZZ\_1 part\_frac)}\\
neuper@42468
  1551
\>{\rm 13}\>\> $X^\prime z = {\cal Z}^{-1} (4\cdot\frac{z}{z - \frac{1}{2}} + -4\cdot\frac{z}{z - \frac{-1}{4}})$ \`{\footnotesize{\tt Rewrite\_Set} ruleYZ X'\_eq }\\
neuper@42468
  1552
\>{\rm 14}\>\> $X^\prime z = 4\cdot(\frac{1}{2})^n \cdot u [n] + -4\cdot(\frac{-1}{4})^n \cdot u [n]$  \`{\footnotesize {\tt Rewrite\_Set} inverse\_z X'\_eq}\\
neuper@42468
  1553
\>{\rm 15}\> \dots\> $X^\prime z = 4\cdot(\frac{1}{2})^n \cdot u [n] + -4\cdot(\frac{-1}{4})^n \cdot u [n]$ \`{\footnotesize {\tt Check\_Postcond}}
neuper@42468
  1554
\end{tabbing}}
neuper@42468
  1555
% ORIGINAL FROM Inverse_Z_Transform.thy
neuper@42468
  1556
%    "Script InverseZTransform (X_eq::bool) =            "^(*([], Frm), Problem (Isac, [Inverse, Z_Transform, SignalProcessing])*)
neuper@42468
  1557
%    "(let X = Take X_eq;                                "^(*([1], Frm), X z = 3 / (z - 1 / 4 + -1 / 8 * (1 / z))*)
neuper@42468
  1558
%    "  X' = Rewrite ruleZY False X;                     "^(*([1], Res), ?X' z = 3 / (z * (z - 1 / 4 + -1 / 8 * (1 / z)))*)
neuper@42468
  1559
%    "  (X'_z::real) = lhs X';                           "^(*            ?X' z*)
neuper@42468
  1560
%    "  (zzz::real) = argument_in X'_z;                  "^(*            z *)
neuper@42468
  1561
%    "  (funterm::real) = rhs X';                        "^(*            3 / (z * (z - 1 / 4 + -1 / 8 * (1 / z)))*)
neuper@42468
  1562
% 
neuper@42468
  1563
%    "  (pbz::real) = (SubProblem (Isac',                "^(**)
neuper@42468
  1564
%    "    [partial_fraction,rational,simplification],    "^
neuper@42468
  1565
%    "    [simplification,of_rationals,to_partial_fraction]) "^
neuper@42468
  1566
%    "    [REAL funterm, REAL zzz]);                     "^(*([2], Res), 4 / (z - 1 / 2) + -4 / (z - -1 / 4)*)
neuper@42468
  1567
% 
neuper@42468
  1568
%    "  (pbz_eq::bool) = Take (X'_z = pbz);              "^(*([3], Frm), ?X' z = 4 / (z - 1 / 2) + -4 / (z - -1 / 4)*)
neuper@42468
  1569
%    "  pbz_eq = Rewrite ruleYZ False pbz_eq;            "^(*([3], Res), ?X' z = 4 * (?z / (z - 1 / 2)) + -4 * (?z / (z - -1 / 4))*)
neuper@42468
  1570
%    "  pbz_eq = drop_questionmarks pbz_eq;              "^(*               4 * (z / (z - 1 / 2)) + -4 * (z / (z - -1 / 4))*)
neuper@42468
  1571
%    "  (X_zeq::bool) = Take (X_z = rhs pbz_eq);         "^(*([4], Frm), X_z = 4 * (z / (z - 1 / 2)) + -4 * (z / (z - -1 / 4))*)
neuper@42468
  1572
%    "  n_eq = (Rewrite_Set inverse_z False) X_zeq;      "^(*([4], Res), X_z = 4 * (1 / 2) ^^^ ?n * ?u [?n] + -4 * (-1 / 4) ^^^ ?n * ?u [?n]*)
neuper@42468
  1573
%    "  n_eq = drop_questionmarks n_eq                   "^(*            X_z = 4 * (1 / 2) ^^^ n * u [n] + -4 * (-1 / 4) ^^^ n * u [n]*)
neuper@42468
  1574
%    "in n_eq)"                                            (*([], Res), X_z = 4 * (1 / 2) ^^^ n * u [n] + -4 * (-1 / 4) ^^^ n * u [n]*)
neuper@42468
  1575
neuper@42499
  1576
\subsection{Transfer into the Isabelle/{\isac} Knowledge}\label{flow-trans}
neuper@42499
  1577
Finally \textit{Build\_Inverse\_Z\_Transform.thy} has got the job done
neuper@42499
  1578
and the knowledge accumulated in it can be distributed to appropriate
neuper@42499
  1579
theories: the program to \textit{Inverse\_Z\_Transform.thy}, the
neuper@42499
  1580
sub-problem accomplishing the partial fraction decomposition to
neuper@42499
  1581
\textit{Partial\_Fractions.thy}. Since there are hacks into Isabelle's
neuper@42499
  1582
internals, this kind of distribution is not trivial. For instance, the
neuper@42499
  1583
function \texttt{argument\_in} in \S\ref{funs} explicitly contains a
neuper@42499
  1584
string with the theory it has been defined in, so this string needs to
neuper@42499
  1585
be updated from \texttt{Build\_Inverse\_Z\_Transform} to
neuper@42499
  1586
\texttt{Atools} if that function is transferred to theory
neuper@42499
  1587
\textit{Atools.thy}.
neuper@42468
  1588
neuper@42499
  1589
In order to obtain the functionality presented in Fig.\ref{fig-interactive} on p.\pageref{fig-interactive} data must be exported from SML-structures to XML.
neuper@42499
  1590
This process is also rather bare-bones without authoring tools and is
neuper@42499
  1591
described in detail in the {\sisac} wiki~\footnote{http://www.ist.tugraz.at/isac/index.php/Generate\_representations\_for\_ISAC\_Knowledge}.
neuper@42468
  1592
neuper@42478
  1593
% \newpage
neuper@42478
  1594
% -------------------------------------------------------------------
neuper@42478
  1595
% 
neuper@42478
  1596
% Material, falls noch Platz bleibt ...
neuper@42478
  1597
% 
neuper@42478
  1598
% -------------------------------------------------------------------
neuper@42478
  1599
% 
neuper@42478
  1600
% 
neuper@42478
  1601
% \subsubsection{Trials on Notation and Termination}
neuper@42478
  1602
% 
neuper@42478
  1603
% \paragraph{Technical notations} are a big problem for our piece of software,
neuper@42478
  1604
% but the reason for that isn't a fault of the software itself, one of the
neuper@42478
  1605
% troubles comes out of the fact that different technical subtopics use different
neuper@42478
  1606
% symbols and notations for a different purpose. The most famous example for such
neuper@42478
  1607
% a symbol is the complex number $i$ (in cassique math) or $j$ (in technical
neuper@42478
  1608
% math). In the specific part of signal processing one of this notation issues is
neuper@42478
  1609
% the use of brackets --- we use round brackets for analoge signals and squared
neuper@42478
  1610
% brackets for digital samples. Also if there is no problem for us to handle this
neuper@42478
  1611
% fact, we have to tell the machine what notation leads to wich meaning and that
neuper@42478
  1612
% this purpose seperation is only valid for this special topic - signal
neuper@42478
  1613
% processing.
neuper@42478
  1614
% \subparagraph{In the programming language} itself it is not possible to declare
neuper@42478
  1615
% fractions, exponents, absolutes and other operators or remarks in a way to make
neuper@42478
  1616
% them pretty to read; our only posssiblilty were ASCII characters and a handfull
neuper@42478
  1617
% greek symbols like: $\alpha, \beta, \gamma, \phi,\ldots$.
neuper@42478
  1618
% \par
neuper@42478
  1619
% With the upper collected knowledge it is possible to check if we were able to
neuper@42478
  1620
% donate all required terms and expressions.
neuper@42478
  1621
% 
neuper@42478
  1622
% \subsubsection{Definition and Usage of Rules}
neuper@42478
  1623
% 
neuper@42478
  1624
% \paragraph{The core} of our implemented problem is the Z-Transformation, due
neuper@42478
  1625
% the fact that the transformation itself would require higher math which isn't
neuper@42478
  1626
% yet avaible in our system we decided to choose the way like it is applied in
neuper@42478
  1627
% labratory and problem classes at our university - by applying transformation
neuper@42478
  1628
% rules (collected in transformation tables).
neuper@42478
  1629
% \paragraph{Rules,} in {\sisac{}}'s programming language can be designed by the
neuper@42478
  1630
% use of axiomatizations like shown in Example~\ref{eg:ruledef}
neuper@42478
  1631
% 
neuper@42478
  1632
% \begin{example}
neuper@42478
  1633
%   \label{eg:ruledef}
neuper@42478
  1634
%   \hfill\\
neuper@42478
  1635
%   \begin{verbatim}
neuper@42478
  1636
%   axiomatization where
neuper@42478
  1637
%     rule1: ``1 = $\delta$[n]'' and
neuper@42478
  1638
%     rule2: ``|| z || > 1 ==> z / (z - 1) = u [n]'' and
neuper@42478
  1639
%     rule3: ``|| z || < 1 ==> z / (z - 1) = -u [-n - 1]''
neuper@42478
  1640
%   \end{verbatim}
neuper@42478
  1641
% \end{example}
neuper@42478
  1642
% 
neuper@42478
  1643
% This rules can be collected in a ruleset and applied to a given expression as
neuper@42478
  1644
% follows in Example~\ref{eg:ruleapp}.
neuper@42478
  1645
% 
neuper@42478
  1646
% \begin{example}
neuper@42478
  1647
%   \hfill\\
neuper@42478
  1648
%   \label{eg:ruleapp}
neuper@42478
  1649
%   \begin{enumerate}
neuper@42478
  1650
%   \item Store rules in ruleset:
neuper@42478
  1651
%   \begin{verbatim}
neuper@42478
  1652
%   val inverse_Z = append_rls "inverse_Z" e_rls
neuper@42478
  1653
%     [ Thm ("rule1",num_str @{thm rule1}),
neuper@42478
  1654
%       Thm ("rule2",num_str @{thm rule2}),
neuper@42478
  1655
%       Thm ("rule3",num_str @{thm rule3})
neuper@42478
  1656
%     ];\end{verbatim}
neuper@42478
  1657
%   \item Define exression:
neuper@42478
  1658
%   \begin{verbatim}
neuper@42478
  1659
%   val sample_term = str2term "z/(z-1)+z/(z-</delta>)+1";\end{verbatim}
neuper@42478
  1660
%   \item Apply ruleset:
neuper@42478
  1661
%   \begin{verbatim}
neuper@42478
  1662
%   val SOME (sample_term', asm) = 
neuper@42478
  1663
%     rewrite_set_ thy true inverse_Z sample_term;\end{verbatim}
neuper@42478
  1664
%   \end{enumerate}
neuper@42478
  1665
% \end{example}
neuper@42478
  1666
% 
neuper@42478
  1667
% The use of rulesets makes it much easier to develop our designated applications,
neuper@42478
  1668
% but the programmer has to be careful and patient. When applying rulesets
neuper@42478
  1669
% two important issues have to be mentionend:
neuper@42478
  1670
% \subparagraph{How often} the rules have to be applied? In case of
neuper@42478
  1671
% transformations it is quite clear that we use them once but other fields
neuper@42478
  1672
% reuqire to apply rules until a special condition is reached (e.g.
neuper@42478
  1673
% a simplification is finished when there is nothing to be done left).
neuper@42478
  1674
% \subparagraph{The order} in which rules are applied often takes a big effect
neuper@42478
  1675
% and has to be evaluated for each purpose once again.
neuper@42478
  1676
% \par
neuper@42478
  1677
% In our special case of Signal Processing and the rules defined in
neuper@42478
  1678
% Example~\ref{eg:ruledef} we have to apply rule~1 first of all to transform all
neuper@42478
  1679
% constants. After this step has been done it no mather which rule fit's next.
neuper@42478
  1680
% 
neuper@42478
  1681
% \subsubsection{Helping Functions}
neuper@42478
  1682
% 
neuper@42478
  1683
% \paragraph{New Programms require,} often new ways to get through. This new ways
neuper@42478
  1684
% means that we handle functions that have not been in use yet, they can be 
neuper@42478
  1685
% something special and unique for a programm or something famous but unneeded in
neuper@42478
  1686
% the system yet. In our dedicated example it was for example neccessary to split
neuper@42478
  1687
% a fraction into numerator and denominator; the creation of such function and
neuper@42478
  1688
% even others is described in upper Sections~\ref{simp} and \ref{funs}.
neuper@42478
  1689
% 
neuper@42478
  1690
% \subsubsection{Trials on equation solving}
neuper@42478
  1691
% %simple eq and problem with double fractions/negative exponents
neuper@42478
  1692
% \paragraph{The Inverse Z-Transformation} makes it neccessary to solve
neuper@42478
  1693
% equations degree one and two. Solving equations in the first degree is no 
neuper@42478
  1694
% problem, wether for a student nor for our machine; but even second degree
neuper@42478
  1695
% equations can lead to big troubles. The origin of this troubles leads from
neuper@42478
  1696
% the build up process of our equation solving functions; they have been
neuper@42478
  1697
% implemented some time ago and of course they are not as good as we want them to
neuper@42478
  1698
% be. Wether or not following we only want to show how cruel it is to build up new
neuper@42478
  1699
% work on not well fundamentials.
neuper@42478
  1700
% \subparagraph{A simple equation solving,} can be set up as shown in the next
neuper@42478
  1701
% example:
neuper@42478
  1702
% 
neuper@42478
  1703
% \begin{example}
neuper@42478
  1704
% \begin{verbatim}
neuper@42478
  1705
%   
neuper@42478
  1706
%   val fmz =
neuper@42478
  1707
%     ["equality (-1 + -2 * z + 8 * z ^^^ 2 = (0::real))",
neuper@42478
  1708
%      "solveFor z",
neuper@42478
  1709
%      "solutions L"];                                    
neuper@42478
  1710
% 
neuper@42478
  1711
%   val (dI',pI',mI') =
neuper@42478
  1712
%     ("Isac", 
neuper@42478
  1713
%       ["abcFormula","degree_2","polynomial","univariate","equation"],
neuper@42478
  1714
%       ["no_met"]);\end{verbatim}
neuper@42478
  1715
% \end{example}
neuper@42478
  1716
% 
neuper@42478
  1717
% Here we want to solve the equation: $-1+-2\cdot z+8\cdot z^{2}=0$. (To give
neuper@42478
  1718
% a short overview on the commands; at first we set up the equation and tell the
neuper@42478
  1719
% machine what's the bound variable and where to store the solution. Second step 
neuper@42478
  1720
% is to define the equation type and determine if we want to use a special method
neuper@42478
  1721
% to solve this type.) Simple checks tell us that the we will get two results for
neuper@42478
  1722
% this equation and this results will be real.
neuper@42478
  1723
% So far it is easy for us and for our machine to solve, but
neuper@42478
  1724
% mentioned that a unvariate equation second order can have three different types
neuper@42478
  1725
% of solutions it is getting worth.
neuper@42478
  1726
% \subparagraph{The solving of} all this types of solutions is not yet supported.
neuper@42478
  1727
% Luckily it was needed for us; but something which has been needed in this 
neuper@42478
  1728
% context, would have been the solving of an euation looking like:
neuper@42478
  1729
% $-z^{-2}+-2\cdot z^{-1}+8=0$ which is basically the same equation as mentioned
neuper@42478
  1730
% before (remember that befor it was no problem to handle for the machine) but
neuper@42478
  1731
% now, after a simple equivalent transformation, we are not able to solve
neuper@42478
  1732
% it anymore.
neuper@42478
  1733
% \subparagraph{Error messages} we get when we try to solve something like upside
neuper@42478
  1734
% were very confusing and also leads us to no special hint about a problem.
neuper@42478
  1735
% \par The fault behind is, that we have no well error handling on one side and
neuper@42478
  1736
% no sufficient formed equation solving on the other side. This two facts are
neuper@42478
  1737
% making the implemention of new material very difficult.
neuper@42478
  1738
% 
neuper@42478
  1739
% \subsection{Formalization of missing knowledge in Isabelle}
neuper@42478
  1740
% 
neuper@42478
  1741
% \paragraph{A problem} behind is the mechanization of mathematic
neuper@42478
  1742
% theories in TP-bases languages. There is still a huge gap between
neuper@42478
  1743
% these algorithms and this what we want as a solution - in Example
neuper@42478
  1744
% Signal Processing. 
neuper@42478
  1745
% 
neuper@42478
  1746
% \vbox{
neuper@42478
  1747
%   \begin{example}
neuper@42478
  1748
%     \label{eg:gap}
neuper@42478
  1749
%     \[
neuper@42478
  1750
%       X\cdot(a+b)+Y\cdot(c+d)=aX+bX+cY+dY
neuper@42478
  1751
%     \]
neuper@42478
  1752
%     {\small\textit{
neuper@42478
  1753
%       \noindent A very simple example on this what we call gap is the
neuper@42478
  1754
% simplification above. It is needles to say that it is correct and also
neuper@42478
  1755
% Isabelle for fills it correct - \emph{always}. But sometimes we don't
neuper@42478
  1756
% want expand such terms, sometimes we want another structure of
neuper@42478
  1757
% them. Think of a problem were we now would need only the coefficients
neuper@42478
  1758
% of $X$ and $Y$. This is what we call the gap between mechanical
neuper@42478
  1759
% simplification and the solution.
neuper@42478
  1760
%     }}
neuper@42478
  1761
%   \end{example}
neuper@42478
  1762
% }
neuper@42478
  1763
% 
neuper@42478
  1764
% \paragraph{We are not able to fill this gap,} until we have to live
neuper@42478
  1765
% with it but first have a look on the meaning of this statement:
neuper@42478
  1766
% Mechanized math starts from mathematical models and \emph{hopefully}
neuper@42478
  1767
% proceeds to match physics. Academic engineering starts from physics
neuper@42478
  1768
% (experimentation, measurement) and then proceeds to mathematical
neuper@42478
  1769
% modeling and formalization. The process from a physical observance to
neuper@42478
  1770
% a mathematical theory is unavoidable bound of setting up a big
neuper@42478
  1771
% collection of standards, rules, definition but also exceptions. These
neuper@42478
  1772
% are the things making mechanization that difficult.
neuper@42478
  1773
% 
neuper@42478
  1774
% \vbox{
neuper@42478
  1775
%   \begin{example}
neuper@42478
  1776
%     \label{eg:units}
neuper@42478
  1777
%     \[
neuper@42478
  1778
%       m,\ kg,\ s,\ldots
neuper@42478
  1779
%     \]
neuper@42478
  1780
%     {\small\textit{
neuper@42478
  1781
%       \noindent Think about some units like that one's above. Behind
neuper@42478
  1782
% each unit there is a discerning and very accurate definition: One
neuper@42478
  1783
% Meter is the distance the light travels, in a vacuum, through the time
neuper@42478
  1784
% of 1 / 299.792.458 second; one kilogram is the weight of a
neuper@42478
  1785
% platinum-iridium cylinder in paris; and so on. But are these
neuper@42478
  1786
% definitions usable in a computer mechanized world?!
neuper@42478
  1787
%     }}
neuper@42478
  1788
%   \end{example}
neuper@42478
  1789
% }
neuper@42478
  1790
% 
neuper@42478
  1791
% \paragraph{A computer} or a TP-System builds on programs with
neuper@42478
  1792
% predefined logical rules and does not know any mathematical trick
neuper@42478
  1793
% (follow up example \ref{eg:trick}) or recipe to walk around difficult
neuper@42478
  1794
% expressions. 
neuper@42478
  1795
% 
neuper@42478
  1796
% \vbox{
neuper@42478
  1797
%   \begin{example}
neuper@42478
  1798
%     \label{eg:trick}
neuper@42478
  1799
%   \[ \frac{1}{j\omega}\cdot\left(e^{-j\omega}-e^{j3\omega}\right)= \]
neuper@42478
  1800
%   \[ \frac{1}{j\omega}\cdot e^{-j2\omega}\cdot\left(e^{j\omega}-e^{-j\omega}\right)=
neuper@42478
  1801
%      \frac{1}{\omega}\, e^{-j2\omega}\cdot\colorbox{lgray}{$\frac{1}{j}\,\left(e^{j\omega}-e^{-j\omega}\right)$}= \]
neuper@42478
  1802
%   \[ \frac{1}{\omega}\, e^{-j2\omega}\cdot\colorbox{lgray}{$2\, sin(\omega)$} \]
neuper@42478
  1803
%     {\small\textit{
neuper@42478
  1804
%       \noindent Sometimes it is also useful to be able to apply some
neuper@42478
  1805
% \emph{tricks} to get a beautiful and particularly meaningful result,
neuper@42478
  1806
% which we are able to interpret. But as seen in this example it can be
neuper@42478
  1807
% hard to find out what operations have to be done to transform a result
neuper@42478
  1808
% into a meaningful one.
neuper@42478
  1809
%     }}
neuper@42478
  1810
%   \end{example}
neuper@42478
  1811
% }
neuper@42478
  1812
% 
neuper@42478
  1813
% \paragraph{The only possibility,} for such a system, is to work
neuper@42478
  1814
% through its known definitions and stops if none of these
neuper@42478
  1815
% fits. Specified on Signal Processing or any other application it is
neuper@42478
  1816
% often possible to walk through by doing simple creases. This creases
neuper@42478
  1817
% are in general based on simple math operational but the challenge is
neuper@42478
  1818
% to teach the machine \emph{all}\footnote{Its pride to call it
neuper@42478
  1819
% \emph{all}.} of them. Unfortunately the goal of TP Isabelle is to
neuper@42478
  1820
% reach a high level of \emph{all} but it in real it will still be a
neuper@42478
  1821
% survey of knowledge which links to other knowledge and {{\sisac}{}} a
neuper@42478
  1822
% trainer and helper but no human compensating calculator. 
neuper@42478
  1823
% \par
neuper@42478
  1824
% {{{\sisac}{}}} itself aims to adds \emph{Algorithmic Knowledge} (formal
neuper@42478
  1825
% specifications of problems out of topics from Signal Processing, etc.)
neuper@42478
  1826
% and \emph{Application-oriented Knowledge} to the \emph{deductive} axis of
neuper@42478
  1827
% physical knowledge. The result is a three-dimensional universe of
neuper@42478
  1828
% mathematics seen in Figure~\ref{fig:mathuni}.
neuper@42478
  1829
% 
neuper@42478
  1830
% \begin{figure}
neuper@42478
  1831
%   \begin{center}
neuper@42478
  1832
%     \includegraphics{fig/universe}
neuper@42478
  1833
%     \caption{Didactic ``Math-Universe'': Algorithmic Knowledge (Programs) is
neuper@42478
  1834
%              combined with Application-oriented Knowledge (Specifications) and Deductive Knowledge (Axioms, Definitions, Theorems). The Result
neuper@42478
  1835
%              leads to a three dimensional math universe.\label{fig:mathuni}}
neuper@42478
  1836
%   \end{center}
neuper@42478
  1837
% \end{figure}
neuper@42478
  1838
% 
neuper@42478
  1839
% %WN Deine aktuelle Benennung oben wird Dir kein Fachmann abnehmen;
neuper@42478
  1840
% %WN bitte folgende Bezeichnungen nehmen:
neuper@42478
  1841
% %WN 
neuper@42478
  1842
% %WN axis 1: Algorithmic Knowledge (Programs)
neuper@42478
  1843
% %WN axis 2: Application-oriented Knowledge (Specifications)
neuper@42478
  1844
% %WN axis 3: Deductive Knowledge (Axioms, Definitions, Theorems)
neuper@42478
  1845
% %WN 
neuper@42478
  1846
% %WN und bitte die R"ander von der Grafik wegschneiden (was ich f"ur *.pdf
neuper@42478
  1847
% %WN nicht hinkriege --- weshalb ich auch die eJMT-Forderung nicht ganz
neuper@42478
  1848
% %WN verstehe, separierte PDFs zu schicken; ich w"urde *.png schicken)
neuper@42478
  1849
% 
neuper@42478
  1850
% %JR Ränder und beschriftung geändert. Keine Ahnung warum eJMT sich pdf's
neuper@42478
  1851
% %JR wünschen, würde ebenfalls png oder ähnliches verwenden, aber wenn pdf's
neuper@42478
  1852
% %JR gefordert werden WN2...
neuper@42478
  1853
% %WN2 meiner Meinung nach hat sich eJMT unklar ausgedr"uckt (z.B. kann
neuper@42478
  1854
% %WN2 man meines Wissens pdf-figures nicht auf eine bestimmte Gr"osse
neuper@42478
  1855
% %WN2 zusammenschneiden um die R"ander weg zu bekommen)
neuper@42478
  1856
% %WN2 Mein Vorschlag ist, in umserem tex-file bei *.png zu bleiben und
neuper@42478
  1857
% %WN2 png + pdf figures mitzuschicken.
neuper@42478
  1858
% 
neuper@42478
  1859
% \subsection{Notes on Problems with Traditional Notation}
neuper@42478
  1860
% 
neuper@42478
  1861
% \paragraph{During research} on these topic severely problems on
neuper@42478
  1862
% traditional notations have been discovered. Some of them have been
neuper@42478
  1863
% known in computer science for many years now and are still unsolved,
neuper@42478
  1864
% one of them aggregates with the so called \emph{Lambda Calculus},
neuper@42478
  1865
% Example~\ref{eg:lamda} provides a look on the problem that embarrassed
neuper@42478
  1866
% us.
neuper@42478
  1867
% 
neuper@42478
  1868
% \vbox{
neuper@42478
  1869
%   \begin{example}
neuper@42478
  1870
%     \label{eg:lamda}
neuper@42478
  1871
% 
neuper@42478
  1872
%   \[ f(x)=\ldots\;  \quad R \rightarrow \quad R \]
neuper@42478
  1873
% 
neuper@42478
  1874
% 
neuper@42478
  1875
%   \[ f(p)=\ldots\;  p \in \quad R \]
neuper@42478
  1876
% 
neuper@42478
  1877
%     {\small\textit{
neuper@42478
  1878
%       \noindent Above we see two equations. The first equation aims to
neuper@42478
  1879
% be a mapping of an function from the reel range to the reel one, but
neuper@42478
  1880
% when we change only one letter we get the second equation which
neuper@42478
  1881
% usually aims to insert a reel point $p$ into the reel function. In
neuper@42478
  1882
% computer science now we have the problem to tell the machine (TP) the
neuper@42478
  1883
% difference between this two notations. This Problem is called
neuper@42478
  1884
% \emph{Lambda Calculus}.
neuper@42478
  1885
%     }}
neuper@42478
  1886
%   \end{example}
neuper@42478
  1887
% }
neuper@42478
  1888
% 
neuper@42478
  1889
% \paragraph{An other problem} is that terms are not full simplified in
neuper@42478
  1890
% traditional notations, in {{\sisac}} we have to simplify them complete
neuper@42478
  1891
% to check weather results are compatible or not. in e.g. the solutions
neuper@42478
  1892
% of an second order linear equation is an rational in {{\sisac}} but in
neuper@42478
  1893
% tradition we keep fractions as long as possible and as long as they
neuper@42478
  1894
% aim to be \textit{beautiful} (1/8, 5/16,...).
neuper@42478
  1895
% \subparagraph{The math} which should be mechanized in Computer Theorem
neuper@42478
  1896
% Provers (\emph{TP}) has (almost) a problem with traditional notations
neuper@42478
  1897
% (predicate calculus) for axioms, definitions, lemmas, theorems as a
neuper@42478
  1898
% computer program or script is not able to interpret every Greek or
neuper@42478
  1899
% Latin letter and every Greek, Latin or whatever calculations
neuper@42478
  1900
% symbol. Also if we would be able to handle these symbols we still have
neuper@42478
  1901
% a problem to interpret them at all. (Follow up \hbox{Example
neuper@42478
  1902
% \ref{eg:symbint1}})
neuper@42478
  1903
% 
neuper@42478
  1904
% \vbox{
neuper@42478
  1905
%   \begin{example}
neuper@42478
  1906
%     \label{eg:symbint1}
neuper@42478
  1907
%     \[
neuper@42478
  1908
%       u\left[n\right] \ \ldots \ unitstep
neuper@42478
  1909
%     \]
neuper@42478
  1910
%     {\small\textit{
neuper@42478
  1911
%       \noindent The unitstep is something we need to solve Signal
neuper@42478
  1912
% Processing problem classes. But in {{{\sisac}{}}} the rectangular
neuper@42478
  1913
% brackets have a different meaning. So we abuse them for our
neuper@42478
  1914
% requirements. We get something which is not defined, but usable. The
neuper@42478
  1915
% Result is syntax only without semantic.
neuper@42478
  1916
%     }}
neuper@42478
  1917
%   \end{example}
neuper@42478
  1918
% }
neuper@42478
  1919
% 
neuper@42478
  1920
% In different problems, symbols and letters have different meanings and
neuper@42478
  1921
% ask for different ways to get through. (Follow up \hbox{Example
neuper@42478
  1922
% \ref{eg:symbint2}}) 
neuper@42478
  1923
% 
neuper@42478
  1924
% \vbox{
neuper@42478
  1925
%   \begin{example}
neuper@42478
  1926
%     \label{eg:symbint2}
neuper@42478
  1927
%     \[
neuper@42478
  1928
%       \widehat{\ }\ \widehat{\ }\ \widehat{\ } \  \ldots \  exponent
neuper@42478
  1929
%     \]
neuper@42478
  1930
%     {\small\textit{
neuper@42478
  1931
%     \noindent For using exponents the three \texttt{widehat} symbols
neuper@42478
  1932
% are required. The reason for that is due the development of
neuper@42478
  1933
% {{{\sisac}{}}} the single \texttt{widehat} and also the double were
neuper@42478
  1934
% already in use for different operations.
neuper@42478
  1935
%     }}
neuper@42478
  1936
%   \end{example}
neuper@42478
  1937
% }
neuper@42478
  1938
% 
neuper@42478
  1939
% \paragraph{Also the output} can be a problem. We are familiar with a
neuper@42478
  1940
% specified notations and style taught in university but a computer
neuper@42478
  1941
% program has no knowledge of the form proved by a professor and the
neuper@42478
  1942
% machines themselves also have not yet the possibilities to print every
neuper@42478
  1943
% symbol (correct) Recent developments provide proofs in a human
neuper@42478
  1944
% readable format but according to the fact that there is no money for
neuper@42478
  1945
% good working formal editors yet, the style is one thing we have to
neuper@42478
  1946
% live with.
neuper@42478
  1947
% 
neuper@42478
  1948
% \section{Problems rising out of the Development Environment}
neuper@42478
  1949
% 
neuper@42478
  1950
% fehlermeldungen! TODO
jan@42463
  1951
neuper@42492
  1952
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\end{verbatim}
neuper@42492
  1953
neuper@42464
  1954
\section{Conclusion}\label{conclusion}
neuper@42492
  1955
This paper gives a first experience report about programming with a
neuper@42492
  1956
TP-based programming language.
jan@42463
  1957
neuper@42492
  1958
\medskip A brief re-introduction of the novel kind of programming
neuper@42492
  1959
language by example of the {\sisac}-prototype makes the paper
neuper@42492
  1960
self-contained. The main section describes all the main concepts
neuper@42492
  1961
involved in TP-based programming and all the sub-tasks concerning
neuper@42492
  1962
respective implementation: mechanisation of mathematics and domain
neuper@42492
  1963
modelling, implementation of term rewriting systems for the
neuper@42492
  1964
rewriting-engine, formal (implicit) specification of the problem to be
neuper@42492
  1965
(explicitly) described by the program, implement the many components
neuper@42492
  1966
required for Lucas-Interpretation and finally implementation of the
neuper@42492
  1967
program itself.
neuper@42492
  1968
neuper@42492
  1969
The many concepts and sub-tasks involved in programming require a
neuper@42492
  1970
comprehensive workflow; first experiences with the workflow as
neuper@42492
  1971
supported by the present prototype are described as well: Isabelle +
neuper@42492
  1972
Isar + jEdit provide appropriate components for establishing an
neuper@42492
  1973
efficient development environment integrating computation and
neuper@42492
  1974
deduction. However, the present state of the prototype is far off a
neuper@42492
  1975
state appropriate for wide-spread use: the prototype of the program
neuper@42492
  1976
language lacks expressiveness and elegance, the prototype of the
neuper@42492
  1977
development environment is hardly usable: error messages still address
neuper@42492
  1978
the developer of the prototype's interpreter rather than the
neuper@42492
  1979
application programmer, implementation of the many settings for the
neuper@42492
  1980
Lucas-Interpreter is cumbersome.
neuper@42492
  1981
neuper@42492
  1982
From these experiences a successful proof of concept can be concluded:
neuper@42492
  1983
programming arbitrary problems from engineering sciences is possible,
neuper@42492
  1984
in principle even in the prototype. Furthermore the experiences allow
neuper@42492
  1985
to conclude detailed requirements for further development:
neuper@42492
  1986
\begin{itemize}
neuper@42492
  1987
\item Clarify underlying logics such that programming is smoothly
neuper@42492
  1988
integrated with verification of the program; the post-condition should
neuper@42492
  1989
be proved more or less automatically, otherwise working engineers
neuper@42492
  1990
would not encounter such programming.
neuper@42492
  1991
\item Combine the prototype's programming language with Isabelle's
neuper@42492
  1992
powerful function package and probably with more of SML's
neuper@42492
  1993
pattern-matching features; include parallel execution on multi-core
neuper@42492
  1994
machines into the language desing.
neuper@42492
  1995
\item Extend the prototype's Lucas-Interpreter such that it also
neuper@42492
  1996
handles functions defined by use of Isabelle's functions package; and
neuper@42492
  1997
generalize Isabelle's code generator such that efficient code for the
neuper@42492
  1998
whole of the defined programming language can be generated (for
neuper@42492
  1999
multi-core machines).
neuper@42492
  2000
\item Develop an efficient development environment with
neuper@42492
  2001
integration of programming and proving, with management not only of
neuper@42492
  2002
Isabelle theories, but also of large collections of specifications and
neuper@42492
  2003
of programs.
neuper@42492
  2004
\end{itemize} 
neuper@42492
  2005
Provided successful accomplishment, these points provide distinguished
neuper@42492
  2006
components for virtual workbenches appealing to practictioner of
neuper@42492
  2007
engineering in the near future.
neuper@42492
  2008
neuper@42492
  2009
\medskip And all programming with a TP-based language will
neuper@42492
  2010
subsequently create interactive tutoring as a side-effect:
neuper@42492
  2011
Lucas-Interpretation not only provides an interactive programming
neuper@42492
  2012
environment, Lucas-Interpretation also can provide TP-based services
neuper@42492
  2013
for a flexible dialog component with adaptive user guidance for
neuper@42492
  2014
independent and inquiry-based learning.
neuper@42492
  2015
jan@42463
  2016
jan@42463
  2017
\bibliographystyle{alpha}
jan@42463
  2018
\bibliography{references}
jan@42463
  2019
jan@42463
  2020
\end{document}