Which is larger, $e^\pi$ or $\pi ^ e$?
Some people claim that this is the problem 22 of the Math test of the 2014 College Entrance Exam Math in Hubei Province, China. This is not true, the actual probem 22 in that exam is a lot more difficult than this one, but we will discuss that problem later in this article. For now, let us focus on solving this simpler problem.
Let's first use the Python way to get the numerical solution, and we will see that $e^\pi$ is slightly larger.
import math
a = math.e ** math.pi
b = math.pi ** math.e
a, b
(23.140692632779263, 22.45915771836104)
The standard way to solve the problem is to re-write it:
$e^\pi \Leftrightarrow \pi^e$
$log(e^\pi) \Leftrightarrow log(\pi)$
$\frac{log(e)}{e} \Leftrightarrow \frac{log(\pi)}{\pi}$
So we only need to consider the function $f(x)=\frac{log(x)}{x}$
$f'(x) = \frac{x * 1/x - log(x)}{x^2} = \frac{1-log(x)}{x^2}$
The function is greater than zero from $x=0$ until $x=e$,and then less than zero afterwards; since $\pi>e$, $f(\pi)<f(e)$, so $e^\pi > \pi^e$
we can also use a plot function to show how the value of $y$ changes with respect to $x$, you can see that the maximum point is reached around e=2.718
from matplotlib import pyplot as plt
import numpy as np
import math
x = np.arange(1, 5, 0.1)
#print ("x array is:", x)
y=np.zeros(len(x))
for i in range(0, len(x), 1):
y[i] = math.log(x[i]) / x[i]
#print ("y array is:", y)
plt.plot(x,y, 'ro')
plt.axvline(x=math.e, c='b')
plt.show()
Incredibly, I found that somebody actually published a scientific manuscript to prove this equation The Mathematical Intelligencer volume 42, page74(2020).
I confess that this is likely the shortest scientific paper that I have ever read.
I reproduce the content of the paper below.
from matplotlib import pyplot as plt
import numpy as np
import math
x = np.arange(-1, 4, 0.1)
#print ("x array is:", x)
y=np.zeros(len(x))
for i in range(0, len(x), 1):
y[i] = math.e ** x[i] / math.e - 1
#print ("y array is:", y)
plt.plot(x,y)
plt.axvline(x=0, c='black')
plt.axhline(y=0, c='black')
plt.fill_between(x[20:40],y[20:40], color="grey")
plt.xlabel("X axis")
plt.ylabel("Y axis")
plt.xticks([1,2.9], ["1", "A/e"])
plt.legend(["y=e^x/e-1"])
plt.show()
Theorem: For all real numbers $A$ with $e<A$, $e^A > A^e$.
Based on the figure above, we know the area of the shade is greater than zero. Therefore,
$0 < \int\limits_1^{A/e} \big(\frac{e^x}{e}-1\big)dx = \frac{e^{A/e}}{e} - \frac{A}{e} \implies A < e^{A/e} \implies A^e < e^A$
While reading references of this paper, I found another visual proof published in the same journal available at here. Frankly I love this proof. This is absolutely amazing and this is truly a demonstration that "a picture is worth a thousand words".
I reproduce this proof below:
from matplotlib import pyplot as plt
import numpy as np
import math
x = np.arange(0.5, 5, 0.1)
#print ("x array is:", x)
y=np.zeros(len(x))
for i in range(0, len(x), 1):
y[i] = 1/x[i]
#print ("y array is:", y)
plt.plot(x,y)
plt.axvline(x=0, c='black')
plt.axhline(y=0, c='black')
plt.fill_between(x[22:27],y[22:27], color="grey")
plt.xlabel("X axis")
plt.ylabel("Y axis")
plt.xticks([2.7, 3.1], ["$e$", "$\pi$"])
plt.legend(["y=1/x"])
plt.plot([2.7, 3.1], [1/2.7, 1/2.7], [2.7, 2.7], [0, 1/2.7], [3.1, 3.1], [0, 1/2.7])
plt.show()
See above figure, the shaded area (integral of the function $y=1/x$ from $e$ to $\pi$) is less than the square area (length=$\pi-e$, height=$1/e$), so we have
$ln\pi - 1 = \int\limits_e^\pi \frac{dx}{x} < \frac{1}{e}(\pi-e) = \frac{\pi}{e}-1$
Therefore, $e^\pi > \pi^e$.
An alternative way is to use Tayler series. The Taylor series of a real or complex-valued function $f(x)$ that is infinitely differentiable at a real or complex number $a$ is the power series
$f(x) = \displaystyle\sum_{i=0}^{\infty} \frac{f^{(n)}(a)}{n!} (x-a)^n$
Given the $e^x$ form that can be easily expanded:
$e^{(\pi/e-1)} = \displaystyle\sum_{i=0}^{\infty} \frac{(\pi/e-1)^i}{j!} > 1 + (\frac{\pi}{e}-1) = \pi/e$
so $e^{\pi/e} > \pi$, so $e^\pi > \pi^e$
Remember that this question could be in a college entrance exam for high school students. They do not know Tayler series, they do not have access to a calculator and they cannot do any programming during the exam. They can only use high school knowledge.
There is a famous equation in middle/high school that $log(1+x)<x$, and $log(1+x) \approx x$ when $x \approx 0$.
We put $x = \pi/e-1$ into the equation above:
$log(1+\pi/e-1) < \pi/e-1$
$1 + \pi/e - 1 < e^{\pi/e-1}$
$\pi/e < e^{\pi/e-1}$
$\pi < e^{\pi/e}$
$\pi^e < e^\pi$
In case you are wondering (if you did not remember that you learned this equation in high school), note that the $log(1+x)<x$ can be easily proved by Taylor series as well:
$log(1+x) = \displaystyle\sum_{i=1}^{\infty} (-1)^{n+1} \frac{x^n}{n} \leq (-1)^{1+1} \frac{x^1}{1} = x$
Before we proceed further, we should create a more generalized form of the theorem above. We use $log()$ as the natural logarithm, and use $log_a()$ as the logarithm with base $a$ ($a$ is a positive real number, $a \in \mathbb{R} \mid a>0$).
Consider the function $f(x)=\frac{log_a(x)}{x}$
$f'(x) = \frac{1/log(a) - log_a(x)}{x^2} = \frac{1 - log(x)}{log(a)x^2}$
So regardless of the base of the logarithm, the maximum value is reached when $x=e$. I know this may be somewhat counter-intuitive for some readers, who may think the maximum is reached when $x=a$, but this is not the case.
Now consider $b \in \mathbb{R} \mid b>0$, try find a way to split b into several numbers $a_1$, $a_2$, ..., $a_i$ (that is, $b = \sum_{j=1}^i a_j$), such that the product of $a_1$, $a_2$, ..., $a_i$ is maximized.
The solution is to find an integer $i$, where $| b/i - e|$ is minimized. In practice, you can calculate $b/e$ first, and then try the two integers that encloses $b/e$, to find the solution.
This is an extraordinarily important theorem. It essentially tells people how to allocate resources to maximize throughput of products, by allocating $e$ to each portion. I have a strong suspicion that it has many practical implications in modern economics and law and logistics and other areas, but I do not know whether anybody actually uses it or is even aware of it.
This theorem also has important implications in simple math settings. In particular, whenever you have two numbers $c$ and $d$, then $c^d > d^c$ if $c$ is close to $e$ than $d$.
As I mentioned earlier, the actual probelm 22 in the exam is slightly more difficult than what is described above.
I found the actual question from Zhihu, it has three sub-questions. The first two are addressed here, and the third one is addressed here.
If you do not understand Chinese, I translate them below:
Suppose $\pi$ is the the ratio of a circle's circumference to its diameter, and $e=2.71828...$ is the base of the natural logarithm.
I should mention that the natural logarithm is strictly written as $ln()$ in China, which I think it is far less confusing than $log()$ which is written in US sometimes but also $ln()$ in other times. Nevertheless, I will use $log()$ in my description below for natural logarithm to help English readers.
The sub-problem 2 is somewhat self-evident, if we split them into 3 pairwise comparisons. We can immediately see that the max is $3^\pi$ and mim is $3^e$.
The key challenge is sub-problem 3: we now know that $3^\pi > \pi^3 > \pi^e$ (equation 1) and $e^\pi > e^3 > 3^e$ (equation 2). We need to determine where $\pi^e$ ranks in equation 2, and where $e^\pi$ ranks in equation 1.
Obviously we want to compare it to $e^3$, and this determines its ranking in equation 2. Let's first use the Python way to do this:
#The Python way of doing this
a = math.pi ** math.e
b = math.e ** 3
a, b
(22.45915771836104, 20.085536923187664)
Without programming, again we need to hand calculate the difference of $\pi^e$ and $e^3$.
This is equivalent to calculate the numerical value of $log(\pi)$ by hand, and we want to compare it to $3/e=1.104$
The method in Zhihu is actually quite neat, after trying a few different ways, the teacher thinks it most reasonable to tackle $x=e^2/\pi$ using the $log(x)/x<1/e$ formula (because we want to find a value that is close to e, and $e^2/\pi$ is reasonably close to e to be a good candidate of the calculation).
Given $x=e^2/\pi$, we have $log(e^2/\pi)/(e^2/\pi)<1/e$, which turns into $log(\pi)>2-3/\pi=1.135>1.104 \approx 3/e$. So we can place $\pi^e$ before $e^3$ in equation 2.
Obvious we want to compare it with $\pi^3$. Given $3*log(\pi) \approx 3.405 > 3.142 \approx \pi$, we can place it smaller than $\pi^3$.
The final solution to sub-problem 3 is $3^\pi > \pi^3 > e^\pi > \pi^e > e^3 > 3^3$. Cheers! And I applaud the Zhihu teacher 雪地叹息瓶.
I came across this issue in a completely different context. There is another problem to compare $\pi-2$ and $log(\pi)$. This is a very difficult problem.
Again let's first use the Python way of finding solutions:
import math
a = math.pi-2
b = math.log(math.pi)
a, b
(1.1415926535897931, 1.1447298858494002)
We can see that these two numbers are incredibly close to each other. Hand calculation to solve this problem is therefore quite difficult.
To calculate $log(\pi)$, we can also use another famous equation $log(x) \geq \frac{2(x-1)}{x+1}$. This famous equation is taught in high school, and can be proved by differentiating $f(x) = log(x) - \frac{2(x-1)}{x+1}$.
We treat $x=\pi/e$, then $log\frac{\pi}{e} > \frac{2(\pi-e)}{\pi+e}$. Now just put in 3.1416 and 2.7183 into the equation, do some hand calculation, then we can find that $log\frac{\pi}{e} > 0.1447$, so $log(\pi) > 1.1447$. So $3 \times log(\pi) \approx 3.4341 > \pi$. Note that we used $x=\pi/e$ rather than $x=\pi$ because the former is closer to 1 to minimize scaling error in calculation.
Now, let us take a moment to address the problem to compare $\pi-2$ and $log(\pi)$ using a visual solution. We construct $f(x)=log(x)-x+2$, and plot its values:
from matplotlib import pyplot as plt
import numpy as np
import math
x = np.arange(0.1, 5, 0.01)
#print ("x array is:", x)
y=np.zeros(len(x))
for i in range(0, len(x), 1):
y[i] = math.log(x[i])-x[i]+2
#print ("y array is:", y)
plt.plot(x,y)
plt.axvline(x=0, c='black')
plt.axvline(x=math.pi, c='red')
plt.axhline(y=0, c='black')
plt.xlabel("X axis")
plt.ylabel("Y axis")
plt.xticks([3.1416], ["pi"])
plt.legend(["y=log(x)-x+2"])
plt.show()
How amazing!!! The red line almost exactly cross the zero point when $x=\pi$! We will have to zoom into the region to see more information:
from matplotlib import pyplot as plt
import numpy as np
import math
x = np.arange(3.1, 3.2, 0.01)
#print ("x array is:", x)
y=np.zeros(len(x))
for i in range(0, len(x), 1):
y[i] = math.log(x[i])-x[i]+2
#print ("y array is:", y)
plt.plot(x,y, c='orange')
plt.axhline(y=0, c='blue')
plt.axvline(x=math.pi, c='red')
#plt.xlabel("X axis")
#plt.ylabel("Y axis")
#plt.xticks(list(plt.xticks()[0])+[3.1416])
plt.xticks([3.11, 3.13, 3.1416, 3.15, 3.17, 3.19], [3.11, 3.13, '$\pi$', 3.15, 3.17, 3.19])
#plt.xticks([3.1416], ["pi"])
plt.legend(["$y=log(x)-x+2$", "$y=0$", "$x=\pi$"])
plt.show()
Finally it is clear that the value is greater than zero when $x=\pi$!
Next we describe an alternative way to solve it by comparing two functions.
#an alternative way is to directly compare two functions y=ln(x) and y=x-2, and see where they intercept (before or after pi)
from matplotlib import pyplot as plt
import numpy as np
import math
x = np.arange(3.1, 3.2, 0.01)
#print ("x array is:", x)
y=np.zeros(len(x))
z=np.zeros(len(x))
for i in range(0, len(x), 1):
y[i] = math.log(x[i])
z[i] = x[i]-2
#print ("y array is:", y)
plt.plot(x,y, c='orange')
plt.plot(x,z, c='blue')
plt.axvline(x=math.pi, c='red')
#plt.xlabel("X axis")
#plt.ylabel("Y axis")
#plt.xticks(list(plt.xticks()[0])+[3.1416])
plt.xticks([3.11, 3.13, 3.1416, 3.15, 3.17, 3.19], [3.11, 3.13, '$\pi$', 3.15, 3.17, 3.19])
#plt.xticks([3.1416], ["pi"])
plt.legend(["$y=log(x)$", "$y=x-2$", "$x=\pi$"])
plt.show()