Add
+

Add (+
), Plus, Addition, or Sum, is a dyadic scalar function that adds numbers together. As a basic arithmetic operation, Add is subject to the language's number specification. Add shares the glyph +
with the monadic function Conjugate, and is closely related to Subtract (
).
Contents
Examples
1 2 3 + 2 3 4
3 5 7
0.1 + 3 4 5
3.1 4.1 5.1
Properties
Addition is commutative in almost all number systems. It is associative when performed with no rounding, but is unlikely to be associative when rounded to an inexact precision (see Floating point error).
The identity element for Add is 0
. The inverse of the function n∘+
or the equivalent function +∘n
is ∘n
. Using Commute (⍨
), we can write +⍣¯1
⍨
.
Since adding a number to itself is equivalent to doubling that number, we can express the double function as +⍨
.
Scalar mapping
In mathematics, addition of two identical structures almost always follows the same rules as in APL: it maps over the structures elementwise. This is a fundamental property of a (finitedimensional) vector space, in which addition of two vectors is equivalent to adding the coefficients of basis vectors one by one. This property likely inspired APL's definition of a scalar function.
Addition of complex and hypercomplex numbers can also be considered an elementwise operation, since each of these types of numbers forms a vector space over the reals. Addition of scalars is always performed within a single domain: mixedtype addition such as adding a real to a complex number treats the real number as complex with imaginary part zero.
Addition in mathematics does not exhibit scalar extension: there is usually no way to add values of different types. The Multiply function on vector spaces does extend scalars, in that a scalar element of a field can be multiplied by a vector over that field.
Floating point error
When using a limitedprecision format such as 8byte floats, the results of addition are rounded in order to fit into the result type. This rounding can cause the results of adding several numbers to be different depending on the order in which they are added, that is, addition fails to be associative:
1e20 + ¯1e20 + 1
0
1e20 + (¯1e20 + 1) ⍝ Equivalent
0
(1e20 + ¯1e20) + 1 ⍝ Not equivalent
1
Addition of floatingpoint numbers may also be subject to overflow, resulting in a DOMAIN ERROR or an infinite result.
External Links
Documentation
APL builtins [edit]  

Primitive functions  
Scalar  
Monadic  Conjugate ∙ Not ∙ Roll ∙ Type  
Dyadic  Add ∙ Subtract ∙ Equal to (Xnor) ∙ Not Equal to (Xor)  
NonScalar  
Structural  Shape ∙ Reshape ∙ Tally ∙ Depth ∙ Ravel ∙ Reverse ∙ Raze ∙ Mix ∙ Cut (K)  
Selection  Take ∙ Drop ∙ Unique ∙ Identity  
Selector  Interval Index  
Computational  Match ∙ Not Match ∙ Nub Sieve  
Primitive operators  Each  
Quad names  
Arrays  Index origin ∙ Migration level  
Functions  
Operators  
Other  Zilde ∙ High minus ∙ Function axis 