The value of `2^n` and `2.0^n` is different in `Julia`. The former remains an integer and is subject to integer overflow for `n > 62`. As used above, `2^(n/6)` will not overflow for larger `n`, as when the exponent is a floating point value, the base is promoted to a floating point value.
The famous [Fibonacci](https://en.wikipedia.org/wiki/Fibonacci_number)
numbers are $1,1,2,3,5,8,13,\dots$, where $F_{n+1}=F_n+F_{n-1}$. These numbers increase. To see how fast, if we *guess* that
the growth is eventually exponential and assume $F_n \approx c \cdot a^n$, then
our equation is approximately $ca^{n+1} = ca^n + ca^{n-1}$. Factoring out common terms gives ``ca^{n-1} \cdot (a^2 - a - 1) = 0``. The term ``a^{n-1}`` is always positive, so any solution would satisfy $a^2 - a -1 = 0$. The positve solution is
$(1 + \sqrt{5})/2 \approx 1.618$
That is evidence that the $F_n \approx c\cdot 1.618^n$. (See
[Relation to golden ratio](https://en.wikipedia.org/wiki/Fibonacci_number#Relation_to_the_golden_ratio)
for a related, but more explicit exact formula.
##### Example
In the previous example, the exponential family of functions is used
to describe growth. Polynomial functions also increase. Could these be
used instead? If so that would be great, as they are easier to reason
about.
The key fact is that exponential growth is much greater than
polynomial growth. That is for large enough $x$ and for any fixed
$a>1$ and positive integer $n$ it is true that $a^x \gg x^n$.
Later we will see an easy way to certify this statement.
##### The mathematical constant ``e``
Euler's number, ``e``, may be defined several ways. One way is to
define ``e^x`` by the limit ``(1+x/n)^n``. Then ``e=e^1``. The value
is an irrational number. This number turns up to be the natural base
to use for many problems arising in Calculus. In `Julia` there are a
few mathematical constants that get special treatment, so that when
needed, extra precision is available. The value `e` is not immediately
assigned to this value, rather `ℯ` is. This is typed
`\euler[tab]`. The label `e` is thought too important for other uses
to reserve the name for representing a single number. However, users
can issue the command `using Base.MathConstants` and `e` will be
available to represent this number. When the `CalculusWithJulia`
package is loaded, the value `e` is defined to be the floating point
number returned by `exp(1)`. This loses the feature of arbitrary
precision, but has other advantages.
A [cute](https://www.mathsisfun.com/numbers/e-eulers-number.html) appearance of ``e`` is in this problem: Let ``a>0``. Cut ``a`` into ``n`` equal pieces and then multiply them. What ``n`` will produce the largest value? Note that the formula is ``(a/n)^n`` for a given ``a`` and ``n``.
Suppose ``a=5`` then for ``n=1,2,3`` we get:
```julia; hold=true;
a = 5
(a/1)^1, (a/2)^2, (a/3)^3
```
We'd need to compare more, but at this point ``n=2`` is the winner when ``a=5``.
With calculus, we will be able to see that the function ``f(x) = (a/x)^x`` will be maximized at ``a/e``, but for now we approach this in an exploratory manner. Suppose ``a=5``, then we have:
We can see more clearly that ``n=2`` is the largest value for ``f`` and ``a/2`` is the closest value to ``e``. This would be the case for any ``a>0``, pick ``n`` so that ``a/n`` is closest to ``e``.
##### Example: The limits to growth
The ``1972`` book [The limits to growth](https://donellameadows.org/wp-content/userfiles/Limits-to-Growth-digital-scan-version.pdf) by Meadows et. al. discusses the implications of exponential growth. It begins stating their conclusion (emphasis added): "If the present *growth* trends in world population, industrialization, pollution, food production, and resource depletion continue *unchanged*, the limits to growth on this planet will be reached sometime in the next *one hundred* years." They note it is possible to alter these growth trends. We are now half way into this time period.
Let's consider one of their examples, the concentration of carbon dioxide in the atmosphere. In their Figure ``15`` they show data from ``1860`` onward of CO``_2`` concentration extrapolated out to the year ``2000``. At [climate.gov](https://www.climate.gov/news-features/understanding-climate/climate-change-atmospheric-carbon-dioxide) we can see actual measurements from ``1960`` to ``2020``. Numbers from each graph are read from the graphs, and plotted in the code below:
(The `unzip` function is from the `CalculusWithJulia` package and will be explained in a subsequent section.) We can see that the projections from the year ``1970`` hold up fairly well
On this plot we added two *exponential* models. at ``1960`` we added a *roughly* ``0.2`` percent per year growth (a rate mentioned in an accompanying caption) and at ``2000`` a roughly ``0.5`` percent per year growth. The former barely keeping up with the data.
The word **roughly** above could be made exact. Suppose we knew that between ``1960`` and ``1970`` the rate went from ``313`` to ``320``. If this followed an exponential model, then ``r`` above would satisfy:
```math
P_{1970} = P_{1960} e^{r * (1970 - 1960)}
```
or on division ``320/313 = e^{r\cdot 10}``. Solving for ``r`` can be done -- as explained next -- and yields ``0.002211\dots``.
## Logarithmic functions
As the exponential functions are strictly *decreasing* when $0 < a <
1$ and strictly *increasing* when $a>1,$ in both cases an inverse
function will exist. (When $a=1$ the function is a constant and is not
one-to-one.) The domain of an exponential function is all real $x$ and
the range is all *positive* $x$, so these are switched around for the
inverse function. Explicitly: the inverse function to ``f(x)=a^x`` will have domain ``(0,\infty)`` and range ``(-\infty, \infty)`` when ``a > 0, a \neq 1``.
The inverse function will solve for $x$ in the equation $a^x = y$. The
answer, formally, is the logarithm base $a$, written $\log_a(x)$.
That is $a^{\log_a(x)} = x$ for ``x > 0`` and $\log_a(a^x) = x$ for all ``x``.
To see how a logarithm is mathematically defined will have to wait,
though the family of functions - one for each $a>0$ - are implemented in `Julia` through the function
`log(a,x)`. There are special cases requiring just one argument: `log(x)` will compute the natural
log, base $e$ - the inverse of $f(x) = e^x$; `log2(x)` will compute the
log base $2$ - the inverse of $f(x) = 2^x$; and `log10(x)` will compute
the log base $10$ - the inverse of $f(x)=10^x$. (Also `log1p` computes an accurate value of ``\log(1 + p)`` when ``p \approx 0``.)
To see this in an example, we plot for base $2$ the exponential
function $f(x)=2^x$, its inverse, and the logarithm function with base
Though we made three graphs, only two are seen, as the graph of `log2`
matches that of the inverse function.
Note that we needed a bit of care to plot the inverse function
directly, as the domain of $f$ is *not* the domain of $f^{-1}$. Again, in
this case the domain of $f$ is all $x$, but the domain of $f^{-1}$ is only all *positive* $x$ values.
Knowing that `log2` implements an inverse function allows us to solve
many problems involving doubling.
##### Example
An [old](https://en.wikipedia.org/wiki/Wheat_and_chessboard_problem) story about doubling is couched in terms of doubling grains of wheat. To simplify the story, suppose each day an amount of grain is doubled. How many days of doubling will it take ``1`` grain to become ``1`` million grains?
The number of grains after one day is $2$, two days is $4$, three days
is $8$ and so after $n$ days the number of grains is $2^n$. To answer
the question, we need to solve $2^x = 1,000,000$. The logarithm
function yields ``20`` days (after rounding up):
```julia;
log2(1_000_000)
```
##### Example
The half-life of a radioactive material is the time it takes for half the material to decay. Different materials have quite different half lives with some quite long, and others quite short. See [half lives](https://en.wikipedia.org/wiki/List_of_radioactive_isotopes_by_half-life) for some details.
The carbon ``14`` isotope is a naturally occurring isotope on Earth,
appearing in trace amounts. Unlike Carbon ``12`` and ``13`` it decays, in this
case with a half life of ``5730`` years (plus or minus ``40`` years). In a
[technique](https://en.wikipedia.org/wiki/Radiocarbon_dating) due to
Libby, measuring the amount of Carbon 14 present in an organic item
can indicate the time since death. The amount of Carbon ``14`` at death is
essentially that of the atmosphere, and this amount decays over
time. So, for example, if roughly half the carbon ``14`` remains, then the death occurred
about ``5730`` years ago.
A formula for the amount of carbon ``14`` remaining $t$ years after death would be $P(t) = P_0 \cdot 2^{-t/5730}$.
If $1/10$ of the original carbon ``14`` remains, how old is the item? This amounts to solving $2^{-t/5730} = 1/10$. We have: $-t/5730 = \log_2(1/10)$ or:
(Historically) Libby and James Arnold proceeded to test the radiocarbon dating theory by analyzing samples with known ages. For example, two samples taken from the tombs of two Egyptian kings, Zoser and Sneferu, independently dated to ``2625`` BC plus or minus ``75`` years, were dated by radiocarbon measurement to an average of ``2800`` BC plus or minus ``250`` years. These results were published in Science in ``1949``. Within ``11`` years of their announcement, more than ``20`` radiocarbon dating laboratories had been set up worldwide. Source: [Wikipedia](http://tinyurl.com/p5msnh6).
Finally, since $a^x$ is one-to-one (when $a>0$ and $a \neq 1$), if $a^{\log_a(b^x)}=a^{x \log_a(b)}$ it must be that $\log_a(b^x) = x \log_a(b)$. That is, logarithms turn powers into products.
Finally, we use the inverse property of logarithms and powers to show that logarithms can be defined for any base. Say $a, b > 0$. Then $\log_a(x) = \log_b(x)/\log_b(a)$. Again, to verify this we apply $a^x$ to both sides to see we get the same answer:
```math
a^{\log_a(x)} = x,
```
this by the inverse property. Whereas, by expressing $a=b^{\log_b(a)}$ we have: