Subtract


 * This page describes the dyadic arithmetic function. For negation of a single argument, see Negate. For subtraction of sets, see Without.

, Minus, Subtraction, or Difference is a dyadic scalar function which gives the arithmetic difference of its arguments. Subtract shares the glyph  with the arithmetic function Negate, and its result is the left argument plus the negation of the right.

Examples
The second example computes a three-way comparison of each pair of arguments, with a result of  to indicate the left argument was greater,   to indicate the arguments are intolerantly equal, and   to indicate the right argument was greater.

Properties
See also Add.

Subtraction is anti-commutative: swapping the arguments negates the result, or using Commute,.

Reduction and scan
Reduction with Subtract gives an alternating sum of the argument array, that is, elements are alternately added and subtracted to the result. The first element, third element, and so on are added to the final result while the second, fourth, and so on are subtracted. In the absense of rounding error we have     for a vector.

An interesting property of the alternating difference is that it can be used as a divisibility test for division by 11, a counterpart to the better-known test for divisibility by 9. A number is divisible by 11 if and only if the sum of its digits is divisible by 11, so repeatedly taking the alternating sum of the digits determines divisibility by 11.

Scan with subtraction produces a prefix of an alternating series. This property is one of the reasons why scan was designed to reduce prefixes rather than suffixes of the argument array. As an example, we can see that an alternating series using the powers of two begins to converge to a third:

Documentation

 * Dyalog
 * APLX
 * J Dictionary, NuVoc
 * BQN