Reciprocal: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
m (Text replacement - "<source" to "<syntaxhighlight")
Line 1: Line 1:
{{Built-in|Reciprocal|÷}} is a [[monadic]] [[scalar function]] which gives the [[wikipedia:Multiplicative inverse|multiplicative inverse]] of a real or [[complex]] number. Reciprocal shares the [[glyph]] <source lang=apl inline>÷</source> with the dyadic arithmetic function [[Divide]].
{{Built-in|Reciprocal|÷}} is a [[monadic]] [[scalar function]] which gives the [[wikipedia:Multiplicative inverse|multiplicative inverse]] of a real or [[complex]] number. Reciprocal shares the [[glyph]] <syntaxhighlight lang=apl inline>÷</source> with the dyadic arithmetic function [[Divide]].


== Examples ==
== Examples ==
<source lang=apl>
<syntaxhighlight lang=apl>
       ÷1 2 3 4 5
       ÷1 2 3 4 5
1 0.5 0.3333333333 0.25 0.2
1 0.5 0.3333333333 0.25 0.2
Line 21: Line 21:
== Properties ==
== Properties ==


The reciprocal of any real or complex number is equal to 1 [[divide]]d by that number. Therefore the monadic <source lang=apl inline>÷</source> can be seen as dyadic <source lang=apl inline>÷</source> with default left argument of 1. This applies even to the reciprocal of 0; <source lang=apl inline>÷0</source> and <source lang=apl inline>1÷0</source> show identical behavior for both <source lang=apl inline>⎕DIV←0</source> (raising [[DOMAIN ERROR]]) and <source lang=apl inline>⎕DIV←1</source> (returning 0).
The reciprocal of any real or complex number is equal to 1 [[divide]]d by that number. Therefore the monadic <syntaxhighlight lang=apl inline>÷</source> can be seen as dyadic <syntaxhighlight lang=apl inline>÷</source> with default left argument of 1. This applies even to the reciprocal of 0; <syntaxhighlight lang=apl inline>÷0</source> and <syntaxhighlight lang=apl inline>1÷0</source> show identical behavior for both <syntaxhighlight lang=apl inline>⎕DIV←0</source> (raising [[DOMAIN ERROR]]) and <syntaxhighlight lang=apl inline>⎕DIV←1</source> (returning 0).


<source lang=apl>
<syntaxhighlight lang=apl>
       ÷1 2 3 4 5
       ÷1 2 3 4 5
1 0.5 0.3333333333 0.25 0.2
1 0.5 0.3333333333 0.25 0.2
Line 33: Line 33:
For any non-zero real or complex numbers, the [[signum]] of reciprocal is equal to the [[conjugate]] of signum, and the [[magnitude]] of reciprocal is equal to the reciprocal of magnitude.
For any non-zero real or complex numbers, the [[signum]] of reciprocal is equal to the [[conjugate]] of signum, and the [[magnitude]] of reciprocal is equal to the reciprocal of magnitude.


<source lang=apl>
<syntaxhighlight lang=apl>
       (×∘÷ ≡ +∘×)1 2 3 ¯2 0.5 1J2
       (×∘÷ ≡ +∘×)1 2 3 ¯2 0.5 1J2
1
1

Revision as of 21:44, 10 September 2022

÷

Reciprocal (÷) is a monadic scalar function which gives the multiplicative inverse of a real or complex number. Reciprocal shares the glyph <syntaxhighlight lang=apl inline>÷</source> with the dyadic arithmetic function Divide.

Examples

<syntaxhighlight lang=apl>

     ÷1 2 3 4 5

1 0.5 0.3333333333 0.25 0.2

     ÷¯2 0.5 1J2

¯0.5 2 0.2J¯0.4

     ÷0

DOMAIN ERROR: Divide by zero

÷0                         
∧

     ⎕DIV←1  ⍝ this sets division by 0 to always return 0
     ÷0

0 </source>

Properties

The reciprocal of any real or complex number is equal to 1 divided by that number. Therefore the monadic <syntaxhighlight lang=apl inline>÷</source> can be seen as dyadic <syntaxhighlight lang=apl inline>÷</source> with default left argument of 1. This applies even to the reciprocal of 0; <syntaxhighlight lang=apl inline>÷0</source> and <syntaxhighlight lang=apl inline>1÷0</source> show identical behavior for both <syntaxhighlight lang=apl inline>⎕DIV←0</source> (raising DOMAIN ERROR) and <syntaxhighlight lang=apl inline>⎕DIV←1</source> (returning 0).

<syntaxhighlight lang=apl>

     ÷1 2 3 4 5

1 0.5 0.3333333333 0.25 0.2

     1÷1 2 3 4 5

1 0.5 0.3333333333 0.25 0.2 </source>

For any non-zero real or complex numbers, the signum of reciprocal is equal to the conjugate of signum, and the magnitude of reciprocal is equal to the reciprocal of magnitude.

<syntaxhighlight lang=apl>

     (×∘÷ ≡ +∘×)1 2 3 ¯2 0.5 1J2

1

     (|∘÷ ≡ ÷∘|)1 2 3 ¯2 0.5 1J2

1

</source>

Works in: Dyalog APL

See also

External links

Documentation

APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
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 axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)
Quad names Index originComparison toleranceMigration levelAtomic vector