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