Power (function): Difference between revisions

From APL Wiki
Jump to navigation Jump to search
m (Text replacement - "<source" to "<syntaxhighlight")
Line 1: Line 1:
:''This page describes the dyadic function. For the monadic function that uses <math>e</math> as a base, see [[Exponential]]. For the iteration operator, see [[Power (operator)]].''
:''This page describes the dyadic function. For the monadic function that uses <math>e</math> as a base, see [[Exponential]]. For the iteration operator, see [[Power (operator)]].''


{{Built-in|Power|*}} is a [[dyadic]] [[scalar function]] that computes the [[wikipedia:exponentiation|exponentiation]] function of the two [[argument|arguments]], so that <source lang=apl inline>X*Y</source> is <source lang=apl inline>X</source> raised to the power <source lang=apl inline>Y</source>. Power shares the [[glyph]] <source lang=apl inline>*</source> with the monadic arithmetic function [[Exponential]].
{{Built-in|Power|*}} is a [[dyadic]] [[scalar function]] that computes the [[wikipedia:exponentiation|exponentiation]] function of the two [[argument|arguments]], so that <syntaxhighlight lang=apl inline>X*Y</source> is <syntaxhighlight lang=apl inline>X</source> raised to the power <syntaxhighlight lang=apl inline>Y</source>. Power shares the [[glyph]] <syntaxhighlight lang=apl inline>*</source> with the monadic arithmetic function [[Exponential]].


== Examples ==
== Examples ==
<source lang=apl>
<syntaxhighlight lang=apl>
       2*¯1 0 1 2 3 4 5
       2*¯1 0 1 2 3 4 5
0.5 1 2 4 8 16 32
0.5 1 2 4 8 16 32
</source>
</source>
A common technique is to choose [[sign]] based on a [[Boolean]] array:
A common technique is to choose [[sign]] based on a [[Boolean]] array:
<source lang=apl>
<syntaxhighlight lang=apl>
       ¯1*1 0 0 1 0
       ¯1*1 0 0 1 0
¯1 1 1 ¯1 1
¯1 1 1 ¯1 1
Line 16: Line 16:
== Properties ==
== Properties ==


For positive integer <source lang=apl inline>Y</source>, <source lang=apl inline>X*Y</source> equals the [[times|product]] of <source lang=apl inline>Y</source> copies of <source lang=apl inline>X</source>. When <source lang=apl inline>Y</source> is 0, <source lang=apl inline>X*Y</source> equals 1, possibly except when <source lang=apl inline>X</source> is also 0 (since [[wikipedia:zero to the power of zero|zero to the power of zero]] is undefined in mathematics).
For positive integer <syntaxhighlight lang=apl inline>Y</source>, <syntaxhighlight lang=apl inline>X*Y</source> equals the [[times|product]] of <syntaxhighlight lang=apl inline>Y</source> copies of <syntaxhighlight lang=apl inline>X</source>. When <syntaxhighlight lang=apl inline>Y</source> is 0, <syntaxhighlight lang=apl inline>X*Y</source> equals 1, possibly except when <syntaxhighlight lang=apl inline>X</source> is also 0 (since [[wikipedia:zero to the power of zero|zero to the power of zero]] is undefined in mathematics).


<source lang=apl>
<syntaxhighlight lang=apl>
       3*5
       3*5
243  
243  
Line 29: Line 29:
[[negate|Negating]] the exponent (right argument) gives the [[reciprocal]] of the return value.
[[negate|Negating]] the exponent (right argument) gives the [[reciprocal]] of the return value.


<source lang=apl>
<syntaxhighlight lang=apl>
       (2*¯4)=÷2*4
       (2*¯4)=÷2*4
1
1
</source>
</source>


If the exponent is the [[reciprocal]] of some number n, the result is the n-th [[root]] of the base. For example, a right argument of <source lang=apl inline>÷2</source> gives the [[square root]].
If the exponent is the [[reciprocal]] of some number n, the result is the n-th [[root]] of the base. For example, a right argument of <syntaxhighlight lang=apl inline>÷2</source> gives the [[square root]].


<source lang=apl>
<syntaxhighlight lang=apl>
       3*2
       3*2
9
9
Line 44: Line 44:


Power has two inverses, [[Root]] and [[Logarithm]]:
Power has two inverses, [[Root]] and [[Logarithm]]:
<source lang=apl>
<syntaxhighlight lang=apl>
       2*3
       2*3
8
8

Revision as of 21:32, 10 September 2022

This page describes the dyadic function. For the monadic function that uses as a base, see Exponential. For the iteration operator, see Power (operator).
*

Power (*) is a dyadic scalar function that computes the exponentiation function of the two arguments, so that <syntaxhighlight lang=apl inline>X*Y</source> is <syntaxhighlight lang=apl inline>X</source> raised to the power <syntaxhighlight lang=apl inline>Y</source>. Power shares the glyph <syntaxhighlight lang=apl inline>*</source> with the monadic arithmetic function Exponential.

Examples

<syntaxhighlight lang=apl>

     2*¯1 0 1 2 3 4 5

0.5 1 2 4 8 16 32 </source> A common technique is to choose sign based on a Boolean array: <syntaxhighlight lang=apl>

     ¯1*1 0 0 1 0

¯1 1 1 ¯1 1 </source>

Properties

For positive integer <syntaxhighlight lang=apl inline>Y</source>, <syntaxhighlight lang=apl inline>X*Y</source> equals the product of <syntaxhighlight lang=apl inline>Y</source> copies of <syntaxhighlight lang=apl inline>X</source>. When <syntaxhighlight lang=apl inline>Y</source> is 0, <syntaxhighlight lang=apl inline>X*Y</source> equals 1, possibly except when <syntaxhighlight lang=apl inline>X</source> is also 0 (since zero to the power of zero is undefined in mathematics).

<syntaxhighlight lang=apl>

     3*5

243

     ×/5⍴3

243

     1 2 3*0

1 1 1 </source>

Negating the exponent (right argument) gives the reciprocal of the return value.

<syntaxhighlight lang=apl>

     (2*¯4)=÷2*4

1 </source>

If the exponent is the reciprocal of some number n, the result is the n-th root of the base. For example, a right argument of <syntaxhighlight lang=apl inline>÷2</source> gives the square root.

<syntaxhighlight lang=apl>

     3*2

9

     9*÷2

3 </source>

Power has two inverses, Root and Logarithm: <syntaxhighlight lang=apl>

     2*3

8

     2⍟8

3

     3√8

2 </source>

External links

Documentation

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