7.1. Expressions with More Than One Container Value

Science and math is filled with aggregated values. A vector contains several components, and a matrix is a two-dimensional object. Operations on individual values are frequently extended to operations on these aggregated values. For example, two vectors having the same length are added by adding corresponding components. The product of two matrices is defined in terms of sums and products on its components. The sine of an array is an array containing the sine of every value in it.

A data-parallel expression simultaneously refers to multiple container values. Data-parallel statements, i.e., statements using data-parallel expressions, frequently occur in scientific programs. For example, the sum of two vectors v and w is written as v+w. Algorithms frequently use data-parallel syntax. Consider, for example, computing the total energy E as the sum of kinetic energy K and potential energy U. For a simple particle subject to the earth's gravity, the kinetic energy K equals mv2/2, and the potential energy U equals mgh. These formulae apply to both an individual particle with a particular mass m and height h and to an entire field of particles with masses m and heights h. Our algorithm works with data-parallel syntax, and we would like to write the corresponding computer program using data-parallel syntax as well.