doc-src/TutorialI/Recdef/document/Nested1.tex
author wenzelm
Fri, 18 Jan 2002 18:30:19 +0100
changeset 12815 1f073030b97a
parent 12491 e28870d8b223
child 13758 ee898d32de21
permissions -rw-r--r--
tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9722
a5f86aed785b *** empty log message ***
nipkow
parents: 9721
diff changeset
     1
%
a5f86aed785b *** empty log message ***
nipkow
parents: 9721
diff changeset
     2
\begin{isabellebody}%
10267
325ead6d9457 updated;
wenzelm
parents: 10186
diff changeset
     3
\def\isabellecontext{Nested{\isadigit{1}}}%
11866
fbd097aec213 updated;
wenzelm
parents: 11636
diff changeset
     4
\isamarkupfalse%
10186
499637e8f2c6 *** empty log message ***
nipkow
parents: 9933
diff changeset
     5
%
9698
f0740137a65d updated;
wenzelm
parents:
diff changeset
     6
\begin{isamarkuptext}%
f0740137a65d updated;
wenzelm
parents:
diff changeset
     7
\noindent
11277
a2bff98d6e5d *** empty log message ***
nipkow
parents: 10878
diff changeset
     8
Although the definition of \isa{trev} below is quite natural, we will have
10878
b254d5ad6dd4 auto update
paulson
parents: 10267
diff changeset
     9
to overcome a minor difficulty in convincing Isabelle of its termination.
9754
a123a64cadeb *** empty log message ***
nipkow
parents: 9722
diff changeset
    10
It is precisely this difficulty that is the \textit{raison d'\^etre} of
9698
f0740137a65d updated;
wenzelm
parents:
diff changeset
    11
this subsection.
f0740137a65d updated;
wenzelm
parents:
diff changeset
    12
f0740137a65d updated;
wenzelm
parents:
diff changeset
    13
Defining \isa{trev} by \isacommand{recdef} rather than \isacommand{primrec}
f0740137a65d updated;
wenzelm
parents:
diff changeset
    14
simplifies matters because we are now free to use the recursion equation
f0740137a65d updated;
wenzelm
parents:
diff changeset
    15
suggested at the end of \S\ref{sec:nested-datatype}:%
f0740137a65d updated;
wenzelm
parents:
diff changeset
    16
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11636
diff changeset
    17
\isamarkuptrue%
11636
wenzelm
parents: 11627
diff changeset
    18
\isacommand{recdef}\ trev\ {\isachardoublequote}measure\ size{\isachardoublequote}\isanewline
wenzelm
parents: 11627
diff changeset
    19
\ {\isachardoublequote}trev\ {\isacharparenleft}Var\ x{\isacharparenright}\ \ \ \ {\isacharequal}\ Var\ x{\isachardoublequote}\isanewline
11866
fbd097aec213 updated;
wenzelm
parents: 11636
diff changeset
    20
\ {\isachardoublequote}trev\ {\isacharparenleft}App\ f\ ts{\isacharparenright}\ {\isacharequal}\ App\ f\ {\isacharparenleft}rev{\isacharparenleft}map\ trev\ ts{\isacharparenright}{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
fbd097aec213 updated;
wenzelm
parents: 11636
diff changeset
    21
%
11636
wenzelm
parents: 11627
diff changeset
    22
\begin{isamarkuptext}%
wenzelm
parents: 11627
diff changeset
    23
\noindent
wenzelm
parents: 11627
diff changeset
    24
Remember that function \isa{size} is defined for each \isacommand{datatype}.
wenzelm
parents: 11627
diff changeset
    25
However, the definition does not succeed. Isabelle complains about an
wenzelm
parents: 11627
diff changeset
    26
unproved termination condition
wenzelm
parents: 11627
diff changeset
    27
\begin{isabelle}%
wenzelm
parents: 11627
diff changeset
    28
\ \ \ \ \ t\ {\isasymin}\ set\ ts\ {\isasymlongrightarrow}\ size\ t\ {\isacharless}\ Suc\ {\isacharparenleft}term{\isacharunderscore}list{\isacharunderscore}size\ ts{\isacharparenright}%
wenzelm
parents: 11627
diff changeset
    29
\end{isabelle}
wenzelm
parents: 11627
diff changeset
    30
where \isa{set} returns the set of elements of a list
wenzelm
parents: 11627
diff changeset
    31
and \isa{term{\isacharunderscore}list{\isacharunderscore}size\ {\isacharcolon}{\isacharcolon}\ term\ list\ {\isasymRightarrow}\ nat} is an auxiliary
wenzelm
parents: 11627
diff changeset
    32
function automatically defined by Isabelle
wenzelm
parents: 11627
diff changeset
    33
(while processing the declaration of \isa{term}).  Why does the
wenzelm
parents: 11627
diff changeset
    34
recursive call of \isa{trev} lead to this
wenzelm
parents: 11627
diff changeset
    35
condition?  Because \isacommand{recdef} knows that \isa{map}
wenzelm
parents: 11627
diff changeset
    36
will apply \isa{trev} only to elements of \isa{ts}. Thus the 
wenzelm
parents: 11627
diff changeset
    37
condition expresses that the size of the argument \isa{t\ {\isasymin}\ set\ ts} of any
wenzelm
parents: 11627
diff changeset
    38
recursive call of \isa{trev} is strictly less than \isa{size\ {\isacharparenleft}App\ f\ ts{\isacharparenright}},
wenzelm
parents: 11627
diff changeset
    39
which equals \isa{Suc\ {\isacharparenleft}term{\isacharunderscore}list{\isacharunderscore}size\ ts{\isacharparenright}}.  We will now prove the termination condition and
wenzelm
parents: 11627
diff changeset
    40
continue with our definition.  Below we return to the question of how
12491
e28870d8b223 *** empty log message ***
nipkow
parents: 11866
diff changeset
    41
\isacommand{recdef} knows about \isa{map}.
e28870d8b223 *** empty log message ***
nipkow
parents: 11866
diff changeset
    42
e28870d8b223 *** empty log message ***
nipkow
parents: 11866
diff changeset
    43
The termination condition is easily proved by induction:%
11636
wenzelm
parents: 11627
diff changeset
    44
\end{isamarkuptext}%
11866
fbd097aec213 updated;
wenzelm
parents: 11636
diff changeset
    45
\isamarkuptrue%
fbd097aec213 updated;
wenzelm
parents: 11636
diff changeset
    46
\isamarkupfalse%
11636
wenzelm
parents: 11627
diff changeset
    47
\end{isabellebody}%
9698
f0740137a65d updated;
wenzelm
parents:
diff changeset
    48
%%% Local Variables:
f0740137a65d updated;
wenzelm
parents:
diff changeset
    49
%%% mode: latex
f0740137a65d updated;
wenzelm
parents:
diff changeset
    50
%%% TeX-master: "root"
f0740137a65d updated;
wenzelm
parents:
diff changeset
    51
%%% End: