section numdefs |
This contains the CADi version of the definitions of
numbers in the mathematical toolkit of Z.
Written by Sam Valentine
Last updated September 1999
The Z community includes a wide spectrum of attitudes to numbers. At one extreme are those who require nothing more abstruse than the natural numbers, and who do not wish to be reminded that anything more complicated exists. At the other extreme are people who are concerned with real and complex floating-point numbers as implemented by particular hardware and software.
The reconciliation of these needs is constrained by the fact that Z does not allow overloading of its operators, so there can be only one addition function, and so on. Furthermore, all users who want to use addition want to use the same familiar operator, _ + _, to do so.
This has led to the decision to adopt a single numeric type,
whose whole extent is deliberately left unspecified, but
of which all practical versions of numbers are considered to be subsets.
This is to be denoted by , which can be pronounced ``arithmos''.
The description, and usually the implementation of Z are layered into a core language and a mathematical toolkit. Spivey's Reference Manual suggested that everything about numbers could go into the toolkit, but did not spell out the detail.
The trouble with putting numbers wholly into the toolkit is that numbers can appear in the concrete syntax as literals, and also positive integers are generated to form the domain elements of sequence displays, and the ranges of bags. The difficulty of finding a solution to these problems has led to a compromise proposal, whereby natural numbers are given just enough description in the core language to support the definition of natural number literals. Definition of wider sets of numbers is then left to the toolkit.
Rather than specify the required properties of natural numbers incomprehensibly in the core metalanguage, we propose that there should be a ``prelude'', which resembles the core language in being fixed, but is specified in Z like the toolkit.
We here confine our attention to the real numbers, ignoring things like complex numbers, quaternions, and so on. These wider sorts of number could be defined within the framework we are developing here, but we ignore them for now, because there is no pressing need, and the way we develop the theory of the reals should make it clear enough how to go further.
From the natural number base we have described, we develop the theory in the well-known ways:
us subtraction and real division. Thus we have all the rational numbers.
series, and thus specify all the computable numbers.
The things we want to do with our real numbers include the following:
to simplest terms, including where possible the total reduction to a canonical form, which we can refer to as ``evaluation'';
as a result of any manipulations we do.
function 40 leftassoc (_ * _) |
function 40 leftassoc (_ ![]() |
function 30 leftassoc (_ - _) |
The mark-up directives (not typeset) and operator templates above
are to assist in allowing us to use, from here on,
a multiplication infix function called _ * _,
a subtraction infix function called _ - _,
a unary negation function called -,
and a real division infix function called _ _.
Our presentations of numbers are then as follows:
as described above. This is unique apart from the optional
presence of leading zeroes.
We can therefore take as the canonical form of a positive integer
its representation as a string of digits where the first digit
is not 0.
Nevertheless, all equivalent representations are equally valid.
Thus 7, 007, 49 - 42, 42 6,
x:
| x * x = 49
are all equally valid ways of representing the same integer value,
although a tool should take the first of them
as the preferred one to create, if it has enough information
to be able to make the choice.
Their canonical form is defined as follows:
of -, then give the representation of the absolute value as follows.
give its digit string as described above.
numerator denominator, where each of those is described in
the canonical form of a natural number, and they have no common factor.
Again, all representations are equally valid.
Thus - 1 3,
- (- 2
- 6),
2 * - 7
42
are all equally valid ways of representing the same rational value,
although a tool should preferably use the first of them.
We represent them as best we can, and a tool may simplify up to a point. All representations are equally valid.
Note that it is not necessary to provide for the representation
of numbers using decimal points and explicit decimal exponents
as is usual in programming languages.
It is enough to write 1.23 as 123 100, and so on.
Note also that the arithmetic we define will be exact.
If we want to model the operation of some computer floating-point
arithmetic, for example, we can define that separately
in terms of the exact arithmetic basis.
To summarise this section:
which describes its value.
In CADi there are currently two built-in rules of inference
with specific recognition of numbers, namely
Both of these are subject to change, but they are nevertheless well representative of the sort of support which one wishes a practical tool to give to numeric work in Z. Both now apply to rationals,
Presburger is a decision procedure. Its result take the form of true or false. The choice of output format is therefore irrelevant in this case.
The evaluation procedure produces output, and so in that case we need to decide the output format. For natural number results, we can assume that the procedure can generate the appropriate digit string. It is probably safe to assume that the evaluation procedure cannot generate fractional results except where there was a division in the input, and similarly cannot generate negative results except where there was a subtraction or a negation in the input. These divisions and subtractions must be described using operators defined in the toolkit. If we know enough about them to make correct sense of the input, we have enough to generate the correct output. The question of output format thus reduces to the question of soundness.
A built-in procedure which makes reference to functions and relations defined in the toolkit can be proved sound in two ways. One way would be that all its actions were parametrised to make use of the toolkit definitions for the time being in force. This would be ideal theoretically, but hardly practicable. The other approach is to prove the actions sound with respect to a particular toolkit, and only allow those actions in the presence of that toolkit. This seems to be the only viable solution.
Thus the urgent need is to define the basic rational arithmetic operations formally, and to show, at least semi-formally, the soundness of the built-in procedures with respect to these definitions.
As we have just said, one of the purposes of the definitions of the arithmetic functions and relations is to provide a base for verification of the built-in procedures.
The other issues which arise here are:
or is it better that they should stand alone? The answer must be that it is preferable that they stand alone, so that the built-in functions depend as little as possible on other definitions, and are as widely as possible usable.
their model conjecture is implicit in the form of the definition, or is it enough to describe them and to prove the consistency of the model separately? My answer is that since the properties which we want numbers to have are very familiar, and since it is still not completely clear precisely what form the logical foundations of Z take, it is more sensible to create a structure which one is sure is right, but expressed in a way most convenient for its other purposes, and rely on the fact that a proof of its consistency must be possible somehow.
the checking of the built-in procedures which they are to verify? The answer is that this is not strictly required, but would be helpful, and that doing it with this in view may well help to create a form of definition which is generally useful anyway.
The total amount of defining text is fairly large, but we stratify it into what are, it is hoped, manageable chunks as follows.
The development introduces positive rationals before it introduces subtraction. This ordering is chosen because:
implementation of rational arithmetic.
It is also, interestingly, the order in which these concepts were developed historically.
The "prelude" contains the definition of arithmos, the natural numbers, and the addition function on the natural numbers
succ == ![]() ![]() ![]() |
![]() ![]() ![]() |
_ * _ : ![]() ![]() ![]() ![]() ![]() ![]() | ||
![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() | ||
![]() ![]() ![]() |
We introduce the set of positive rational numbers, +, which we
can pronounce as the ``fractions''. The arithmetic of
1 is
embedded in that of
+, and the latter is also extended
to make it an Abelian group under _ * _.
![]() ![]() ![]() | ||
_ ![]() ![]() ![]() ![]() ![]() ![]() ![]() | ||
![]() |
![]() |
![]() |
"the functions are total and closed" | ||
![]() ![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() | ||
"define the embedding and the extension" | ||
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() | ||
"make it an Abelian group under multiplication" | ||
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() | ||
![]() ![]() ![]() | ||
![]() ![]() ![]() |
Embed + in the rationals,
, and extend to make
into a field.
![]() ![]() ![]() | ||
- : ![]() ![]() ![]() ![]() | ||
_ - _ : ![]() ![]() ![]() ![]() ![]() ![]() | ||
![]() |
![]() |
![]() |
"the functions are total and closed" | ||
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() | ||
"define the embedding and the extension" | ||
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() ![]() | ||
"define enough properties to guarantee a field" | ||
![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() | ||
z = x ![]() ![]() | ||
![]() ![]() ![]() | ||
![]() ![]() ![]() | ||
![]() ![]() ![]() | ||
![]() ![]() ![]() |
relation (_ < _) |
_ < _ : ![]() ![]() ![]() ![]() | ||
![]() |
![]() |
![]() |
"< is an irreflexive total order" | ||
![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() | ||
"define how it is mapped onto the numbers" | ||
![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Embed the ordered field of rationals into the reals, which have the property of completeness, where least upper bounds always exist.
![]() ![]() ![]() | ||
![]() |
![]() |
![]() |
"the functions are total and closed" | ||
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() | ||
"< is an irreflexive total order" | ||
![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() | ||
"define the embedding" | ||
![]() ![]() ![]() ![]() ![]() | ||
"define completeness" | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() ![]() | ||
"confirm field properties on the wider set" | ||
![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() | ||
z = x ![]() ![]() | ||
![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() | ||
![]() ![]() ![]() |
relation (_ ![]() |
relation (_ ![]() |
relation (_ > _) |
_ ![]() ![]() ![]() ![]() ![]() | ||
_ ![]() ![]() ![]() ![]() ![]() | ||
_ > _ : ![]() ![]() ![]() ![]() | ||
![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() ![]() |
![]() ![]() ![]() ![]() |
![]() ![]() ![]() |
function 40 leftassoc (_ div _) |
function 40 leftassoc (_ mod _) |
_ div _ : ![]() ![]() ![]() ![]() ![]() ![]() | ||
_ mod _ : ![]() ![]() ![]() ![]() ![]() ![]() | ||
![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() | ||
![]() ![]() | ||
![]() ![]() ![]() ![]() | ||
![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() | ||
![]() ![]() ![]() ![]() | ||
![]() ![]() ![]() |
The structure of definitions given above is readily adaptable for different needs:
rational, the rest of the reals can be ignored.
To do this, replace the section ``Define the Real Numbers''
with the definition ==
, and leave everything else the same.
``Define the Fractions'' with the definition + ==
1,
delete all predicates containing _
_ from
``Define the Rationals'' and replace the section ``Define the Real Numbers''
with the definition
==
.
replace the section
``Define the Fractions'' with the definition + ==
1,
replace the section ``Define the Rationals'' with
==
,
and replace the section ``Define the Real Numbers''
with the definition
==
.
This material has been worked over several times in the recent past. A constructive definition of numbers, building the whole theory up from free type definitions, is given in ``Putting Numbers into the Mathematical Toolkit'', by S. H. Valentine, in Proceedings of the Seventh Z User Meeting December 1992, edited Bowen and Nicholls, published Springer 1993.
The same material also appears in ``Enhancing the Z Mathematical Toolkit'', by Sam Valentine, University of Brighton Department of Computing Technical Report UBC 93/3, February 1993.
The algebraic approach, where we describe only the properties we require, was issued as document 172 of the Z Standards Panel, entitled Mathematical Tool-kit Draft 3, March 1995.
The same material also appeared as ``An Algebraic Introduction of Real Numbers into Z'', by S. H. Valentine, published in Proceedings of Conference ``Z Twenty Years On'' in Nantes, October 1995, proceedings edited by H Habrias.
The document ``Arithmetic for Z'', by Rob Arthan, Z Standards Panel document D-188, is another treatment of the algebraic approach, differing in style of presentation from the other documents, but not in substantive content.
The presentation here is algebraic. It differs from the previous versions in the following respects
approach.
as guided by experience with proof attempts in CADi.
This material is primarily a draft specification of the numeric
toolkit which is to be included in CADi.
All the definitions given here should be included.
The definitions of the rationals will be used to verify
the built-in numeric inference rules of CADi
.
A description of computer arithmetic on the lines of that given by Geoff Barrett in his monograph ``Formal Methods Applied to a Floating-point Number System'' (Oxford 1987) can now be undertaken. Barrett's work was as right as could reasonably be attempted at the time, but simply assumed the existence and properties of real numbers without definition. No Z proof tool was available to him, and his proof style now seems very informal, as indeed does some of his specification.