Signum: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
m (Text replacement - "</source>" to "</syntaxhighlight>")
Line 3: Line 3:
== Examples ==
== Examples ==


The three possible results of Signum on a real argument are <source lang=apl inline>0</source>, <source lang=apl inline>1</source>, and <source lang=apl inline>¯1</source>.
The three possible results of Signum on a real argument are <source lang=apl inline>0</syntaxhighlight>, <source lang=apl inline>1</syntaxhighlight>, and <source lang=apl inline>¯1</syntaxhighlight>.
<source lang=apl>
<source lang=apl>
       × ¯3 0 5
       × ¯3 0 5
¯1 0 1
¯1 0 1
</source>
</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.
<source lang=apl>
<source lang=apl>
       × 3j4
       × 3j4
0.6J0.8
0.6J0.8
</source>
</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]]:
<source lang=apl>
<source lang=apl>
Line 19: Line 19:
       3j4 ÷ | 3j4
       3j4 ÷ | 3j4
0.6J0.8
0.6J0.8
</source>
</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.
<source lang=apl>
<source lang=apl>
       | × 3j4 ¯2j1 6j¯7
       | × 3j4 ¯2j1 6j¯7
1 1 1
1 1 1
</source>
</syntaxhighlight>


== Zero divided by zero ==
== Zero divided by zero ==


The identity <source lang=apl inline>×z</source> {{←→}} <source lang=apl inline>z÷|z</source> holds only when <source lang=apl inline>z</source> 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 <source lang=apl inline>0÷0</source> to be equal to <source lang=apl inline>0</source>. In [[J]], which took McDonnell's suggestion, the identity always holds. [[Dyalog APL]] and [[NARS2000]] allow choosing [[division method]] though the default remains 1.
The identity <source lang=apl inline>×z</syntaxhighlight> {{←→}} <source lang=apl inline>z÷|z</syntaxhighlight> holds only when <source 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 <source lang=apl inline>0÷0</syntaxhighlight> to be equal to <source 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 ==
== See also ==

Revision as of 21:07, 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 <source lang=apl inline>0</syntaxhighlight>, <source lang=apl inline>1</syntaxhighlight>, and <source lang=apl inline>¯1</syntaxhighlight>. <source lang=apl>

     × ¯3 0 5

¯1 0 1 </syntaxhighlight> In dialects with complex numbers, Signum is a somewhat more complicated function, and may return any unit complex number. <source lang=apl>

     × 3j4

0.6J0.8 </syntaxhighlight> The result is still equal to the original number divided by its magnitude: <source lang=apl>

     | 3j4

5

     3j4 ÷ | 3j4

0.6J0.8 </syntaxhighlight> The magnitude of the result for a non-zero argument is always 1. <source lang=apl>

     | × 3j4 ¯2j1 6j¯7

1 1 1 </syntaxhighlight>

Zero divided by zero

The identity <source lang=apl inline>×z</syntaxhighlight> <source lang=apl inline>z÷|z</syntaxhighlight> holds only when <source lang=apl inline>z</syntaxhighlight> is not zero in most APLs. In "Zero Divided by Zero"[1], Eugene McDonnell gave this identity as a reason to define <source lang=apl inline>0÷0</syntaxhighlight> to be equal to <source 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

External links

Documentation

References

APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare RootRound
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentityStopSelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndexCartesian ProductSort
Selector Index generatorGradeIndex OfInterval IndexIndicesDealPrefix and suffix vectors
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-BeamSpawnFunction axisIdentity (Null, Ident)
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)Identity (Lev, Dex)
Quad names Index originComparison toleranceMigration levelAtomic vector