14526
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
|
3 |
\def\isabellecontext{a{\isadigit{2}}}%
|
|
4 |
\isamarkupfalse%
|
|
5 |
%
|
|
6 |
\isamarkupsubsection{Trees%
|
|
7 |
}
|
|
8 |
\isamarkuptrue%
|
|
9 |
%
|
|
10 |
\begin{isamarkuptext}%
|
|
11 |
Define a datatype \isa{{\isacharprime}a\ tree} for binary trees. Both leaf
|
|
12 |
and internal nodes store information.%
|
|
13 |
\end{isamarkuptext}%
|
|
14 |
\isamarkuptrue%
|
|
15 |
\isacommand{datatype}\ {\isacharprime}a\ tree\isamarkupfalse%
|
|
16 |
%
|
|
17 |
\begin{isamarkuptext}%
|
|
18 |
Define the functions \isa{preOrder}, \isa{postOrder}, and \isa{inOrder} that traverse an \isa{{\isacharprime}a\ tree} in the respective order.%
|
|
19 |
\end{isamarkuptext}%
|
|
20 |
\isamarkuptrue%
|
|
21 |
\ \ preOrder\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ tree\ {\isasymRightarrow}\ {\isacharprime}a\ list{\isachardoublequote}\isanewline
|
|
22 |
\ \ postOrder\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ tree\ {\isasymRightarrow}\ {\isacharprime}a\ list{\isachardoublequote}\isanewline
|
|
23 |
\ \ inOrder\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ tree\ {\isasymRightarrow}\ {\isacharprime}a\ list{\isachardoublequote}\isamarkupfalse%
|
|
24 |
%
|
|
25 |
\begin{isamarkuptext}%
|
|
26 |
Define a function \isa{mirror} that returns the mirror image of an \isa{{\isacharprime}a\ tree}.%
|
|
27 |
\end{isamarkuptext}%
|
|
28 |
\isamarkuptrue%
|
|
29 |
\ \ mirror\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ tree\ {\isasymRightarrow}\ {\isacharprime}a\ tree{\isachardoublequote}\isamarkupfalse%
|
|
30 |
%
|
|
31 |
\begin{isamarkuptext}%
|
|
32 |
Suppose that \isa{xOrder} and \isa{yOrder} are tree traversal
|
|
33 |
functions chosen from \isa{preOrder}, \isa{postOrder}, and \isa{inOrder}. Formulate and prove all valid properties of the form
|
|
34 |
\mbox{\isa{xOrder\ {\isacharparenleft}mirror\ xt{\isacharparenright}\ {\isacharequal}\ rev\ {\isacharparenleft}yOrder\ xt{\isacharparenright}}}.%
|
|
35 |
\end{isamarkuptext}%
|
|
36 |
\isamarkuptrue%
|
|
37 |
%
|
|
38 |
\begin{isamarkuptext}%
|
|
39 |
Define the functions \isa{root}, \isa{leftmost} and \isa{rightmost}, that return the root, leftmost, and rightmost element
|
|
40 |
respectively.%
|
|
41 |
\end{isamarkuptext}%
|
|
42 |
\isamarkuptrue%
|
|
43 |
\ \ root\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ tree\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequote}\isanewline
|
|
44 |
\ \ leftmost\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ tree\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequote}\isanewline
|
|
45 |
\ \ rightmost\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ tree\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequote}\isamarkupfalse%
|
|
46 |
%
|
|
47 |
\begin{isamarkuptext}%
|
|
48 |
Prove or disprove (by counter example) the theorems that follow. You may have to prove some lemmas first.%
|
|
49 |
\end{isamarkuptext}%
|
|
50 |
\isamarkuptrue%
|
|
51 |
\isacommand{theorem}\ {\isachardoublequote}last{\isacharparenleft}inOrder\ xt{\isacharparenright}\ {\isacharequal}\ rightmost\ xt{\isachardoublequote}\isamarkupfalse%
|
|
52 |
\ \isanewline
|
|
53 |
\isamarkupfalse%
|
|
54 |
\isacommand{theorem}\ {\isachardoublequote}hd\ {\isacharparenleft}inOrder\ xt{\isacharparenright}\ {\isacharequal}\ leftmost\ xt\ {\isachardoublequote}\isamarkupfalse%
|
|
55 |
\ \isanewline
|
|
56 |
\isamarkupfalse%
|
|
57 |
\isacommand{theorem}\ {\isachardoublequote}hd{\isacharparenleft}preOrder\ xt{\isacharparenright}\ {\isacharequal}\ last{\isacharparenleft}postOrder\ xt{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
|
|
58 |
\ \isanewline
|
|
59 |
\isamarkupfalse%
|
|
60 |
\isacommand{theorem}\ {\isachardoublequote}hd{\isacharparenleft}preOrder\ xt{\isacharparenright}\ {\isacharequal}\ root\ xt{\isachardoublequote}\isamarkupfalse%
|
|
61 |
\ \isanewline
|
|
62 |
\isamarkupfalse%
|
|
63 |
\isacommand{theorem}\ {\isachardoublequote}hd{\isacharparenleft}inOrder\ xt{\isacharparenright}\ {\isacharequal}\ root\ xt\ {\isachardoublequote}\isamarkupfalse%
|
|
64 |
\ \isanewline
|
|
65 |
\isamarkupfalse%
|
|
66 |
\isacommand{theorem}\ {\isachardoublequote}last{\isacharparenleft}postOrder\ xt{\isacharparenright}\ {\isacharequal}\ root\ xt{\isachardoublequote}\isamarkupfalse%
|
|
67 |
\ \isanewline
|
|
68 |
\isanewline
|
|
69 |
\isamarkupfalse%
|
|
70 |
\isamarkupfalse%
|
|
71 |
\end{isabellebody}%
|
|
72 |
%%% Local Variables:
|
|
73 |
%%% mode: latex
|
|
74 |
%%% TeX-master: "root"
|
|
75 |
%%% End:
|