doc-src/TutorialI/Misc/natsum.thy
changeset 11456 7eb63f63e6c6
parent 11428 332347b9b942
child 11457 279da0358aa9
equal deleted inserted replaced
11455:e07927b980ec 11456:7eb63f63e6c6
    20 apply(auto);
    20 apply(auto);
    21 done
    21 done
    22 
    22 
    23 text{*\newcommand{\mystar}{*%
    23 text{*\newcommand{\mystar}{*%
    24 }
    24 }
       
    25 \index{arithmetic operations!for \protect\isa{nat}}%
    25 The usual arithmetic operations \ttindexboldpos{+}{$HOL2arithfun},
    26 The usual arithmetic operations \ttindexboldpos{+}{$HOL2arithfun},
    26 \ttindexboldpos{-}{$HOL2arithfun}, \ttindexboldpos{\mystar}{$HOL2arithfun},
    27 \ttindexboldpos{-}{$HOL2arithfun}, \ttindexboldpos{\mystar}{$HOL2arithfun},
    27 \sdx{div}, \sdx{mod}, \cdx{min} and
    28 \sdx{div}, \sdx{mod}, \cdx{min} and
    28 \cdx{max} are predefined, as are the relations
    29 \cdx{max} are predefined, as are the relations
    29 \indexboldpos{\isasymle}{$HOL2arithrel} and
    30 \indexboldpos{\isasymle}{$HOL2arithrel} and
    30 \ttindexboldpos{<}{$HOL2arithrel}. As usual, @{prop"m-n = 0"} if
    31 \ttindexboldpos{<}{$HOL2arithrel}. As usual, @{prop"m-n = 0"} if
    31 @{prop"m<n"}. There is even a least number operation
    32 @{prop"m<n"}. There is even a least number operation
    32 \sdx{LEAST}\@.  For example, @{prop"(LEAST n. 1 < n) = 2"}, although
    33 \sdx{LEAST}\@.  For example, @{prop"(LEAST n. 1 < n) = 2"}. 
    33 Isabelle does not prove this automatically. Note that @{term 1}
    34 \REMARK{Isabelle CAN prove it automatically, using \isa{auto intro: Least_equality}.
       
    35  The following needs changing with our new system of numbers.}
       
    36 Note that @{term 1}
    34 and @{term 2} are available as abbreviations for the corresponding
    37 and @{term 2} are available as abbreviations for the corresponding
    35 @{term Suc}-expressions. If you need the full set of numerals,
    38 @{term Suc}-expressions. If you need the full set of numerals,
    36 see~\S\ref{sec:numerals}.
    39 see~\S\ref{sec:numerals}.
    37 
    40 
    38 \begin{warn}
    41 \begin{warn}\index{overloading}
    39   The constant \cdx{0} and the operations
    42   The constant \cdx{0} and the operations
    40   \ttindexboldpos{+}{$HOL2arithfun}, \ttindexboldpos{-}{$HOL2arithfun},
    43   \ttindexboldpos{+}{$HOL2arithfun}, \ttindexboldpos{-}{$HOL2arithfun},
    41   \ttindexboldpos{\mystar}{$HOL2arithfun}, \cdx{min},
    44   \ttindexboldpos{\mystar}{$HOL2arithfun}, \cdx{min},
    42   \cdx{max}, \indexboldpos{\isasymle}{$HOL2arithrel} and
    45   \cdx{max}, \indexboldpos{\isasymle}{$HOL2arithrel} and
    43   \ttindexboldpos{<}{$HOL2arithrel} are overloaded, i.e.\ they are available
    46   \ttindexboldpos{<}{$HOL2arithrel} are overloaded, i.e.\ they are available
    56   For details see \S\ref{sec:numbers} and \S\ref{sec:overloading};
    59   For details see \S\ref{sec:numbers} and \S\ref{sec:overloading};
    57   Table~\ref{tab:overloading} in the appendix shows the most important overloaded
    60   Table~\ref{tab:overloading} in the appendix shows the most important overloaded
    58   operations.
    61   operations.
    59 \end{warn}
    62 \end{warn}
    60 
    63 
    61 Simple arithmetic goals are proved automatically by both @{term auto} and the
    64 Both @{text auto} and @{text simp}
    62 simplification method introduced in \S\ref{sec:Simplification}.  For
    65 (a method introduced below, \S\ref{sec:Simplification}) prove 
    63 example,
    66 simple arithmetic goals automatically:
    64 *}
    67 *}
    65 
    68 
    66 lemma "\<lbrakk> \<not> m < n; m < n+1 \<rbrakk> \<Longrightarrow> m = n"
    69 lemma "\<lbrakk> \<not> m < n; m < n+1 \<rbrakk> \<Longrightarrow> m = n"
    67 (*<*)by(auto)(*>*)
    70 (*<*)by(auto)(*>*)
    68 
    71 
    69 text{*\noindent
    72 text{*\noindent
    70 is proved automatically. The main restriction is that only addition is taken
    73 For efficiency's sake, this built-in prover ignores quantified formulae and all 
    71 into account; other arithmetic operations and quantified formulae are ignored.
    74 arithmetic operations apart from addition.
    72 
    75 
    73 For more complex goals, there is the special method \methdx{arith}
    76 The method \methdx{arith} is more general.  It attempts to prove
    74 (which attacks the first subgoal). It proves arithmetic goals involving the
    77 the first subgoal provided it is a quantifier free \textbf{linear arithmetic} formula.
       
    78 Such formulas may involve the
    75 usual logical connectives (@{text"\<not>"}, @{text"\<and>"}, @{text"\<or>"},
    79 usual logical connectives (@{text"\<not>"}, @{text"\<and>"}, @{text"\<or>"},
    76 @{text"\<longrightarrow>"}), the relations @{text"="}, @{text"\<le>"} and @{text"<"},
    80 @{text"\<longrightarrow>"}), the relations @{text"="}, @{text"\<le>"} and @{text"<"},
    77 and the operations
    81 and the operations
    78 @{text"+"}, @{text"-"}, @{term min} and @{term max}. Technically, this is
    82 @{text"+"}, @{text"-"}, @{term min} and @{term max}. 
    79 known as the class of (quantifier free) \textbf{linear arithmetic} formulae.
       
    80 For example,
    83 For example,
    81 *}
    84 *}
    82 
    85 
    83 lemma "min i (max j (k*k)) = max (min (k*k) i) (min i (j::nat))";
    86 lemma "min i (max j (k*k)) = max (min (k*k) i) (min i (j::nat))";
    84 apply(arith)
    87 apply(arith)
    90 
    93 
    91 lemma "n*n = n \<Longrightarrow> n=0 \<or> n=1"
    94 lemma "n*n = n \<Longrightarrow> n=0 \<or> n=1"
    92 (*<*)oops(*>*)
    95 (*<*)oops(*>*)
    93 
    96 
    94 text{*\noindent
    97 text{*\noindent
    95 is not even proved by @{text arith} because the proof relies essentially
    98 is not proved even by @{text arith} because the proof relies 
    96 on properties of multiplication.
    99 on properties of multiplication.
    97 
   100 
    98 \begin{warn}
   101 \begin{warn}
    99   The running time of @{text arith} is exponential in the number of occurrences
   102   The running time of @{text arith} is exponential in the number of occurrences
   100   of \ttindexboldpos{-}{$HOL2arithfun}, \cdx{min} and
   103   of \ttindexboldpos{-}{$HOL2arithfun}, \cdx{min} and
   101   \cdx{max} because they are first eliminated by case distinctions.
   104   \cdx{max} because they are first eliminated by case distinctions.
   102 
   105 
   103   \isa{arith} is incomplete even for the restricted class of
   106   Even for linear arithmetic formulae, \isa{arith} is incomplete. If divisibility plays a
   104   linear arithmetic formulae. If divisibility plays a
       
   105   role, it may fail to prove a valid formula, for example
   107   role, it may fail to prove a valid formula, for example
   106   @{prop"m+m \<noteq> n+n+1"}. Fortunately, such examples are rare in practice.
   108   @{prop"m+m \<noteq> n+n+1"}. Fortunately, such examples are rare.
   107 \end{warn}
   109 \end{warn}
   108 *}
   110 *}
   109 
   111 
   110 (*<*)
   112 (*<*)
   111 end
   113 end