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