doc-src/TutorialI/Recdef/document/Nested1.tex
author wenzelm
Tue, 29 Aug 2000 12:08:20 +0200
changeset 9719 c753196599f9
parent 9698 f0740137a65d
child 9721 7e51c9f3d5a0
permissions -rw-r--r--
updated;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9719
c753196599f9 updated;
wenzelm
parents: 9698
diff changeset
     1
%
c753196599f9 updated;
wenzelm
parents: 9698
diff changeset
     2
\begin{isabellebody}%
9698
f0740137a65d updated;
wenzelm
parents:
diff changeset
     3
\isacommand{consts}\ trev\ \ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharprime}a{\isacharcomma}{\isacharprime}b{\isacharparenright}term\ {\isacharequal}{\isachargreater}\ {\isacharparenleft}{\isacharprime}a{\isacharcomma}{\isacharprime}b{\isacharparenright}term{\isachardoublequote}%
f0740137a65d updated;
wenzelm
parents:
diff changeset
     4
\begin{isamarkuptext}%
f0740137a65d updated;
wenzelm
parents:
diff changeset
     5
\noindent
f0740137a65d updated;
wenzelm
parents:
diff changeset
     6
Although the definition of \isa{trev} is quite natural, we will have
f0740137a65d updated;
wenzelm
parents:
diff changeset
     7
overcome a minor difficulty in convincing Isabelle of is termination.
f0740137a65d updated;
wenzelm
parents:
diff changeset
     8
It is precisely this difficulty that is the \textit{rasion d'\^etre} of
f0740137a65d updated;
wenzelm
parents:
diff changeset
     9
this subsection.
f0740137a65d updated;
wenzelm
parents:
diff changeset
    10
f0740137a65d updated;
wenzelm
parents:
diff changeset
    11
Defining \isa{trev} by \isacommand{recdef} rather than \isacommand{primrec}
f0740137a65d updated;
wenzelm
parents:
diff changeset
    12
simplifies matters because we are now free to use the recursion equation
f0740137a65d updated;
wenzelm
parents:
diff changeset
    13
suggested at the end of \S\ref{sec:nested-datatype}:%
f0740137a65d updated;
wenzelm
parents:
diff changeset
    14
\end{isamarkuptext}%
f0740137a65d updated;
wenzelm
parents:
diff changeset
    15
\isacommand{recdef}\ trev\ {\isachardoublequote}measure\ size{\isachardoublequote}\isanewline
f0740137a65d updated;
wenzelm
parents:
diff changeset
    16
\ {\isachardoublequote}trev\ {\isacharparenleft}Var\ x{\isacharparenright}\ {\isacharequal}\ Var\ x{\isachardoublequote}\isanewline
f0740137a65d updated;
wenzelm
parents:
diff changeset
    17
\ {\isachardoublequote}trev\ {\isacharparenleft}App\ f\ ts{\isacharparenright}\ {\isacharequal}\ App\ f\ {\isacharparenleft}rev{\isacharparenleft}map\ trev\ ts{\isacharparenright}{\isacharparenright}{\isachardoublequote}%
f0740137a65d updated;
wenzelm
parents:
diff changeset
    18
\begin{isamarkuptext}%
f0740137a65d updated;
wenzelm
parents:
diff changeset
    19
FIXME: recdef should complain and generate unprovable termination condition!
f0740137a65d updated;
wenzelm
parents:
diff changeset
    20
moveto todo
f0740137a65d updated;
wenzelm
parents:
diff changeset
    21
f0740137a65d updated;
wenzelm
parents:
diff changeset
    22
Remember that function \isa{size} is defined for each \isacommand{datatype}.
f0740137a65d updated;
wenzelm
parents:
diff changeset
    23
However, the definition does not succeed. Isabelle complains about an unproved termination
f0740137a65d updated;
wenzelm
parents:
diff changeset
    24
condition
f0740137a65d updated;
wenzelm
parents:
diff changeset
    25
\begin{quote}
f0740137a65d updated;
wenzelm
parents:
diff changeset
    26
f0740137a65d updated;
wenzelm
parents:
diff changeset
    27
\begin{isabelle}%
f0740137a65d updated;
wenzelm
parents:
diff changeset
    28
\mbox{t}\ {\isasymin}\ set\ \mbox{ts}\ {\isasymlongrightarrow}\ size\ \mbox{t}\ {\isacharless}\ Suc\ {\isacharparenleft}term{\isacharunderscore}size\ \mbox{ts}{\isacharparenright}
f0740137a65d updated;
wenzelm
parents:
diff changeset
    29
\end{isabelle}%
f0740137a65d updated;
wenzelm
parents:
diff changeset
    30
f0740137a65d updated;
wenzelm
parents:
diff changeset
    31
\end{quote}
f0740137a65d updated;
wenzelm
parents:
diff changeset
    32
where \isa{set} returns the set of elements of a list---no special knowledge of sets is
f0740137a65d updated;
wenzelm
parents:
diff changeset
    33
required in the following.
f0740137a65d updated;
wenzelm
parents:
diff changeset
    34
First we have to understand why the recursive call of \isa{trev} underneath \isa{map} leads
f0740137a65d updated;
wenzelm
parents:
diff changeset
    35
to the above condition. The reason is that \isacommand{recdef} ``knows'' that \isa{map} will
f0740137a65d updated;
wenzelm
parents:
diff changeset
    36
apply \isa{trev} only to elements of \isa{\mbox{ts}}. Thus the above condition expresses that
f0740137a65d updated;
wenzelm
parents:
diff changeset
    37
the size of the argument \isa{\mbox{t}\ {\isasymin}\ set\ \mbox{ts}} of any recursive call of \isa{trev} is strictly
f0740137a65d updated;
wenzelm
parents:
diff changeset
    38
less than \isa{size\ {\isacharparenleft}App\ \mbox{f}\ \mbox{ts}{\isacharparenright}\ {\isacharequal}\ Suc\ {\isacharparenleft}term{\isacharunderscore}size\ \mbox{ts}{\isacharparenright}}.
f0740137a65d updated;
wenzelm
parents:
diff changeset
    39
We will now prove the termination condition and continue with our definition.
f0740137a65d updated;
wenzelm
parents:
diff changeset
    40
Below we return to the question of how \isacommand{recdef} ``knows'' about \isa{map}.%
f0740137a65d updated;
wenzelm
parents:
diff changeset
    41
\end{isamarkuptext}%
9719
c753196599f9 updated;
wenzelm
parents: 9698
diff changeset
    42
\end{isabellebody}%
9698
f0740137a65d updated;
wenzelm
parents:
diff changeset
    43
%%% Local Variables:
f0740137a65d updated;
wenzelm
parents:
diff changeset
    44
%%% mode: latex
f0740137a65d updated;
wenzelm
parents:
diff changeset
    45
%%% TeX-master: "root"
f0740137a65d updated;
wenzelm
parents:
diff changeset
    46
%%% End: