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