Logarithm

From APL Wiki
Revision as of 22:05, 10 September 2022 by Adám Brudzewsky (talk | contribs) (Text replacement - "<source" to "<syntaxhighlight")
Jump to navigation Jump to search
This page describes the dyadic arithmetic function. For the monadic natural logarithm function, see Natural Logarithm.

Logarithm (), or Log, is a dyadic scalar function which computes the logarithm of the two arguments. More precisely, <syntaxhighlight lang=apl inline>X⍟Y</source> computes how much power of X equals Y, i.e. the value of R that satisfies <syntaxhighlight lang=apl inline>Y=X*R</source>. Logarithm shares the glyph <syntaxhighlight lang=apl inline>⍟</source> with the monadic arithmetic function Natural Logarithm. The glyph, a composition of the glyphs for Circular (<syntaxhighlight lang=apl inline>○</source>) and Power (<syntaxhighlight lang=apl inline>*</source>) to indicate its close mathematical ties with these two functions, is a stylised tree log.[1]

Examples

<syntaxhighlight lang=apl>

     2⍟0.5 1 2 32 1024

¯1 0 1 5 10 </source>

Logarithm can be used to determine how many digits are needed to write a positive integer Y in base X:

<syntaxhighlight lang=apl>

     Digits←{1+⌊⍺⍟⍵}
     ToBase←⊥⍣¯1
     (2 Digits 100) (2 ToBase 100)

┌─┬─────────────┐ │7│1 1 0 0 1 0 0│ └─┴─────────────┘

     (10 Digits 100) (10 ToBase 100)

┌─┬─────┐ │3│1 0 0│ └─┴─────┘

</source>

Works in: Dyalog APL

Properties

By definition, logarithm is the inverse of the power with the same base (left argument).

<syntaxhighlight lang=apl>

     2*1 2 3 4 5

2 4 8 16 32

     2⍟2 4 8 16 32

1 2 3 4 5

     2 (*⍣¯1 ≡ ⍟) ⍳10

1

</source>

Works in: Dyalog APL

Reciprocal on the left or right argument gives the negated result.

<syntaxhighlight lang=apl>

     2⍟÷2 4 8 16 32

¯1 ¯2 ¯3 ¯4 ¯5

     (÷2)⍟2 4 8 16 32

¯1 ¯2 ¯3 ¯4 ¯5 </source>

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