Residue (|
), Remainder, or Modulus is a dyadic scalar function which gives the remainder of division between two real numbers. It takes the divisor as the left argument, and the dividend as the right argument. Residue shares the glyph |
with the monadic arithmetic function Magnitude.
Examples
2|¯2 ¯1 0 1 2 3 4 5
0 1 0 1 0 1 0 1
3.5|5 10 14
1.5 3 0
Properties
For positive x and y, the following identity holds:
x←?⍨10 ⋄ y←?⍨10
x≡(y|x)+y×⌊x÷y
1
Caveats
The usual definition of "remainder" only holds when both arguments are positive. An implementation is free to decide what to do when the left argument is zero, or at least one of the arguments is negative or complex.
For negative arguments, one may decide to return non-negative numbers in all cases or follow the sign of the dividend or the divisor. For complex arguments, the floor of a complex number is not mathematically defined, so allowing complex arguments does not add much of mathematical value.
Dyalog APL uses the expression Y-X×⌊Y÷X+0=X
as the definition of X|Y
, so that the above identity holds for all possible arguments. With this definition, zero X returns Y unchanged, and negative X returns a value between X and 0 (excluding the value X). The result for complex arguments is also defined (since Dyalog APL allows them as the argument to Floor).
5 5 ¯5 ¯5 0 0|2 ¯2 2 ¯2 2 ¯2
2 3 ¯3 ¯2 2 ¯2
3J4|5J12
3J1
3J4{⍵-⍺×⌊⍵÷⍺+0=⍺}5J12
3J1
See also
External links
Documentation
APL built-ins [edit]
|
Primitives (Timeline) |
Functions
|
Scalar
|
Monadic
|
Conjugate ∙ Negate ∙ Signum ∙ Reciprocal ∙ Magnitude ∙ Exponential ∙ Natural Logarithm ∙ Floor ∙ Ceiling ∙ Factorial ∙ Not ∙ Pi Times ∙ Roll ∙ Type ∙ Imaginary ∙ Square Root ∙ Round
|
Dyadic
|
Add ∙ Subtract ∙ Times ∙ Divide ∙ Residue ∙ Power ∙ Logarithm ∙ Minimum ∙ Maximum ∙ Binomial ∙ Comparison functions ∙ Boolean functions (And, Or, Nand, Nor) ∙ GCD ∙ LCM ∙ Circular ∙ Complex ∙ Root
|
Non-Scalar
|
Structural
|
Shape ∙ Reshape ∙ Tally ∙ Depth ∙ Ravel ∙ Enlist ∙ Table ∙ Catenate ∙ Reverse ∙ Rotate ∙ Transpose ∙ Raze ∙ Mix ∙ Split ∙ Enclose ∙ Nest ∙ Cut (K) ∙ Pair ∙ Link ∙ Partitioned Enclose ∙ Partition
|
Selection
|
First ∙ Pick ∙ Take ∙ Drop ∙ Unique ∙ Identity ∙ Stop ∙ Select ∙ Replicate ∙ Expand ∙ Set functions (Intersection ∙ Union ∙ Without) ∙ Bracket indexing ∙ Index ∙ Cartesian Product ∙ Sort
|
Selector
|
Index generator ∙ Grade ∙ Index Of ∙ Interval Index ∙ Indices ∙ Deal ∙ Prefix and suffix vectors
|
Computational
|
Match ∙ Not Match ∙ Membership ∙ Find ∙ Nub Sieve ∙ Encode ∙ Decode ∙ Matrix Inverse ∙ Matrix Divide ∙ Format ∙ Execute ∙ Materialise ∙ Range
|
Operators |
Monadic
|
Each ∙ Commute ∙ Constant ∙ Replicate ∙ Expand ∙ Reduce ∙ Windowed Reduce ∙ Scan ∙ Outer Product ∙ Key ∙ I-Beam ∙ Spawn ∙ Function axis ∙ Identity (Null, Ident)
|
Dyadic
|
Bind ∙ Compositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner Product ∙ Determinant ∙ Power ∙ At ∙ Under ∙ Rank ∙ Depth ∙ Variant ∙ Stencil ∙ Cut ∙ Direct definition (operator) ∙ Identity (Lev, Dex)
|
Quad names
|
Index origin ∙ Comparison tolerance ∙ Migration level ∙ Atomic vector
|