Residue: Difference between revisions
Jump to navigation
Jump to search
m (Text replacement - "</source>" to "</syntaxhighlight>") |
m (Text replacement - "<source" to "<syntaxhighlight") Tags: Mobile edit Mobile web edit |
||
Line 1: | Line 1: | ||
{{Built-in|Residue|<nowiki>|</nowiki>}}, '''Remainder''', or '''Modulus''' is a [[dyadic]] [[scalar function]] which gives the [[wikipedia:Remainder|remainder]] of [[divide|division]] between two real numbers. It takes the divisor as the left [[argument]], and the dividend as the right argument. Residue shares the [[glyph]] < | {{Built-in|Residue|<nowiki>|</nowiki>}}, '''Remainder''', or '''Modulus''' is a [[dyadic]] [[scalar function]] which gives the [[wikipedia:Remainder|remainder]] of [[divide|division]] between two real numbers. It takes the divisor as the left [[argument]], and the dividend as the right argument. Residue shares the [[glyph]] <syntaxhighlight lang=apl inline>|</syntaxhighlight> with the monadic arithmetic function [[Magnitude]]. | ||
== Examples == | == Examples == | ||
< | <syntaxhighlight lang=apl> | ||
2|¯2 ¯1 0 1 2 3 4 5 | 2|¯2 ¯1 0 1 2 3 4 5 | ||
0 1 0 1 0 1 0 1 | 0 1 0 1 0 1 0 1 | ||
Line 14: | Line 14: | ||
For positive x and y, the following identity holds: | For positive x and y, the following identity holds: | ||
< | <syntaxhighlight lang=apl> | ||
x←?⍨10 ⋄ y←?⍨10 | x←?⍨10 ⋄ y←?⍨10 | ||
x≡(y|x)+y×⌊x÷y | x≡(y|x)+y×⌊x÷y | ||
Line 26: | Line 26: | ||
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. | 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 < | Dyalog APL uses the expression <syntaxhighlight lang=apl inline>Y-X×⌊Y÷X+0=X</syntaxhighlight> as the definition of <syntaxhighlight lang=apl inline>X|Y</syntaxhighlight>, 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]]). | ||
< | <syntaxhighlight lang=apl> | ||
5 5 ¯5 ¯5 0 0|2 ¯2 2 ¯2 2 ¯2 | 5 5 ¯5 ¯5 0 0|2 ¯2 2 ¯2 2 ¯2 | ||
2 3 ¯3 ¯2 2 ¯2 | 2 3 ¯3 ¯2 2 ¯2 |