| 9722 |      1 | %
 | 
|  |      2 | \begin{isabellebody}%
 | 
| 9924 |      3 | \def\isabellecontext{natsum}%
 | 
| 17056 |      4 | %
 | 
|  |      5 | \isadelimtheory
 | 
|  |      6 | %
 | 
|  |      7 | \endisadelimtheory
 | 
|  |      8 | %
 | 
|  |      9 | \isatagtheory
 | 
|  |     10 | %
 | 
|  |     11 | \endisatagtheory
 | 
|  |     12 | {\isafoldtheory}%
 | 
|  |     13 | %
 | 
|  |     14 | \isadelimtheory
 | 
|  |     15 | %
 | 
|  |     16 | \endisadelimtheory
 | 
| 8749 |     17 | %
 | 
|  |     18 | \begin{isamarkuptext}%
 | 
|  |     19 | \noindent
 | 
| 9541 |     20 | In particular, there are \isa{case}-expressions, for example
 | 
|  |     21 | \begin{isabelle}%
 | 
| 10187 |     22 | \ \ \ \ \ case\ n\ of\ {\isadigit{0}}\ {\isasymRightarrow}\ {\isadigit{0}}\ {\isacharbar}\ Suc\ m\ {\isasymRightarrow}\ m%
 | 
| 9924 |     23 | \end{isabelle}
 | 
| 8749 |     24 | primitive recursion, for example%
 | 
|  |     25 | \end{isamarkuptext}%
 | 
| 17175 |     26 | \isamarkuptrue%
 | 
|  |     27 | \isacommand{consts}\isamarkupfalse%
 | 
|  |     28 | \ sum\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ nat{\isachardoublequoteclose}\isanewline
 | 
|  |     29 | \isacommand{primrec}\isamarkupfalse%
 | 
|  |     30 | \ {\isachardoublequoteopen}sum\ {\isadigit{0}}\ {\isacharequal}\ {\isadigit{0}}{\isachardoublequoteclose}\isanewline
 | 
|  |     31 | \ \ \ \ \ \ \ \ {\isachardoublequoteopen}sum\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isacharequal}\ Suc\ n\ {\isacharplus}\ sum\ n{\isachardoublequoteclose}%
 | 
| 8749 |     32 | \begin{isamarkuptext}%
 | 
|  |     33 | \noindent
 | 
|  |     34 | and induction, for example%
 | 
|  |     35 | \end{isamarkuptext}%
 | 
| 17175 |     36 | \isamarkuptrue%
 | 
|  |     37 | \isacommand{lemma}\isamarkupfalse%
 | 
|  |     38 | \ {\isachardoublequoteopen}sum\ n\ {\isacharplus}\ sum\ n\ {\isacharequal}\ n{\isacharasterisk}{\isacharparenleft}Suc\ n{\isacharparenright}{\isachardoublequoteclose}\isanewline
 | 
| 17056 |     39 | %
 | 
|  |     40 | \isadelimproof
 | 
|  |     41 | %
 | 
|  |     42 | \endisadelimproof
 | 
|  |     43 | %
 | 
|  |     44 | \isatagproof
 | 
| 17175 |     45 | \isacommand{apply}\isamarkupfalse%
 | 
|  |     46 | {\isacharparenleft}induct{\isacharunderscore}tac\ n{\isacharparenright}\isanewline
 | 
|  |     47 | \isacommand{apply}\isamarkupfalse%
 | 
|  |     48 | {\isacharparenleft}auto{\isacharparenright}\isanewline
 | 
|  |     49 | \isacommand{done}\isamarkupfalse%
 | 
|  |     50 | %
 | 
| 17056 |     51 | \endisatagproof
 | 
|  |     52 | {\isafoldproof}%
 | 
|  |     53 | %
 | 
|  |     54 | \isadelimproof
 | 
|  |     55 | %
 | 
|  |     56 | \endisadelimproof
 | 
| 11866 |     57 | %
 | 
| 10538 |     58 | \begin{isamarkuptext}%
 | 
|  |     59 | \newcommand{\mystar}{*%
 | 
|  |     60 | }
 | 
| 11456 |     61 | \index{arithmetic operations!for \protect\isa{nat}}%
 | 
| 15364 |     62 | The arithmetic operations \isadxboldpos{+}{$HOL2arithfun},
 | 
|  |     63 | \isadxboldpos{-}{$HOL2arithfun}, \isadxboldpos{\mystar}{$HOL2arithfun},
 | 
| 11428 |     64 | \sdx{div}, \sdx{mod}, \cdx{min} and
 | 
|  |     65 | \cdx{max} are predefined, as are the relations
 | 
| 15364 |     66 | \isadxboldpos{\isasymle}{$HOL2arithrel} and
 | 
|  |     67 | \isadxboldpos{<}{$HOL2arithrel}. As usual, \isa{m\ {\isacharminus}\ n\ {\isacharequal}\ {\isadigit{0}}} if
 | 
| 10654 |     68 | \isa{m\ {\isacharless}\ n}. There is even a least number operation
 | 
| 12327 |     69 | \sdx{LEAST}\@.  For example, \isa{{\isacharparenleft}LEAST\ n{\isachardot}\ {\isadigit{0}}\ {\isacharless}\ n{\isacharparenright}\ {\isacharequal}\ Suc\ {\isadigit{0}}}.
 | 
| 11456 |     70 | \begin{warn}\index{overloading}
 | 
| 12327 |     71 |   The constants \cdx{0} and \cdx{1} and the operations
 | 
| 15364 |     72 |   \isadxboldpos{+}{$HOL2arithfun}, \isadxboldpos{-}{$HOL2arithfun},
 | 
|  |     73 |   \isadxboldpos{\mystar}{$HOL2arithfun}, \cdx{min},
 | 
|  |     74 |   \cdx{max}, \isadxboldpos{\isasymle}{$HOL2arithrel} and
 | 
|  |     75 |   \isadxboldpos{<}{$HOL2arithrel} are overloaded: they are available
 | 
| 12332 |     76 |   not just for natural numbers but for other types as well.
 | 
| 12327 |     77 |   For example, given the goal \isa{x\ {\isacharplus}\ {\isadigit{0}}\ {\isacharequal}\ x}, there is nothing to indicate
 | 
|  |     78 |   that you are talking about natural numbers. Hence Isabelle can only infer
 | 
|  |     79 |   that \isa{x} is of some arbitrary type where \isa{{\isadigit{0}}} and \isa{{\isacharplus}} are
 | 
|  |     80 |   declared. As a consequence, you will be unable to prove the
 | 
|  |     81 |   goal. To alert you to such pitfalls, Isabelle flags numerals without a
 | 
|  |     82 |   fixed type in its output: \isa{x\ {\isacharplus}\ {\isacharparenleft}{\isadigit{0}}{\isasymColon}{\isacharprime}a{\isacharparenright}\ {\isacharequal}\ x}. (In the absence of a numeral,
 | 
| 16523 |     83 |   it may take you some time to realize what has happened if \pgmenu{Show
 | 
|  |     84 |   Types} is not set).  In this particular example, you need to include
 | 
| 12327 |     85 |   an explicit type constraint, for example \isa{x{\isacharplus}{\isadigit{0}}\ {\isacharequal}\ {\isacharparenleft}x{\isacharcolon}{\isacharcolon}nat{\isacharparenright}}. If there
 | 
|  |     86 |   is enough contextual information this may not be necessary: \isa{Suc\ x\ {\isacharequal}\ x} automatically implies \isa{x{\isacharcolon}{\isacharcolon}nat} because \isa{Suc} is not
 | 
|  |     87 |   overloaded.
 | 
| 10978 |     88 | 
 | 
| 12327 |     89 |   For details on overloading see \S\ref{sec:overloading}.
 | 
|  |     90 |   Table~\ref{tab:overloading} in the appendix shows the most important
 | 
|  |     91 |   overloaded operations.
 | 
|  |     92 | \end{warn}
 | 
|  |     93 | \begin{warn}
 | 
| 15364 |     94 |   The symbols \isadxboldpos{>}{$HOL2arithrel} and
 | 
|  |     95 |   \isadxboldpos{\isasymge}{$HOL2arithrel} are merely syntax: \isa{x\ {\isachargreater}\ y}
 | 
|  |     96 |   stands for \isa{y\ {\isacharless}\ x} and similary for \isa{{\isasymge}} and
 | 
|  |     97 |   \isa{{\isasymle}}.
 | 
|  |     98 | \end{warn}
 | 
|  |     99 | \begin{warn}
 | 
| 12332 |    100 |   Constant \isa{{\isadigit{1}}{\isacharcolon}{\isacharcolon}nat} is defined to equal \isa{Suc\ {\isadigit{0}}}. This definition
 | 
| 12327 |    101 |   (see \S\ref{sec:ConstDefinitions}) is unfolded automatically by some
 | 
|  |    102 |   tactics (like \isa{auto}, \isa{simp} and \isa{arith}) but not by
 | 
|  |    103 |   others (especially the single step tactics in Chapter~\ref{chap:rules}).
 | 
|  |    104 |   If you need the full set of numerals, see~\S\ref{sec:numerals}.
 | 
| 12328 |    105 |   \emph{Novices are advised to stick to \isa{{\isadigit{0}}} and \isa{Suc}.}
 | 
| 10538 |    106 | \end{warn}
 | 
|  |    107 | 
 | 
| 11456 |    108 | Both \isa{auto} and \isa{simp}
 | 
|  |    109 | (a method introduced below, \S\ref{sec:Simplification}) prove 
 | 
|  |    110 | simple arithmetic goals automatically:%
 | 
| 10538 |    111 | \end{isamarkuptext}%
 | 
| 17175 |    112 | \isamarkuptrue%
 | 
|  |    113 | \isacommand{lemma}\isamarkupfalse%
 | 
|  |    114 | \ {\isachardoublequoteopen}{\isasymlbrakk}\ {\isasymnot}\ m\ {\isacharless}\ n{\isacharsemicolon}\ m\ {\isacharless}\ n\ {\isacharplus}\ {\isacharparenleft}{\isadigit{1}}{\isacharcolon}{\isacharcolon}nat{\isacharparenright}\ {\isasymrbrakk}\ {\isasymLongrightarrow}\ m\ {\isacharequal}\ n{\isachardoublequoteclose}%
 | 
| 17056 |    115 | \isadelimproof
 | 
|  |    116 | %
 | 
|  |    117 | \endisadelimproof
 | 
|  |    118 | %
 | 
|  |    119 | \isatagproof
 | 
|  |    120 | %
 | 
|  |    121 | \endisatagproof
 | 
|  |    122 | {\isafoldproof}%
 | 
|  |    123 | %
 | 
|  |    124 | \isadelimproof
 | 
|  |    125 | %
 | 
|  |    126 | \endisadelimproof
 | 
| 11866 |    127 | %
 | 
| 10538 |    128 | \begin{isamarkuptext}%
 | 
|  |    129 | \noindent
 | 
| 11458 |    130 | For efficiency's sake, this built-in prover ignores quantified formulae,
 | 
| 16797 |    131 | many logical connectives, and all arithmetic operations apart from addition.
 | 
| 13181 |    132 | In consequence, \isa{auto} and \isa{simp} cannot prove this slightly more complex goal:%
 | 
| 11458 |    133 | \end{isamarkuptext}%
 | 
| 17175 |    134 | \isamarkuptrue%
 | 
|  |    135 | \isacommand{lemma}\isamarkupfalse%
 | 
|  |    136 | \ {\isachardoublequoteopen}m\ {\isasymnoteq}\ {\isacharparenleft}n{\isacharcolon}{\isacharcolon}nat{\isacharparenright}\ {\isasymLongrightarrow}\ m\ {\isacharless}\ n\ {\isasymor}\ n\ {\isacharless}\ m{\isachardoublequoteclose}%
 | 
| 17056 |    137 | \isadelimproof
 | 
|  |    138 | %
 | 
|  |    139 | \endisadelimproof
 | 
|  |    140 | %
 | 
|  |    141 | \isatagproof
 | 
|  |    142 | %
 | 
|  |    143 | \endisatagproof
 | 
|  |    144 | {\isafoldproof}%
 | 
|  |    145 | %
 | 
|  |    146 | \isadelimproof
 | 
|  |    147 | %
 | 
|  |    148 | \endisadelimproof
 | 
| 11866 |    149 | %
 | 
| 11458 |    150 | \begin{isamarkuptext}%
 | 
| 13996 |    151 | \noindent The method \methdx{arith} is more general.  It attempts to
 | 
|  |    152 | prove the first subgoal provided it is a \textbf{linear arithmetic} formula.
 | 
|  |    153 | Such formulas may involve the usual logical connectives (\isa{{\isasymnot}},
 | 
|  |    154 | \isa{{\isasymand}}, \isa{{\isasymor}}, \isa{{\isasymlongrightarrow}}, \isa{{\isacharequal}},
 | 
|  |    155 | \isa{{\isasymforall}}, \isa{{\isasymexists}}), the relations \isa{{\isacharequal}},
 | 
|  |    156 | \isa{{\isasymle}} and \isa{{\isacharless}}, and the operations \isa{{\isacharplus}}, \isa{{\isacharminus}},
 | 
| 23059 |    157 | \isa{min} and \isa{max}.  For example,%
 | 
| 10538 |    158 | \end{isamarkuptext}%
 | 
| 17175 |    159 | \isamarkuptrue%
 | 
|  |    160 | \isacommand{lemma}\isamarkupfalse%
 | 
|  |    161 | \ {\isachardoublequoteopen}min\ i\ {\isacharparenleft}max\ j\ {\isacharparenleft}k{\isacharasterisk}k{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ max\ {\isacharparenleft}min\ {\isacharparenleft}k{\isacharasterisk}k{\isacharparenright}\ i{\isacharparenright}\ {\isacharparenleft}min\ i\ {\isacharparenleft}j{\isacharcolon}{\isacharcolon}nat{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}\isanewline
 | 
| 17056 |    162 | %
 | 
|  |    163 | \isadelimproof
 | 
|  |    164 | %
 | 
|  |    165 | \endisadelimproof
 | 
|  |    166 | %
 | 
|  |    167 | \isatagproof
 | 
| 17175 |    168 | \isacommand{apply}\isamarkupfalse%
 | 
| 17181 |    169 | {\isacharparenleft}arith{\isacharparenright}%
 | 
| 17056 |    170 | \endisatagproof
 | 
|  |    171 | {\isafoldproof}%
 | 
|  |    172 | %
 | 
|  |    173 | \isadelimproof
 | 
|  |    174 | %
 | 
|  |    175 | \endisadelimproof
 | 
| 17175 |    176 | %
 | 
|  |    177 | \begin{isamarkuptext}%
 | 
|  |    178 | \noindent
 | 
|  |    179 | succeeds because \isa{k\ {\isacharasterisk}\ k} can be treated as atomic. In contrast,%
 | 
|  |    180 | \end{isamarkuptext}%
 | 
| 11866 |    181 | \isamarkuptrue%
 | 
| 17175 |    182 | \isacommand{lemma}\isamarkupfalse%
 | 
|  |    183 | \ {\isachardoublequoteopen}n{\isacharasterisk}n\ {\isacharequal}\ n\ {\isasymLongrightarrow}\ n{\isacharequal}{\isadigit{0}}\ {\isasymor}\ n{\isacharequal}{\isadigit{1}}{\isachardoublequoteclose}%
 | 
|  |    184 | \isadelimproof
 | 
|  |    185 | %
 | 
|  |    186 | \endisadelimproof
 | 
|  |    187 | %
 | 
|  |    188 | \isatagproof
 | 
|  |    189 | %
 | 
|  |    190 | \endisatagproof
 | 
|  |    191 | {\isafoldproof}%
 | 
|  |    192 | %
 | 
|  |    193 | \isadelimproof
 | 
|  |    194 | %
 | 
|  |    195 | \endisadelimproof
 | 
| 11866 |    196 | %
 | 
| 10538 |    197 | \begin{isamarkuptext}%
 | 
|  |    198 | \noindent
 | 
| 11456 |    199 | is not proved even by \isa{arith} because the proof relies 
 | 
| 13996 |    200 | on properties of multiplication. Only multiplication by numerals (which is
 | 
|  |    201 | the same as iterated addition) is allowed.
 | 
| 10538 |    202 | 
 | 
| 13996 |    203 | \begin{warn} The running time of \isa{arith} is exponential in the number
 | 
|  |    204 |   of occurrences of \ttindexboldpos{-}{$HOL2arithfun}, \cdx{min} and
 | 
| 11428 |    205 |   \cdx{max} because they are first eliminated by case distinctions.
 | 
| 10538 |    206 | 
 | 
| 13996 |    207 | If \isa{k} is a numeral, \sdx{div}~\isa{k}, \sdx{mod}~\isa{k} and
 | 
|  |    208 | \isa{k}~\sdx{dvd} are also supported, where the former two are eliminated
 | 
|  |    209 | by case distinctions, again blowing up the running time.
 | 
|  |    210 | 
 | 
| 16797 |    211 | If the formula involves quantifiers, \isa{arith} may take
 | 
| 13996 |    212 | super-exponential time and space.
 | 
| 10538 |    213 | \end{warn}%
 | 
|  |    214 | \end{isamarkuptext}%
 | 
| 17175 |    215 | \isamarkuptrue%
 | 
| 17056 |    216 | %
 | 
|  |    217 | \isadelimtheory
 | 
|  |    218 | %
 | 
|  |    219 | \endisadelimtheory
 | 
|  |    220 | %
 | 
|  |    221 | \isatagtheory
 | 
|  |    222 | %
 | 
|  |    223 | \endisatagtheory
 | 
|  |    224 | {\isafoldtheory}%
 | 
|  |    225 | %
 | 
|  |    226 | \isadelimtheory
 | 
|  |    227 | %
 | 
|  |    228 | \endisadelimtheory
 | 
| 9722 |    229 | \end{isabellebody}%
 | 
| 9145 |    230 | %%% Local Variables:
 | 
|  |    231 | %%% mode: latex
 | 
|  |    232 | %%% TeX-master: "root"
 | 
|  |    233 | %%% End:
 |