Rank (J programming language)

Last updated

Rank is a generalization of looping as used in scalar (non-array-oriented) programming languages. [1] [2] It is also a generalization of mapcar in the language Lisp [3] and map in modern functional programming languages, and a generalization of scalar extension, inner (matrix) product, and outer product in APL\360. The canonical implementation of rank may be the language J , but it is also available in Dyalog APL, the International Organization for Standardization (ISO) technical standard on Extended APL, and NARS2000.

Contents

Rank has several different meanings. In general, the concept of rank is used to treat an orthogonal array in terms of its subarrays. [4] For example, a two-dimensional array may be dealt with at rank 2 as the entire matrix, or at rank 1 to work with its implicit one-dimensional columns or rows, or at rank 0 to work at the level of its individual atoms.

Rank as a generalization of looping

Understanding rank requires knowing some very basic array-oriented programming concepts. In most array-based languages, reduction is denoted with a forward slash /. In J, the slash takes a left argument of the function and a right argument of the array to be reduced by that function.

+/1236

The result is 1 + 2 + 3, as expected.

An N-dimensional integer array can also be created with i. which takes a vector of integers as its arguments. The number of integers defines the dimension and the absolute value of each integer defines the length of the corresponding dimension.

i.3012i.23012345i.23401234567891011121314151617181920212223

Now let's reduce a two-dimensional array by addition.

+/i.23357

The result is 0 1 2 + 3 4 5, as expected. Reduction runs down each column, adding together all the numbers in that column.

This application of +/ to a two-dimensional array corresponds to the C code fragment: [5]

for(j=0;j<3;++j){sum[j]=0;}for(i=0;i<2;++i){for(j=0;j<3;++j){sum[j]+=array[i][j];}}

Suppose we wanted to add up the items of each row, as in the C code fragment:

for(i=0;i<2;++i){sum[i]=0;for(j=0;j<3;++j){sum[i]+=array[i][j];}}

To produce the result 3 12. We can do this in J without looping simply by using rank.

+/"1i.23312

To illustrate further how rank works in J, we can see the original expression is rank 2. The operator is mapped at the highest rank to the array.

+/"2i.23357

It is common to refer to the lower-dimensional arrays by these names, [6] though they are disputed sometimes. [7]

NameRank
Atom or scalar0
Vector or list1
Table or matrix2
Tensor or cube3

Noun rank

Nouns, in J, are arrays. The rank of a noun is the number of dimensions of that array. The derived verb #@$ determines the rank of a noun.

Verb rank

Verbs, in J, are functions which take noun arguments and produce noun results. The rank of a verb controls how the verb is applied to nouns with ranks greater than 0. This verb rank is expressed as three numbers:

  1. Rank for the monad case; for example, y uses as a monad
  2. Rank for the left argument for the dyad case; for example, xy uses as a dyad
  3. Rank for the right argument for the dyad case

In all cases, there is some underlying verb definition which applies to cells, which are subarrays of the indicated rank. Or, if the argument does not have that many dimensions, the entire argument.

In verbs, negative rank is interpreted as the rank of the noun supplied for that argument less the indicated value. (But never less than zero.)

For example, a verb with monadic rank of negative one when given an argument of rank 3, breaks the argument down into a list of rank 2 arrays. The verb's body is applied once to each of these two-dimensional subarrays.

In the context of a specific verb and a specific noun, the dimensions of that noun are divided into the sequence of prefix dimensions, called the frame, and the sequence of suffix dimensions, called the cells. Positive verb ranks indicate the number of cell dimensions, negative verb ranks indicate the number of frame dimensions.

In the dyadic case, there are two frames: one for the left argument, and one for the right argument. These frames must agree. If the frames are not identical, one must be a prefix of the other; e.g. (i. 2 3) *"0 1 i. 2 3 4 multiplies each scalar (zero-dimensional item) on the left by each vector (one-dimensional item) on the right. The result of evaluating this verb will have the dimensions of the longest frame as the prefix dimensions of its result. Trailing result dimensions, if any, would be the result of the verb applied to the relevant cell(s). In degenerate cases, where the arguments do not have sufficient dimensions, the rank of the verb is effectively reduced (which would influence its result).

For example,

10+456141516

Here, the verb + has a rank of 0 0 0, the left argument has a rank of 0, and the right argument has a rank of 1 (with a dimension of 3). Thus, the left argument has a rank 0 frame and the right argument has a rank 1 frame (with a dimension 3). The left argument's (empty) frame is a valid suffix for the right argument's frame, so this is a valid operation. The result has a rank of 1 and a dimension of 3.

The rank conjunction

The rank conjunction takes a verb left argument and a noun right argument to create a new verb. The noun right argument consists of up to three numbers specifying the monadic rank, the dyadic left rank, and the dyadic right rank, respectively. [8]

If the right argument is only two numbers, they are taken as the ranks for the dyadic case: the first number is the rank of the left argument and the second number is the rank of the right argument. So, if we want to add a vector to each vector in a matrix:

   1 2 3 +"1 1 i. 3 3 1 3  5 4 6  8 7 9 11 

If we want instead to add each scalar on the left to each vector on the right, we would do it this way:

   1 2 3 +"0 1 i. 3 3 1  2  3 5  6  7 9 10 11 

If the right argument is only one number, it is taken as the rank for all three cases.

If the right argument is a verb, its rank is used. For example, these all derive the same verb:

* +"0 0 0 * +"0 0 * +"0 * +"+ 

If the left argument to the rank conjunction is a noun, a constant verb is created. The body of this verb ignores the values of any arguments and always produces a result which is that noun.

Related Research Articles

APL is a programming language developed in the 1960s by Kenneth E. Iverson. Its central datatype is the multidimensional array. It uses a large range of special graphic symbols to represent most functions and operators, leading to very concise code. It has been an important influence on the development of concept modeling, spreadsheets, functional programming, and computer math packages. It has also inspired several other programming languages.

In mathematics, a (real) interval is a set of real numbers that contains all real numbers lying between any two numbers of the set. For example, the set of numbers x satisfying 0 ≤ x ≤ 1 is an interval which contains 0, 1 and all numbers in between. Other examples of intervals are the set of numbers such that 0 < x < 1, the set of all of real numbers , the set of nonnegative real numbers, the set of positive real numbers, the empty set, and any singleton.

The J programming language, developed in the early 1990s by Kenneth E. Iverson and Roger Hui, is an array programming language based primarily on APL.

In linear algebra, the outer product of two coordinate vectors is a matrix. If the two vectors have dimensions n and m, then their outer product is an n × m matrix. More generally, given two tensors, their outer product is a tensor. The outer product of tensors is also referred to as their tensor product and can be used to define the tensor algebra.

Kenneth E. Iverson Canadian computer scientist

Kenneth Eugene Iverson was a Canadian computer scientist noted for the development of the programming language APL. He was honored with the Turing Award in 1979 "for his pioneering effort in programming languages and mathematical notation resulting in what the computing field now knows as APL; for his contributions to the implementation of interactive systems, to educational uses of APL, and to programming language theory and practice".

E<sub>8</sub> (mathematics) 248-dimensional exceptional simple Lie group

In mathematics, E8 is any of several closely related exceptional simple Lie groups, linear algebraic groups or Lie algebras of dimension 248; the same notation is used for the corresponding root lattice, which has rank 8. The designation E8 comes from the Cartan–Killing classification of the complex simple Lie algebras, which fall into four infinite series labeled An, Bn, Cn, Dn, and five exceptional cases labeled E6, E7, E8, F4, and G2. The E8 algebra is the largest and most complicated of these exceptional cases.

In computer programming, array slicing is an operation that extracts a subset of elements from an array and packages them as another array, possibly in a different dimension from the original.

In computer science, array programming refers to solutions which allow the application of operations to an entire set of values at once. Such solutions are commonly used in scientific and engineering settings.

K is a proprietary array processing programming language developed by Arthur Whitney and commercialized by Kx Systems. The language serves as the foundation for kdb+, an in-memory, column-based database, and other related financial products. The language, originally developed in 1993, is a variant of APL and contains elements of Scheme. Advocates of the language emphasize its speed, facility in handling arrays, and expressive syntax.

In computer programming, a guard is a boolean expression that must evaluate to true if the program execution is to continue in the branch in question.

I. P. Sharp Associates (IPSA) was a major Canadian computer time-sharing, consulting and services firm of the 1970s and 1980s. IPSA is well known for its work on the programming language APL, an early packet switching computer network named IPSANET, and a powerful mainframe computer-based email system named 666 Box, stylized as 666 BOX. It was purchased in 1987 by Reuters Group, which used them until 2005 as a data warehousing center for business data.

The programming language APL is distinctive in being symbolic rather than lexical: its primitives are denoted by symbols, not words. These symbols were originally devised as a mathematical notation to describe algorithms. APL programmers often assign informal names when discussing functions and operators but the core functions and operators provided by the language are denoted by non-textual symbols.

Tacit programming, also called point-free style, is a programming paradigm in which function definitions do not identify the arguments on which they operate. Instead the definitions merely compose other functions, among which are combinators that manipulate the arguments. Tacit programming is of theoretical interest, because the strict use of composition results in programs that are well adapted for equational reasoning. It is also the natural style of certain programming languages, including APL and its derivatives, and concatenative languages such as Forth. The lack of argument naming gives point-free style a reputation of being unnecessarily obscure, hence the epithet "pointless style".

This is an overview of Fortran 95 language features. Included are the additional features of TR-15581:Enhanced Data Type Facilities, which have been universally implemented. Old features that have been superseded by new ones are not described – few of those historic features are used in modern programs although most have been retained in the language to maintain backward compatibility. The current standard is Fortran 2018; many of its new features are still being implemented in compilers. The additional features of Fortran 2003, Fortran 2008 and Fortran 2018 are described by Metcalf, Reid and Cohen.

Maximum subarray problem

In computer science, the maximum sum subarray problem is the task of finding a contiguous subarray with the largest sum, within a given one-dimensional array A[1...n] of numbers. Formally, the task is to find indices and with , such that the sum

Proxmap sort

ProxmapSort, or Proxmap sort, is a sorting algorithm that works by partitioning an array of data items, or keys, into a number of "subarrays". The name is short for computing a "proximity map," which indicates for each key K the beginning of a subarray where K will reside in the final sorted order. Keys are placed into each subarray using insertion sort. If keys are "well distributed" among the subarrays, sorting occurs in linear time. The computational complexity estimates involve the number of subarrays and the proximity mapping function, the "map key," used. It is a form of bucket and radix sort.

ELI is an interactive array programming language system based on the programming language APL. It has most of the functions of the International Organization for Standardization (ISO) APL standard ISO/IEC 13751:2001, and also list for non-homogeneous or non-rectangular data, complex numbers, symbols, temporal data, and control structures. A scripting file facility is available to organize programs in a fashion similar to using #include in C, which also provides convenient data input/output. ELI has dictionaries, tables, and a basic set of SQL-like statements. For performance, it has a compiler restricted to flat array programs.

Robert (Bob) Bernecky is a Canadian computer scientist notable as a designer and implementer of APL. His APL career started at I.P. Sharp Associates (IPSA) in 1971.

John M. Scholes British computer scientist

John Morley Scholes (1948–2019) was a British computer scientist. His professional career was devoted to the development of the programming language APL. He was the designer and implementer of direct functions.

A direct function is an alternative way to define a function and operator in the programming language APL. A direct operator can also be called a dop. They were invented by John Scholes in 1996. They are a unique combination of array programming, higher-order function, and functional programming, and are a major distinguishing advance of early 21st century APL over prior versions.

References

  1. Slepak, Justin; Shivers, Olin; Manolios, Panagiotis. "An array-oriented language with static rank polymorphism" (PDF).
  2. "Loopless Code I: Verbs Have Rank". Jsoftware.
  3. "The mapcar Function". Free Software Foundation.
  4. Bernecky, R. (December 1987). "An Introduction to Function Rank". APL88 Conference Proceedings, APL Quote Quad. 18.
  5. "Controlling Verb Execution By Specifying a Rank". Jsoftware.
  6. Rabanser, Stephan; Shchur, Oleksandr; Günnemann, Stephan (2017-11-29). "Introduction to Tensor Decompositions and their Applications in Machine Learning". arXiv: 1711.10781 [stat.ML].
  7. kgwgk; nabla9; azag0; tome; radarsat1 (2017-04-24). "HPTT: A High-Performance Tensor Transposition C++". Hacker News. Y Combinator. Retrieved 2019-12-10.
  8. Burke, Chris (2014-09-12). "Essays: Rank". Jsoftware.

Abrams, P.S. (February 1970). "§II.E". An APL Machine (PDF). Stanford University (PhD).

Backus, J.W., Can Programming be Liberated from the von Neumann Style? A Functional Style and Its Algebra of Programs (https://www.thocp.net/biographies/papers/backus_turingaward_lecture.pdf), Communications of the ACM, Volume 21, Number 8, 1978-08.; §11.3.3.

Bernecky, R., An Introduction to Function Rank (https://dl.acm.org/citation.cfm?id=55632), APL88 Conference Proceedings, APL Quote Quad, Volume 18, Number 2, 1987-12.

Bernecky, R.; Iverson, K.E. (6–8 October 1980). "Operators and Enclosed Arrays". Proceedings. 1980 APL Users Meeting. Jsoftware.

Bernecky, R.; Iverson, K.E.; McDonnell, E.E.; Metzger, R.C.; Schueler, J.H. (1983-05-02). "SATN 45: Language Extensions of May 1983". Jsoftware. I.P. Sharp Associates Limited.

Brown, J.A., The Principles of APL2 (http://www.softwarepreservation.org/projects/apl/Papers/PRINCIPLESOFAPL2), TR 03.247, IBM Santa Teresa Laboratory, San Jose, California, 1984-03; §20.0.

Dyalog, Dyalog APL Version 14.0 Release Notes (http://www.dyalog.com/dyalog-version-140.htm), Dyalog Limited, 2015.

Hui, R.K.W., Rank and Uniformity (http://www.jsoftware.com/papers/rank.htm), APL95 Conference Proceedings, APL Quote Quad, Volume 25, Number 4, 1995-06.

Hui, R.K.W., Remembering Ken Iverson (https://keiapl.org/rhui/remember.htm), 2004-11.

Hui, R.K.W., Inner Product—An Old/New Problem (http://www.jsoftware.com/papers/innerproduct/ip.htm), British APL Association Conference 2009, 2009-06-08.

Iverson, K.E., Operators and Functions (http://www.jsoftware.com/papers/opfns.htm), Research Report #RC7091, IBM, 1978-04-26.

Iverson, K.E., A Dictionary of APL (http://www.jsoftware.com/papers/APLDictionary.htm), APL Quote Quad, Volume 18, Number 1, 1987-09.

Iverson, K.E., A Personal View of APL (http://www.jsoftware.com/papers/APLPersonalView1.htm), IBM Systems Journal, Volume 30, Number 4, 1991-12.

Slepak,Justin; Shivers, Olin; Manolios, Panagiotis, An array-oriented language with static rank polymorphism (http://www.ccs.neu.edu/home/jrslepak/typed-j.pdf).