# Array programming

﻿
Array programming

In computer science, array programming languages (also known as vector or multidimensional languages) generalize operations on scalars to apply transparently to vectors, matrices, and higher dimensional arrays.

Array programming primitives concisely express broad ideas about data manipulation. The level of conciseness can be dramatic in certain cases: it is not uncommon to find array programming language one-liners that require more than a couple of pages of Java code. [cite web |url=http://www.cs.nyu.edu/~michaels/screencasts/Java_vs_K/Java_vs_K.html |title=Java and K |accessdate=2008-01-23 |author=Michael Schidlowsky]

APL, designed by Ken Iverson, was the first programming language to provide array programming capabilities.

Concepts

The fundamental idea behind array programming is that operations apply at once to an entire set of values. This makes it a high-level programming model as it allows the programmer to think and operate on whole aggregates of data, without having to resort to explicit loops of individual scalar operations.

The basis behind array programming and thinking is to find and exploit the properties of data where individual elements are similar and/or adjacent. Unlike object orientation which implicitly breaks down data to its constituent parts (or scalar quantities), array orientation looks to group data and apply a uniform handling.

Function rank is an important concept to array programming languages in general, by analogy to tensor rank in mathematics: functions that operate on data may be classified by the number of dimensions they act on. Ordinary multiplication, for example, is a scalar ranked function because it operates on zero-dimensional data (individual numbers). The cross product operation is an example of a vector rank function because it operates on vectors, not scalars. Matrix multiplication is an example of a 2-rank function, because it operates on 2-dimensional objects (matrices). Collapse operators reduce the dimensionality of an input data array by one or more dimensions. For example, summing over elements collapses the input array by 1 dimension.

Uses

Array programming is very well suited to implicit parallelization; a topic of much research nowadays. Further, Intel and compatible CPUs developed and produced after 1997 contained various instruction set extensions, starting from MMX and continuing through SSSE3 and 3DNow!, which include rudimentary SIMD array capablilties. Array processing is distinct from parallel processing in that one physical processor performs operations on a group of items simulataneously while parallel processing aims to split a larger problem into smaller ones (MIMD) to be solved piecemeal by numerous processors. Processors with two or more cores are increasingly common today.

Languages

The canonical examples of array programming languages are APL, its successor J, and Fortran 90. Others include: A+, Analytica, IDL, K, Mathematica, MATLAB, NumPy, GNU Octave, PDL, R, S-Lang, SAC, Nial and ZPL.

provides an exhaustive list.

Examples

In scalar languages like FORTRAN 77, C, Pascal, Ada, etc. operations apply only to single values, so "a"+"b" expresses the addition of two numbers. In such languages adding two arrays requires indexing and looping:

FORTRAN 77

00 DO 10 I = 1, N DO 10 J = 1, N10 A(J,I) = A(J,I) + B(J,I)Cfor (i = 0; i < n; i++) for (j = 0; j < n; j++) a [i] [j] += b [i] [j] ;PASCALfor i:=1 to n do for j:=1 to n do a [i,j] := a [i,j] + b [i,j] ;This need to loop and index to perform operations on arrays is both tedious and error prone.

In array languages, operations are generalized to apply to both scalars and arrays. Thus, "a"+"b" expresses the sum of two scalars if "a" and "b" are scalars, or the sum of two arrays if they are arrays. When applied to arrays, the operations act on corresponding elements as illustrated in the loops above. Indeed, when the array language compiler/interpreter encounters a statement like:

A := A + B

where "A" and "B" are two-dimensional arrays, it generates code that is effectively the same as the C loops shown above. An array language, therefore, simplifies programming.

As another example, the following generates the inner product of two arrays (matrix multiplication) in the array language Nial:

a inner [+,*] b

Notice how the operations are sequenced on the arrays.

ee also

* Array slicing

References

* [http://www.nsl.com/ "No stinking loops" programming]
* [http://www.vector.org.uk/archive/v223/smill222.htm Discovering Array Languages]

Wikimedia Foundation. 2010.

### Look at other dictionaries:

• Array Programming Language — …   Википедия

• Programming language — lists Alphabetical Categorical Chronological Generational A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that… …   Wikipedia

• Array data type — Not to be confused with Array data structure. In computer science, an array type is a data type that is meant to describe a collection of elements (values or variables), each selected by one or more indices that can be computed at run time by the …   Wikipedia

• Array — In computer science an array [Paul E. Black, array , in Dictionary of Algorithms and Data Structures , Paul E. Black, ed., U.S. National Institute of Standards and Technology. 26 August 2008 (accessed 10 September 2008).… …   Wikipedia

• Array Theory — From [ftp://ftp.nial.com/nial.com/Papers/Papers.zip Nial Papers] : Array Theory is primarily a theory about the definition and manipulation of array data objects. Every data object in the theory is an array, even numbers and characters, which are …   Wikipedia

• Programming style — is a set of rules or guidelines used when writing the source code for a computer program. It is often claimed that following a particular programming style will help programmers to read and understand source code conforming to the style, and help …   Wikipedia

• Programming paradigm — Programming paradigms Agent oriented Automata based Component based Flow based Pipelined Concatenative Concu …   Wikipedia

• Programming in the large and programming in the small — Programming paradigms Agent oriented Automata based Component based Flow based Pipelined Concatenative Concurrent computin …   Wikipedia

• Array slicing — In computer programming, array slicing is an operation that extracts certain elements from an array and packages them as another array, possibly with different number of indices (or dimensions) and different index ranges. Two common examples are… …   Wikipedia

• Programming idiom — A programming idiom is a means of expressing a recurring construct in one or more programming languages. Generally speaking, a programming idiom is an expression of a simple task or algorithm that is not a built in feature in the programming… …   Wikipedia