Dyadic Scalar Functions


As stated in the introduction, the term integer is used in this manual to indicate not only a domain of values but also a particular internal representation. To refer to the same domain of values when both integer and floating-point representations are allowed, the term restricted whole number is used. These floating-point representations need only be tolerably equal to the integers.

Classification of Dyadic Scalar Functions

Although they are listed alphabetically in this chapter, for convenient reference, the A+ dyadic scalar primitive functions can be grouped in five categories:

Application, Conformability, and Result Shape

All dyadic scalar functions produce scalars from scalars, and apply element by element to their arguments: they are applied to each pair of elements - one from each argument - independently of the others. There are three conformable cases for dyadic scalar functions:

  1. The arguments have identical shapes. In this case, corresponding elements from the two arguments are paired. The shape of the result equals the common shape of the arguments.

  2. One argument has exactly one element and the other does not. Then the single element (a "singleton") from the one argument is paired independently with each element of the other. The shape of the result equals the shape of the one with either more or fewer than one element. This case is called scalar extension.

    then:

  3. Each argument has one element. Then the result has a single element also. The rank of the result equals the larger of the two argument ranks.

    
         2+,2       Shapes are conformable
    4
    
         2+2       Scalar plus scalar
    (empty)
    
         2+,2      Scalar plus one-element vector
    1
    
    
The element-by-element application of the functions and the above conformability rules for their arguments are assumed in the following descriptions.

Common Error Reports

Multiple errors elicit but one report. Eight reports, including interrupt, are common to all dyadic primitive scalar functions, and each of these reports is issued only if none of the preceding ones apply:

Except where noted, the omission of the left argument results not in a valence error report, but in the invocation of a monadic function or an operator that shares the function symbol.

Function Definitions

Add y+x

   Arguments and Result
The arguments and result are simple numeric arrays. For two nonempty arguments, the result is integer if both arguments are integer and all result elements lie inside the range of integer representation, and floating point otherwise. If exactly one argument is empty, the result is floating point if that argument is floating point, and otherwise its type is the type of the nonempty argument. If both are empty, then if one is floating point and the other integer the result is floating point, and otherwise its type is the type of the right argument.

   Definition
y plus x. The result may include Inf or Inf.

   Example
     1 0 1 1e308+10 20 30 1e308
 9 20 31 Inf

And y^x

   Arguments and Result
The arguments are simple arrays of restricted whole numbers. The result is an integer array.

   Definition
If x and y have boolean values (0 and 1) then y^x is the Logical And of y and x. That is:

   Additional Error Report Condition
If none of the common error conditions are reported (including an illicit, i.e., not simple numeric, type) then:

   Examples
     0 0 1 1^0 1 0 1
 0 0 0 1
     43^14
 1

Circle yx

   Arguments and Result
The arguments and result are simple numeric arrays. Additionally, the left argument can also be symbolic. The result is always in floating point.

   Definition
Strictly, the elements of a numeric left argument y must be restricted whole numbers from -7 to 7; however, all floating-point numbers greater than -8 and less than 8 are accepted and, in effect, rounded toward zero to produce integers. Each element of y indicates the trigonometric, hyperbolic, or algebraic function to be applied to the corresponding element of the right argument x. All angles are in radians. See the table for details.

Notation for the Circle Functions
A+ ExpressionMeaning A+ ExpressionMeaning
`sinarccos x or 0x(1-x*2)*0.5  

`sin x or 1xsin x `arcsin x or 1xarcsin x
`cos x or 2xcos x `arccos x or 2xarccos x
`tan x or 3xtan x `arctan x or 3xarctan x
`secarctan x or 4x(1+x*2)*0.5 `tanarcsec x or 4x(1+x*2)*0.5
`sinh x or 5xsinh x `arcsinh x or 5xarcsinh x
`cosh x or 6xcosh x `arccosh x or 6xarccosh x
`tanh x or 7xtanh x `arctanh x or 7xarctanh x

When both arguments are scalar, using the symbolic form adds about 40% to the processing time; the symbolic form adds less, of course, when the right argument is non-scalar. Symbolic form is heartily encouraged for all but the most time-critical applications.

   Additional Error Report
If none of the common errors listed above are reported, then:

   Example
   1 1 3 3  2 4 2 0   sin(pi/2), sin(pi/4), tan(pi/2), arctan(Inf)
 1 0.7071067812 1.633177873e+16 1.570796327

Combine Symbols yx

   Arguments and Result
The arguments and result are simple arrays of symbols.

   Definition
This function takes context names and unqualified names and produces qualified names. More generally, for each scalar pair y,x: if, as displayed, x has a dot (period) in it, then the value of yx is x, and y is ignored; otherwise, the result is the symbol that is displayed as y, followed by a dot, followed by x without its backquote.

   Examples
     `c  `x `d.y `.z
 `c.x `d.y `.z
     `b.c `a  `x `y
 `b.c.x `a.y

Divide yx

   Arguments and Result
The arguments and result are simple numeric arrays. The result is always floating point.

   Definition
y divided by x. Division of a positive number by zero yields Inf, a unique scalar, and division of a negative number by zero yields Inf.

   Additional Error Report
If none of the errors listed in "Common Error Reports" are reported, then:

   Example
     0 1 2 3 4 52 2 2 2 0 0
 0 0.5 1 1.5 Inf Inf

Equal to y=x

   Arguments and Result
The arguments can be of any type. The result is boolean (integer type with values 0 and 1).

   Dependency
Comparison tolerance, if an argument is in floating point (see "Comparison Tolerance").

   Definition
The value is 1 if y tolerably equals x, and 0 if not.

   Additional Error Report
If there is no parse or value error (see "Common Error Reports"), then:

   Examples
     ' '='this is it'
 0 0 0 0 1 0 0 1 0 0
     (<2 3, 4+1e-13)=(2 3 4;'abcde';5 6)
 1 0 0
     1 2 3 = '123'
 0 0 0

Greater than y>x

   Arguments and Result
The arguments are simple numeric, character, or symbol arrays. The result is boolean (integer type with values 0 and 1).

   Dependency
Comparison tolerance, if an argument is in floating point (see "Comparison Tolerance").

   Definition
The value is 1 if y is greater than x and not tolerably equal to x, and 0 otherwise. Characters are compared using their ASCII codes and symbols using the usual lexical ordering based on the ASCII codes of their component letters.

   Examples
     (200 0 90 100 101 200,(100+1e-12),100+1e-11)>100
 0 0 0 0 1 1 0 1
     'b' > 'abc'
 1 0 0
     'B' > 'abc'       ASCII, not English, order.
 0 0 0
     `b > `a`b`c
 1 0 0
     `B > `a`b`c       Likewise.
 0 0 0
     `pint > `cup `pints `pound `quart `snootful `gallon
 1 0 0 0 0 1

Greater than or Equal to yx

   Arguments and Result
The arguments are simple numeric, character, or symbol arrays. The result is boolean (integer type with values 0 and 1).

   Dependency
Comparison tolerance, if an argument is in floating point (see "Comparison Tolerance").

   Definition
The value is 1 if y is greater than x or tolerably equal to x, and 0 otherwise. Characters are compared using their ASCII codes and symbols using the usual lexical ordering based on the ASCII codes of their component letters.

   Additional Error Report
If there is no parse or value error (see "Common Error Reports"), then:

   Example
     200 0 90 100 101 200100
 0 0 0 1 1 1

Less than y<x

   Arguments and Result
The arguments are simple numeric, character, or symbol arrays. The result is boolean (integer type with values 0 and 1).

   Dependency
Comparison tolerance, if an argument is in floating point (see "Comparison Tolerance").

   Definition
The value is 1 if y is less than x and not tolerably equal to x, and 0 otherwise. Characters are compared using their ASCII codes and symbols using the usual lexical ordering based on the ASCII codes of their component letters.

   Example
     200 0 90 100 101 200<100
 1 1 1 0 0 0

Less than or Equal to yx

   Arguments and Result
The arguments are simple numeric, character, or symbol arrays. The result is boolean (integer type with values 0 and 1).

   Dependency
Comparison tolerance, if an argument is in floating point (see "Comparison Tolerance").

   Definition
The value is 1 if y is less than x or tolerably equal to x, and 0 otherwise. Characters are compared using their ASCII codes and symbols using the usual lexical ordering based on the ASCII codes of their component letters.

   Additional Error Report
If there is no parse or value error (see "Common Error Reports"), then:

   Example
     200 0 90 100 101 200100
 1 1 1 1 0 0

Log yx

   Arguments and Result
The arguments and result are simple numeric arrays. The result is always in floating point.

   Definition
The logarithm of x to the base y.

   Example
     10.1 1 10 100 1000 1234.5 0
 1 0 1 2 3 3.091491094 Inf
   Additional Error Report
If none of the reports cited in "Common Error Reports" is issued, then:

Max yx

   Arguments and Result
The arguments and result are simple numeric arrays. For two nonempty arguments, the result is integer if both arguments are integer, and floating point otherwise. If exactly one argument is empty, the result is floating point if that argument is floating point, and otherwise its type is the type of the nonempty argument. If both are empty, then if one is floating point and the other integer the result is floating point, and otherwise its type is the type of the right argument.

   Definition
The greater of y and x. When this function is used in Reduction (/), the name Max is appropriate.

   Example
     0  3 .5 1 5 .1
 3 .5 0 5 0

Min yx

   Arguments and Result
The arguments and result are simple numeric arrays. For two nonempty arguments, the result is integer if both arguments are integer, and floating point otherwise. If exactly one argument is empty, the result is floating point if that argument is floating point, and otherwise its type is the type of the nonempty argument. If both are empty, then if one is floating point and the other integer the result is floating point, and otherwise its type is the type of the right argument.

   Definition
The lesser of y and x. When this function is used in Reduction (/), the name Min is appropriate.

   Example
     99.5 100 91.1 112 99  100
 99.5 100 91.1 100 99

Multiply yx

   Arguments and Result
The arguments and result are simple numeric arrays. For two nonempty arguments, the result is integer if both arguments are integer and all result elements lie inside the range of integer representation, and floating point otherwise. If exactly one argument is empty, the result is floating point if that argument is floating point, and otherwise its type is the type of the nonempty argument. If both are empty, then if one is floating point and the other integer the result is floating point, and otherwise its type is the type of the right argument.

   Definition
y times x.

   Example
     100 1 2 3 1e308
 0 10 20 30 Inf

Not equal to yx

   Arguments and Result
The arguments can be of any type. The result is boolean (integer type with values 0 and 1).

   Dependency
Comparison tolerance, if an argument is in floating point (see "Comparison Tolerance").

   Definition
The value is 1 if y is not tolerably equal to x, and 0 if it is.

   Additional Error Report
If there is no parse or value error (see "Common Error Reports"), then:

   Examples
     ' ''this is it'
 1 1 1 1 0 1 1 0 1 1
     (<2 3, 4+1e-13)(2 3 4;'abcde';5 6)
 0 1 1
     1 2 3  '123'
 1 1 1

Or yx

   Arguments and Result
The arguments are simple numeric arrays of restricted whole numbers. The result is an integer array.

   Definition
If x and y have boolean values (0 or 1) then yx is the Logical Or of x and y. That is:

11 equals 10 equals 01 equals 1;
00 equals 0.

Or is strictly boolean, never bitwise. All nonzero restricted whole numbers are treated as if they were 1.

To get bitwise behavior, use the Bitwise operator.

   Additional Error Reports
If none of the common error conditions is reported, then, with a domain report preempting a type report:

   Examples
     0 0 1 10 1 0 1
 0 1 1 1
     4314
 1

Power y*x

   Arguments and Result
The arguments and result are simple numeric arrays. The result is always floating point.

   Definition
y to the power x10*2 is exactly equal to 1e2 but in general there is a very slight (tolerable) difference between 10*N and 1eN, because logarithms are used except in this special case, whereas 1eN is exact.

   Example
     2*0 .5 1 2 3 4 5 6 7 8 1025
 1 1.414213562 2 4 8 16 32 64 128 256 Inf

Residue y|x

   Arguments and Result
The arguments and result are simple numeric arrays. For two nonempty arguments, the result is integer if both arguments are integer, and floating point otherwise. If exactly one argument is empty, the result is floating point if that argument is floating point, and otherwise its type is the type of the nonempty argument. If both are empty, then if one is floating point and the other integer the result is floating point, and otherwise its type is the type of the right argument.

   Dependency
Comparison tolerance, if an argument is in floating point (see "Comparison Tolerance").

   Definition
y|x is the remainder when x is divided by y. 0|x equals x. If y is nonzero, then y|x is x-yxy, in accordance with the mathematical definition of modular arithmetic, except as follows. If x is tolerably equal to ny, where n is a whole number not necessarily representable by type `int, then the result is 0. (So Inf|x and Inf|x are always 0.)

   Examples
     100 | 1930 1941 1952 1978, 100+1e-12
 30 41 52 78 0
     1.4 1.4 1.4 1.4 | 3.7 3.7 3.7 3.7
 0.9 0.5 0.5 0.9

Subtract y-x

   Arguments and Result
The arguments and result are simple numeric arrays. For two nonempty arguments, the result is integer if both arguments are integer and all result elements lie inside the range of integer representation, and floating point otherwise. If exactly one argument is empty, the result is floating point if that argument is floating point, and otherwise its type is the type of the nonempty argument. If both are empty, then if one is floating point and the other integer the result is floating point, and otherwise its type is the type of the right argument.

   Definition
y minus x.

   Example
     1 0 99.5 1e308 - .5 1 .5 1e308
 1.5 1 99 Inf

doc@aplusdev.org© Copyright 1995–2008 Morgan Stanley Dean Witter & Co. All rights reserved.