doc-src/TutorialI/Types/numerics.tex
author nipkow
Thu, 25 Jan 2001 15:31:31 +0100
changeset 10978 5eebea8f359f
parent 10881 03f06372230b
child 10983 59961d32b1ae
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
     1
% $Id$
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
     2
Until now, our numerical have used the type of \textbf{natural numbers},
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
     3
\isa{nat}.  This is a recursive datatype generated by the constructors
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
     4
zero  and successor, so it works well with inductive proofs and primitive
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
     5
recursive function definitions. Isabelle/HOL also provides the type
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
     6
\isa{int} of \textbf{integers}, which lack induction but support true
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
     7
subtraction. The logic HOL-Real also has the type \isa{real} of real
10777
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
     8
numbers.  Isabelle has no subtyping,  so the numeric types are distinct and
10978
5eebea8f359f *** empty log message ***
nipkow
parents: 10881
diff changeset
     9
there are  functions to convert between them. Fortunately most numeric
5eebea8f359f *** empty log message ***
nipkow
parents: 10881
diff changeset
    10
operations are overloaded: the same symbol can be used at all numeric types.
5eebea8f359f *** empty log message ***
nipkow
parents: 10881
diff changeset
    11
Table~\ref{tab:overloading} in the appendix shows the most important operations,
5eebea8f359f *** empty log message ***
nipkow
parents: 10881
diff changeset
    12
together with the priorities of the infix symbols.
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    13
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    14
The integers are preferable to the natural  numbers for reasoning about
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    15
complicated arithmetic expressions. For  example, a termination proof
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    16
typically involves an integer metric  that is shown to decrease at each
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    17
loop iteration. Even if the  metric cannot become negative, proofs 
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    18
may be easier if you use the integers instead of the natural
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    19
numbers. 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    20
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    21
Many theorems involving numeric types can be proved automatically by
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    22
Isabelle's arithmetic decision procedure, the method
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    23
\isa{arith}.  Linear arithmetic comprises addition, subtraction
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    24
and multiplication by constant factors; subterms involving other operators
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    25
are regarded as variables.  The procedure can be slow, especially if the
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    26
subgoal to be proved involves subtraction over type \isa{nat}, which 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    27
causes case splits.  
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    28
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    29
The simplifier reduces arithmetic expressions in other
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    30
ways, such as dividing through by common factors.  For problems that lie
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    31
outside the scope of automation, HOL provides hundreds of
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    32
theorems about multiplication, division, etc., that can be brought to
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    33
bear.  You can locate them using Proof General's Find
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    34
button.  A few lemmas are given below to show what
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    35
is available.
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    36
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    37
\subsection{Numeric Literals}
10779
nipkow
parents: 10777
diff changeset
    38
\label{sec:numerals}
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    39
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    40
Literals are available for the types of natural numbers, integers 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    41
and reals and denote integer values of arbitrary size. 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    42
They begin 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    43
with a number sign (\isa{\#}), have an optional minus sign (\isa{-}) and 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    44
then one or more decimal digits. Examples are \isa{\#0}, \isa{\#-3} 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    45
and \isa{\#441223334678}.
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    46
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    47
Literals look like constants, but they abbreviate 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    48
terms, representing the number in a two's complement binary notation. 
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    49
Isabelle performs arithmetic on literals by rewriting rather 
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    50
than using the hardware arithmetic. In most cases arithmetic 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    51
is fast enough, even for large numbers. The arithmetic operations 
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    52
provided for literals include addition, subtraction, multiplication, 
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    53
integer division and remainder.  Fractions of literals (expressed using
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    54
division) are reduced to lowest terms.
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    55
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    56
\begin{warn}
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    57
The arithmetic operators are 
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    58
overloaded, so you must be careful to ensure that each numeric 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    59
expression refers to a specific type, if necessary by inserting 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    60
type constraints.  Here is an example of what can go wrong:
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    61
\par
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    62
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    63
\isacommand{lemma}\ "\#2\ *\ m\ =\ m\ +\ m"
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    64
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    65
%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    66
Carefully observe how Isabelle displays the subgoal:
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    67
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    68
\ 1.\ (\#2::'a)\ *\ m\ =\ m\ +\ m
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    69
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    70
The type \isa{'a} given for the literal \isa{\#2} warns us that no numeric
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    71
type has been specified.  The problem is underspecified.  Given a type
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    72
constraint such as \isa{nat}, \isa{int} or \isa{real}, it becomes trivial.
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    73
\end{warn}
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    74
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    75
\begin{warn}
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    76
Numeric literals are not constructors and therefore must not be used in
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    77
patterns.  For example, this declaration is rejected:
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    78
\begin{isabelle}
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    79
\isacommand{recdef}\ h\ "\isacharbraceleft \isacharbraceright "\isanewline
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    80
h\ \#3\ =\ \#2\isanewline
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    81
h\ i\ \ =\ i
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    82
\end{isabelle}
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    83
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    84
You should use a conditional expression instead:
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    85
\begin{isabelle}
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    86
"h\ i\ =\ (if\ i\ =\ \#3\ then\ \#2\ else\ i)"
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    87
\end{isabelle}
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    88
\end{warn}
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    89
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    90
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    91
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    92
\subsection{The type of natural numbers, {\tt\slshape nat}}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    93
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    94
This type requires no introduction: we have been using it from the
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    95
beginning.  Hundreds of theorems about the natural numbers are
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    96
proved in the theories \isa{Nat}, \isa{NatArith} and \isa{Divides}.  Only
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    97
in exceptional circumstances should you resort to induction.
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    98
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    99
\subsubsection{Literals}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   100
The notational options for the natural numbers can be confusing. The 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   101
constant \isa{0} is overloaded to serve as the neutral value 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   102
in a variety of additive types. The symbols \isa{1} and \isa{2} are 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   103
not constants but abbreviations for \isa{Suc 0} and \isa{Suc(Suc 0)},
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   104
respectively. The literals \isa{\#0}, \isa{\#1} and \isa{\#2}  are
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   105
syntactically different from \isa{0}, \isa{1} and \isa{2}. You  will
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   106
sometimes prefer one notation to the other. Literals are  obviously
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   107
necessary to express large values, while \isa{0} and \isa{Suc}  are needed
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   108
in order to match many theorems, including the rewrite  rules for primitive
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   109
recursive functions. The following default  simplification rules replace
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   110
small literals by zero and successor: 
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   111
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   112
\#0\ =\ 0
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   113
\rulename{numeral_0_eq_0}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   114
\#1\ =\ 1
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   115
\rulename{numeral_1_eq_1}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   116
\#2\ +\ n\ =\ Suc\ (Suc\ n)
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   117
\rulename{add_2_eq_Suc}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   118
n\ +\ \#2\ =\ Suc\ (Suc\ n)
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   119
\rulename{add_2_eq_Suc'}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   120
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   121
In special circumstances, you may wish to remove or reorient 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   122
these rules. 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   123
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   124
\subsubsection{Typical lemmas}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   125
Inequalities involving addition and subtraction alone can be proved
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   126
automatically.  Lemmas such as these can be used to prove inequalities
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   127
involving multiplication and division:
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   128
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   129
\isasymlbrakk i\ \isasymle \ j;\ k\ \isasymle \ l\isasymrbrakk \ \isasymLongrightarrow \ i\ *\ k\ \isasymle \ j\ *\ l%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   130
\rulename{mult_le_mono}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   131
\isasymlbrakk i\ <\ j;\ 0\ <\ k\isasymrbrakk \ \isasymLongrightarrow \ i\
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   132
*\ k\ <\ j\ *\ k%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   133
\rulename{mult_less_mono1}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   134
m\ \isasymle \ n\ \isasymLongrightarrow \ m\ div\ k\ \isasymle \ n\ div\ k%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   135
\rulename{div_le_mono}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   136
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   137
%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   138
Various distributive laws concerning multiplication are available:
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   139
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   140
(m\ +\ n)\ *\ k\ =\ m\ *\ k\ +\ n\ *\ k%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   141
\rulename{add_mult_distrib}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   142
(m\ -\ n)\ *\ k\ =\ m\ *\ k\ -\ n\ *\ k%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   143
\rulename{diff_mult_distrib}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   144
(m\ mod\ n)\ *\ k\ =\ (m\ *\ k)\ mod\ (n\ *\ k)
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   145
\rulename{mod_mult_distrib}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   146
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   147
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   148
\subsubsection{Division}
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   149
The infix operators \isa{div} and \isa{mod} are overloaded.
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   150
Isabelle/HOL provides the basic facts about quotient and remainder
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   151
on the natural numbers:
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   152
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   153
m\ mod\ n\ =\ (if\ m\ <\ n\ then\ m\ else\ (m\ -\ n)\ mod\ n)
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   154
\rulename{mod_if}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   155
m\ div\ n\ *\ n\ +\ m\ mod\ n\ =\ m%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   156
\rulename{mod_div_equality}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   157
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   158
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   159
Many less obvious facts about quotient and remainder are also provided. 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   160
Here is a selection:
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   161
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   162
a\ *\ b\ div\ c\ =\ a\ *\ (b\ div\ c)\ +\ a\ *\ (b\ mod\ c)\ div\ c%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   163
\rulename{div_mult1_eq}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   164
a\ *\ b\ mod\ c\ =\ a\ *\ (b\ mod\ c)\ mod\ c%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   165
\rulename{mod_mult1_eq}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   166
a\ div\ (b*c)\ =\ a\ div\ b\ div\ c%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   167
\rulename{div_mult2_eq}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   168
a\ mod\ (b*c)\ =\ b * (a\ div\ b\ mod\ c)\ +\ a\ mod\ b%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   169
\rulename{mod_mult2_eq}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   170
0\ <\ c\ \isasymLongrightarrow \ (c\ *\ a)\ div\ (c\ *\ b)\ =\ a\ div\ b%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   171
\rulename{div_mult_mult1}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   172
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   173
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   174
Surprisingly few of these results depend upon the
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   175
divisors' being nonzero.  That is because division by
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   176
zero yields zero:
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   177
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   178
a\ div\ 0\ =\ 0
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   179
\rulename{DIVISION_BY_ZERO_DIV}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   180
a\ mod\ 0\ =\ a%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   181
\rulename{DIVISION_BY_ZERO_MOD}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   182
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   183
As a concession to convention, these equations are not installed as default
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   184
simplification rules but are merely used to remove nonzero-divisor
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   185
hypotheses by case analysis.  In \isa{div_mult_mult1} above, one of
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   186
the two divisors (namely~\isa{c}) must be still be nonzero.
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   187
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   188
The \textbf{divides} relation has the standard definition, which
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   189
is overloaded over all numeric types: 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   190
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   191
m\ dvd\ n\ \isasymequiv\ {\isasymexists}k.\ n\ =\ m\ *\ k
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   192
\rulename{dvd_def}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   193
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   194
%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   195
Section~\ref{sec:proving-euclid} discusses proofs involving this
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   196
relation.  Here are some of the facts proved about it:
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   197
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   198
\isasymlbrakk m\ dvd\ n;\ n\ dvd\ m\isasymrbrakk \ \isasymLongrightarrow \ m\ =\ n%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   199
\rulename{dvd_anti_sym}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   200
\isasymlbrakk k\ dvd\ m;\ k\ dvd\ n\isasymrbrakk \ \isasymLongrightarrow \ k\ dvd\ (m\ +\ n)
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   201
\rulename{dvd_add}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   202
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   203
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   204
\subsubsection{Simplifier tricks}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   205
The rule \isa{diff_mult_distrib} shown above is one of the few facts
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   206
about \isa{m\ -\ n} that is not subject to
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   207
the condition \isa{n\ \isasymle \  m}.  Natural number subtraction has few
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   208
nice properties; often you should remove it by simplifying with this split
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   209
rule:
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   210
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   211
P(a-b)\ =\ ((a<b\ \isasymlongrightarrow \ P\
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   212
0)\ \isasymand \ (\isasymforall d.\ a\ =\ b+d\ \isasymlongrightarrow \ P\
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   213
d))
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   214
\rulename{nat_diff_split}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   215
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   216
For example, it proves the following fact, which lies outside the scope of
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   217
linear arithmetic:
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   218
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   219
\isacommand{lemma}\ "(n-1)*(n+1)\ =\ n*n\ -\ 1"\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   220
\isacommand{apply}\ (simp\ split:\ nat_diff_split)\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   221
\isacommand{done}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   222
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   223
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   224
Suppose that two expressions are equal, differing only in 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   225
associativity and commutativity of addition.  Simplifying with the
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   226
following equations sorts the terms and groups them to the right, making
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   227
the two expressions identical:
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   228
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   229
m\ +\ n\ +\ k\ =\ m\ +\ (n\ +\ k)
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   230
\rulename{add_assoc}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   231
m\ +\ n\ =\ n\ +\ m%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   232
\rulename{add_commute}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   233
x\ +\ (y\ +\ z)\ =\ y\ +\ (x\
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   234
+\ z)
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   235
\rulename{add_left_commute}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   236
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   237
The name \isa{add_ac} refers to the list of all three theorems, similarly
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   238
there is \isa{mult_ac}.  Here is an example of the sorting effect.  Start
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   239
with this goal:
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   240
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   241
\ 1.\ Suc\ (i\ +\ j\ *\ l\ *\ k\ +\ m\ *\ n)\ =\
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   242
f\ (n\ *\ m\ +\ i\ +\ k\ *\ j\ *\ l)
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   243
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   244
%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   245
Simplify using  \isa{add_ac} and \isa{mult_ac}:
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   246
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   247
\isacommand{apply}\ (simp\ add:\ add_ac\ mult_ac)
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   248
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   249
%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   250
Here is the resulting subgoal:
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   251
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   252
\ 1.\ Suc\ (i\ +\ (m\ *\ n\ +\ j\ *\ (k\ *\ l)))\
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   253
=\ f\ (i\ +\ (m\ *\ n\ +\ j\ *\ (k\ *\ l)))%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   254
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   255
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   256
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   257
\subsection{The type of integers, {\tt\slshape int}}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   258
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   259
Reasoning methods resemble those for the natural numbers, but induction and
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   260
the constant \isa{Suc} are not available.  HOL provides many lemmas
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   261
for proving inequalities involving integer multiplication and division,
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   262
similar to those shown above for type~\isa{nat}.  
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   263
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   264
The absolute value function \isa{abs} is overloaded for the numeric types.
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   265
It is defined for the integers; we have for example the obvious law
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   266
\begin{isabelle}
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   267
\isasymbar x\ *\ y\isasymbar \ =\ \isasymbar x\isasymbar \ *\ \isasymbar y\isasymbar 
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   268
\rulename{abs_mult}
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   269
\end{isabelle}
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   270
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   271
\begin{warn}
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   272
The absolute value bars shown above cannot be typed on a keyboard.  They
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   273
can be entered using the X-symbol package.  In ASCII, type \isa{abs x} to
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   274
get \isa{\isasymbar x\isasymbar}.
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   275
\end{warn}
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   276
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   277
The \isa{arith} method can prove facts about \isa{abs} automatically, 
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   278
though as it does so by case analysis, the cost can be exponential.
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   279
\begin{isabelle}
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   280
\isacommand{lemma}\ "\isasymlbrakk abs\ x\ <\ a;\ abs\ y\ <\ b\isasymrbrakk \ \isasymLongrightarrow \ abs\ x\ +\ abs\ y\ <\ (a\ +\ b\ ::\ int)"\isanewline
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   281
\isacommand{by}\ arith
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   282
\end{isabelle}
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   283
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   284
Concerning simplifier tricks, we have no need to eliminate subtraction: it
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   285
is well-behaved.  As with the natural numbers, the simplifier can sort the
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   286
operands of sums and products.  The name \isa{zadd_ac} refers to the
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   287
associativity and commutativity theorems for integer addition, while
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   288
\isa{zmult_ac} has the analogous theorems for multiplication.  The
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   289
prefix~\isa{z} in many theorem names recalls the use of $\mathbb{Z}$ to
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   290
denote the set of integers.
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   291
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   292
For division and remainder, the treatment of negative divisors follows
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   293
mathematical practice: the sign of the remainder follows that
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   294
of the divisor:
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   295
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   296
\#0\ <\ b\ \isasymLongrightarrow \ \#0\ \isasymle \ a\ mod\ b%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   297
\rulename{pos_mod_sign}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   298
\#0\ <\ b\ \isasymLongrightarrow \ a\ mod\ b\ <\ b%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   299
\rulename{pos_mod_bound}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   300
b\ <\ \#0\ \isasymLongrightarrow \ a\ mod\ b\ \isasymle \ \#0
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   301
\rulename{neg_mod_sign}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   302
b\ <\ \#0\ \isasymLongrightarrow \ b\ <\ a\ mod\ b%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   303
\rulename{neg_mod_bound}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   304
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   305
ML treats negative divisors in the same way, but most computer hardware
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   306
treats signed operands using the same rules as for multiplication.
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   307
Many facts about quotients and remainders are provided:
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   308
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   309
(a\ +\ b)\ div\ c\ =\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   310
a\ div\ c\ +\ b\ div\ c\ +\ (a\ mod\ c\ +\ b\ mod\ c)\ div\ c%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   311
\rulename{zdiv_zadd1_eq}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   312
\par\smallskip
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   313
(a\ +\ b)\ mod\ c\ =\ (a\ mod\ c\ +\ b\ mod\ c)\ mod\ c%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   314
\rulename{zmod_zadd1_eq}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   315
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   316
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   317
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   318
(a\ *\ b)\ div\ c\ =\ a\ *\ (b\ div\ c)\ +\ a\ *\ (b\ mod\ c)\ div\ c%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   319
\rulename{zdiv_zmult1_eq}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   320
(a\ *\ b)\ mod\ c\ =\ a\ *\ (b\ mod\ c)\ mod\ c%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   321
\rulename{zmod_zmult1_eq}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   322
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   323
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   324
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   325
\#0\ <\ c\ \isasymLongrightarrow \ a\ div\ (b*c)\ =\ a\ div\ b\ div\ c%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   326
\rulename{zdiv_zmult2_eq}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   327
\#0\ <\ c\ \isasymLongrightarrow \ a\ mod\ (b*c)\ =\ b*(a\ div\ b\ mod\
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   328
c)\ +\ a\ mod\ b%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   329
\rulename{zmod_zmult2_eq}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   330
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   331
The last two differ from their natural number analogues by requiring
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   332
\isa{c} to be positive.  Since division by zero yields zero, we could allow
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   333
\isa{c} to be zero.  However, \isa{c} cannot be negative: a counterexample
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   334
is
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   335
$\isa{a} = 7$, $\isa{b} = 2$ and $\isa{c} = -3$, when the left-hand side of
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   336
\isa{zdiv_zmult2_eq} is $-2$ while the right-hand side is~$-1$.
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   337
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   338
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   339
\subsection{The type of real numbers, {\tt\slshape real}}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   340
10777
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   341
The real numbers enjoy two significant properties that the integers lack. 
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   342
They are
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   343
\textbf{dense}: between every two distinct real numbers there lies another.
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   344
This property follows from the division laws, since if $x<y$ then between
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   345
them lies $(x+y)/2$.  The second property is that they are
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   346
\textbf{complete}: every set of reals that is bounded above has a least
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   347
upper bound.  Completeness distinguishes the reals from the rationals, for
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   348
which the set $\{x\mid x^2<2\}$ has no least upper bound.  (It could only be
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   349
$\surd2$, which is irrational.)
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   350
The formalization of completeness is complicated; rather than
10777
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   351
reproducing it here, we refer you to the theory \texttt{RComplete} in
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   352
directory \texttt{Real}.
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   353
Density, however, is trivial to express:
10777
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   354
\begin{isabelle}
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   355
x\ <\ y\ \isasymLongrightarrow \ \isasymexists r.\ x\ <\ r\ \isasymand \ r\ <\ y%
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   356
\rulename{real_dense}
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   357
\end{isabelle}
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   358
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   359
Here is a selection of rules about the division operator.  The following
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   360
are installed as default simplification rules in order to express
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   361
combinations of products and quotients as rational expressions:
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   362
\begin{isabelle}
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   363
x\ *\ (y\ /\ z)\ =\ x\ *\ y\ /\ z%
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   364
\rulename{real_times_divide1_eq}\isanewline
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   365
y\ /\ z\ *\ x\ =\ y\ *\ x\ /\ z%
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   366
\rulename{real_times_divide2_eq}\isanewline
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   367
x\ /\ (y\ /\ z)\ =\ x\ *\ z\ /\ y%
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   368
\rulename{real_divide_divide1_eq}\isanewline
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   369
x\ /\ y\ /\ z\ =\ x\ /\ (y\ *\ z)
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   370
\rulename{real_divide_divide2_eq}
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   371
\end{isabelle}
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   372
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   373
Signs are extracted from quotients in the hope that complementary terms can
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   374
then be cancelled:
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   375
\begin{isabelle}
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   376
-\ x\ /\ y\ =\ -\ (x\ /\ y)
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   377
\rulename{real_minus_divide_eq}\isanewline
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   378
x\ /\ -\ y\ =\ -\ (x\ /\ y)
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   379
\rulename{real_divide_minus_eq}
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   380
\end{isabelle}
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   381
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   382
The following distributive law is available, but it is not installed as a
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   383
simplification rule.
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   384
\begin{isabelle}
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   385
(x\ +\ y)\ /\ z\ =\ x\ /\ z\ +\ y\ /\ z%
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   386
\rulename{real_add_divide_distrib}
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   387
\end{isabelle}
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   388
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   389
As with the other numeric types, the simplifier can sort the operands of
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   390
addition and multiplication.  The name \isa{real_add_ac} refers to the
10777
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   391
associativity and commutativity theorems for addition, while similarly
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   392
\isa{real_mult_ac} contains those properties for multiplication. 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   393
10777
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   394
The absolute value function \isa{abs} is
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   395
defined for the reals, along with many theorems such as this one about
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   396
exponentiation:
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   397
\begin{isabelle}
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   398
\isasymbar r\isasymbar \ \isacharcircum \ n\ =\ \isasymbar r\ \isacharcircum \ n\isasymbar 
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   399
\rulename{realpow_abs}
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   400
\end{isabelle}
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   401
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   402
\begin{warn}
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   403
Type \isa{real} is only available in the logic HOL-Real, which
10777
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   404
is  HOL extended with the rather substantial development of the real
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   405
numbers.  Base your theory upon theory \isa{Real}, not the usual \isa{Main}.
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   406
\end{warn}
10777
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   407
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   408
Also distributed with Isabelle is HOL-Hyperreal,
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   409
whose theory \isa{Hyperreal} defines the type \isa{hypreal} of non-standard
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   410
reals.  These
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   411
\textbf{hyperreals} include infinitesimals, which represent infinitely
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   412
small and infinitely large quantities; they facilitate proofs
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   413
about limits, differentiation and integration~\cite{fleuriot-jcm}.  The
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   414
development defines an infinitely large number, \isa{omega} and an
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   415
infinitely small positive number, \isa{epsilon}.  The 
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   416
relation $x\approx y$ means ``$x$ is infinitely close to~$y$''.