Hard Light Productions Forums

Off-Topic Discussion => General Discussion => Topic started by: Rampage on March 14, 2003, 07:58:17 am

Title: It's PI Day!
Post by: Rampage on March 14, 2003, 07:58:17 am
Happy PI Day!  That's right, it's March 14 today!  Math and science nerds galore!

Post anything related to PI, Euler, etc.  Or did I mention PIES?!?!

NOTE: I'm just bored!
Title: It's PI Day!
Post by: WMCoolmon on March 14, 2003, 08:02:07 am
Great, a math pr0n thread. At least CP will be happy.
Title: It's PI Day!
Post by: Stunaep on March 14, 2003, 08:07:16 am
It's the national Mothertongue day here. So **** PI.
Title: It's PI Day!
Post by: Tiara on March 14, 2003, 08:09:50 am
Its the national End of school - Beginning of a new weekend day over here :D
Title: It's PI Day!
Post by: Stunaep on March 14, 2003, 08:20:09 am
oh yes, it's the end of school - beginning of the spring break day here. :ha:
Title: It's PI Day!
Post by: Styxx on March 14, 2003, 08:21:56 am
* yawns * (http://pi.autopron.org/pi)
Title: It's PI Day!
Post by: Joey_21 on March 14, 2003, 08:45:24 am
:lol:

Here's some c++ programs I've been working on lately... one calculates Bernoulli numbers recursively and the other makes usage of the numbers in stirling's approximation for the logarithm of the gamma function (and applies anti logarithm to get exact gamma function value).

http://denebsystem.250free.com/bernoulli.exe
http://denebsystem.250free.com/lngamma.exe

Edit: Oh ya, just now added the factorial, double factorial, and beta function in there... easy to implement. :p
Title: It's PI Day!
Post by: beatspete on March 14, 2003, 08:45:55 am
:)  Nice on styxx.
Title: It's PI Day!
Post by: Knight Templar on March 14, 2003, 11:12:54 am
CP should release PI today. Yes, Procyon Insurgency.  :p
Title: It's PI Day!
Post by: CP5670 on March 14, 2003, 12:38:29 pm
This has to be the best thread around in a while. :D unfortunately, my campaign isn't ready yet though. :( but soon...

Styxx: That thing is really neat. :yes: It must have taken the guy quite a while to do it though...

Anyway, hmm lets see, here is some neat stuff involving pi and bernoulli numbers:

(http://www.3dap.com/hlp/hosted/procyon/misc/Image2.gif)

can anyone prove them? ;7
Title: It's PI Day!
Post by: Joey_21 on March 14, 2003, 01:35:38 pm
Quote
Originally posted by CP5670
(http://denebsystem.250free.com/math.gif)


:wtf: Which log base is that? :wtf:
Title: It's PI Day!
Post by: CP5670 on March 14, 2003, 01:43:45 pm
eh...you know, the usual one, base e
Title: It's PI Day!
Post by: Joey_21 on March 14, 2003, 01:44:32 pm
Quote
Originally posted by CP5670
eh...you know, the usual one, base e


Hmm... weird... I don't get those results when I sum it...
Title: It's PI Day!
Post by: CP5670 on March 14, 2003, 01:46:01 pm
probably a typo on my part then, one minute...

hmm, it seems to work fine for me if I try it numerically; how are you calculating it?
Title: It's PI Day!
Post by: Joey_21 on March 14, 2003, 01:51:46 pm
Quote
Originally posted by CP5670
probably a typo on my part then, one minute...

hmm, it seems to work fine for me if I try it numerically; how are you calculating it?


Code: [Select]

(java app)

sum = 0;
for (i = 1; i <= 9999999; i++)
sum += (i * Math.log(1 + 1/i) + 1/(2*i) - 1);

Title: It's PI Day!
Post by: CP5670 on March 14, 2003, 01:56:37 pm
The convergence is quite slow, but with that many terms you should still get quite a few digits. The value I am getting (and an approximate value of the expression on the right) is 0.3696692992460937; what are you getting there?
Title: It's PI Day!
Post by: Joey_21 on March 14, 2003, 01:58:05 pm
-9999998.30685282
Title: It's PI Day!
Post by: Goober5000 on March 14, 2003, 02:00:07 pm
I think just plain "log" stands for logarithm base 10.  You're supposed to use "ln" for natural logarithm (base e).  Java ought to have a ln function - if not, use log(...)/log(e).
Title: It's PI Day!
Post by: Joey_21 on March 14, 2003, 02:01:10 pm
Quote
Originally posted by Goober5000
Possibly the program may be using log base 10.  I think you're supposed to use ln for natural logarithm (base e).  Java ought to have an ln function - if not, use log(...)/log(e).


Java's default log is base e.
Title: It's PI Day!
Post by: CP5670 on March 14, 2003, 02:01:37 pm
Quote
-9999998.30685282


:wtf:

oh wait I think I know what is going on; the series is not absolutely convergent, and after some one million terms they start to oscillate between positive and negative values, so that may well be skewing the result. Try something like 50000 terms and see if that works any better.

Quote
I think just plain "log" stands for logarithm base 10. You're supposed to use "ln" for natural logarithm (base e). Java ought to have a ln function - if not, use log(...)/log(e).


:D This is one of the (many) cases of bad notations used in math. It seems that physicists and applied math guys use ln while pure math guys use log. Personally I like log much better; I mean, what the heck is ln supposed to mean when it is called a logarithm, and the e base is about the only one ever used anyway... :p :D
Title: It's PI Day!
Post by: Joey_21 on March 14, 2003, 02:04:53 pm
Quote
Originally posted by CP5670
:wtf:

oh wait I think I know what is going on; the series is not absolutely convergent, and after some one million terms they start to oscillate between positive and negative values, so that may well be skewing the result. Try something like 50000 terms and see if that works any better.


50000 terms: -49999.30685281944
5000 terms: -4999.30685281944
500 terms: -499.30685281944

Notice any pattern? :p

Edit: 50000 + -49999.30685281944 = ln(2) :wtf:
Title: It's PI Day!
Post by: CP5670 on March 14, 2003, 02:10:51 pm
hmm there is definitely something wrong there. Mathematica seems to be giving the right answer, but if I am reading it correctly that java function looks correct as well. The only thing I can think of now is something funny with the logarithm base...
Title: It's PI Day!
Post by: Joey_21 on March 14, 2003, 02:12:39 pm
I did this test:

Code: [Select]

System.out.println(Math.log(2.718281828459045));


...and it returned 1.0

Another way of interpreting my loop above:

Code: [Select]

sum = 0;
i = 1;
while (i <= 9999999)
{
sum = sum + (i * Math.log(1 + 1/i) + 1/(2*i) - 1);
i = i + 1;
}
Title: It's PI Day!
Post by: Razor on March 14, 2003, 02:18:16 pm
Quote
Originally posted by CP5670

(http://www.3dap.com/hlp/hosted/procyon/misc/Image2.gif)

 


Woah :eek: I understand it all.
Title: It's PI Day!
Post by: CP5670 on March 14, 2003, 02:21:03 pm
A loss of "machine precision" maybe then? (e.g. where the log(1+1/k) gets very small and k gets very large) still, I doubt that would account for this much error. seems to work for me...

Code: [Select]
In[33]:= NSum[k Log[1+1/k]+1/(2k)-1,{k,1,Infinity}]
Out[33]= 0.3696692985404519

In[34]:= N[EulerGamma/2+1-1/2 Log[2Pi]]
Out[34]= 0.3696692992460937


Well, at any rate, I have a proof of the exact result. :D
Title: It's PI Day!
Post by: Joey_21 on March 14, 2003, 02:24:41 pm
Hmm... what programming language is that? or is that a language?


Anyway, here's a nice infinite approximation I like...

(http://denebsystem.250free.com/gamma.gif)

It makes a nice graph when I do 1/that.

(http://denebsystem.250free.com/gamgraph.gif)

;7
Title: It's PI Day!
Post by: Hippo on March 14, 2003, 02:28:14 pm
lol, PI was the answer to a bonous question on a math test i had today... its also Einsteins birthday...
Title: It's PI Day!
Post by: CP5670 on March 14, 2003, 02:32:45 pm
Quote
Hmm... what programming language is that? or is that a language?


I did that with Mathematica 4.2, which is a bit similar to C++ but with some different syntax and stuff.
Title: It's PI Day!
Post by: Joey_21 on March 14, 2003, 05:25:05 pm
Stupid integer datatype!!!!! :mad: :mad:

I had 'i' defined as an integer in the code so when it was being divided by or whatever it would do integer division and just leave the whole part of the result and left the fractional portion off.

That's java for ya... :doubt:

C++ does the same thing! I probably wouldn't have ever realized this until looking over the code in good ole VB4. :thepimp:
Title: It's PI Day!
Post by: Kamikaze on March 14, 2003, 06:27:41 pm
yay.. pi... 3.1415926535897932384626... I only remember that far, bah :p

Coincidental, today I finished a good math book I was reading named Godel, Escher, Bach: The Eternal Golden Braid. It's about various things like formal systems, strange loops, AI, genetics, Godel's theorem and Godel numbers ;7
Title: It's PI Day!
Post by: Sesquipedalian on March 14, 2003, 06:38:53 pm
May I have a large container of coffee?  Thank you!

3.141592653

You get two extra digits for being polite.
Title: It's PI Day!
Post by: Sesquipedalian on March 14, 2003, 06:43:19 pm
Title: It's PI Day!
Post by: Anaz on March 14, 2003, 07:29:22 pm
Quote
Originally posted by Joey_21
Stupid integer datatype!!!!! :mad: :mad:

I had 'i' defined as an integer in the code so when it was being divided by or whatever it would do integer division and just leave the whole part of the result and left the fractional portion off.

That's java for ya... :doubt:

C++ does the same thing! I probably wouldn't have ever realized this until looking over the code in good ole VB4. :thepimp:


...which is why you typecast it as a float...
Title: It's PI Day!
Post by: Joey_21 on March 14, 2003, 07:41:32 pm
Quote
Originally posted by Analazon


...which is why you typecast it as a float...


I suppose... I had kinda forgotten about integer division though because I don't like to make it a part of regular calculations. :)
Title: It's PI Day!
Post by: CP5670 on March 14, 2003, 09:38:24 pm
Sesq: rofl :D :D

I have 41 digits of that one. :p 3.1415926535897932384626433832795028841971

Quote
I had 'i' defined as an integer in the code so when it was being divided by or whatever it would do integer division and just leave the whole part of the result and left the fractional portion off.


Ah, that would explain it. I was really puzzled about the multiplication by 10 thing; it must have been because the sum gave 1 every time after some point, and the log(2) must have come in from the first term.

Quote

Anyway, here's a nice infinite approximation I like...

(http://denebsystem.250free.com/gamma.gif)


That is actually an exact value of the gamma function if you do it forever; many books I have seen initially define the function with that product. The nice thing about this is that it is one of those products obtained with the weierstrass factor theorem, which all converge for all values of the function; that's always nice... :yes:

BTW here are the graphs of three functions closely related to the gamma function; can anyone recognize what they are? ;7

(http://www.3dap.com/hlp/hosted/procyon/misc/Image4.gif)
Title: It's PI Day!
Post by: Sesquipedalian on March 14, 2003, 11:03:55 pm
So, CP, did you intentionally name your campaign such that it would be abbreviated to pi, or was it mere deliciously fitting happenstance?
Title: It's PI Day!
Post by: CP5670 on March 15, 2003, 01:33:43 am
Actually that particular thing was just coincidence. I couldn't think of anything really good for the campaign title, so I decided to do Procyon (something) since the majority of it takes place there. I picked insurgency for the second word because just about all other synonyms for "political rebellion" were already taken by other campaigns. sorry, I'm no good with these names. :p