Skip to content

Log2 ​

The base-2 (binary) logarithm of z.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageLog2✓
Log2(z)the base-2 logarithm of z, log⁡2(z)\log_2(z).
SageMathlog(z, 2)✓SymPylog(z, 2)mpmathlog(z, 2)Juliaenumeratio_ball(_log2, z)Rustlog2(z)
Typed signatures
TypePackageApplies
(number) -> numbercompute-enginealways

Domain: Elementary functions

Details
  • Equivalent to Log(z, 2), and identical to Lb.
  • Folds exactly for an integer power of 2 in either direction -- positive (1024→101024 \to 10) or negative (1/8→−31/8 \to -3).

Plot

Examples

Basic #
live ↗
Inlog⁡2(8)\log_{2}(8)Out33
live ↗
Inlog⁡2(1)\log_{2}(1)Out00
live ↗
Inlog⁡2(1 024)\log_{2}(1\,024)Out1010
live ↗
Inlog⁡2(210)\log_{2}(2^{10})Out1010

A machine-precision argument evaluates numerically

live ↗
Inlog⁡2(1.414 2)\log_{2}(1.414\,2)Out0.499 986 164 421 874 256 4670.499\,986\,164\,421\,874\,256\,467
live ↗
InSeries⁡(log⁡2(x+1),x,0,5)\operatorname{Series}(\log_{2}(x+1), x, 0, 5)Outxln⁡(2)−x22ln⁡(2)+x33ln⁡(2)−x44ln⁡(2)+x55ln⁡(2)+O(x6)\frac{x}{\ln(2)}-\frac{x^2}{2\ln(2)}+\frac{x^3}{3\ln(2)}-\frac{x^4}{4\ln(2)}+\frac{x^5}{5\ln(2)}+O\left(x^6\right)
Scope #

An exact negative power of 2 folds too: log⁡218=−3\log_2 \tfrac18 = -3

live ↗
Inlog⁡2(18)\log_{2}(\frac{1}{8})Out−3-3

A symbolic argument becomes the two-argument Log

live ↗
Inlog⁡2(x)\log_{2}(x)Outlog⁡2(x)\log_{2}(x)

An integer power is pulled out: 2log⁡232\log_2 3

live ↗
Inlog⁡2(9)\log_{2}(9)Out2log⁡2(3)2\log_{2}(3)
live ↗
InN(log⁡2(9))N(\log_{2}(9))Out3.169 925 001 442 312 362 913.169\,925\,001\,442\,312\,362\,91
live ↗
Inlog⁡2(0)\log_{2}(0)Out−∞-∞

As with Ln, the logarithm of complex infinity is +∞+\infty

live ↗
Inlog⁡2(∞~)\log_{2}(\tilde∞)Out∞∞

Element-wise over a matrix, including the exact 12\tfrac12 entry

live ↗
Inlog⁡2([[2,1],[0,12]])\log_{2}(\bigl\lbrack\bigl\lbrack2, 1\bigr\rbrack, \bigl\lbrack0, \frac{1}{2}\bigr\rbrack\bigr\rbrack)Out[[1,0],[−∞,−1]]\bigl\lbrack\bigl\lbrack1, 0\bigr\rbrack, \bigl\lbrack-∞, -1\bigr\rbrack\bigr\rbrack

Interval arithmetic: log⁡2[13,2]=[log⁡213,1]\log_2[\tfrac13, 2] = [\log_2 \tfrac13, 1]

live ↗
Inlog⁡2(Interval(13,2))\log_{2}(\mathrm{Interval}(\frac{1}{3}, 2))OutInterval(log⁡2(13),1)\mathrm{Interval}(\log_{2}(\frac{1}{3}), 1)

Uncertainty propagation, to first order: log⁡2(15±0.01)≈−2.322±0.072\log_2(\tfrac15 \pm 0.01) \approx -2.322 \pm 0.072

live ↗
Inlog⁡2(Around(15,0.01))\log_{2}(\mathrm{Around}(\frac{1}{5}, 0.01))OutAround(−2.321 928 094 887 362,0.072 134 752 044 448 18)\mathrm{Around}(-2.321\,928\,094\,887\,362, 0.072\,134\,752\,044\,448\,18)

Derivative: 1xln⁡2\frac{1}{x\ln 2}

live ↗
Indlog⁡2(x)dx\frac{\mathrm{d}\log_{2}(x)}{\mathrm{d}x}Out1xln⁡(2)\frac{1}{x\ln(2)}

To 30 significant digits, every one correctly rounded

live ↗
InN(log⁡2(3),30)N(\log_{2}(3), 30)Out1.584 962 500 721 156 181 453 738 943 951.584\,962\,500\,721\,156\,181\,453\,738\,943\,95

A 100-digit logarithm in base 2

live ↗
InN(log⁡2(45),100)N(\log_{2}(45), 100)Out5.491 853 096 329 674 710 777 797 317 385 023 193 384 460 208 409 542 732 966 261 704 898 131 232 197 342 340 894 700 693 195 546 6395.491\,853\,096\,329\,674\,710\,777\,797\,317\,385\,023\,193\,384\,460\,208\,409\,542\,732\,966\,261\,704\,898\,131\,232\,197\,342\,340\,894\,700\,693\,195\,546\,639

A complex argument in base 2

live ↗
InN(log⁡2(2+i))N(\log_{2}(2+i))Out1.160 964 047 443 681+0.668 902 106 225 488 1i1.160\,964\,047\,443\,681+0.668\,902\,106\,225\,488\,1i

A matrix function with exact eigenvalues 1 and −1-1, since log⁡212=−1\log_2\frac12=-1

live ↗
InFullSimplify(MatrixFunction(Log2,[[2,1],[0,1/2]]))\mathrm{FullSimplify}(\mathrm{MatrixFunction}(\mathrm{Log2}, \bigl\lbrack\bigl\lbrack2, 1\bigr\rbrack, \bigl\lbrack0, 1/2\bigr\rbrack\bigr\rbrack))Out[[1,43],[0,−1]]\bigl\lbrack\bigl\lbrack1, \frac{4}{3}\bigr\rbrack, \bigl\lbrack0, -1\bigr\rbrack\bigr\rbrack

log⁡2∞=∞\log_2\infty=\infty

live ↗
Inlog⁡2(∞)\log_{2}(∞)Out∞∞
Applications #

A float argument folds even for a fractional power of 2

live ↗
Inlog⁡2(0.5)\log_{2}(0.5)Out−1.0-1.0
Properties #

Same as Log(z, 2)

live ↗
Inlog⁡2(8)=log⁡2(8)\log_{2}(8)=\log_{2}(8)OutTrue\mathrm{True}
About
Examples23
Checked againstWolfram Language 23 agreeSageMath 20 agreeSymPy 19 agree3 differmpmath 16 agreeJulia 13 agree3 errorRust 12 agree2 error
CrosswalkWolfram LanguageSageMathSymPympmathJuliaRust

Implementation

mappedsympypackages/oracle/src/mappings.ts
mappedmpmathpackages/oracle/src/mappings.ts
mappedsagepackages/oracle/src/mappings.ts
mappedjuliapackages/oracle/src/mappings.ts
mappedrustpackages/oracle/src/mappings.ts

See also: Log, Log10, Lb