doc-src/TutorialI/Misc/document/natsum.tex
author nipkow
Wed Dec 13 09:39:53 2000 +0100 (2000-12-13)
changeset 10654 458068404143
parent 10608 620647438780
child 10788 ea48dd8b0232
permissions -rw-r--r--
*** empty log message ***
nipkow@9722
     1
%
nipkow@9722
     2
\begin{isabellebody}%
wenzelm@9924
     3
\def\isabellecontext{natsum}%
nipkow@8749
     4
%
nipkow@8749
     5
\begin{isamarkuptext}%
nipkow@8749
     6
\noindent
nipkow@9541
     7
In particular, there are \isa{case}-expressions, for example
nipkow@9541
     8
\begin{isabelle}%
nipkow@10187
     9
\ \ \ \ \ case\ n\ of\ {\isadigit{0}}\ {\isasymRightarrow}\ {\isadigit{0}}\ {\isacharbar}\ Suc\ m\ {\isasymRightarrow}\ m%
wenzelm@9924
    10
\end{isabelle}
nipkow@8749
    11
primitive recursion, for example%
nipkow@8749
    12
\end{isamarkuptext}%
wenzelm@9673
    13
\isacommand{consts}\ sum\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}nat\ {\isasymRightarrow}\ nat{\isachardoublequote}\isanewline
nipkow@10187
    14
\isacommand{primrec}\ {\isachardoublequote}sum\ {\isadigit{0}}\ {\isacharequal}\ {\isadigit{0}}{\isachardoublequote}\isanewline
wenzelm@9673
    15
\ \ \ \ \ \ \ \ {\isachardoublequote}sum\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isacharequal}\ Suc\ n\ {\isacharplus}\ sum\ n{\isachardoublequote}%
nipkow@8749
    16
\begin{isamarkuptext}%
nipkow@8749
    17
\noindent
nipkow@8749
    18
and induction, for example%
nipkow@8749
    19
\end{isamarkuptext}%
wenzelm@9673
    20
\isacommand{lemma}\ {\isachardoublequote}sum\ n\ {\isacharplus}\ sum\ n\ {\isacharequal}\ n{\isacharasterisk}{\isacharparenleft}Suc\ n{\isacharparenright}{\isachardoublequote}\isanewline
wenzelm@9673
    21
\isacommand{apply}{\isacharparenleft}induct{\isacharunderscore}tac\ n{\isacharparenright}\isanewline
nipkow@10171
    22
\isacommand{apply}{\isacharparenleft}auto{\isacharparenright}\isanewline
nipkow@10538
    23
\isacommand{done}%
nipkow@10538
    24
\begin{isamarkuptext}%
nipkow@10538
    25
\newcommand{\mystar}{*%
nipkow@10538
    26
}
nipkow@10538
    27
The usual arithmetic operations \ttindexboldpos{+}{$HOL2arithfun},
nipkow@10538
    28
\ttindexboldpos{-}{$HOL2arithfun}, \ttindexboldpos{\mystar}{$HOL2arithfun},
nipkow@10538
    29
\isaindexbold{div}, \isaindexbold{mod}, \isaindexbold{min} and
nipkow@10538
    30
\isaindexbold{max} are predefined, as are the relations
nipkow@10538
    31
\indexboldpos{\isasymle}{$HOL2arithrel} and
nipkow@10654
    32
\ttindexboldpos{<}{$HOL2arithrel}. As usual, \isa{m\ {\isacharminus}\ n\ {\isacharequal}\ {\isadigit{0}}} if
nipkow@10654
    33
\isa{m\ {\isacharless}\ n}. There is even a least number operation
nipkow@10538
    34
\isaindexbold{LEAST}. For example, \isa{{\isacharparenleft}LEAST\ n{\isachardot}\ {\isadigit{1}}\ {\isacharless}\ n{\isacharparenright}\ {\isacharequal}\ {\isadigit{2}}}, although
nipkow@10538
    35
Isabelle does not prove this completely automatically. Note that \isa{{\isadigit{1}}}
nipkow@10538
    36
and \isa{{\isadigit{2}}} are available as abbreviations for the corresponding
nipkow@10538
    37
\isa{Suc}-expressions. If you need the full set of numerals,
nipkow@10608
    38
see~\S\ref{sec:numerals}.
nipkow@10538
    39
nipkow@10538
    40
\begin{warn}
nipkow@10538
    41
  The constant \ttindexbold{0} and the operations
nipkow@10538
    42
  \ttindexboldpos{+}{$HOL2arithfun}, \ttindexboldpos{-}{$HOL2arithfun},
nipkow@10538
    43
  \ttindexboldpos{\mystar}{$HOL2arithfun}, \isaindexbold{min},
nipkow@10538
    44
  \isaindexbold{max}, \indexboldpos{\isasymle}{$HOL2arithrel} and
nipkow@10538
    45
  \ttindexboldpos{<}{$HOL2arithrel} are overloaded, i.e.\ they are available
nipkow@10538
    46
  not just for natural numbers but at other types as well (see
nipkow@10538
    47
  \S\ref{sec:overloading}). For example, given the goal \isa{x\ {\isacharplus}\ {\isadigit{0}}\ {\isacharequal}\ x},
nipkow@10538
    48
  there is nothing to indicate that you are talking about natural numbers.
nipkow@10538
    49
  Hence Isabelle can only infer that \isa{x} is of some arbitrary type where
nipkow@10538
    50
  \isa{{\isadigit{0}}} and \isa{{\isacharplus}} are declared. As a consequence, you will be unable
nipkow@10538
    51
  to prove the goal (although it may take you some time to realize what has
nipkow@10538
    52
  happened if \isa{show{\isacharunderscore}types} is not set).  In this particular example,
nipkow@10538
    53
  you need to include an explicit type constraint, for example
nipkow@10538
    54
  \isa{x\ {\isacharplus}\ {\isadigit{0}}\ {\isacharequal}\ x}. If there is enough contextual information this
nipkow@10538
    55
  may not be necessary: \isa{Suc\ x\ {\isacharequal}\ x} automatically implies
nipkow@10538
    56
  \isa{x{\isacharcolon}{\isacharcolon}nat} because \isa{Suc} is not overloaded.
nipkow@10538
    57
\end{warn}
nipkow@10538
    58
nipkow@10538
    59
Simple arithmetic goals are proved automatically by both \isa{auto} and the
nipkow@10538
    60
simplification methods introduced in \S\ref{sec:Simplification}.  For
nipkow@10538
    61
example,%
nipkow@10538
    62
\end{isamarkuptext}%
nipkow@10538
    63
\isacommand{lemma}\ {\isachardoublequote}{\isasymlbrakk}\ {\isasymnot}\ m\ {\isacharless}\ n{\isacharsemicolon}\ m\ {\isacharless}\ n{\isacharplus}{\isadigit{1}}\ {\isasymrbrakk}\ {\isasymLongrightarrow}\ m\ {\isacharequal}\ n{\isachardoublequote}%
nipkow@10538
    64
\begin{isamarkuptext}%
nipkow@10538
    65
\noindent
nipkow@10538
    66
is proved automatically. The main restriction is that only addition is taken
nipkow@10538
    67
into account; other arithmetic operations and quantified formulae are ignored.
nipkow@10538
    68
nipkow@10538
    69
For more complex goals, there is the special method \isaindexbold{arith}
nipkow@10538
    70
(which attacks the first subgoal). It proves arithmetic goals involving the
nipkow@10538
    71
usual logical connectives (\isa{{\isasymnot}}, \isa{{\isasymand}}, \isa{{\isasymor}},
nipkow@10538
    72
\isa{{\isasymlongrightarrow}}), the relations \isa{{\isasymle}} and \isa{{\isacharless}}, and the operations
nipkow@10654
    73
\isa{{\isacharplus}}, \isa{{\isacharminus}}, \isa{min} and \isa{max}. Technically, this is
nipkow@10654
    74
known as the class of (quantifier free) \bfindex{linear arithmetic} formulae.
nipkow@10654
    75
For example,%
nipkow@10538
    76
\end{isamarkuptext}%
nipkow@10538
    77
\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
nipkow@10538
    78
\isacommand{apply}{\isacharparenleft}arith{\isacharparenright}%
nipkow@10538
    79
\begin{isamarkuptext}%
nipkow@10538
    80
\noindent
nipkow@10538
    81
succeeds because \isa{k\ {\isacharasterisk}\ k} can be treated as atomic. In contrast,%
nipkow@10538
    82
\end{isamarkuptext}%
nipkow@10538
    83
\isacommand{lemma}\ {\isachardoublequote}n{\isacharasterisk}n\ {\isacharequal}\ n\ {\isasymLongrightarrow}\ n{\isacharequal}{\isadigit{0}}\ {\isasymor}\ n{\isacharequal}{\isadigit{1}}{\isachardoublequote}%
nipkow@10538
    84
\begin{isamarkuptext}%
nipkow@10538
    85
\noindent
nipkow@10538
    86
is not even proved by \isa{arith} because the proof relies essentially
nipkow@10538
    87
on properties of multiplication.
nipkow@10538
    88
nipkow@10538
    89
\begin{warn}
nipkow@10538
    90
  The running time of \isa{arith} is exponential in the number of occurrences
nipkow@10538
    91
  of \ttindexboldpos{-}{$HOL2arithfun}, \isaindexbold{min} and
nipkow@10538
    92
  \isaindexbold{max} because they are first eliminated by case distinctions.
nipkow@10538
    93
nipkow@10654
    94
  \isa{arith} is incomplete even for the restricted class of
nipkow@10654
    95
  linear arithmetic formulae. If divisibility plays a
nipkow@10538
    96
  role, it may fail to prove a valid formula, for example
nipkow@10538
    97
  \isa{m\ {\isacharplus}\ m\ {\isasymnoteq}\ n\ {\isacharplus}\ n\ {\isacharplus}\ {\isadigit{1}}}. Fortunately, such examples are rare in practice.
nipkow@10538
    98
\end{warn}%
nipkow@10538
    99
\end{isamarkuptext}%
nipkow@9722
   100
\end{isabellebody}%
wenzelm@9145
   101
%%% Local Variables:
wenzelm@9145
   102
%%% mode: latex
wenzelm@9145
   103
%%% TeX-master: "root"
wenzelm@9145
   104
%%% End: