9722
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
9924
|
3 |
\def\isabellecontext{Fundata}%
|
11866
|
4 |
\isamarkupfalse%
|
|
5 |
\isacommand{datatype}\ {\isacharparenleft}{\isacharprime}a{\isacharcomma}{\isacharprime}i{\isacharparenright}bigtree\ {\isacharequal}\ Tip\ {\isacharbar}\ Br\ {\isacharprime}a\ {\isachardoublequote}{\isacharprime}i\ {\isasymRightarrow}\ {\isacharparenleft}{\isacharprime}a{\isacharcomma}{\isacharprime}i{\isacharparenright}bigtree{\isachardoublequote}\isamarkupfalse%
|
|
6 |
%
|
8749
|
7 |
\begin{isamarkuptext}%
|
9792
|
8 |
\noindent
|
|
9 |
Parameter \isa{{\isacharprime}a} is the type of values stored in
|
10420
|
10 |
the \isa{Br}anches of the tree, whereas \isa{{\isacharprime}i} is the index
|
9792
|
11 |
type over which the tree branches. If \isa{{\isacharprime}i} is instantiated to
|
8749
|
12 |
\isa{bool}, the result is a binary tree; if it is instantiated to
|
|
13 |
\isa{nat}, we have an infinitely branching tree because each node
|
|
14 |
has as many subtrees as there are natural numbers. How can we possibly
|
9541
|
15 |
write down such a tree? Using functional notation! For example, the term
|
|
16 |
\begin{isabelle}%
|
12627
|
17 |
\ \ \ \ \ Br\ {\isadigit{0}}\ {\isacharparenleft}{\isasymlambda}i{\isachardot}\ Br\ i\ {\isacharparenleft}{\isasymlambda}n{\isachardot}\ Tip{\isacharparenright}{\isacharparenright}%
|
9924
|
18 |
\end{isabelle}
|
9673
|
19 |
of type \isa{{\isacharparenleft}nat{\isacharcomma}\ nat{\isacharparenright}\ bigtree} is the tree whose
|
8771
|
20 |
root is labeled with 0 and whose $i$th subtree is labeled with $i$ and
|
8749
|
21 |
has merely \isa{Tip}s as further subtrees.
|
|
22 |
|
9792
|
23 |
Function \isa{map{\isacharunderscore}bt} applies a function to all labels in a \isa{bigtree}:%
|
8749
|
24 |
\end{isamarkuptext}%
|
11866
|
25 |
\isamarkuptrue%
|
9673
|
26 |
\isacommand{consts}\ map{\isacharunderscore}bt\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}b{\isacharparenright}\ {\isasymRightarrow}\ {\isacharparenleft}{\isacharprime}a{\isacharcomma}{\isacharprime}i{\isacharparenright}bigtree\ {\isasymRightarrow}\ {\isacharparenleft}{\isacharprime}b{\isacharcomma}{\isacharprime}i{\isacharparenright}bigtree{\isachardoublequote}\isanewline
|
11866
|
27 |
\isamarkupfalse%
|
8749
|
28 |
\isacommand{primrec}\isanewline
|
10420
|
29 |
{\isachardoublequote}map{\isacharunderscore}bt\ f\ Tip\ \ \ \ \ \ {\isacharequal}\ Tip{\isachardoublequote}\isanewline
|
11866
|
30 |
{\isachardoublequote}map{\isacharunderscore}bt\ f\ {\isacharparenleft}Br\ a\ F{\isacharparenright}\ {\isacharequal}\ Br\ {\isacharparenleft}f\ a{\isacharparenright}\ {\isacharparenleft}{\isasymlambda}i{\isachardot}\ map{\isacharunderscore}bt\ f\ {\isacharparenleft}F\ i{\isacharparenright}{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
|
|
31 |
%
|
8749
|
32 |
\begin{isamarkuptext}%
|
|
33 |
\noindent This is a valid \isacommand{primrec} definition because the
|
14188
|
34 |
recursive calls of \isa{map{\isacharunderscore}bt} involve only subtrees of
|
|
35 |
\isa{F}, which is itself a subterm of the left-hand side. Thus termination
|
|
36 |
is assured. The seasoned functional programmer might try expressing
|
11458
|
37 |
\isa{{\isasymlambda}i{\isachardot}\ map{\isacharunderscore}bt\ f\ {\isacharparenleft}F\ i{\isacharparenright}} as \isa{map{\isacharunderscore}bt\ f\ {\isasymcirc}\ F}, which Isabelle
|
|
38 |
however will reject. Applying \isa{map{\isacharunderscore}bt} to only one of its arguments
|
|
39 |
makes the termination proof less obvious.
|
8749
|
40 |
|
11309
|
41 |
The following lemma has a simple proof by induction:%
|
8749
|
42 |
\end{isamarkuptext}%
|
11866
|
43 |
\isamarkuptrue%
|
9673
|
44 |
\isacommand{lemma}\ {\isachardoublequote}map{\isacharunderscore}bt\ {\isacharparenleft}g\ o\ f{\isacharparenright}\ T\ {\isacharequal}\ map{\isacharunderscore}bt\ g\ {\isacharparenleft}map{\isacharunderscore}bt\ f\ T{\isacharparenright}{\isachardoublequote}\isanewline
|
11866
|
45 |
\isamarkupfalse%
|
|
46 |
\isamarkupfalse%
|
|
47 |
\isamarkupfalse%
|
15481
|
48 |
\isamarkupfalse%
|
|
49 |
\isamarkupfalse%
|
11866
|
50 |
\isamarkuptrue%
|
15614
|
51 |
\isanewline
|
11866
|
52 |
\isamarkupfalse%
|
|
53 |
\isamarkupfalse%
|
9722
|
54 |
\end{isabellebody}%
|
9145
|
55 |
%%% Local Variables:
|
|
56 |
%%% mode: latex
|
|
57 |
%%% TeX-master: "root"
|
|
58 |
%%% End:
|