In J or APL, is a scalar an array? (Is an atom an array?)

Contents

## Affirmative

The following documents answer in the affirmative:

• Arrays of ranks 0, 1, 2 are also called atom, list, and table, or, in math, scalar, vector, and matrix.
— Hui and Iverson, J Introduction and Dictionary, 2010, Section II A. (Also in editions dating back to 1991 or earlier.)

• Arrays of ranks 0, 1, and 2 have the special names, item, list, and table, or, alternatively (in mathematics) scalar, vector, and matrix.
— K.E. Iverson, A Dictionary of APL, APL Quote Quad, Volume 18, Number 1, 1987-09.

• An array with 0 axes (rank 0) is called a scalar.
Dyalog APL Language Reference, Version 12.1, 2009.

Scalar: An array whose rank is zero.
Programming Language APL, Extended, ISO/IEC 13751:2001 (E), 2001-02-01, Section 5.3.2.

• The number of axes that an array has is called its rank. ... Figure 5 summarizes array structure by rank and gives sample arrays of various ranks. As the figure shows, arrays of rank 0, 1, and 2 have special names. [Figure 5 gives "scalar" as the name of a rank 0 array.]
APL2 Programming: Language Reference, Second Edition, SH21-1061-01, IBM Corporation, 1994-02, Chapter 2.

• All of the above examples are arrays. A single value is a scalar. A string of numbers, no matter how long, is a vector. A two-dimensional array, with numbers in rows and columns, is a matrix. Arrays with more than two dimensions are multidimensional arrays.
APL*Plus III User Manual, Manugistics Inc., 1994, page 1-3.

• The major focus of Nial is on the creation and manipulation of data objects which are organized under a structuring scheme known as nested rectangular arrays (or arrays for short). ... The data objects of Nial are nested rectangular arrays. Atomic data objects such as numbers and characters are included within this description by virtue of an atom being considered as a self-containing array object with no dimensions.
— Jenkins and Jenkins, Nested Interactive Array Language, Q'Nial Version 6.0, 1993-03-22, pages 1 and 2.

• An array that contains only one item and has no axes at all is just a particular case of "array", sometimes called a scalar.
Iverson APL Reference Manual, Iverson Software Inc., 1993-02, page 2-12.

• The single value is treated as an array of 0 dimensions ... (p. 16)

• The behaviour of dyadic-scalar-extension is relaxed to allow a multi-dimensional array containing one element to conform with a non-scalar array. (p. 51)

— Camacho, Chapman, Ziemann, and Cherlin, I-APL Instruction Manual, First North American edition for IBM PCs and compatibles, 1990.

• APL2 is best at computing on collections of data called arrays. The simplest type of array consists of a single number or a single character and is called a simple scalar.

Scalar: An array whose rank is zero.
Fifth Working Draft Standard for Programming Language APL, ISO TC97/SC5 WG 6 N38, Section 3.3.3, 1983-06-30.
(APL Quote Quad, Volume 14, Number 2, 1983-12.)

• However, to apply to a non-scalar array of arguments x ,  ...
— K.E. Iverson, Notation as a Tool of Thought, 1979-10-29, Section 2.

• Special terms are in use for arrays of certain common ranks: Rank 0 Scalar. (page 45)

• scalar: array of rank 0 (in Index)

— P.C. Berry, SHARP APL Reference Manual, 1979-03.

• The mathematical background shows itself in a variety of ways, notably: ... 3. In the use of concepts and terminology from tensor analysis, as in inner product and outer product and in the use of rank for the “dimensionality” of an array, and in the treatment of a scalar as an array of rank zero.
— Falkoff and Iverson, The Evolution of APL, ACM SIGPLAN Notices 13, 1978-08.

• Arrays range from scalars, which are dimensionless, to multi-dimensional arrays of arbitrary rank and shape. These arrays are referred to by the following terms: A scalar is an array having no dimensions. A vector is an array having one dimension. ...
— Falkoff and Iverson, APL Language, Fifth Edition, GC26-3847-4, IBM Corporation, 1978-07, p. 26.

• Array is the general term for a collection of data, and includes scalars (single data items), vectors (strings of data), matrices (tables of data), and arrays of higher dimensions (multiple tables).
-- IBM 5100 APL Reference Manual, SA21-9213-0, IBM Corporation, 1975-08, p. 32.

• [A] scalar ... is an array of rank 0.
— Falkoff and Iverson, APL\360 User's Manual, IBM T.J. Watson Research Center, 1968-08, p. 3.26.

• A vector has a “rank” of one, the term being used, as in tensor analysis, to mean the number of indices required to identify a single element in an array. Hence, a scalar has rank zero and a matrix has rank two.

• [I]n the expression a+b , for example, a and b may be any pair of matching arrays. If one argument is a scalar the other may be any array, and the operation is defined as if the scalar argument were a matching array comprised of identical elements.

— Falkoff and Iverson, The APL\360 Terminal System, Research Report RC-1922, IBM Research, 1967-10-16.

• Vectors and matrices are arrays which exhibit one level and two levels of structure, respectively. Although in certain fields, such as tensor analysis, it is convenient to define more general arrays whose rank specifies the number of levels of structure (i.e., zero for a scalar, one for a vector of scalars, two for a vector of vectors (matrix), three for a vector of matrices, etc.), ...
— K.E. Iverson, A Programming Language, Wiley, 1962-05, Section 1.20.

## Negative

I was able to find only two texts (actually just one) which answered the question in the negative.

What Is the Shape of a Single Number?

The answer to this question depends upon whether the single number is an array or not. Suppose you generate an array which has one dimension, and the length of that dimension is 1. When you ask for the length of that array, the answer will be 1:

A←1⍴5
⍴A
1

By contrast, if you simply store a single number under the name A , without involving any of the operations that generate arrays, then A is not an array. Like a point in geometry, which is presumed to have no length, breadth or height, a single number or literal character, unless produced by some array-generating operation, has no dimensions, and is called a scalar. If you ask for its length, the length is neither 1 nor 0: length just isn't an attribute of a scalar.

— Paul Berry, APL\360 Primer, IBM Corporation, 1969, p. 124.

The other text is the APL\1130 Primer by the same author, where the above quotation appears on page 116. (The APL\1130 Primer is an adaptation of the APL\360 Primer.)

• The same author answered in the affirmative about 10 years later in the SHARP APL Reference Manual (quoted above).

• The contemporaneous and closely-related documents (APL\360 User's Manual and The APL\360 Terminal System, both quoted above) contradicted the negative answer.

I therefore e-mailed Paul Berry on 2010-10-27 on the matter, with the subject line "Is a scalar an array?" In reply, Berry said that before he looked at the body of my message he saw the subject line, and his immediate answer was "a scalar is an array of rank 0; that is, it has no axes." He then read the body of my message, and professed surprise that he had once thought otherwise.

Berry went on to say that at the time he wrote the Primer he was learning APL from Adin Falkoff. It seems unlikely that Falkoff would have told Berry that a scalar was not an array. Documents from that time (quoted above) for which he was a co-author say that a scalar was an array. As well, he said in APL\360 History in 1969-07 that

In the matter of using sub-scripts and super-scripts for indexing, if you are going to do that, you are fairly well limited to two dimensions; if you want to sneak around the back side of characters you can get four dimensions, but if you want to go any higher you are more or less stuck; so, by linearizing that operation it is possible now to generalize to arbitrarily large numbers of dimensions without changing the notation.

So Falkoff was certainly thinking in terms of n-dimensional arrays at the time, and thinking in such terms it'd be jarring to exclude the case n=0.

## Discussion

In the late 1990s some non-mathematician friends asked me why 1 was not a prime. (Presumably having been taught that a prime is a positive whole number divisible only by itself and by 1.) I thought for a few seconds and answered, "Because it makes lots of statements simpler." That is, if by fiat you make 1 a prime number, you'd find yourself saying a lot, "for any prime which is not 1". (As it is, there are statements in math of the sort, "let n be an odd prime.")

Similarly, if a scalar is defined to be not an array, you'd have to say, "a monadic function take an array or scalar as argument and returns an array or scalar result", "an operator takes function or array or scalar argument(s), and derives a function", "\$\$x (⍴⍴x in APL) computes the rank of an array or scalar", etc. etc.

Perhaps some confusion arises due to the use of "scalar" in the study of vector spaces in mathematics. But here the subject is arrays, not vector spaces. In this regard, the use in J of the term atom instead of scalar is advantageous.

So now we know a scalar is an array. But what is an array? Answer.

Contributed by RogerHui.

Essays/Scalars (last edited 2011-10-21 03:08:13 by RogerHui)