9 \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 |
9 \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 |
10 \isacommand{by}{\isacharparenleft}induct{\isacharunderscore}tac\ ts{\isacharcomma}\ auto{\isacharparenright}% |
10 \isacommand{by}{\isacharparenleft}induct{\isacharunderscore}tac\ ts{\isacharcomma}\ auto{\isacharparenright}% |
11 \begin{isamarkuptext}% |
11 \begin{isamarkuptext}% |
12 \noindent |
12 \noindent |
13 By making this theorem a simplification rule, \isacommand{recdef} |
13 By making this theorem a simplification rule, \isacommand{recdef} |
14 applies it automatically and the above definition of \isa{trev} |
14 applies it automatically and the definition of \isa{trev} |
15 succeeds now. As a reward for our effort, we can now prove the desired |
15 succeeds now. As a reward for our effort, we can now prove the desired |
16 lemma directly. The key is the fact that we no longer need the verbose |
16 lemma directly. We no longer need the verbose |
17 induction schema for type \isa{term} but the simpler one arising from |
17 induction schema for type \isa{term} and can use the simpler one arising from |
18 \isa{trev}:% |
18 \isa{trev}:% |
19 \end{isamarkuptext}% |
19 \end{isamarkuptext}% |
20 \isacommand{lemma}\ {\isachardoublequote}trev{\isacharparenleft}trev\ t{\isacharparenright}\ {\isacharequal}\ t{\isachardoublequote}\isanewline |
20 \isacommand{lemma}\ {\isachardoublequote}trev{\isacharparenleft}trev\ t{\isacharparenright}\ {\isacharequal}\ t{\isachardoublequote}\isanewline |
21 \isacommand{apply}{\isacharparenleft}induct{\isacharunderscore}tac\ t\ rule{\isacharcolon}trev{\isachardot}induct{\isacharparenright}% |
21 \isacommand{apply}{\isacharparenleft}induct{\isacharunderscore}tac\ t\ rule{\isacharcolon}trev{\isachardot}induct{\isacharparenright}% |
22 \begin{isamarkuptxt}% |
22 \begin{isamarkuptxt}% |
29 both of which are solved by simplification:% |
29 both of which are solved by simplification:% |
30 \end{isamarkuptxt}% |
30 \end{isamarkuptxt}% |
31 \isacommand{by}{\isacharparenleft}simp{\isacharunderscore}all\ add{\isacharcolon}rev{\isacharunderscore}map\ sym{\isacharbrackleft}OF\ map{\isacharunderscore}compose{\isacharbrackright}\ cong{\isacharcolon}map{\isacharunderscore}cong{\isacharparenright}% |
31 \isacommand{by}{\isacharparenleft}simp{\isacharunderscore}all\ add{\isacharcolon}rev{\isacharunderscore}map\ sym{\isacharbrackleft}OF\ map{\isacharunderscore}compose{\isacharbrackright}\ cong{\isacharcolon}map{\isacharunderscore}cong{\isacharparenright}% |
32 \begin{isamarkuptext}% |
32 \begin{isamarkuptext}% |
33 \noindent |
33 \noindent |
34 If the proof of the induction step mystifies you, we recommend to go through |
34 If the proof of the induction step mystifies you, we recommend that you go through |
35 the chain of simplification steps in detail; you will probably need the help of |
35 the chain of simplification steps in detail; you will probably need the help of |
36 \isa{trace{\isacharunderscore}simp}. Theorem \isa{map{\isacharunderscore}cong} is discussed below. |
36 \isa{trace{\isacharunderscore}simp}. Theorem \isa{map{\isacharunderscore}cong} is discussed below. |
37 %\begin{quote} |
37 %\begin{quote} |
38 %{term[display]"trev(trev(App f ts))"}\\ |
38 %{term[display]"trev(trev(App f ts))"}\\ |
39 %{term[display]"App f (rev(map trev (rev(map trev ts))))"}\\ |
39 %{term[display]"App f (rev(map trev (rev(map trev ts))))"}\\ |
42 %{term[display]"App f (map (trev o trev) ts)"}\\ |
42 %{term[display]"App f (map (trev o trev) ts)"}\\ |
43 %{term[display]"App f (map (%x. x) ts)"}\\ |
43 %{term[display]"App f (map (%x. x) ts)"}\\ |
44 %{term[display]"App f ts"} |
44 %{term[display]"App f ts"} |
45 %\end{quote} |
45 %\end{quote} |
46 |
46 |
47 The above definition of \isa{trev} is superior to the one in |
47 The definition of \isa{trev} above is superior to the one in |
48 \S\ref{sec:nested-datatype} because it brings \isa{rev} into play, about |
48 \S\ref{sec:nested-datatype} because it uses \isa{rev} |
49 which already know a lot, in particular \isa{rev\ {\isacharparenleft}rev\ xs{\isacharparenright}\ {\isacharequal}\ xs}. |
49 and lets us use existing facts such as \hbox{\isa{rev\ {\isacharparenleft}rev\ xs{\isacharparenright}\ {\isacharequal}\ xs}}. |
50 Thus this proof is a good example of an important principle: |
50 Thus this proof is a good example of an important principle: |
51 \begin{quote} |
51 \begin{quote} |
52 \emph{Chose your definitions carefully\\ |
52 \emph{Chose your definitions carefully\\ |
53 because they determine the complexity of your proofs.} |
53 because they determine the complexity of your proofs.} |
54 \end{quote} |
54 \end{quote} |