diff -r 1d2f15504d38 -r d1bf9ca9008d doc-src/TutorialI/Misc/document/natsum.tex --- a/doc-src/TutorialI/Misc/document/natsum.tex Wed Nov 29 10:22:38 2000 +0100 +++ b/doc-src/TutorialI/Misc/document/natsum.tex Wed Nov 29 13:44:26 2000 +0100 @@ -20,7 +20,80 @@ \isacommand{lemma}\ {\isachardoublequote}sum\ n\ {\isacharplus}\ sum\ n\ {\isacharequal}\ n{\isacharasterisk}{\isacharparenleft}Suc\ n{\isacharparenright}{\isachardoublequote}\isanewline \isacommand{apply}{\isacharparenleft}induct{\isacharunderscore}tac\ n{\isacharparenright}\isanewline \isacommand{apply}{\isacharparenleft}auto{\isacharparenright}\isanewline -\isacommand{done}\isanewline +\isacommand{done}% +\begin{isamarkuptext}% +\newcommand{\mystar}{*% +} +The usual arithmetic operations \ttindexboldpos{+}{$HOL2arithfun}, +\ttindexboldpos{-}{$HOL2arithfun}, \ttindexboldpos{\mystar}{$HOL2arithfun}, +\isaindexbold{div}, \isaindexbold{mod}, \isaindexbold{min} and +\isaindexbold{max} are predefined, as are the relations +\indexboldpos{\isasymle}{$HOL2arithrel} and +\ttindexboldpos{<}{$HOL2arithrel}. There is even a least number operation +\isaindexbold{LEAST}. For example, \isa{{\isacharparenleft}LEAST\ n{\isachardot}\ {\isadigit{1}}\ {\isacharless}\ n{\isacharparenright}\ {\isacharequal}\ {\isadigit{2}}}, although +Isabelle does not prove this completely automatically. Note that \isa{{\isadigit{1}}} +and \isa{{\isadigit{2}}} are available as abbreviations for the corresponding +\isa{Suc}-expressions. If you need the full set of numerals, +see~\S\ref{nat-numerals}. + +\begin{warn} + The constant \ttindexbold{0} and the operations + \ttindexboldpos{+}{$HOL2arithfun}, \ttindexboldpos{-}{$HOL2arithfun}, + \ttindexboldpos{\mystar}{$HOL2arithfun}, \isaindexbold{min}, + \isaindexbold{max}, \indexboldpos{\isasymle}{$HOL2arithrel} and + \ttindexboldpos{<}{$HOL2arithrel} are overloaded, i.e.\ they are available + not just for natural numbers but at other types as well (see + \S\ref{sec:overloading}). For example, given the goal \isa{x\ {\isacharplus}\ {\isadigit{0}}\ {\isacharequal}\ x}, + there is nothing to indicate that you are talking about natural numbers. + Hence Isabelle can only infer that \isa{x} is of some arbitrary type where + \isa{{\isadigit{0}}} and \isa{{\isacharplus}} are declared. As a consequence, you will be unable + to prove the goal (although it may take you some time to realize what has + happened if \isa{show{\isacharunderscore}types} is not set). In this particular example, + you need to include an explicit type constraint, for example + \isa{x\ {\isacharplus}\ {\isadigit{0}}\ {\isacharequal}\ x}. If there 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 overloaded. +\end{warn} + +Simple arithmetic goals are proved automatically by both \isa{auto} and the +simplification methods introduced in \S\ref{sec:Simplification}. For +example,% +\end{isamarkuptext}% +\isacommand{lemma}\ {\isachardoublequote}{\isasymlbrakk}\ {\isasymnot}\ m\ {\isacharless}\ n{\isacharsemicolon}\ m\ {\isacharless}\ n{\isacharplus}{\isadigit{1}}\ {\isasymrbrakk}\ {\isasymLongrightarrow}\ m\ {\isacharequal}\ n{\isachardoublequote}% +\begin{isamarkuptext}% +\noindent +is proved automatically. The main restriction is that only addition is taken +into account; other arithmetic operations and quantified formulae are ignored. + +For more complex goals, there is the special method \isaindexbold{arith} +(which attacks the first subgoal). It proves arithmetic goals involving the +usual logical connectives (\isa{{\isasymnot}}, \isa{{\isasymand}}, \isa{{\isasymor}}, +\isa{{\isasymlongrightarrow}}), the relations \isa{{\isasymle}} and \isa{{\isacharless}}, and the operations +\isa{{\isacharplus}}, \isa{{\isacharminus}}, \isa{min} and \isa{max}. For example,% +\end{isamarkuptext}% +\isacommand{lemma}\ {\isachardoublequote}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}{\isachardoublequote}\isanewline +\isacommand{apply}{\isacharparenleft}arith{\isacharparenright}% +\begin{isamarkuptext}% +\noindent +succeeds because \isa{k\ {\isacharasterisk}\ k} can be treated as atomic. In contrast,% +\end{isamarkuptext}% +\isacommand{lemma}\ {\isachardoublequote}n{\isacharasterisk}n\ {\isacharequal}\ n\ {\isasymLongrightarrow}\ n{\isacharequal}{\isadigit{0}}\ {\isasymor}\ n{\isacharequal}{\isadigit{1}}{\isachardoublequote}% +\begin{isamarkuptext}% +\noindent +is not even proved by \isa{arith} because the proof relies essentially +on properties of multiplication. + +\begin{warn} + The running time of \isa{arith} is exponential in the number of occurrences + of \ttindexboldpos{-}{$HOL2arithfun}, \isaindexbold{min} and + \isaindexbold{max} because they are first eliminated by case distinctions. + + \isa{arith} is incomplete even for the restricted class of formulae + described above (known as ``linear arithmetic''). If divisibility plays a + role, it may fail to prove a valid formula, for example + \isa{m\ {\isacharplus}\ m\ {\isasymnoteq}\ n\ {\isacharplus}\ n\ {\isacharplus}\ {\isadigit{1}}}. Fortunately, such examples are rare in practice. +\end{warn}% +\end{isamarkuptext}% \end{isabellebody}% %%% Local Variables: %%% mode: latex