4 ms·
Some π-ography for Pi day
- 3pt14159 9y agoFor obvious reasons, I'm going to love today. There are so many fun things with pi. 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.
- 52-6F-62 9y agoThat's fun. I'm recently working my way back through my fundamentals prepping for some future hopeful coursework and had to play with number 1. #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.
- jwilk 9y agoBoth log() in C and Math.log() in JS are natural logarithms, so there's no need to define your own ln() functions.
- 3pt14159 9y agoIf I ever make a programming language the log function will take two parameters, value and base. It's too confusing when engineers, mathematicians, and computer scientists all use different implicit bases.
- 52-6F-62 9y agoI had to do a double take for that reason. They're 100% correct, but I assumed what I'd learned from math. 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?
- jwilk 9y agoFor common cases of n=2 and n=10, consider using dedicated functions log2() and log10(), because they are more precise. For example: log(1E42)/log(10) == 42 - 7.105427357601002e-15 log10(1E42) == 42.0
- 52-6F-62 9y agoNoted. It’s more for other cases. While doing any algebra coursework I usually (loosely) confirm my thoughts by running them in a repl with said functions to at least keep me on track— so logn usually serves uncommon bases. My thinking that way might not make much sense, but I start to explain it in other comments. Anyway— thanks, I appreciate the insights. That’s the reason I like this forum
- 52-6F-62 9y agoTIL! 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.
- AtomicOrbital 9y agoinitially I tried pasting ln(6) ^ (ln(5) ^ (ln(4) ^ (ln(3) ^ ln(2)))) into bc to no avail ... magically paste it into google - Bam
- jwilk 9y agobc does have natural logarithm, but it's called l(), and you have to enable the math library with the -l option. There's another problem, though: the ^ operator requires that the second expression is integer.
- jwilk 9y agoAnother weird thing about your C code is that is uses "long double" as argument and return types; but pow() and log() functions use doubles, so there's some unexpected rounding going on. 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().
- jwilk 9y agoYou got the sign wrong. e^(iπ) = −1
- 3pt14159 9y agoHa! Serves me right for trying to comment from my phone. You're right, but I can no longer edit the comment.
- zamalek 9y agoThe thing I love most about π is that its nature comparable to that of circles: circles have infinitely many corners (technically extreme points), just like π has infinitely many digits.
- madcaptenor 9y agoWhat do you have in mind as a terse solution? I'm thinking as folllows: 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.
- tim_hutton 9y agoIs anyone else a bit sick of these 'pi days'? Every year we get the same old shtick. 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.) [0] https://xkcd.com/1179/ https://xkcd.com/1179/
- shawabawa3 9y agoPi day works in that format... 2018-03-14
- kej 9y agoYou might appreciate one of my favorite Pi Day related comics, then: http://www.qwantz.com/index.php?comic=955 http://www.qwantz.com/index.php?comic=955
- tim_hutton 9y agoThe value on pi approximation day (22/7) is closer to pi than the value on pi day (3.14).
- scrooched_moose 9y agoAlso, my favorite pi related comic: https://www.smbc-comics.com/?id=1777 https://www.smbc-comics.com/?id=1777 It's not specific to pi-day, but it still seems appropriate.
- simonbyrne 9y agoThe author of this post is the creator of the Julia visualization package Luxor.jl (https://github.com/JuliaGraphics/Luxor.jl https://github.com/JuliaGraphics/Luxor.jl). One thing I like about it is the nice turtle graphics feature (http://juliagraphics.github.io/Luxor.jl/stable/turtle.html http://juliagraphics.github.io/Luxor.jl/stable/turtle.html).