9722
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
10267
|
3 |
\def\isabellecontext{Nested{\isadigit{2}}}%
|
12491
|
4 |
\isanewline
|
11866
|
5 |
\isamarkupfalse%
|
9754
|
6 |
\isacommand{lemma}\ {\isacharbrackleft}simp{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}t\ {\isasymin}\ set\ ts\ {\isasymlongrightarrow}\ size\ t\ {\isacharless}\ Suc{\isacharparenleft}term{\isacharunderscore}list{\isacharunderscore}size\ ts{\isacharparenright}{\isachardoublequote}\isanewline
|
11866
|
7 |
\isamarkupfalse%
|
15614
|
8 |
\isanewline
|
15481
|
9 |
\isamarkupfalse%
|
11866
|
10 |
\isamarkupfalse%
|
|
11 |
%
|
9690
|
12 |
\begin{isamarkuptext}%
|
|
13 |
\noindent
|
|
14 |
By making this theorem a simplification rule, \isacommand{recdef}
|
10878
|
15 |
applies it automatically and the definition of \isa{trev}
|
9690
|
16 |
succeeds now. As a reward for our effort, we can now prove the desired
|
10878
|
17 |
lemma directly. We no longer need the verbose
|
|
18 |
induction schema for type \isa{term} and can use the simpler one arising from
|
9690
|
19 |
\isa{trev}:%
|
|
20 |
\end{isamarkuptext}%
|
11866
|
21 |
\isamarkuptrue%
|
9698
|
22 |
\isacommand{lemma}\ {\isachardoublequote}trev{\isacharparenleft}trev\ t{\isacharparenright}\ {\isacharequal}\ t{\isachardoublequote}\isanewline
|
11866
|
23 |
\isamarkupfalse%
|
15481
|
24 |
\isamarkupfalse%
|
11866
|
25 |
\isamarkuptrue%
|
15481
|
26 |
\isamarkupfalse%
|
11866
|
27 |
%
|
9690
|
28 |
\begin{isamarkuptext}%
|
|
29 |
\noindent
|
10878
|
30 |
If the proof of the induction step mystifies you, we recommend that you go through
|
9754
|
31 |
the chain of simplification steps in detail; you will probably need the help of
|
9933
|
32 |
\isa{trace{\isacharunderscore}simp}. Theorem \isa{map{\isacharunderscore}cong} is discussed below.
|
9721
|
33 |
%\begin{quote}
|
|
34 |
%{term[display]"trev(trev(App f ts))"}\\
|
|
35 |
%{term[display]"App f (rev(map trev (rev(map trev ts))))"}\\
|
|
36 |
%{term[display]"App f (map trev (rev(rev(map trev ts))))"}\\
|
|
37 |
%{term[display]"App f (map trev (map trev ts))"}\\
|
|
38 |
%{term[display]"App f (map (trev o trev) ts)"}\\
|
|
39 |
%{term[display]"App f (map (%x. x) ts)"}\\
|
|
40 |
%{term[display]"App f ts"}
|
|
41 |
%\end{quote}
|
9690
|
42 |
|
10878
|
43 |
The definition of \isa{trev} above is superior to the one in
|
|
44 |
\S\ref{sec:nested-datatype} because it uses \isa{rev}
|
|
45 |
and lets us use existing facts such as \hbox{\isa{rev\ {\isacharparenleft}rev\ xs{\isacharparenright}\ {\isacharequal}\ xs}}.
|
9690
|
46 |
Thus this proof is a good example of an important principle:
|
|
47 |
\begin{quote}
|
|
48 |
\emph{Chose your definitions carefully\\
|
|
49 |
because they determine the complexity of your proofs.}
|
|
50 |
\end{quote}
|
|
51 |
|
9721
|
52 |
Let us now return to the question of how \isacommand{recdef} can come up with
|
|
53 |
sensible termination conditions in the presence of higher-order functions
|
11494
|
54 |
like \isa{map}. For a start, if nothing were known about \isa{map}, then
|
9792
|
55 |
\isa{map\ trev\ ts} might apply \isa{trev} to arbitrary terms, and thus
|
|
56 |
\isacommand{recdef} would try to prove the unprovable \isa{size\ t\ {\isacharless}\ Suc\ {\isacharparenleft}term{\isacharunderscore}list{\isacharunderscore}size\ ts{\isacharparenright}}, without any assumption about \isa{t}. Therefore
|
9721
|
57 |
\isacommand{recdef} has been supplied with the congruence theorem
|
9754
|
58 |
\isa{map{\isacharunderscore}cong}:
|
9690
|
59 |
\begin{isabelle}%
|
10696
|
60 |
\ \ \ \ \ {\isasymlbrakk}xs\ {\isacharequal}\ ys{\isacharsemicolon}\ {\isasymAnd}x{\isachardot}\ x\ {\isasymin}\ set\ ys\ {\isasymLongrightarrow}\ f\ x\ {\isacharequal}\ g\ x{\isasymrbrakk}\isanewline
|
10950
|
61 |
\isaindent{\ \ \ \ \ }{\isasymLongrightarrow}\ map\ f\ xs\ {\isacharequal}\ map\ g\ ys%
|
9924
|
62 |
\end{isabelle}
|
11494
|
63 |
Its second premise expresses that in \isa{map\ f\ xs},
|
|
64 |
function \isa{f} is only applied to elements of list \isa{xs}. Congruence
|
|
65 |
rules for other higher-order functions on lists are similar. If you get
|
10212
|
66 |
into a situation where you need to supply \isacommand{recdef} with new
|
11494
|
67 |
congruence rules, you can append a hint after the end of
|
13111
|
68 |
the recursion equations:\cmmdx{hints}%
|
9940
|
69 |
\end{isamarkuptext}%
|
11866
|
70 |
\isamarkuptrue%
|
|
71 |
\isamarkupfalse%
|
|
72 |
{\isacharparenleft}\isakeyword{hints}\ recdef{\isacharunderscore}cong{\isacharcolon}\ map{\isacharunderscore}cong{\isacharparenright}\isamarkupfalse%
|
|
73 |
%
|
9940
|
74 |
\begin{isamarkuptext}%
|
|
75 |
\noindent
|
11494
|
76 |
Or you can declare them globally
|
|
77 |
by giving them the \attrdx{recdef_cong} attribute:%
|
9940
|
78 |
\end{isamarkuptext}%
|
11866
|
79 |
\isamarkuptrue%
|
|
80 |
\isacommand{declare}\ map{\isacharunderscore}cong{\isacharbrackleft}recdef{\isacharunderscore}cong{\isacharbrackright}\isamarkupfalse%
|
|
81 |
%
|
9940
|
82 |
\begin{isamarkuptext}%
|
11494
|
83 |
The \isa{cong} and \isa{recdef{\isacharunderscore}cong} attributes are
|
9940
|
84 |
intentionally kept apart because they control different activities, namely
|
10171
|
85 |
simplification and making recursive definitions.
|
9933
|
86 |
%The simplifier's congruence rules cannot be used by recdef.
|
|
87 |
%For example the weak congruence rules for if and case would prevent
|
|
88 |
%recdef from generating sensible termination conditions.%
|
9690
|
89 |
\end{isamarkuptext}%
|
11866
|
90 |
\isamarkuptrue%
|
|
91 |
\isamarkupfalse%
|
9722
|
92 |
\end{isabellebody}%
|
9690
|
93 |
%%% Local Variables:
|
|
94 |
%%% mode: latex
|
|
95 |
%%% TeX-master: "root"
|
|
96 |
%%% End:
|