Difference between revisions of "Residue"

From APL Wiki
Jump to navigation Jump to search
m (Text replacement - "http://help.dyalog.com" to "https://help.dyalog.com")
Line 43: Line 43:
=== Documentation ===
=== Documentation ===
* [http://help.dyalog.com/17.1/#Language/Primitive%20Functions/Residue.htm Dyalog]
* [https://help.dyalog.com/17.1/#Language/Primitive%20Functions/Residue.htm Dyalog]
* [https://www.jsoftware.com/help/dictionary/d230.htm J Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/bar NuVoc]
* [https://www.jsoftware.com/help/dictionary/d230.htm J Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/bar NuVoc]
{{APL built-ins}}[[Category:Primitive functions]][[Category:Scalar dyadic functions]]
{{APL built-ins}}[[Category:Primitive functions]][[Category:Scalar dyadic functions]]

Latest revision as of 14:34, 14 July 2020


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.


      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


For positive x and y, the following identity holds:

      x?10  y?10


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
Works in: Dyalog APL

See also

External links


APL built-ins [edit]
Primitive functions
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentitySelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndex
Selector Index generatorGradeIndex OfInterval IndexIndicesDeal
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Primitive operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-beamSpawnFunction axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Atop, Over) ∙ Inner ProductPowerAtUnderRankDepthVariantStencilCut (J)
Quad names
Arrays Index originMigration levelAtomic vector
Functions Case convertUnicode convert
Operators SearchReplace