This commit is contained in:
Miloslav Ciz 2025-04-02 17:51:15 +02:00
parent 2275f9c44d
commit 490ffab10e
10 changed files with 2008 additions and 1962 deletions

44
log.md
View file

@ -2,19 +2,19 @@
*For computer logs see [logging](logging.md).*
Logarithm (from Greek "logo arithmos", roughly "ratio/word number", often shortened to *log*, *lg* or *ln*) is a very important [mathematical](math.md) [function](function.md) telling us to what [power](power.md) a [number](number.md) has to be raised to in order to obtain another number; i.e. in terms of mathematics it is the inverse function to exponentiation. Logarithms are enormously important and useful: for example they allow fast and efficient multiplication and division of numbers (see e.g. [sliding rule](sliding_rule.md)), solving certain kinds of equations but also, very notably, they introduce **logarithmic scales** -- a type of alternative measuring scales (to the traditional linear scales found on rulers etc.) in which steps are not spaced by constant distance but by constant ratio, and it turns out this is exceptionally handy for measuring and plotting various values (such as loudness, earthquake intensity etc.). This is because in nature it often happens that the step to "the next level" is not an additive constant, but rather some ratio of previous step (or imagine a video [game](game.md) where leveling up each subsequent level takes more and more experience, let's say three halves of that required for the previous one). So dealing with logarithms sort of takes us from the realm of additions and differences to one where multiplications and ratios rule.
Logarithm (from Greek "logo arithmos", roughly "ratio/word number", often shortened to *log*, *lg* or *ln*) is a very important [mathematical](math.md) [function](function.md) telling us to what [power](power.md) a [number](number.md) has to be raised to in order to obtain another number; i.e. in the language of mathematics it is the inverse function to exponentiation. Logarithms are enormously important and useful: for example they allow fast and efficient multiplication and division of numbers (see e.g. [sliding rule](sliding_rule.md)), solving certain kinds of equations but also, very notably, they introduce **logarithmic scales** -- a type of alternative measuring scales (to the traditional linear scales found on rulers etc.) in which steps are not spaced by constant distance but by constant ratio, and it turns out this is exceptionally handy for measuring and plotting various values (such as loudness, earthquake intensity etc.). This is because in nature it often happens that the step to "the next level" is not an additive constant, but rather some ratio of previous step (or imagine a video [game](game.md) where leveling up each subsequent level takes more and more experience, let's say three halves of that required for the previous one). So dealing with logarithms sort of takes us from the realm of additions and differences to one where multiplications and ratios rule.
Human senses are known to perceive logarithmically (and this is exploited in lossy [compression](compression.md) algorithms) -- one of the best examples are musical tones: what we hear as an increase in pitch by one semitone is actually a frequency that's 12th root of 2 TIMES increased frequency of the previous one. [Interestingly](interesting.md) some studies even suggested that "logarithmic thinking" is possibly even more natural to us and only at school we're forced to adopt the traditional "linear thinking". However it might be, the first confrontation (normally during high school) with the mathematics of logarithms usually scares people off and average [IQs](iq.md) never fully grasp them (because they "don't need it [in real life](irl.md)"), but they're really not hard, just require some getting used to. To anyone dealing with math in any way (including [programmers](programming.md)) logarithms are absolutely required basic knowledge, don't try to avoid them.
Human senses are known to perceive logarithmically (and this is exploited in lossy [compression](compression.md) algorithms) -- one of the best examples are [musical](music.md) tones: what we hear as an increase in pitch by one semitone is actually a frequency that's 12th root of 2 TIMES increased frequency of the previous one. [Interestingly](interesting.md) some studies even suggested that "logarithmic thinking" is possibly more natural to our brains and only at school we're forced to adopt the traditional "linear thinking". However it might be, the first confrontation (normally during high school) with the mathematics of logarithms usually scares people off and average [IQs](iq.md) never fully grasp them (because they "don't need it [in real life](irl.md)"), but they're really not hard, just require some getting used to. To anyone dealing with math in any way (including [programmers](programming.md)) logarithms are absolutely required basic knowledge, don't try to avoid them.
Logarithms were introduced in 1614 by John Napier (white male).
## Details
There are different kinds of logarithms distinguished by their **base**: every logarithm has a base, so we have a "base 10 logarithm", "base 2 logarithm" etc. (one note here: *base* in this context does NOT signify the numeral system base, it's just a name for the number that gets raised to some power). The base is written as a subscript; here we'll write base *N* logarithm simply as *logN* (log10, log2 etc.). You may see logarithm written without the base, which either means some [implicit](implicit.md) base is assumed (often 10 or [e](e.md), see below) or that the base doesn't matter.
Different kinds of logarithms exist, distinguished by their **base**: every logarithm has a base, so we talk about "base 10 logarithm", "base 2 logarithm" etc. (note: *base* in this context does NOT signify the numeral system base, it's just a name for the number that gets raised to some power). The base is written as a subscript; here we'll write base *N* logarithm simply as *logN* (log10, log2 etc.). You may see logarithm written without the base, which either means some [implicit](implicit.md) base is assumed (often 10 or [e](e.md), see below) or that the base doesn't matter.
So logarithm is not a single function but rather a class of functions. Alternatively you MAY imagine logarithm as a single function of two arguments: the input number *x* and the base. However conventionally we prefer to view logarithms with different bases as different functions of one argument, perhaps because it rarely happens we need the base to be variable (quite often the base doesn't even matter and it's only a convention of choosing one).
Logarithm is thus not a single function but rather a class of functions. Alternatively you MAY imagine logarithm as a single function of two arguments: the input number *x* and the base. However conventionally we prefer to view logarithms with different bases as different functions of one argument, perhaps because it rarely happens we need the base to be variable (quite often the base doesn't even matter and it's only a convention of choosing one), and fewer variables means more [simplicity](kiss.md), which is always a positive.
Now finally for the **definition** itself: base *N* logarithm of number *x* gives number *y*, which we write as
Now finally for the proper **definition**: base *N* logarithm of number *x* gives number *y*, which we write as
*logN(x) = y*
@ -22,7 +22,7 @@ so that the following holds:
*N^y = x*
NOTE: Don't confuse the function *N^x* with *x^N* (variable in exponent vs variable in base); inverse function of the former is logarithm *N* whereas the inverse of the latter is *Nth [root](root.md)*. These are similar and even the graphs of logarithm and Nth root look similar, but they aren't the same.
NOTE: Please don't confuse the function *N^x* with *x^N* (variable in exponent vs variable in base); inverse function of the former is logarithm *N* whereas the inverse of the latter is *Nth [root](root.md)*. These are similar and even the graphs of logarithm and Nth root look similar, but they aren't the same.
So answering the question "What's the base *N* logarithm of number x?" means answering **"N to WHAT power gives x?"**. Of course we know that both *N* and *y* don't have to be just integers, but can be any [real number](real_number.md) (including fractions, negative numbers etc., however excluding both being zero!), so logarithm is a **continuous function**, but we also know that (in the realm or real numbers) the operation of raising anything to a power can't ever yield a negative number (and neither [zero](zero.md), unless the base itself was zero), so **logarithm is only defined for positive numbers**.
@ -111,6 +111,38 @@ Other important formulas with logarithms include these:
To get back to the **logarithmic scales** for a moment: these are scales whose value at each step increases not by a constant added number, but by multiplying the value of the previous step by some fixed fraction. In graphs such scale may be used on the *x* or *y* axis or both, depending on the need -- imagine for instance we were about to plot some exponentially increasing phenomenon, i.e. something that over each period of time (such as a year) grows by some fixed PERCENTAGE (fraction). Example may be the [Moore's law](moores_law.md) stating that the number of [transistors](transistor.md) in integrated circuits doubles every two years. Plotting this with linear scales we'll see a curve that very quickly shoots up, turning steeper and steeper, creating a very inconvenient, hard to read graph. If instead we used logarithmic scale on the *y* axis (number of transistors), we'd get a nice straight line! This is because now as we're moving by years on the *x* axis, we are jumping by orders of magnitude on the *y* axis, and since that is logarithmic, a jump by order of magnitude shift us a constant step up. This is therefore very useful for handling phenomena that "up closer" need higher resolution and "further away" rather need more more space and bigger "zoom out" on detriment of resolution, such as the map of our Universe perhaps.
```
| | 2^x / | / 2^x
5 + | _/ x 16 + _/
| | / | /
4 + | _/ 8 + _/ __
| / / | / _--'''
3 + | _/ _--''' 4 + _/ _--'' x
| / / _--'' log2(x) | / _-'' _____
2 + | _/ _-'' 2 + _/ _-' __---''''
| / / _-' |/ _' _--' log2(x)
1 +'_/ _' 1 + / _/
|/ / : '
--+--+--+--+--+--+--+--+--+- ..+--+--+--+--+--+--+--+-
0 | 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8
| 2^x | | / | | 2^x /
5 + | | x _/ 16 + | _/ x
| | | / | / /
4 + / | _/ log2(x) 8 + | _/
| | / / | / / ___
3 + | | _/ 4 + | _/ __---'''
| / / / | _/ / _.' log2(x)
2 + | | _/ 2 + / _/ _.'
| / / / | / /
1 +' .'_/ 1 + _/ _/
: ' / :/ /
..+--+--+--+--+--+--+--+- ..+--+--+--+--+--+--+--+-
1 2 4 8 16 32 64 128 1 2 4 8 16 32 64 128
```
*Graphs of functions 2^x, x and log2(x) with various combinations of linear and logarithmic (base 2) scales on x and y axes: linear, logarithmic y, logarithmic x and both logarithmic (log-log). Notice how one of the curves is always "straightened".*
## Programming And Approximations
It won't come as a surprise that we'll find the logarithm function built in most of the popular [programming_languages](programming_language.md), most often present as part of the standard math [library](library.md)/module. Make sure to check which base it uses etc. [C](c.md) for example has the functions *log(x)* (natural logarithm), *log10(x)* and *log2(x)* under *math.h* -- if you need logarithm with different base, the simple formula given somewhere above will serve you to convert between arbitrary bases (also shown in an example below).