| 10365 |      1 | %
 | 
|  |      2 | \begin{isabellebody}%
 | 
|  |      3 | \def\isabellecontext{Even}%
 | 
|  |      4 | \isanewline
 | 
| 10878 |      5 | \isacommand{theory}\ Even\ {\isacharequal}\ Main{\isacharcolon}\isanewline
 | 
|  |      6 | \isanewline
 | 
|  |      7 | \isanewline
 | 
| 11866 |      8 | \isamarkupfalse%
 | 
| 10365 |      9 | \isacommand{consts}\ even\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}nat\ set{\isachardoublequote}\isanewline
 | 
| 11866 |     10 | \isamarkupfalse%
 | 
| 10365 |     11 | \isacommand{inductive}\ even\isanewline
 | 
|  |     12 | \isakeyword{intros}\isanewline
 | 
|  |     13 | zero{\isacharbrackleft}intro{\isacharbang}{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}{\isadigit{0}}\ {\isasymin}\ even{\isachardoublequote}\isanewline
 | 
| 11866 |     14 | step{\isacharbrackleft}intro{\isacharbang}{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}n\ {\isasymin}\ even\ {\isasymLongrightarrow}\ {\isacharparenleft}Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}{\isacharparenright}\ {\isasymin}\ even{\isachardoublequote}\isamarkupfalse%
 | 
|  |     15 | %
 | 
| 10365 |     16 | \begin{isamarkuptext}%
 | 
| 10878 |     17 | An inductive definition consists of introduction rules. 
 | 
| 10365 |     18 | 
 | 
|  |     19 | \begin{isabelle}%
 | 
| 14470 |     20 | \ \ \ \ \ n\ {\isasymin}\ Even{\isachardot}even\ {\isasymLongrightarrow}\ Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isasymin}\ Even{\isachardot}even%
 | 
| 10365 |     21 | \end{isabelle}
 | 
|  |     22 | \rulename{even.step}
 | 
|  |     23 | 
 | 
|  |     24 | \begin{isabelle}%
 | 
| 14470 |     25 | \ \ \ \ \ {\isasymlbrakk}xa\ {\isasymin}\ Even{\isachardot}even{\isacharsemicolon}\ P\ {\isadigit{0}}{\isacharsemicolon}\ {\isasymAnd}n{\isachardot}\ {\isasymlbrakk}n\ {\isasymin}\ Even{\isachardot}even{\isacharsemicolon}\ P\ n{\isasymrbrakk}\ {\isasymLongrightarrow}\ P\ {\isacharparenleft}Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}{\isacharparenright}{\isasymrbrakk}\isanewline
 | 
|  |     26 | \isaindent{\ \ \ \ \ }{\isasymLongrightarrow}\ P\ xa%
 | 
| 10365 |     27 | \end{isabelle}
 | 
|  |     28 | \rulename{even.induct}
 | 
|  |     29 | 
 | 
|  |     30 | Attributes can be given to the introduction rules.  Here both rules are
 | 
| 10878 |     31 | specified as \isa{intro!}
 | 
|  |     32 | 
 | 
|  |     33 | Our first lemma states that numbers of the form $2\times k$ are even.%
 | 
| 10365 |     34 | \end{isamarkuptext}%
 | 
| 11866 |     35 | \isamarkuptrue%
 | 
| 11708 |     36 | \isacommand{lemma}\ two{\isacharunderscore}times{\isacharunderscore}even{\isacharbrackleft}intro{\isacharbang}{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}{\isadigit{2}}{\isacharasterisk}k\ {\isasymin}\ even{\isachardoublequote}\isanewline
 | 
| 11866 |     37 | \isamarkupfalse%
 | 
| 12328 |     38 | \isacommand{apply}\ {\isacharparenleft}induct{\isacharunderscore}tac\ k{\isacharparenright}\isamarkupfalse%
 | 
| 11866 |     39 | %
 | 
| 10878 |     40 | \begin{isamarkuptxt}%
 | 
|  |     41 | The first step is induction on the natural number \isa{k}, which leaves
 | 
|  |     42 | two subgoals:
 | 
|  |     43 | \begin{isabelle}%
 | 
| 14470 |     44 | \ {\isadigit{1}}{\isachardot}\ {\isadigit{2}}\ {\isacharasterisk}\ {\isadigit{0}}\ {\isasymin}\ Even{\isachardot}even\isanewline
 | 
|  |     45 | \ {\isadigit{2}}{\isachardot}\ {\isasymAnd}n{\isachardot}\ {\isadigit{2}}\ {\isacharasterisk}\ n\ {\isasymin}\ Even{\isachardot}even\ {\isasymLongrightarrow}\ {\isadigit{2}}\ {\isacharasterisk}\ Suc\ n\ {\isasymin}\ Even{\isachardot}even%
 | 
| 10878 |     46 | \end{isabelle}
 | 
|  |     47 | Here \isa{auto} simplifies both subgoals so that they match the introduction
 | 
|  |     48 | rules, which then are applied automatically.%
 | 
|  |     49 | \end{isamarkuptxt}%
 | 
| 11866 |     50 | \ \isamarkuptrue%
 | 
|  |     51 | \isacommand{apply}\ auto\isanewline
 | 
|  |     52 | \isamarkupfalse%
 | 
|  |     53 | \isacommand{done}\isamarkupfalse%
 | 
|  |     54 | %
 | 
| 10365 |     55 | \begin{isamarkuptext}%
 | 
|  |     56 | Our goal is to prove the equivalence between the traditional definition
 | 
|  |     57 | of even (using the divides relation) and our inductive definition.  Half of
 | 
|  |     58 | this equivalence is trivial using the lemma just proved, whose \isa{intro!}
 | 
|  |     59 | attribute ensures it will be applied automatically.%
 | 
|  |     60 | \end{isamarkuptext}%
 | 
| 11866 |     61 | \isamarkuptrue%
 | 
| 11708 |     62 | \isacommand{lemma}\ dvd{\isacharunderscore}imp{\isacharunderscore}even{\isacharcolon}\ {\isachardoublequote}{\isadigit{2}}\ dvd\ n\ {\isasymLongrightarrow}\ n\ {\isasymin}\ even{\isachardoublequote}\isanewline
 | 
| 11866 |     63 | \isamarkupfalse%
 | 
|  |     64 | \isacommand{by}\ {\isacharparenleft}auto\ simp\ add{\isacharcolon}\ dvd{\isacharunderscore}def{\isacharparenright}\isamarkupfalse%
 | 
|  |     65 | %
 | 
| 10365 |     66 | \begin{isamarkuptext}%
 | 
|  |     67 | our first rule induction!%
 | 
|  |     68 | \end{isamarkuptext}%
 | 
| 11866 |     69 | \isamarkuptrue%
 | 
| 11708 |     70 | \isacommand{lemma}\ even{\isacharunderscore}imp{\isacharunderscore}dvd{\isacharcolon}\ {\isachardoublequote}n\ {\isasymin}\ even\ {\isasymLongrightarrow}\ {\isadigit{2}}\ dvd\ n{\isachardoublequote}\isanewline
 | 
| 11866 |     71 | \isamarkupfalse%
 | 
|  |     72 | \isacommand{apply}\ {\isacharparenleft}erule\ even{\isachardot}induct{\isacharparenright}\isamarkupfalse%
 | 
|  |     73 | %
 | 
| 10878 |     74 | \begin{isamarkuptxt}%
 | 
|  |     75 | \begin{isabelle}%
 | 
| 11708 |     76 | \ {\isadigit{1}}{\isachardot}\ {\isadigit{2}}\ dvd\ {\isadigit{0}}\isanewline
 | 
| 14470 |     77 | \ {\isadigit{2}}{\isachardot}\ {\isasymAnd}n{\isachardot}\ {\isasymlbrakk}n\ {\isasymin}\ Even{\isachardot}even{\isacharsemicolon}\ {\isadigit{2}}\ dvd\ n{\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isadigit{2}}\ dvd\ Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}%
 | 
| 10878 |     78 | \end{isabelle}%
 | 
|  |     79 | \end{isamarkuptxt}%
 | 
| 11866 |     80 | \isamarkuptrue%
 | 
|  |     81 | \isacommand{apply}\ {\isacharparenleft}simp{\isacharunderscore}all\ add{\isacharcolon}\ dvd{\isacharunderscore}def{\isacharparenright}\isamarkupfalse%
 | 
|  |     82 | %
 | 
| 10878 |     83 | \begin{isamarkuptxt}%
 | 
|  |     84 | \begin{isabelle}%
 | 
| 14470 |     85 | \ {\isadigit{1}}{\isachardot}\ {\isasymAnd}n{\isachardot}\ {\isasymlbrakk}n\ {\isasymin}\ Even{\isachardot}even{\isacharsemicolon}\ {\isasymexists}k{\isachardot}\ n\ {\isacharequal}\ {\isadigit{2}}\ {\isacharasterisk}\ k{\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isasymexists}k{\isachardot}\ Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isacharequal}\ {\isadigit{2}}\ {\isacharasterisk}\ k%
 | 
| 10878 |     86 | \end{isabelle}%
 | 
|  |     87 | \end{isamarkuptxt}%
 | 
| 11866 |     88 | \isamarkuptrue%
 | 
|  |     89 | \isacommand{apply}\ clarify\isamarkupfalse%
 | 
|  |     90 | %
 | 
| 10878 |     91 | \begin{isamarkuptxt}%
 | 
|  |     92 | \begin{isabelle}%
 | 
| 14470 |     93 | \ {\isadigit{1}}{\isachardot}\ {\isasymAnd}n\ k{\isachardot}\ {\isadigit{2}}\ {\isacharasterisk}\ k\ {\isasymin}\ Even{\isachardot}even\ {\isasymLongrightarrow}\ {\isasymexists}ka{\isachardot}\ Suc\ {\isacharparenleft}Suc\ {\isacharparenleft}{\isadigit{2}}\ {\isacharasterisk}\ k{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ {\isadigit{2}}\ {\isacharasterisk}\ ka%
 | 
| 10878 |     94 | \end{isabelle}%
 | 
|  |     95 | \end{isamarkuptxt}%
 | 
| 11866 |     96 | \isamarkuptrue%
 | 
| 10878 |     97 | \isacommand{apply}\ {\isacharparenleft}rule{\isacharunderscore}tac\ x\ {\isacharequal}\ {\isachardoublequote}Suc\ k{\isachardoublequote}\ \isakeyword{in}\ exI{\isacharcomma}\ simp{\isacharparenright}\isanewline
 | 
| 11866 |     98 | \isamarkupfalse%
 | 
|  |     99 | \isacommand{done}\isamarkupfalse%
 | 
|  |    100 | %
 | 
| 10365 |    101 | \begin{isamarkuptext}%
 | 
|  |    102 | no iff-attribute because we don't always want to use it%
 | 
|  |    103 | \end{isamarkuptext}%
 | 
| 11866 |    104 | \isamarkuptrue%
 | 
| 11708 |    105 | \isacommand{theorem}\ even{\isacharunderscore}iff{\isacharunderscore}dvd{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}n\ {\isasymin}\ even{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}{\isadigit{2}}\ dvd\ n{\isacharparenright}{\isachardoublequote}\isanewline
 | 
| 11866 |    106 | \isamarkupfalse%
 | 
|  |    107 | \isacommand{by}\ {\isacharparenleft}blast\ intro{\isacharcolon}\ dvd{\isacharunderscore}imp{\isacharunderscore}even\ even{\isacharunderscore}imp{\isacharunderscore}dvd{\isacharparenright}\isamarkupfalse%
 | 
|  |    108 | %
 | 
| 10365 |    109 | \begin{isamarkuptext}%
 | 
|  |    110 | this result ISN'T inductive...%
 | 
|  |    111 | \end{isamarkuptext}%
 | 
| 11866 |    112 | \isamarkuptrue%
 | 
| 10365 |    113 | \isacommand{lemma}\ Suc{\isacharunderscore}Suc{\isacharunderscore}even{\isacharunderscore}imp{\isacharunderscore}even{\isacharcolon}\ {\isachardoublequote}Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isasymin}\ even\ {\isasymLongrightarrow}\ n\ {\isasymin}\ even{\isachardoublequote}\isanewline
 | 
| 11866 |    114 | \isamarkupfalse%
 | 
|  |    115 | \isacommand{apply}\ {\isacharparenleft}erule\ even{\isachardot}induct{\isacharparenright}\isamarkupfalse%
 | 
|  |    116 | %
 | 
| 10878 |    117 | \begin{isamarkuptxt}%
 | 
|  |    118 | \begin{isabelle}%
 | 
| 14470 |    119 | \ {\isadigit{1}}{\isachardot}\ n\ {\isasymin}\ Even{\isachardot}even\isanewline
 | 
|  |    120 | \ {\isadigit{2}}{\isachardot}\ {\isasymAnd}na{\isachardot}\ {\isasymlbrakk}na\ {\isasymin}\ Even{\isachardot}even{\isacharsemicolon}\ n\ {\isasymin}\ Even{\isachardot}even{\isasymrbrakk}\ {\isasymLongrightarrow}\ n\ {\isasymin}\ Even{\isachardot}even%
 | 
| 10878 |    121 | \end{isabelle}%
 | 
|  |    122 | \end{isamarkuptxt}%
 | 
| 11866 |    123 | \isamarkuptrue%
 | 
|  |    124 | \isacommand{oops}\isamarkupfalse%
 | 
|  |    125 | %
 | 
| 10365 |    126 | \begin{isamarkuptext}%
 | 
|  |    127 | ...so we need an inductive lemma...%
 | 
|  |    128 | \end{isamarkuptext}%
 | 
| 11866 |    129 | \isamarkuptrue%
 | 
| 11708 |    130 | \isacommand{lemma}\ even{\isacharunderscore}imp{\isacharunderscore}even{\isacharunderscore}minus{\isacharunderscore}{\isadigit{2}}{\isacharcolon}\ {\isachardoublequote}n\ {\isasymin}\ even\ {\isasymLongrightarrow}\ n\ {\isacharminus}\ {\isadigit{2}}\ {\isasymin}\ even{\isachardoublequote}\isanewline
 | 
| 11866 |    131 | \isamarkupfalse%
 | 
|  |    132 | \isacommand{apply}\ {\isacharparenleft}erule\ even{\isachardot}induct{\isacharparenright}\isamarkupfalse%
 | 
|  |    133 | %
 | 
| 10878 |    134 | \begin{isamarkuptxt}%
 | 
|  |    135 | \begin{isabelle}%
 | 
| 14470 |    136 | \ {\isadigit{1}}{\isachardot}\ {\isadigit{0}}\ {\isacharminus}\ {\isadigit{2}}\ {\isasymin}\ Even{\isachardot}even\isanewline
 | 
|  |    137 | \ {\isadigit{2}}{\isachardot}\ {\isasymAnd}n{\isachardot}\ {\isasymlbrakk}n\ {\isasymin}\ Even{\isachardot}even{\isacharsemicolon}\ n\ {\isacharminus}\ {\isadigit{2}}\ {\isasymin}\ Even{\isachardot}even{\isasymrbrakk}\isanewline
 | 
|  |    138 | \isaindent{\ {\isadigit{2}}{\isachardot}\ {\isasymAnd}n{\isachardot}\ }{\isasymLongrightarrow}\ Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isacharminus}\ {\isadigit{2}}\ {\isasymin}\ Even{\isachardot}even%
 | 
| 10878 |    139 | \end{isabelle}%
 | 
|  |    140 | \end{isamarkuptxt}%
 | 
| 11866 |    141 | \isamarkuptrue%
 | 
| 10365 |    142 | \isacommand{apply}\ auto\isanewline
 | 
| 11866 |    143 | \isamarkupfalse%
 | 
|  |    144 | \isacommand{done}\isamarkupfalse%
 | 
|  |    145 | %
 | 
| 10365 |    146 | \begin{isamarkuptext}%
 | 
|  |    147 | ...and prove it in a separate step%
 | 
|  |    148 | \end{isamarkuptext}%
 | 
| 11866 |    149 | \isamarkuptrue%
 | 
| 10365 |    150 | \isacommand{lemma}\ Suc{\isacharunderscore}Suc{\isacharunderscore}even{\isacharunderscore}imp{\isacharunderscore}even{\isacharcolon}\ {\isachardoublequote}Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isasymin}\ even\ {\isasymLongrightarrow}\ n\ {\isasymin}\ even{\isachardoublequote}\isanewline
 | 
| 11866 |    151 | \isamarkupfalse%
 | 
| 10878 |    152 | \isacommand{by}\ {\isacharparenleft}drule\ even{\isacharunderscore}imp{\isacharunderscore}even{\isacharunderscore}minus{\isacharunderscore}{\isadigit{2}}{\isacharcomma}\ simp{\isacharparenright}\isanewline
 | 
|  |    153 | \isanewline
 | 
| 10365 |    154 | \isanewline
 | 
| 11866 |    155 | \isamarkupfalse%
 | 
| 10365 |    156 | \isacommand{lemma}\ {\isacharbrackleft}iff{\isacharbrackright}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharparenleft}Suc\ {\isacharparenleft}Suc\ n{\isacharparenright}{\isacharparenright}\ {\isasymin}\ even{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}n\ {\isasymin}\ even{\isacharparenright}{\isachardoublequote}\isanewline
 | 
| 11866 |    157 | \isamarkupfalse%
 | 
| 10878 |    158 | \isacommand{by}\ {\isacharparenleft}blast\ dest{\isacharcolon}\ Suc{\isacharunderscore}Suc{\isacharunderscore}even{\isacharunderscore}imp{\isacharunderscore}even{\isacharparenright}\isanewline
 | 
| 10365 |    159 | \isanewline
 | 
| 11866 |    160 | \isamarkupfalse%
 | 
| 10365 |    161 | \isacommand{end}\isanewline
 | 
|  |    162 | \isanewline
 | 
| 11866 |    163 | \isamarkupfalse%
 | 
| 10365 |    164 | \end{isabellebody}%
 | 
|  |    165 | %%% Local Variables:
 | 
|  |    166 | %%% mode: latex
 | 
|  |    167 | %%% TeX-master: "root"
 | 
|  |    168 | %%% End:
 |