[comp.lang.prolog] integers and reals

abc@cs.nott.ac.uk (Andy Cheese) (04/18/88)

My own intuition, having a maths degree, is that integers are real numbers,
it's just that you can represent integers in a machine in general. But on
the otherhand i would like to see built-in predicates keep their "usual"
(QP, SICStus, etc) meanings.
---------------------------------------------------------------------

JANET : abc@uk.ac.nott.cs              Andy Cheese
ARPA  : abc%nott.cs@ucl-cs.arpa        Department of Computer Science,
                                       University of Nottingham,
Functional vs. Logic Programming       University Park,
If You Can't Decide Between Em,        Nottingham.
-- Join Em                             NG7 2RD.
                                       England.
 
                                       Tel. No. : (0602) 484848 ext. 2765
-- 
Andy Cheese

ok@quintus.UUCP (Richard A. O'Keefe) (04/20/88)

In article <1152@robin.cs.nott.ac.uk>, abc@cs.nott.ac.uk (Andy Cheese) writes:
> My own intuition, having a maths degree, is that integers are real numbers,
> it's just that you can represent integers in a machine in general. But on
> the otherhand i would like to see built-in predicates keep their "usual"
> (QP, SICStus, etc) meanings.

Reminds me of "Dr Science", a radio character who announces
	"I have a PhD in .......... SCIENCE!"

Yes, integers are (isomorphic to a subring of the field of) real numbers.
The trouble is that FLOATING-POINT numbers AREN'T.  If floating-point
numbers behaved like a subfield (or even a subring) of the reals, there
would be no objection to identifying integers and floats.  But when
something as basic as trichotomy fails (that is, there are IEEE values
X, Y such that none of X < Y, X = Y, X > Y is true), the mathmetical
intuition which tells us that integers are like reals tells us that
integers cannot therefore be like things which are NOT like reals!

Issue No 8 of the Logic Programming Newsletter is out, and it contains a
copy of the Formal specification of Prolog, by P. Deransart, and G. Richard,
of INRIA.  This is the BSI/ISO thingy.  Interestingly enough, they rule that

	1.14) is-a-L-constant ( X ) <= L-atom ( X )
	      is-a-L-constant ( X ) <= |N-integer ( X )
	      is-a-L-constant ( X ) <= |R-real ( X )

That is, _every_ integer is to be a valid Prolog constant,
     and _every_ real is to be a valid Prolog constant.

However, section 7 (type testing) says that "there is a _denumerable_
infinity of clauses
	|N-integer ( X )		for all integers X
	|R-real ( X )			for all reals X
" and section 9 (arithmetic operations) rules in 9.1 that the ONLY valid
expressions are ones built out of constants, _+_, _-_, _*_, _/_,
_ mod _, and length(AList).  That's right: there is no unary minus, and
there is no integer division operator, and 'length' can appear in
arithmetic expressions.  Any rate, with this repertoire of arithmetic
operations, there is no way of constructing an irrational number, so
|R-real(X) presumably is intended to read "X is a RATIONAL number"
(which would make sense of the claim that there are denumerably many of
them).  The specification uses an integer->real conversion, but to get
it yourself you have to write e.g. X*1.0, and there is no real->integer
conversion at all.

Myself, I don't see that allowing you to write
	X is length(L)
instead of the shorter version
	length(L, X)
and requiring you to write
	Q is X - (X mod Y)*Y
instead of the shorter version
	Q is X // Y
is any real improvement, but that's a standard for you.  (To be honest,
I have always detested the spelling '//' and would prefer the older
DEC-10 library spelling 'div', but current practice is current practice.)