src/Doc/Tutorial/document/numerics.tex
author haftmann
Sun, 16 Oct 2016 09:31:05 +0200
changeset 64242 93c6f0da5c70
parent 57514 bdc2c6b40bf2
child 68635 8094b853a92f
permissions -rw-r--r--
more standardized theorem names for facts involving the div and mod identity
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11389
55e2aef8909b the records section
paulson
parents: 11216
diff changeset
     1
\section{Numbers}
55e2aef8909b the records section
paulson
parents: 11216
diff changeset
     2
\label{sec:numbers}
55e2aef8909b the records section
paulson
parents: 11216
diff changeset
     3
11494
23a118849801 revisions and indexing
paulson
parents: 11480
diff changeset
     4
\index{numbers|(}%
11174
96a533d300a6 revisions in response to comments by Tobias
paulson
parents: 11161
diff changeset
     5
Until now, our numerical examples have used the type of \textbf{natural
96a533d300a6 revisions in response to comments by Tobias
paulson
parents: 11161
diff changeset
     6
numbers},
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
     7
\isa{nat}.  This is a recursive datatype generated by the constructors
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
     8
zero  and successor, so it works well with inductive proofs and primitive
11174
96a533d300a6 revisions in response to comments by Tobias
paulson
parents: 11161
diff changeset
     9
recursive function definitions.  HOL also provides the type
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    10
\isa{int} of \textbf{integers}, which lack induction but support true
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
    11
subtraction.  With subtraction, arithmetic reasoning is easier, which makes
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
    12
the integers preferable to the natural numbers for
31678
752f23a37240 reworked section on type classes
haftmann
parents: 30242
diff changeset
    13
complicated arithmetic expressions, even if they are non-negative.  There are also the types
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
    14
\isa{rat}, \isa{real} and \isa{complex}: the rational, real and complex numbers.  Isabelle has no 
13979
4c3a638828b9 HOL-Complex
paulson
parents: 13750
diff changeset
    15
subtyping,  so the numeric
4c3a638828b9 HOL-Complex
paulson
parents: 13750
diff changeset
    16
types are distinct and there are functions to convert between them.
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
    17
Most numeric operations are overloaded: the same symbol can be
11174
96a533d300a6 revisions in response to comments by Tobias
paulson
parents: 11161
diff changeset
    18
used at all numeric types. Table~\ref{tab:overloading} in the appendix
96a533d300a6 revisions in response to comments by Tobias
paulson
parents: 11161
diff changeset
    19
shows the most important operations, together with the priorities of the
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
    20
infix symbols. Algebraic properties are organized using type classes
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
    21
around algebraic concepts such as rings and fields;
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
    22
a property such as the commutativity of addition is a single theorem 
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 48985
diff changeset
    23
(\isa{add.commute}) that applies to all numeric types.
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    24
11416
91886738773a indexing
paulson
parents: 11389
diff changeset
    25
\index{linear arithmetic}%
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    26
Many theorems involving numeric types can be proved automatically by
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    27
Isabelle's arithmetic decision procedure, the method
11416
91886738773a indexing
paulson
parents: 11389
diff changeset
    28
\methdx{arith}.  Linear arithmetic comprises addition, subtraction
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    29
and multiplication by constant factors; subterms involving other operators
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    30
are regarded as variables.  The procedure can be slow, especially if the
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    31
subgoal to be proved involves subtraction over type \isa{nat}, which 
13996
a994b92ab1ea *** empty log message ***
nipkow
parents: 13983
diff changeset
    32
causes case splits.  On types \isa{nat} and \isa{int}, \methdx{arith}
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
    33
can deal with quantifiers---this is known as Presburger arithmetic---whereas on type \isa{real} it cannot.
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    34
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    35
The simplifier reduces arithmetic expressions in other
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    36
ways, such as dividing through by common factors.  For problems that lie
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    37
outside the scope of automation, HOL provides hundreds of
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    38
theorems about multiplication, division, etc., that can be brought to
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    39
bear.  You can locate them using Proof General's Find
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    40
button.  A few lemmas are given below to show what
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    41
is available.
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    42
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    43
\subsection{Numeric Literals}
10779
nipkow
parents: 10777
diff changeset
    44
\label{sec:numerals}
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    45
11416
91886738773a indexing
paulson
parents: 11389
diff changeset
    46
\index{numeric literals|(}%
12156
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
    47
The constants \cdx{0} and \cdx{1} are overloaded.  They denote zero and one,
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
    48
respectively, for all numeric types.  Other values are expressed by numeric
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
    49
literals, which consist of one or more decimal digits optionally preceeded by a minus sign (\isa{-}).  Examples are \isa{2}, \isa{-3} and
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
    50
\isa{441223334678}.  Literals are available for the types of natural
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
    51
numbers, integers, rationals, reals, etc.; they denote integer values of
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
    52
arbitrary size.
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    53
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    54
Literals look like constants, but they abbreviate 
12156
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
    55
terms representing the number in a two's complement binary notation. 
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    56
Isabelle performs arithmetic on literals by rewriting rather 
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    57
than using the hardware arithmetic. In most cases arithmetic 
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
    58
is fast enough, even for numbers in the millions. The arithmetic operations 
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    59
provided for literals include addition, subtraction, multiplication, 
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    60
integer division and remainder.  Fractions of literals (expressed using
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    61
division) are reduced to lowest terms.
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    62
11416
91886738773a indexing
paulson
parents: 11389
diff changeset
    63
\begin{warn}\index{overloading!and arithmetic}
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    64
The arithmetic operators are 
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    65
overloaded, so you must be careful to ensure that each numeric 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    66
expression refers to a specific type, if necessary by inserting 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    67
type constraints.  Here is an example of what can go wrong:
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    68
\par
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    69
\begin{isabelle}
12156
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
    70
\isacommand{lemma}\ "2\ *\ m\ =\ m\ +\ m"
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    71
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    72
%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    73
Carefully observe how Isabelle displays the subgoal:
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    74
\begin{isabelle}
12156
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
    75
\ 1.\ (2::'a)\ *\ m\ =\ m\ +\ m
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    76
\end{isabelle}
12156
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
    77
The type \isa{'a} given for the literal \isa{2} warns us that no numeric
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    78
type has been specified.  The problem is underspecified.  Given a type
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
    79
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
    80
\end{warn}
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
    81
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    82
\begin{warn}
31682
358cdcdf56d2 corrected some issues
haftmann
parents: 31678
diff changeset
    83
\index{function@\isacommand {function} (command)!and numeric literals}  
11416
91886738773a indexing
paulson
parents: 11389
diff changeset
    84
Numeric literals are not constructors and therefore
91886738773a indexing
paulson
parents: 11389
diff changeset
    85
must not be used in patterns.  For example, this declaration is
91886738773a indexing
paulson
parents: 11389
diff changeset
    86
rejected:
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    87
\begin{isabelle}
31682
358cdcdf56d2 corrected some issues
haftmann
parents: 31678
diff changeset
    88
\isacommand{function}\ h\ \isakeyword{where}\isanewline
12156
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
    89
"h\ 3\ =\ 2"\isanewline
31682
358cdcdf56d2 corrected some issues
haftmann
parents: 31678
diff changeset
    90
\isacharbar "h\ i\ \ =\ i"
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    91
\end{isabelle}
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    92
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    93
You should use a conditional expression instead:
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    94
\begin{isabelle}
12156
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
    95
"h\ i\ =\ (if\ i\ =\ 3\ then\ 2\ else\ i)"
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    96
\end{isabelle}
11416
91886738773a indexing
paulson
parents: 11389
diff changeset
    97
\index{numeric literals|)}
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    98
\end{warn}
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
    99
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   100
11216
279004936bb0 *** empty log message ***
nipkow
parents: 11174
diff changeset
   101
\subsection{The Type of Natural Numbers, {\tt\slshape nat}}
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   102
11416
91886738773a indexing
paulson
parents: 11389
diff changeset
   103
\index{natural numbers|(}\index{*nat (type)|(}%
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   104
This type requires no introduction: we have been using it from the
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   105
beginning.  Hundreds of theorems about the natural numbers are
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   106
proved in the theories \isa{Nat} and \isa{Divides}.  
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   107
Basic properties of addition and multiplication are available through the
31678
752f23a37240 reworked section on type classes
haftmann
parents: 30242
diff changeset
   108
axiomatic type class for semirings (\S\ref{sec:numeric-classes}).
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   109
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   110
\subsubsection{Literals}
11416
91886738773a indexing
paulson
parents: 11389
diff changeset
   111
\index{numeric literals!for type \protect\isa{nat}}%
12156
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   112
The notational options for the natural  numbers are confusing.  Recall that an
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   113
overloaded constant can be defined independently for each type; the definition
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   114
of \cdx{1} for type \isa{nat} is
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   115
\begin{isabelle}
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   116
1\ \isasymequiv\ Suc\ 0
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   117
\rulename{One_nat_def}
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   118
\end{isabelle}
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   119
This is installed as a simplification rule, so the simplifier will replace
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   120
every occurrence of \isa{1::nat} by \isa{Suc\ 0}.  Literals are obviously
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   121
better than nested \isa{Suc}s at expressing large values.  But many theorems,
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   122
including the rewrite rules for primitive recursive functions, can only be
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   123
applied to terms of the form \isa{Suc\ $n$}.
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   124
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   125
The following default  simplification rules replace
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   126
small literals by zero and successor: 
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   127
\begin{isabelle}
12156
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   128
2\ +\ n\ =\ Suc\ (Suc\ n)
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   129
\rulename{add_2_eq_Suc}\isanewline
12156
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   130
n\ +\ 2\ =\ Suc\ (Suc\ n)
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   131
\rulename{add_2_eq_Suc'}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   132
\end{isabelle}
12156
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   133
It is less easy to transform \isa{100} into \isa{Suc\ 99} (for example), and
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   134
the simplifier will normally reverse this transformation.  Novices should
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   135
express natural numbers using \isa{0} and \isa{Suc} only.
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   136
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   137
\subsubsection{Division}
11416
91886738773a indexing
paulson
parents: 11389
diff changeset
   138
\index{division!for type \protect\isa{nat}}%
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   139
The infix operators \isa{div} and \isa{mod} are overloaded.
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   140
Isabelle/HOL provides the basic facts about quotient and remainder
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   141
on the natural numbers:
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   142
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   143
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
   144
\rulename{mod_if}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   145
m\ div\ n\ *\ n\ +\ m\ mod\ n\ =\ m%
64242
93c6f0da5c70 more standardized theorem names for facts involving the div and mod identity
haftmann
parents: 57514
diff changeset
   146
\rulenamedx{div_mult_mod_eq}
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   147
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   148
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   149
Many less obvious facts about quotient and remainder are also provided. 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   150
Here is a selection:
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   151
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   152
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
   153
\rulename{div_mult1_eq}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   154
a\ *\ b\ mod\ c\ =\ a\ *\ (b\ mod\ c)\ mod\ c%
30224
79136ce06bdb removed and renamed redundant lemmas
nipkow
parents: 30200
diff changeset
   155
\rulename{mod_mult_right_eq}\isanewline
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   156
a\ div\ (b*c)\ =\ a\ div\ b\ div\ c%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   157
\rulename{div_mult2_eq}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   158
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
   159
\rulename{mod_mult2_eq}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   160
0\ <\ c\ \isasymLongrightarrow \ (c\ *\ a)\ div\ (c\ *\ b)\ =\ a\ div\ b%
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   161
\rulename{div_mult_mult1}\isanewline
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   162
(m\ mod\ n)\ *\ k\ =\ (m\ *\ k)\ mod\ (n\ *\ k)
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   163
\rulenamedx{mod_mult_distrib}\isanewline
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   164
m\ \isasymle \ n\ \isasymLongrightarrow \ m\ div\ k\ \isasymle \ n\ div\ k%
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   165
\rulename{div_le_mono}
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   166
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   167
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   168
Surprisingly few of these results depend upon the
11416
91886738773a indexing
paulson
parents: 11389
diff changeset
   169
divisors' being nonzero.
91886738773a indexing
paulson
parents: 11389
diff changeset
   170
\index{division!by zero}%
91886738773a indexing
paulson
parents: 11389
diff changeset
   171
That is because division by
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   172
zero yields zero:
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   173
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   174
a\ div\ 0\ =\ 0
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   175
\rulename{DIVISION_BY_ZERO_DIV}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   176
a\ mod\ 0\ =\ a%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   177
\rulename{DIVISION_BY_ZERO_MOD}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   178
\end{isabelle}
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   179
In \isa{div_mult_mult1} above, one of
11161
166f7d87b37f *** empty log message ***
nipkow
parents: 11148
diff changeset
   180
the two divisors (namely~\isa{c}) must still be nonzero.
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   181
11416
91886738773a indexing
paulson
parents: 11389
diff changeset
   182
The \textbf{divides} relation\index{divides relation}
91886738773a indexing
paulson
parents: 11389
diff changeset
   183
has the standard definition, which
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   184
is overloaded over all numeric types: 
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   185
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   186
m\ dvd\ n\ \isasymequiv\ {\isasymexists}k.\ n\ =\ m\ *\ k
11416
91886738773a indexing
paulson
parents: 11389
diff changeset
   187
\rulenamedx{dvd_def}
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   188
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   189
%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   190
Section~\ref{sec:proving-euclid} discusses proofs involving this
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   191
relation.  Here are some of the facts proved about it:
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   192
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   193
\isasymlbrakk m\ dvd\ n;\ n\ dvd\ m\isasymrbrakk \ \isasymLongrightarrow \ m\ =\ n%
33750
0a0d6d79d984 anti_sym -> antisym
nipkow
parents: 31682
diff changeset
   194
\rulenamedx{dvd_antisym}\isanewline
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   195
\isasymlbrakk k\ dvd\ m;\ k\ dvd\ n\isasymrbrakk \ \isasymLongrightarrow \ k\ dvd\ (m\ +\ n)
11416
91886738773a indexing
paulson
parents: 11389
diff changeset
   196
\rulenamedx{dvd_add}
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   197
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   198
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   199
\subsubsection{Subtraction}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   200
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   201
There are no negative natural numbers, so \isa{m\ -\ n} equals zero unless 
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   202
\isa{m} exceeds~\isa{n}. The following is one of the few facts
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   203
about \isa{m\ -\ n} that is not subject to
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   204
the condition \isa{n\ \isasymle \  m}. 
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   205
\begin{isabelle}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   206
(m\ -\ n)\ *\ k\ =\ m\ *\ k\ -\ n\ *\ k%
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   207
\rulenamedx{diff_mult_distrib}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   208
\end{isabelle}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   209
Natural number subtraction has few
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   210
nice properties; often you should remove it by simplifying with this split
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   211
rule.
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   212
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   213
P(a-b)\ =\ ((a<b\ \isasymlongrightarrow \ P\
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   214
0)\ \isasymand \ (\isasymforall d.\ a\ =\ b+d\ \isasymlongrightarrow \ P\
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   215
d))
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   216
\rulename{nat_diff_split}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   217
\end{isabelle}
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   218
For example, splitting helps to prove the following fact.
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   219
\begin{isabelle}
12156
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   220
\isacommand{lemma}\ "(n\ -\ 2)\ *\ (n\ +\ 2)\ =\ n\ *\ n\ -\ (4::nat)"\isanewline
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   221
\isacommand{apply}\ (simp\ split:\ nat_diff_split,\ clarify)\isanewline
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   222
\ 1.\ \isasymAnd d.\ \isasymlbrakk n\ <\ 2;\ n\ *\ n\ =\ 4\ +\ d\isasymrbrakk \ \isasymLongrightarrow \ d\ =\ 0
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   223
\end{isabelle}
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   224
The result lies outside the scope of linear arithmetic, but
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   225
 it is easily found
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   226
if we explicitly split \isa{n<2} as \isa{n=0} or \isa{n=1}:
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   227
\begin{isabelle}
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   228
\isacommand{apply}\ (subgoal_tac\ "n=0\ |\ n=1",\ force,\ arith)\isanewline
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   229
\isacommand{done}
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   230
\end{isabelle}%%%%%%
11416
91886738773a indexing
paulson
parents: 11389
diff changeset
   231
\index{natural numbers|)}\index{*nat (type)|)}
91886738773a indexing
paulson
parents: 11389
diff changeset
   232
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   233
11216
279004936bb0 *** empty log message ***
nipkow
parents: 11174
diff changeset
   234
\subsection{The Type of Integers, {\tt\slshape int}}
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   235
11416
91886738773a indexing
paulson
parents: 11389
diff changeset
   236
\index{integers|(}\index{*int (type)|(}%
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   237
Reasoning methods for the integers resemble those for the natural numbers, 
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   238
but induction and
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   239
the constant \isa{Suc} are not available.  HOL provides many lemmas for
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   240
proving inequalities involving integer multiplication and division, similar
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   241
to those shown above for type~\isa{nat}. The laws of addition, subtraction
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   242
and multiplication are available through the axiomatic type class for rings
31678
752f23a37240 reworked section on type classes
haftmann
parents: 30242
diff changeset
   243
(\S\ref{sec:numeric-classes}).
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   244
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   245
The \rmindex{absolute value} function \cdx{abs} is overloaded, and is 
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   246
defined for all types that involve negative numbers, including the integers.
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   247
The \isa{arith} method can prove facts about \isa{abs} automatically, 
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   248
though as it does so by case analysis, the cost can be exponential.
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   249
\begin{isabelle}
11174
96a533d300a6 revisions in response to comments by Tobias
paulson
parents: 11161
diff changeset
   250
\isacommand{lemma}\ "abs\ (x+y)\ \isasymle \ abs\ x\ +\ abs\ (y\ ::\ int)"\isanewline
10881
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   251
\isacommand{by}\ arith
03f06372230b abs and other small changes
paulson
parents: 10794
diff changeset
   252
\end{isabelle}
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   253
11416
91886738773a indexing
paulson
parents: 11389
diff changeset
   254
For division and remainder,\index{division!by negative numbers}
91886738773a indexing
paulson
parents: 11389
diff changeset
   255
the treatment of negative divisors follows
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   256
mathematical practice: the sign of the remainder follows that
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   257
of the divisor:
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   258
\begin{isabelle}
12156
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   259
0\ <\ b\ \isasymLongrightarrow \ 0\ \isasymle \ a\ mod\ b%
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   260
\rulename{pos_mod_sign}\isanewline
12156
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   261
0\ <\ b\ \isasymLongrightarrow \ a\ mod\ b\ <\ b%
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   262
\rulename{pos_mod_bound}\isanewline
12156
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   263
b\ <\ 0\ \isasymLongrightarrow \ a\ mod\ b\ \isasymle \ 0
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   264
\rulename{neg_mod_sign}\isanewline
12156
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   265
b\ <\ 0\ \isasymLongrightarrow \ b\ <\ a\ mod\ b%
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   266
\rulename{neg_mod_bound}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   267
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   268
ML treats negative divisors in the same way, but most computer hardware
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   269
treats signed operands using the same rules as for multiplication.
10794
65d18005d802 revisions especially concerning the reals
paulson
parents: 10779
diff changeset
   270
Many facts about quotients and remainders are provided:
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   271
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   272
(a\ +\ b)\ div\ c\ =\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   273
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
   274
\rulename{zdiv_zadd1_eq}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   275
\par\smallskip
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   276
(a\ +\ b)\ mod\ c\ =\ (a\ mod\ c\ +\ b\ mod\ c)\ mod\ c%
30224
79136ce06bdb removed and renamed redundant lemmas
nipkow
parents: 30200
diff changeset
   277
\rulename{mod_add_eq}
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   278
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   279
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   280
\begin{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   281
(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
   282
\rulename{zdiv_zmult1_eq}\isanewline
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   283
(a\ *\ b)\ mod\ c\ =\ a\ *\ (b\ mod\ c)\ mod\ c%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   284
\rulename{zmod_zmult1_eq}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   285
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   286
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   287
\begin{isabelle}
12156
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   288
0\ <\ c\ \isasymLongrightarrow \ a\ div\ (b*c)\ =\ a\ div\ b\ div\ c%
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   289
\rulename{zdiv_zmult2_eq}\isanewline
12156
d2758965362e new-style numerals without leading #, along with generic 0 and 1
paulson
parents: 11494
diff changeset
   290
0\ <\ c\ \isasymLongrightarrow \ a\ mod\ (b*c)\ =\ b*(a\ div\ b\ mod\
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   291
c)\ +\ a\ mod\ b%
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   292
\rulename{zmod_zmult2_eq}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   293
\end{isabelle}
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   294
The last two differ from their natural number analogues by requiring
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   295
\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
   296
\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
   297
is
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   298
$\isa{a} = 7$, $\isa{b} = 2$ and $\isa{c} = -3$, when the left-hand side of
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   299
\isa{zdiv_zmult2_eq} is $-2$ while the right-hand side is~$-1$.
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   300
The prefix~\isa{z} in many theorem names recalls the use of $\mathbb{Z}$ to
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   301
denote the set of integers.%
11416
91886738773a indexing
paulson
parents: 11389
diff changeset
   302
\index{integers|)}\index{*int (type)|)}
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   303
13979
4c3a638828b9 HOL-Complex
paulson
parents: 13750
diff changeset
   304
Induction is less important for integers than it is for the natural numbers, but it can be valuable if the range of integers has a lower or upper bound.  There are four rules for integer induction, corresponding to the possible relations of the bound ($\geq$, $>$, $\leq$ and $<$):
13750
b5cd10cb106b integer induction rules
paulson
parents: 12333
diff changeset
   305
\begin{isabelle}
b5cd10cb106b integer induction rules
paulson
parents: 12333
diff changeset
   306
\isasymlbrakk k\ \isasymle \ i;\ P\ k;\ \isasymAnd i.\ \isasymlbrakk k\ \isasymle \ i;\ P\ i\isasymrbrakk \ \isasymLongrightarrow \ P(i+1)\isasymrbrakk \ \isasymLongrightarrow \ P\ i%
b5cd10cb106b integer induction rules
paulson
parents: 12333
diff changeset
   307
\rulename{int_ge_induct}\isanewline
b5cd10cb106b integer induction rules
paulson
parents: 12333
diff changeset
   308
\isasymlbrakk k\ <\ i;\ P(k+1);\ \isasymAnd i.\ \isasymlbrakk k\ <\ i;\ P\ i\isasymrbrakk \ \isasymLongrightarrow \ P(i+1)\isasymrbrakk \ \isasymLongrightarrow \ P\ i%
b5cd10cb106b integer induction rules
paulson
parents: 12333
diff changeset
   309
\rulename{int_gr_induct}\isanewline
b5cd10cb106b integer induction rules
paulson
parents: 12333
diff changeset
   310
\isasymlbrakk i\ \isasymle \ k;\ P\ k;\ \isasymAnd i.\ \isasymlbrakk i\ \isasymle \ k;\ P\ i\isasymrbrakk \ \isasymLongrightarrow \ P(i-1)\isasymrbrakk \ \isasymLongrightarrow \ P\ i%
b5cd10cb106b integer induction rules
paulson
parents: 12333
diff changeset
   311
\rulename{int_le_induct}\isanewline
b5cd10cb106b integer induction rules
paulson
parents: 12333
diff changeset
   312
\isasymlbrakk i\ <\ k;\ P(k-1);\ \isasymAnd i.\ \isasymlbrakk i\ <\ k;\ P\ i\isasymrbrakk \ \isasymLongrightarrow \ P(i-1)\isasymrbrakk \ \isasymLongrightarrow \ P\ i%
b5cd10cb106b integer induction rules
paulson
parents: 12333
diff changeset
   313
\rulename{int_less_induct}
b5cd10cb106b integer induction rules
paulson
parents: 12333
diff changeset
   314
\end{isabelle}
b5cd10cb106b integer induction rules
paulson
parents: 12333
diff changeset
   315
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   316
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   317
\subsection{The Types of Rational, Real and Complex Numbers}
16359
nipkow
parents: 14400
diff changeset
   318
\label{sec:real}
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   319
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   320
\index{rational numbers|(}\index{*rat (type)|(}%
11416
91886738773a indexing
paulson
parents: 11389
diff changeset
   321
\index{real numbers|(}\index{*real (type)|(}%
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   322
\index{complex numbers|(}\index{*complex (type)|(}%
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   323
These types provide true division, the overloaded operator \isa{/}, 
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   324
which differs from the operator \isa{div} of the 
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   325
natural numbers and integers. The rationals and reals are 
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   326
\textbf{dense}: between every two distinct numbers lies another.
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   327
This property follows from the division laws, since if $x\not=y$ then $(x+y)/2$ lies between them:
10777
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   328
\begin{isabelle}
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   329
a\ <\ b\ \isasymLongrightarrow \ \isasymexists r.\ a\ <\ r\ \isasymand \ r\ <\ b%
14295
7f115e5c5de4 more general lemmas for Ring_and_Field
paulson
parents: 14288
diff changeset
   330
\rulename{dense}
10777
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   331
\end{isabelle}
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   332
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   333
The real numbers are, moreover, \textbf{complete}: every set of reals that
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   334
is bounded above has a least upper bound.  Completeness distinguishes the
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   335
reals from the rationals, for which the set $\{x\mid x^2<2\}$ has no least
27093
66d6da816be7 minor typos;
wenzelm
parents: 23525
diff changeset
   336
upper bound.  (It could only be $\surd2$, which is irrational.) The
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   337
formalization of completeness, which is complicated, 
31678
752f23a37240 reworked section on type classes
haftmann
parents: 30242
diff changeset
   338
can be found in theory \texttt{RComplete}.
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   339
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   340
Numeric literals\index{numeric literals!for type \protect\isa{real}}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   341
for type \isa{real} have the same syntax as those for type
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   342
\isa{int} and only express integral values.  Fractions expressed
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   343
using the division operator are automatically simplified to lowest terms:
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   344
\begin{isabelle}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   345
\ 1.\ P\ ((3\ /\ 4)\ *\ (8\ /\ 15))\isanewline
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   346
\isacommand{apply} simp\isanewline
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   347
\ 1.\ P\ (2\ /\ 5)
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   348
\end{isabelle}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   349
Exponentiation can express floating-point values such as
33761
15f9bd93a1dd Minor correction
paulson
parents: 33750
diff changeset
   350
\isa{2 * 10\isacharcircum6}, which will be simplified to integers.
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   351
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   352
\begin{warn}
31678
752f23a37240 reworked section on type classes
haftmann
parents: 30242
diff changeset
   353
Types \isa{rat}, \isa{real} and \isa{complex} are provided by theory HOL-Complex, which is
752f23a37240 reworked section on type classes
haftmann
parents: 30242
diff changeset
   354
Main extended with a definitional development of the rational, real and complex
16359
nipkow
parents: 14400
diff changeset
   355
numbers.  Base your theory upon theory \thydx{Complex_Main}, not the
31678
752f23a37240 reworked section on type classes
haftmann
parents: 30242
diff changeset
   356
usual \isa{Main}.%
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   357
\end{warn}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   358
31678
752f23a37240 reworked section on type classes
haftmann
parents: 30242
diff changeset
   359
Available in the logic HOL-NSA is the
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   360
theory \isa{Hyperreal}, which define the type \tydx{hypreal} of 
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   361
\rmindex{non-standard reals}.  These
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   362
\textbf{hyperreals} include infinitesimals, which represent infinitely
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   363
small and infinitely large quantities; they facilitate proofs
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   364
about limits, differentiation and integration~\cite{fleuriot-jcm}.  The
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   365
development defines an infinitely large number, \isa{omega} and an
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   366
infinitely small positive number, \isa{epsilon}.  The 
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   367
relation $x\approx y$ means ``$x$ is infinitely close to~$y$.''
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   368
Theory \isa{Hyperreal} also defines transcendental functions such as sine,
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   369
cosine, exponential and logarithm --- even the versions for type
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   370
\isa{real}, because they are defined using nonstandard limits.%
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   371
\index{rational numbers|)}\index{*rat (type)|)}%
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   372
\index{real numbers|)}\index{*real (type)|)}%
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   373
\index{complex numbers|)}\index{*complex (type)|)}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   374
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   375
31678
752f23a37240 reworked section on type classes
haftmann
parents: 30242
diff changeset
   376
\subsection{The Numeric Type Classes}\label{sec:numeric-classes}
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   377
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   378
Isabelle/HOL organises its numeric theories using axiomatic type classes.
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   379
Hundreds of basic properties are proved in the theory \isa{Ring_and_Field}.
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   380
These lemmas are available (as simprules if they were declared as such)
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   381
for all numeric types satisfying the necessary axioms. The theory defines
23525
c7ded89c2de0 revised the discussion of type classes
paulson
parents: 23504
diff changeset
   382
dozens of type classes, such as the following:
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   383
\begin{itemize}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   384
\item 
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   385
\tcdx{semiring} and \tcdx{ordered_semiring}: a \emph{semiring}
23525
c7ded89c2de0 revised the discussion of type classes
paulson
parents: 23504
diff changeset
   386
provides the associative operators \isa{+} and~\isa{*}, with \isa{0} and~\isa{1}
c7ded89c2de0 revised the discussion of type classes
paulson
parents: 23504
diff changeset
   387
as their respective identities. The operators enjoy the usual distributive law,
c7ded89c2de0 revised the discussion of type classes
paulson
parents: 23504
diff changeset
   388
and addition (\isa{+}) is also commutative.
c7ded89c2de0 revised the discussion of type classes
paulson
parents: 23504
diff changeset
   389
An \emph{ordered semiring} is also linearly
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   390
ordered, with addition and multiplication respecting the ordering. Type \isa{nat} is an ordered semiring.
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   391
\item 
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   392
\tcdx{ring} and \tcdx{ordered_ring}: a \emph{ring} extends a semiring
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   393
with unary minus (the additive inverse) and subtraction (both
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   394
denoted~\isa{-}). An \emph{ordered ring} includes the absolute value
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   395
function, \cdx{abs}. Type \isa{int} is an ordered ring.
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   396
\item 
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   397
\tcdx{field} and \tcdx{ordered_field}: a field extends a ring with the
27093
66d6da816be7 minor typos;
wenzelm
parents: 23525
diff changeset
   398
multiplicative inverse (called simply \cdx{inverse} and division~(\isa{/})).
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   399
An ordered field is based on an ordered ring. Type \isa{complex} is a field, while type \isa{real} is an ordered field.
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   400
\item 
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   401
\tcdx{division_by_zero} includes all types where \isa{inverse 0 = 0}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   402
and \isa{a / 0 = 0}. These include all of Isabelle's standard numeric types.
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   403
However, the basic properties of fields are derived without assuming
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   404
division by zero.
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   405
\end{itemize}
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   406
23525
c7ded89c2de0 revised the discussion of type classes
paulson
parents: 23504
diff changeset
   407
Hundreds of basic lemmas are proved, each of which
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   408
holds for all types in the corresponding type class. In most
23525
c7ded89c2de0 revised the discussion of type classes
paulson
parents: 23504
diff changeset
   409
cases, it is obvious whether a property is valid for a particular type. No
c7ded89c2de0 revised the discussion of type classes
paulson
parents: 23504
diff changeset
   410
abstract properties involving subtraction hold for type \isa{nat};
c7ded89c2de0 revised the discussion of type classes
paulson
parents: 23504
diff changeset
   411
instead, theorems such as
c7ded89c2de0 revised the discussion of type classes
paulson
parents: 23504
diff changeset
   412
\isa{diff_mult_distrib} are proved specifically about subtraction on
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   413
type~\isa{nat}. All abstract properties involving division require a field.
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   414
Obviously, all properties involving orderings required an ordered
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 16523
diff changeset
   415
structure.
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   416
23504
2b2323124e8e changes for type class ring_no_zero_divisors
paulson
parents: 21243
diff changeset
   417
The class \tcdx{ring_no_zero_divisors} of rings without zero divisors satisfies a number of natural cancellation laws, the first of which characterizes this class:
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   418
\begin{isabelle}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   419
(a\ *\ b\ =\ (0::'a))\ =\ (a\ =\ (0::'a)\ \isasymor \ b\ =\ (0::'a))
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   420
\rulename{mult_eq_0_iff}\isanewline
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   421
(a\ *\ c\ =\ b\ *\ c)\ =\ (c\ =\ (0::'a)\ \isasymor \ a\ =\ b)
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   422
\rulename{mult_cancel_right}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   423
\end{isabelle}
16412
50eab0183aea *** empty log message ***
nipkow
parents: 16359
diff changeset
   424
\begin{pgnote}
16523
f8a734dc0fbc *** empty log message ***
nipkow
parents: 16412
diff changeset
   425
Setting the flag \pgmenu{Isabelle} $>$ \pgmenu{Settings} $>$
f8a734dc0fbc *** empty log message ***
nipkow
parents: 16412
diff changeset
   426
\pgmenu{Show Sorts} will display the type classes of all type variables.
16412
50eab0183aea *** empty log message ***
nipkow
parents: 16359
diff changeset
   427
\end{pgnote}
50eab0183aea *** empty log message ***
nipkow
parents: 16359
diff changeset
   428
\noindent
23504
2b2323124e8e changes for type class ring_no_zero_divisors
paulson
parents: 21243
diff changeset
   429
Here is how the theorem \isa{mult_cancel_left} appears with the flag set.
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   430
\begin{isabelle}
23504
2b2323124e8e changes for type class ring_no_zero_divisors
paulson
parents: 21243
diff changeset
   431
((c::'a::ring_no_zero_divisors)\ *\ (a::'a::ring_no_zero_divisors) =\isanewline
2b2323124e8e changes for type class ring_no_zero_divisors
paulson
parents: 21243
diff changeset
   432
\ c\ *\ (b::'a::ring_no_zero_divisors))\ =\isanewline
2b2323124e8e changes for type class ring_no_zero_divisors
paulson
parents: 21243
diff changeset
   433
(c\ =\ (0::'a::ring_no_zero_divisors)\ \isasymor\ a\ =\ b)
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   434
\end{isabelle}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   435
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   436
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   437
\subsubsection{Simplifying with the AC-Laws}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   438
Suppose that two expressions are equal, differing only in 
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   439
associativity and commutativity of addition.  Simplifying with the
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   440
following equations sorts the terms and groups them to the right, making
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   441
the two expressions identical.
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   442
\begin{isabelle}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   443
a\ +\ b\ +\ c\ =\ a\ +\ (b\ +\ c)
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 48985
diff changeset
   444
\rulenamedx{add.assoc}\isanewline
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   445
a\ +\ b\ =\ b\ +\ a%
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 48985
diff changeset
   446
\rulenamedx{add.commute}\isanewline
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   447
a\ +\ (b\ +\ c)\ =\ b\ +\ (a\ +\ c)
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 48985
diff changeset
   448
\rulename{add.left_commute}
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   449
\end{isabelle}
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   450
The name \isa{ac_simps}\index{*ac_simps (theorems)} 
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   451
refers to the list of all three theorems; similarly
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   452
there is \isa{ac_simps}.\index{*ac_simps (theorems)} 
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   453
They are all proved for semirings and therefore hold for all numeric types.
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   454
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   455
Here is an example of the sorting effect.  Start
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   456
with this goal, which involves type \isa{nat}.
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   457
\begin{isabelle}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   458
\ 1.\ Suc\ (i\ +\ j\ *\ l\ *\ k\ +\ m\ *\ n)\ =\
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   459
f\ (n\ *\ m\ +\ i\ +\ k\ *\ j\ *\ l)
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   460
\end{isabelle}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   461
%
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   462
Simplify using  \isa{ac_simps} and \isa{ac_simps}.
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   463
\begin{isabelle}
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   464
\isacommand{apply}\ (simp\ add:\ ac_simps\ ac_simps)
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   465
\end{isabelle}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   466
%
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   467
Here is the resulting subgoal.
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   468
\begin{isabelle}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   469
\ 1.\ Suc\ (i\ +\ (m\ *\ n\ +\ j\ *\ (k\ *\ l)))\
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   470
=\ f\ (i\ +\ (m\ *\ n\ +\ j\ *\ (k\ *\ l)))%
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   471
\end{isabelle}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   472
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   473
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   474
\subsubsection{Division Laws for Fields}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   475
10777
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   476
Here is a selection of rules about the division operator.  The following
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   477
are installed as default simplification rules in order to express
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   478
combinations of products and quotients as rational expressions:
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   479
\begin{isabelle}
14288
d149e3cbdb39 Moving some theorems from Real/RealArith0.ML
paulson
parents: 13996
diff changeset
   480
a\ *\ (b\ /\ c)\ =\ a\ *\ b\ /\ c
d149e3cbdb39 Moving some theorems from Real/RealArith0.ML
paulson
parents: 13996
diff changeset
   481
\rulename{times_divide_eq_right}\isanewline
d149e3cbdb39 Moving some theorems from Real/RealArith0.ML
paulson
parents: 13996
diff changeset
   482
b\ /\ c\ *\ a\ =\ b\ *\ a\ /\ c
d149e3cbdb39 Moving some theorems from Real/RealArith0.ML
paulson
parents: 13996
diff changeset
   483
\rulename{times_divide_eq_left}\isanewline
d149e3cbdb39 Moving some theorems from Real/RealArith0.ML
paulson
parents: 13996
diff changeset
   484
a\ /\ (b\ /\ c)\ =\ a\ *\ c\ /\ b
d149e3cbdb39 Moving some theorems from Real/RealArith0.ML
paulson
parents: 13996
diff changeset
   485
\rulename{divide_divide_eq_right}\isanewline
d149e3cbdb39 Moving some theorems from Real/RealArith0.ML
paulson
parents: 13996
diff changeset
   486
a\ /\ b\ /\ c\ =\ a\ /\ (b\ *\ c)
d149e3cbdb39 Moving some theorems from Real/RealArith0.ML
paulson
parents: 13996
diff changeset
   487
\rulename{divide_divide_eq_left}
10777
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   488
\end{isabelle}
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   489
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   490
Signs are extracted from quotients in the hope that complementary terms can
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   491
then be cancelled:
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   492
\begin{isabelle}
14295
7f115e5c5de4 more general lemmas for Ring_and_Field
paulson
parents: 14288
diff changeset
   493
-\ (a\ /\ b)\ =\ -\ a\ /\ b
7f115e5c5de4 more general lemmas for Ring_and_Field
paulson
parents: 14288
diff changeset
   494
\rulename{minus_divide_left}\isanewline
7f115e5c5de4 more general lemmas for Ring_and_Field
paulson
parents: 14288
diff changeset
   495
-\ (a\ /\ b)\ =\ a\ /\ -\ b
7f115e5c5de4 more general lemmas for Ring_and_Field
paulson
parents: 14288
diff changeset
   496
\rulename{minus_divide_right}
10777
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   497
\end{isabelle}
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   498
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   499
The following distributive law is available, but it is not installed as a
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   500
simplification rule.
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   501
\begin{isabelle}
14295
7f115e5c5de4 more general lemmas for Ring_and_Field
paulson
parents: 14288
diff changeset
   502
(a\ +\ b)\ /\ c\ =\ a\ /\ c\ +\ b\ /\ c%
7f115e5c5de4 more general lemmas for Ring_and_Field
paulson
parents: 14288
diff changeset
   503
\rulename{add_divide_distrib}
10777
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   504
\end{isabelle}
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   505
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   506
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   507
\subsubsection{Absolute Value}
10594
6330bc4b6fe4 nat and int sections but no real
paulson
parents:
diff changeset
   508
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   509
The \rmindex{absolute value} function \cdx{abs} is available for all 
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   510
ordered rings, including types \isa{int}, \isa{rat} and \isa{real}.
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   511
It satisfies many properties,
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   512
such as the following:
10777
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   513
\begin{isabelle}
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   514
\isasymbar x\ *\ y\isasymbar \ =\ \isasymbar x\isasymbar \ *\ \isasymbar y\isasymbar 
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   515
\rulename{abs_mult}\isanewline
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   516
(\isasymbar a\isasymbar \ \isasymle \ b)\ =\ (a\ \isasymle \ b\ \isasymand \ -\ a\ \isasymle \ b)
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   517
\rulename{abs_le_iff}\isanewline
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   518
\isasymbar a\ +\ b\isasymbar \ \isasymle \ \isasymbar a\isasymbar \ +\ \isasymbar b\isasymbar 
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   519
\rulename{abs_triangle_ineq}
10777
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   520
\end{isabelle}
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   521
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   522
\begin{warn}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   523
The absolute value bars shown above cannot be typed on a keyboard.  They
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   524
can be entered using the X-symbol package.  In \textsc{ascii}, type \isa{abs x} to
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   525
get \isa{\isasymbar x\isasymbar}.
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   526
\end{warn}
11174
96a533d300a6 revisions in response to comments by Tobias
paulson
parents: 11161
diff changeset
   527
96a533d300a6 revisions in response to comments by Tobias
paulson
parents: 11161
diff changeset
   528
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   529
\subsubsection{Raising to a Power}
10777
a5a6255748c3 initial material on the Reals
paulson
parents: 10654
diff changeset
   530
31682
358cdcdf56d2 corrected some issues
haftmann
parents: 31678
diff changeset
   531
Another type class, \tcdx{ordered\_idom}, specifies rings that also have 
14400
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   532
exponentation to a natural number power, defined using the obvious primitive
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   533
recursion. Theory \thydx{Power} proves various theorems, such as the 
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   534
following.
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   535
\begin{isabelle}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   536
a\ \isacharcircum \ (m\ +\ n)\ =\ a\ \isacharcircum \ m\ *\ a\ \isacharcircum \ n%
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   537
\rulename{power_add}\isanewline
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   538
a\ \isacharcircum \ (m\ *\ n)\ =\ (a\ \isacharcircum \ m)\ \isacharcircum \ n%
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   539
\rulename{power_mult}\isanewline
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   540
\isasymbar a\ \isacharcircum \ n\isasymbar \ =\ \isasymbar a\isasymbar \ \isacharcircum \ n%
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   541
\rulename{power_abs}
6069098854b9 new numerics section using type classes
paulson
parents: 14353
diff changeset
   542
\end{isabelle}%%%%%%%%%%%%%%%%%%%%%%%%%
13996
a994b92ab1ea *** empty log message ***
nipkow
parents: 13983
diff changeset
   543
\index{numbers|)}