Issue:REAL-NUMBER-TYPE

Forum:CLEANUP

References:Table 4-1.

Category:ADDITION

Edit history:04-JAN-89, Version 1 by Bob Cassels, Don Sakahara, Kent Pitman,and John Aspinall

08-JAN-89, Version 2 by Bob Cassels -- incorporate

Masinter's suggestion and make

REALa CLOSclass13-JAN-89, Version 3 by Cassels and Aspinall -- incorporate Marc LeBrun's

suggestions clarifying the relationship between CL

numeric type names and mathematical names

05-APR-89, Version 4 by Pitman (changes per X3J13)

Status:Accepted v3 Mar-89 by X3J13 (on a 12-3 vote) withamendments. The proposal as amended is v4.

Problem Description:

There is no

standardtype specifier symbol for the CL type

Proposal (REAL-NUMBER-TYPE:X3J13-MAR-89):

Make

REALbe a CL data type:

p.13 "Numbers"

Add: The

NUMBERdata type encompasses all of these kinds ofnumbers. For convenience, there are names for some

subclasses of numbers. @i[Integers] and @i[ratios] are of

type

RATIONAL. @i[Rational numbers] and @[floating-pointnumbers] are of type

REAL. @i[Real numbers] and @i[complexnumbers] are of type

NUMBER.

Although the names of these types were chosen with the

terminology of mathematics in mind, the correspondences

are not always exact. Integers and ratios model the

corresponding mathematical concepts directly. Numbers

of the

FLOATtype may be used to approximate realnumbers, both rational and irrational. The

REALtypeincludes all Common Lisp numbers which represent

mathematical real numbers, though there are

mathematical real numbers (irrational numbers)

which do not have an exact Common Lisp representation.

Only

REALnumbers may be ordered using the <, >,<=,and

>=functions.

Compatibility note: The Fortran

standarddefines the term"real datum" to mean "a processor approximation to the value

of a real number." In practice the Fortran "basic real" type

is the floating-point data type Common Lisp calls

SINGLE-FLOAT. The Fortran "double precision" type isCommon Lisp's

DOUBLE-FLOAT. The Pascal "real" data type isan "implementation-defined subset of the real numbers." In

practice this is usually a floating-point type, often what

Common Lisp calls

DOUBLE-FLOAT.

A translation of an algorithm written in Fortran or Pascal

which uses "real" data usually will use some appropriate

precision of Common Lisp's

FLOATtype. Some algorithms maygain accuracy and/or flexibility by using Common Lisp's

RATIONALorREALtypes instead.

p.33 "Overlap, Inclusion, and Disjointness of Types":

Remove: The types

RATIONAL,FLOAT, andCOMPLEXare pairwisedisjoint subtypes of

NUMBER.

Rationale: It might be thought that

INTEGERandRATIO...

Rationale: It might be thought that

FIXNUMandBIGNUM...

Add: The types

RATIONALandFLOATare pairwise disjoint subtypesof

REAL.

The types

REALandCOMPLEXare pairwise disjoint subtypesof

NUMBER.

Rationale: It might be thought that

FIXNUMandBIGNUMshouldform an exhaustive partition of the type

INTEGER, thatINTEGERand

RATIOshould form an exhaustive partition ofRATIONAL,that

RATIONALandFLOATshould form an exhaustive partition of

REAL, and thatREALandCOMPLEXshould form an exhaustivepartition of

NUMBER. These are all purposely avoided in orderto permit compatible experimentation with extensions to the

Common Lisp number system, such as the idea of adding explicit

representations of infinity or of positive and negative infinity.

p.43 Table 4-1 "Standard Type Specifier Symbols"

Add:

REAL

p.49 "Type Specifiers that Abbreviate"

Add: (

REALlow high)Denotes the set of real numbers between low and high. ...

Make

REALa built-in CLOSclass.

Add a specific data type predicate

REALPwhich tests for membership inthis type. [By analogy with

NUMBERP.]

Test Case:

If a programmer wishes to test for "a number between 1 and 10", the

only current CL types would be '(or (rational 1 10) (float 1 10)) or

something like '(and

numberp(notcomplexp) (satisfies range-1-10))with (

defunrange-1-10 (real) (<=1 real 10)). Both of these arelikely less efficient, and certainly less expressive than '(real 1 10).

Rationale:

Mathematics has a name for (

ORRATIONALFLOAT) -- it is "real".This

classis important because it is all the numbers which can beordered.

Throughout the "Numbers" chapter, the phrase "non-complex number" is

used.

MAX,MIN, p. 198 "The arguments may be any non-complex numbers."

CISp. 207 "The argument ... may be any non-complex number."

Current Practice:

Probably nobody does this.

Cost to Implementors:

Some work is necessary to add this name. But since the underlying

type already exists the amount of work should be minimal.

Cost to Users:

Since this is an upward-compatible extension, it may be ignored by

users.

Cost of Non-Adoption:

Occasional inconvenience and/or inefficiency.

Benefits:

Mathematical clarity.

Ability to do CLOS

methoddispatch on the type.

Aesthetics:

As mentioned under "rationale," this would be a more concise way to

express a common programming idiom.

Discussion:

The name "non-complex number" is incorrect because future

implementations may wish to include numerical types which are neither

complex nor real. [e.g. pure imaginary numbers or quaternions]

The name "scalar" is incorrect because the mathematical concept of

scalar may indeed include complex numbers.

Fortran and Pascal use the name "real" to mean what CL calls

SINGLE-FLOAT. That should cause no significant problem, since a Lispprogram written using the type

REALwill do mathematically what theequivalent Fortran program would do. This is because Fortran's "real"

data-type is a subtype of the CL

REALtype. The only differencesmight be that the Lisp program could be less efficient and/or more

accurate.

A survey of several Fortran and Pascal books shows that the distinction

between

INTEGERandREALis thatREALnumbers may have fractionalparts, while INTEGERs do not. Later discussions explain that REALs

cover a greater range. Much later discussions cover precision

considerations, over/underflow, etc. So the average Fortran or Pascal

programmer should be completely comfortable with the proposed Lisp

concept of

REAL.