Signum: Difference between revisions
(Created page with "{{Built-in|Signum|×}}, '''Sign''', '''Sign of''', or '''Direction''' is a monadic primitive function which returns the sign of a real or [...") |
m (Text replacement - "<source" to "<syntaxhighlight") |
||
(13 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{Built-in|Signum|×}}, '''Sign''', '''Sign of''', or '''Direction''' is a [[monadic]] [[ | {{Built-in|Signum|×}}, '''Sign''', '''Sign of''', or '''Direction''' is a [[monadic]] [[scalar function]] which returns the [[wikipedia:Sign function|sign]] of a real or [[complex]] number. That is, it returns 0 when given an argument of 0, and otherwise returns a number with [[magnitude]] 1 given by [[Divide|dividing]] the argument by its own magnitude. | ||
== Examples == | == Examples == | ||
The three possible results of Signum on a real argument are < | The three possible results of Signum on a real argument are <syntaxhighlight lang=apl inline>0</syntaxhighlight>, <syntaxhighlight lang=apl inline>1</syntaxhighlight>, and <syntaxhighlight lang=apl inline>¯1</syntaxhighlight>. | ||
< | <syntaxhighlight lang=apl> | ||
× ¯3 0 5 | × ¯3 0 5 | ||
¯1 0 1 | ¯1 0 1 | ||
</ | </syntaxhighlight> | ||
In dialects with [[complex number]]s, Signum is a somewhat more complicated function, and may return any unit complex number. | In dialects with [[complex number]]s, Signum is a somewhat more complicated function, and may return any unit complex number. | ||
< | <syntaxhighlight lang=apl> | ||
× 3j4 | × 3j4 | ||
0.6J0.8 | 0.6J0.8 | ||
</ | </syntaxhighlight> | ||
The result is still equal to the original number [[divide]]d by its [[magnitude]]: | The result is still equal to the original number [[divide]]d by its [[magnitude]]: | ||
< | <syntaxhighlight lang=apl> | ||
| 3j4 | | 3j4 | ||
5 | 5 | ||
3j4 ÷ | 3j4 | 3j4 ÷ | 3j4 | ||
0.6J0.8 | 0.6J0.8 | ||
</ | </syntaxhighlight> | ||
The [[magnitude]] of the result for a non-zero argument is always 1. | The [[magnitude]] of the result for a non-zero argument is always 1. | ||
< | <syntaxhighlight lang=apl> | ||
| × 3j4 ¯2j1 6j¯7 | | × 3j4 ¯2j1 6j¯7 | ||
1 1 1 | 1 1 1 | ||
</ | </syntaxhighlight> | ||
== Zero divided by zero == | == Zero divided by zero == | ||
The identity < | The identity <syntaxhighlight lang=apl inline>×z</syntaxhighlight> {{←→}} <syntaxhighlight lang=apl inline>z÷|z</syntaxhighlight> holds only when <syntaxhighlight lang=apl inline>z</syntaxhighlight> is not zero in most APLs. In "Zero Divided by Zero"<ref>[[Eugene McDonnell|McDonnell, Eugene]]. [https://www.jsoftware.com/papers/eem/0div0.htm "Zero Divided by Zero"]. [[APL76]].</ref>, [[Eugene McDonnell]] gave this identity as a reason to define <syntaxhighlight lang=apl inline>0÷0</syntaxhighlight> to be equal to <syntaxhighlight lang=apl inline>0</syntaxhighlight>. In [[J]], which took McDonnell's suggestion, the identity always holds. [[Dyalog APL]] and [[NARS2000]] allow choosing [[division method]] though the default remains 1. | ||
== See also == | |||
* [[Negate]] | |||
* [[Conjugate]] | |||
== External links == | == External links == | ||
Line 34: | Line 38: | ||
=== Documentation === | === Documentation === | ||
* [ | * [https://help.dyalog.com/latest/index.htm#Language/Primitive%20Functions/Direction.htm Dyalog] | ||
* [http://microapl.com/apl_help/ch_020_020_050.htm APLX] | * [http://microapl.com/apl_help/ch_020_020_050.htm APLX] | ||
* J [https://www.jsoftware.com/help/dictionary/d110.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/star NuVoc] | * J [https://www.jsoftware.com/help/dictionary/d110.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/star NuVoc] | ||
* [https://mlochbaum.github.io/BQN/doc/arithmetic.html#basic-arithmetic BQN] | |||
== References == | == References == | ||
<references /> | <references /> | ||
{{APL built-ins}} | {{APL built-ins}}[[Category:Primitive functions]][[Category:Scalar monadic functions]] |
Latest revision as of 21:32, 10 September 2022
×
|
Signum (×
), Sign, Sign of, or Direction is a monadic scalar function which returns the sign of a real or complex number. That is, it returns 0 when given an argument of 0, and otherwise returns a number with magnitude 1 given by dividing the argument by its own magnitude.
Examples
The three possible results of Signum on a real argument are 0
, 1
, and ¯1
.
× ¯3 0 5 ¯1 0 1
In dialects with complex numbers, Signum is a somewhat more complicated function, and may return any unit complex number.
× 3j4 0.6J0.8
The result is still equal to the original number divided by its magnitude:
| 3j4 5 3j4 ÷ | 3j4 0.6J0.8
The magnitude of the result for a non-zero argument is always 1.
| × 3j4 ¯2j1 6j¯7 1 1 1
Zero divided by zero
The identity ×z
z÷|z
holds only when z
is not zero in most APLs. In "Zero Divided by Zero"[1], Eugene McDonnell gave this identity as a reason to define 0÷0
to be equal to 0
. In J, which took McDonnell's suggestion, the identity always holds. Dyalog APL and NARS2000 allow choosing division method though the default remains 1.
See also
External links
Documentation
- Dyalog
- APLX
- J Dictionary, NuVoc
- BQN