13841
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
|
3 |
\def\isabellecontext{Aufgabe{\isadigit{2}}}%
|
|
4 |
\isamarkupfalse%
|
|
5 |
%
|
|
6 |
\isamarkupsubsection{Trees%
|
|
7 |
}
|
|
8 |
\isamarkuptrue%
|
|
9 |
%
|
|
10 |
\begin{isamarkuptext}%
|
|
11 |
In the sequel we work with skeletons of binary trees where
|
|
12 |
neither the leaves (``tip'') nor the nodes contain any information:%
|
|
13 |
\end{isamarkuptext}%
|
|
14 |
\isamarkuptrue%
|
|
15 |
\isacommand{datatype}\ tree\ {\isacharequal}\ Tp\ {\isacharbar}\ Nd\ tree\ tree\isamarkupfalse%
|
|
16 |
%
|
|
17 |
\begin{isamarkuptext}%
|
|
18 |
Define a function \isa{tips} that counts the tips of a
|
|
19 |
tree, and a function \isa{height} that computes the height of a
|
|
20 |
tree.
|
|
21 |
|
|
22 |
Complete binary trees of a given height are generated as follows:%
|
|
23 |
\end{isamarkuptext}%
|
|
24 |
\isamarkuptrue%
|
|
25 |
\isacommand{consts}\ cbt\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}nat\ {\isasymRightarrow}\ tree{\isachardoublequote}\isanewline
|
|
26 |
\isamarkupfalse%
|
|
27 |
\isacommand{primrec}\isanewline
|
|
28 |
{\isachardoublequote}cbt\ {\isadigit{0}}\ {\isacharequal}\ Tp{\isachardoublequote}\isanewline
|
|
29 |
{\isachardoublequote}cbt{\isacharparenleft}Suc\ n{\isacharparenright}\ {\isacharequal}\ Nd\ {\isacharparenleft}cbt\ n{\isacharparenright}\ {\isacharparenleft}cbt\ n{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
|
|
30 |
%
|
|
31 |
\begin{isamarkuptext}%
|
|
32 |
We will now focus on these complete binary trees.
|
|
33 |
|
|
34 |
Instead of generating complete binary trees, we can also \emph{test}
|
|
35 |
if a binary tree is complete. Define a function \isa{iscbt\ f}
|
|
36 |
(where \isa{f} is a function on trees) that checks for completeness:
|
|
37 |
\isa{Tp} is complete and \isa{Nd\ l\ r} ist complete iff \isa{l} and
|
|
38 |
\isa{r} are complete and \isa{f\ l\ {\isacharequal}\ f\ r}.
|
|
39 |
|
|
40 |
We now have 3 functions on trees, namely \isa{tips}, \isa{height}
|
|
41 |
und \isa{size}. The latter is defined automatically --- look it up
|
|
42 |
in the tutorial. Thus we also have 3 kinds of completeness: complete
|
|
43 |
wrt.\ \isa{tips}, complete wrt.\ \isa{height} and complete wrt.\
|
|
44 |
\isa{size}. Show that
|
|
45 |
\begin{itemize}
|
|
46 |
\item the 3 notions are the same (e.g.\ \isa{iscbt\ tips\ t\ {\isacharequal}\ iscbt\ size\ t}),
|
|
47 |
and
|
|
48 |
\item the 3 notions describe exactly the trees generated by \isa{cbt}:
|
|
49 |
the result of \isa{cbt} is complete (in the sense of \isa{iscbt},
|
|
50 |
wrt.\ any function on trees), and if a tree is complete in the sense of
|
|
51 |
\isa{iscbt}, it is the result of \isa{cbt} (applied to a suitable number
|
|
52 |
--- which one?)
|
|
53 |
\end{itemize}
|
|
54 |
Find a function \isa{f} such that \isa{iscbt\ f} is different from
|
|
55 |
\isa{iscbt\ size}.
|
|
56 |
|
|
57 |
Hints:
|
|
58 |
\begin{itemize}
|
|
59 |
\item Work out and prove suitable relationships between \isa{tips},
|
|
60 |
\isa{height} und \isa{size}.
|
|
61 |
|
|
62 |
\item If you need lemmas dealing only with the basic arithmetic operations
|
|
63 |
(\isa{{\isacharplus}}, \isa{{\isacharasterisk}}, \isa{{\isacharcircum}} etc), you can ``prove'' them
|
|
64 |
with the command \isa{sorry}, if neither \isa{arith} nor you can
|
|
65 |
find a proof. Not \isa{apply\ sorry}, just \isa{sorry}.
|
|
66 |
|
|
67 |
\item
|
|
68 |
You do not need to show that every notion is equal to every other
|
|
69 |
notion. It suffices to show that $A = C$ und $B = C$ --- $A = B$ is a
|
|
70 |
trivial consequence. However, the difficulty of the proof will depend
|
|
71 |
on which of the equivalences you prove.
|
|
72 |
|
|
73 |
\item There is \isa{{\isasymand}} and \isa{{\isasymlongrightarrow}}.
|
|
74 |
\end{itemize}%
|
|
75 |
\end{isamarkuptext}%
|
|
76 |
\isamarkuptrue%
|
|
77 |
\isamarkupfalse%
|
|
78 |
\end{isabellebody}%
|
|
79 |
%%% Local Variables:
|
|
80 |
%%% mode: latex
|
|
81 |
%%% TeX-master: "root"
|
|
82 |
%%% End:
|