Some π-ography for Pi day
julialang.org
julialang.org
1. It's roughly equal to ln(6) ^ (ln(5) ^ (ln(4) ^ (ln(3) ^ ln(2))))
2. It's not exactly hard to figure out whether pi ^ e is greater than e ^ pi (years ago I did it sans calculator on a test in a fast but brutish way), but there are some pretty terse, beautiful solutions that can be elusive.
3. Aside from the whole e^(pi * i) - 1 = 0 just looking too crazy to be true, I also love how it includes the basics tools of mathematics / philosophy. Subtraction (or addition if re-arranged), Multiplication (or division if re-arranged), exponentiation, true / 1, false / 0, equality, geometric ratio (pi) which can be thought of as representing the physical world, a growth ratio (e) which can be though of as representing life, and a number (i) literally name after an aspect of human thought / imagination.
#include "stdio.h"
#include "math.h"
long double ln ( long double n ) {
return log(n) / log(M_E);
}
long double pi ( void ) {
return pow(ln(6), pow(ln(5), pow(ln(4), pow(ln(3), ln(2)))));
}
int main( void ) {
printf("%LE\n", pi());
return 0;
}
Or in JS function ln(n) {
return Math.log(n) / Math.log(Math.E);
}
function pi() {
return (ln(6) ** (ln(5) ** (ln(4) ** (ln(3) ** (ln(2))))));
}
If anybody else wants to toy with it.Getting older and working outside of the fields that employ a lot of certain technicals doesn't leave as much time for exploration as one would like.
Whenever I otherwise work with logarithms in programming I choose to work explicitly to at least save myself confusion. By default I assumed log()/Math.log() referred to common logarithms.
I usually end up re-implementing the log function with 2 values, as with ln/logE above, but substituting the constant.
long double logn( long double n, long double x )
{
return log(x) / log (n);
}
But, yes, all my above code could be shorter.I haven't worked with any explicitly scientific languages like Mathlab— do any languages take a more traditionally mathematical approach? Or any libraries that have taken that torch up?
log(1E42)/log(10) == 42 - 7.105427357601002e-15
log10(1E42) == 42.0Anyway— thanks, I appreciate the insights. That’s the reason I like this forum
I completely and foolishly assumed that when I saw log on its own that it referred to a common logarithm. About 2 seconds on MDN and a math.h reference and I could have known better.
There's another problem, though: the ^ operator requires that the second expression is integer.
Possible ways to fix that:
- Use the "double" type everywhere.
- Use powl() and logl() functions instead.
- Use tgmath.h instead of math.h. (But when I tried this with GCC 7 + glibc 2.27, the compiler ran out of memory. Go figure…)
- Use C++, which has overloads for pow() and log().
e^(iπ) = −1
Let f(x) = x/log(x). Then f has a minimum at e - for example f'(x) = (log(x) - 1)/(log(x)^2), so f is decreasing for x < e and increasing for x > e.
In particular f(e) < f(pi)-- that is, e / log(e) < pi / log(pi).
Multiply through by log(e) log(pi) to get e log(pi) < pi log(e) and exponentiate both sides to get pi^e < e^pi.
Pleasingly, under the one true date format [0] there are no pi days. (Well there are, but long past the heat death of the Universe.)
2018-03-14
It's not specific to pi-day, but it still seems appropriate.