Logarithm: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
No edit summary
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
:''This page describes the dyadic arithmetic function. For the monadic natural logarithm function, see [[Natural Logarithm]].''
:''This page describes the dyadic arithmetic function. For the monadic natural logarithm function, see [[Natural Logarithm]].''


{{Built-in|Logarithm|⍟}}, or '''Log''', is a [[dyadic]] [[scalar function]] which computes the [[wikipedia:logarithm|logarithm]] of the two [[argument|arguments]]. More precisely, <source lang=apl inline>X⍟Y</source> computes how much [[power]] of X equals Y, i.e. the value of R that satisfies <source lang=apl inline>Y=X*R</source>. Logarithm shares the [[glyph]] <source lang=apl inline>⍟</source> with the monadic arithmetic function [[Natural Logarithm]]. The [[glyph]], a composition of the glyphs for [[Circular]] (<source lang=apl inline>○</source>) and [[Power]] (<source lang=apl inline>*</source>) to indicate its close mathematical ties with these two functions, is a stylised tree log.
{{Built-in|Logarithm|⍟}}, or '''Log''', is a [[dyadic]] [[scalar function]] which computes the [[wikipedia:logarithm|logarithm]] of the two [[argument|arguments]]. More precisely, <syntaxhighlight lang=apl inline>X⍟Y</syntaxhighlight> computes how much [[power]] of X equals Y, i.e. the value of R that satisfies <syntaxhighlight lang=apl inline>Y=X*R</syntaxhighlight>. Logarithm shares the [[glyph]] <syntaxhighlight lang=apl inline>⍟</syntaxhighlight> with the monadic arithmetic function [[Natural Logarithm]]. The [[glyph]], a composition of the glyphs for [[Circular]] (<syntaxhighlight lang=apl inline>○</syntaxhighlight>) and [[Power]] (<syntaxhighlight lang=apl inline>*</syntaxhighlight>) to indicate its close mathematical ties with these two functions, is a stylised tree log.<ref>[[E. E. McDonnell|McDonnell, E. E.]]. [https://www.jsoftware.com/papers/eem/storyofo.htm Recreational APL: The Story of <syntaxhighlight lang=apl inline>○</syntaxhighlight>]. [[APL Quote-Quad]], Volume 8, Number 2, 1977-12.</ref>


== Examples ==
== Examples ==


<source lang=apl>
<syntaxhighlight lang=apl>
       2⍟0.5 1 2 32 1024
       2⍟0.5 1 2 32 1024
¯1 0 1 5 10
¯1 0 1 5 10
</source>
</syntaxhighlight>


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


<source lang=apl>
<syntaxhighlight lang=apl>
       Digits←{1+⌊⍺⍟⍵}
       Digits←{1+⌊⍺⍟⍵}
       ToBase←⊥⍣¯1
       ToBase←⊥⍣¯1
Line 23: Line 23:
│3│1 0 0│
│3│1 0 0│
└─┴─────┘
└─┴─────┘
</source>{{Works in|[[Dyalog APL]]}}
</syntaxhighlight>{{Works in|[[Dyalog APL]]}}


== Properties ==
== Properties ==
Line 29: Line 29:
By definition, logarithm is the [[inverse]] of the [[power]] with the same base (left argument).
By definition, logarithm is the [[inverse]] of the [[power]] with the same base (left argument).


<source lang=apl>
<syntaxhighlight lang=apl>
       2*1 2 3 4 5
       2*1 2 3 4 5
2 4 8 16 32
2 4 8 16 32
Line 36: Line 36:
       2 (*⍣¯1 ≡ ⍟) ⍳10
       2 (*⍣¯1 ≡ ⍟) ⍳10
1
1
</source>{{Works in|[[Dyalog APL]]}}
</syntaxhighlight>{{Works in|[[Dyalog APL]]}}


[[Reciprocal]] on the left or right argument gives the [[negate|negated]] result.
[[Reciprocal]] on the left or right argument gives the [[negate|negated]] result.


<source lang=apl>
<syntaxhighlight lang=apl>
       2⍟÷2 4 8 16 32
       2⍟÷2 4 8 16 32
¯1 ¯2 ¯3 ¯4 ¯5
¯1 ¯2 ¯3 ¯4 ¯5
       (÷2)⍟2 4 8 16 32
       (÷2)⍟2 4 8 16 32
¯1 ¯2 ¯3 ¯4 ¯5
¯1 ¯2 ¯3 ¯4 ¯5
</source>
</syntaxhighlight>
 
== See also ==
* [[Root]]


== External links ==
== External links ==
Line 51: Line 54:
=== Documentation ===
=== Documentation ===


* [http://help.dyalog.com/latest/#Language/Primitive%20Functions/Logarithm.htm Dyalog]
* [https://help.dyalog.com/latest/#Language/Primitive%20Functions/Logarithm.htm Dyalog]
* [http://microapl.com/apl_help/ch_020_020_220.htm APLX]
* [http://microapl.com/apl_help/ch_020_020_220.htm APLX]
* J [https://www.jsoftware.com/help/dictionary/d201.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/hatdot#dyadic NuVoc]
* J [https://www.jsoftware.com/help/dictionary/d201.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/hatdot#dyadic NuVoc]
{{APL built-ins}}[[Category:Primitive functions]][[Category:Scalar dyadic functions]]
 
== References ==
<references/>
{{APL built-ins}}[[Category:Primitive functions]][[Category:Scalar monadic functions]]

Latest revision as of 22:06, 10 September 2022

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, X⍟Y computes how much power of X equals Y, i.e. the value of R that satisfies Y=X*R. Logarithm shares the glyph with the monadic arithmetic function Natural Logarithm. The glyph, a composition of the glyphs for Circular () and Power (*) to indicate its close mathematical ties with these two functions, is a stylised tree log.[1]

Examples

      2⍟0.5 1 2 32 1024
¯1 0 1 5 10

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

      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│
└─┴─────┘
Works in: Dyalog APL

Properties

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

      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
Works in: Dyalog APL

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

      2⍟÷2 4 8 16 32
¯1 ¯2 ¯3 ¯4 ¯5
      (÷2)⍟2 4 8 16 32
¯1 ¯2 ¯3 ¯4 ¯5

See also

External links

Documentation

References

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