14525
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
|
3 |
\def\isabellecontext{a{\isadigit{1}}}%
|
|
4 |
\isamarkupfalse%
|
|
5 |
%
|
|
6 |
\isamarkupsubsection{Lists%
|
|
7 |
}
|
|
8 |
\isamarkuptrue%
|
|
9 |
%
|
|
10 |
\begin{isamarkuptext}%
|
|
11 |
Define a function \isa{occurs}, such that \isa{occurs\ x\ xs}
|
|
12 |
is the number of occurrences of the element \isa{x} in the list
|
|
13 |
\isa{xs}.%
|
|
14 |
\end{isamarkuptext}%
|
|
15 |
\isamarkuptrue%
|
|
16 |
\ \ occurs\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ list\ {\isasymRightarrow}\ nat{\isachardoublequote}\isamarkupfalse%
|
|
17 |
%
|
|
18 |
\begin{isamarkuptext}%
|
|
19 |
Prove or disprove (by counter example) the theorems that follow. You may have to prove some lemmas first.
|
|
20 |
|
|
21 |
Use the \isa{{\isacharbrackleft}simp{\isacharbrackright}}-attribute only if the equation is truly a
|
|
22 |
simplification and is necessary for some later proof.
|
|
23 |
|
|
24 |
In the case of a non-theorem try to find a suitable assumption under which the theorem holds.%
|
|
25 |
\end{isamarkuptext}%
|
|
26 |
\isamarkuptrue%
|
|
27 |
\isacommand{theorem}\ {\isachardoublequote}occurs\ a\ {\isacharparenleft}xs\ {\isacharat}\ ys{\isacharparenright}\ {\isacharequal}\ occurs\ a\ xs\ {\isacharplus}\ occurs\ a\ ys\ {\isachardoublequote}\isamarkupfalse%
|
|
28 |
\isanewline
|
|
29 |
\isamarkupfalse%
|
|
30 |
\isacommand{theorem}\ {\isachardoublequote}occurs\ a\ xs\ {\isacharequal}\ occurs\ a\ {\isacharparenleft}rev\ xs{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
|
|
31 |
\isanewline
|
|
32 |
\isamarkupfalse%
|
|
33 |
\isacommand{theorem}\ {\isachardoublequote}occurs\ a\ xs\ {\isacharless}{\isacharequal}\ length\ xs{\isachardoublequote}\isamarkupfalse%
|
|
34 |
\isanewline
|
|
35 |
\isamarkupfalse%
|
|
36 |
\isacommand{theorem}\ {\isachardoublequote}occurs\ a\ {\isacharparenleft}replicate\ n\ a{\isacharparenright}\ {\isacharequal}\ n{\isachardoublequote}\isamarkupfalse%
|
|
37 |
\isamarkupfalse%
|
|
38 |
%
|
|
39 |
\begin{isamarkuptext}%
|
|
40 |
Define a function \isa{areAll}, such that \isa{areAll\ xs\ x} is true iff all elements of \isa{xs} are equal to \isa{x}.%
|
|
41 |
\end{isamarkuptext}%
|
|
42 |
\isamarkuptrue%
|
|
43 |
\ \ areAll\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ bool{\isachardoublequote}\isanewline
|
|
44 |
\isanewline
|
|
45 |
\isamarkupfalse%
|
|
46 |
\isacommand{theorem}\ {\isachardoublequote}areAll\ xs\ a\ {\isasymlongrightarrow}\ occurs\ a\ xs\ {\isacharequal}\ length\ xs{\isachardoublequote}\isamarkupfalse%
|
|
47 |
\isanewline
|
|
48 |
\isamarkupfalse%
|
|
49 |
\isacommand{theorem}\ {\isachardoublequote}occurs\ a\ xs\ {\isacharequal}\ length\ xs\ {\isasymlongrightarrow}\ areAll\ xs\ a{\isachardoublequote}\isamarkupfalse%
|
|
50 |
\isamarkupfalse%
|
|
51 |
%
|
|
52 |
\begin{isamarkuptext}%
|
|
53 |
Define two functions to delete elements from a list:
|
|
54 |
\isa{del{\isadigit{1}}\ x\ xs} deletes the first (leftmost) occurrence of \isa{x} from \isa{xs}.
|
|
55 |
\isa{delall\ x\ xs} deletes all occurrences of \isa{x} from \isa{xs}.%
|
|
56 |
\end{isamarkuptext}%
|
|
57 |
\isamarkuptrue%
|
|
58 |
\ \ delall\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ list{\isachardoublequote}\isanewline
|
|
59 |
\ \ del{\isadigit{1}}\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ list{\isachardoublequote}\isanewline
|
|
60 |
\isanewline
|
|
61 |
\isamarkupfalse%
|
|
62 |
\isacommand{theorem}\ {\isachardoublequote}occurs\ a\ {\isacharparenleft}delall\ a\ xs{\isacharparenright}\ {\isacharequal}\ {\isadigit{0}}{\isachardoublequote}\isamarkupfalse%
|
|
63 |
\ \isanewline
|
|
64 |
\isamarkupfalse%
|
|
65 |
\isacommand{theorem}\ {\isachardoublequote}Suc\ {\isacharparenleft}occurs\ a\ {\isacharparenleft}del{\isadigit{1}}\ a\ xs{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ occurs\ a\ xs{\isachardoublequote}\isamarkupfalse%
|
|
66 |
\isamarkupfalse%
|
|
67 |
%
|
|
68 |
\begin{isamarkuptext}%
|
|
69 |
Define a function \isa{replace}, such that \isa{replace\ x\ y\ zs} yields \isa{zs} with every occurrence of \isa{x} replaced by \isa{y}.%
|
|
70 |
\end{isamarkuptext}%
|
|
71 |
\isamarkuptrue%
|
|
72 |
\ \ replace\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ list{\isachardoublequote}\isanewline
|
|
73 |
\isanewline
|
|
74 |
\isamarkupfalse%
|
|
75 |
\isacommand{theorem}\ {\isachardoublequote}occurs\ a\ xs\ {\isacharequal}\ occurs\ b\ {\isacharparenleft}replace\ a\ b\ xs{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
|
|
76 |
\isamarkupfalse%
|
|
77 |
%
|
|
78 |
\begin{isamarkuptext}%
|
|
79 |
With the help of \isa{occurs}, define a function \isa{remDups} that removes all duplicates from a list.%
|
|
80 |
\end{isamarkuptext}%
|
|
81 |
\isamarkuptrue%
|
|
82 |
\ \ remDups\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a\ list{\isachardoublequote}\isamarkupfalse%
|
|
83 |
%
|
|
84 |
\begin{isamarkuptext}%
|
|
85 |
Use \isa{occurs} to formulate and prove a lemma that expresses the fact that \isa{remDups} never inserts a new element into a list.%
|
|
86 |
\end{isamarkuptext}%
|
|
87 |
\isamarkuptrue%
|
|
88 |
%
|
|
89 |
\begin{isamarkuptext}%
|
|
90 |
Use \isa{occurs} to formulate and prove a lemma that expresses the fact that \isa{remDups} always returns a list without duplicates (i.e.\ the correctness of \isa{remDups}).%
|
|
91 |
\end{isamarkuptext}%
|
|
92 |
\isamarkuptrue%
|
|
93 |
%
|
|
94 |
\begin{isamarkuptext}%
|
|
95 |
Now, with the help of \isa{occurs} define a function \isa{unique}, such that \isa{unique\ xs} is true iff every element in \isa{xs} occurs only once.%
|
|
96 |
\end{isamarkuptext}%
|
|
97 |
\isamarkuptrue%
|
|
98 |
\ \ unique\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharprime}a\ list\ {\isasymRightarrow}\ bool{\isachardoublequote}\isamarkupfalse%
|
|
99 |
%
|
|
100 |
\begin{isamarkuptext}%
|
|
101 |
Formulate and prove the correctness of \isa{remDups} with the help of \isa{unique}.%
|
|
102 |
\end{isamarkuptext}%
|
|
103 |
\isamarkuptrue%
|
|
104 |
\isamarkupfalse%
|
|
105 |
\end{isabellebody}%
|
|
106 |
%%% Local Variables:
|
|
107 |
%%% mode: latex
|
|
108 |
%%% TeX-master: "root"
|
|
109 |
%%% End:
|