Monthly Archives: March 2007

The Origin of Species by Charles Darwin, courtesy of Librivox

Need something to listen to on a really long trip? Librivox has just completed a huge audiobook version of the sixth edition of Charles Darwin’s classic On the origin of species. It’s a fascinating book, and well worth reading if you have any desire to understand the history of biological science.

LibriVox » The Origin of Species by Charles Darwin

[tags]Public Domain,Origin of Species,Charles Darwin[/tags]

Pi, 10m digits, 3m11s, 20 minutes to program…

PiWhile playing around with the GNU Bignum library and Mersenne primes, I decided to code up a simple program to compute pi to an obscene number of decimal places (I chose 10 million, a much larger number than any of my previous efforts). The GNU Bignum Library supports arbitrary precision floating point arithmetic as well, which made the Brent-Salamin (also called the Gauss-Legendre algorithm or the AGM algorithm) to compute pi. It’s very simple, and has quadratic convergence, which means that only 22 iterations are sufficient to generate 10m digits of accuracy. The resulting program worked the very first time I ran it. It takes 3m 11s or so on my AMD64 box, which makes it much, much faster than any other program I’ve written to date. (It still pales to the gmp-chudnovsky program (which I used to check my generated digits) but it’s not bad for 20 minutes of work and a lazy 73 lines of code. The GMPLIB is quite a nice piece of work.

Gauss-Legendre algorithm – Wikipedia, the free encyclopedia

And here’s my source code:

Barely commented, but consider the above link the comments.

[tags]Mathematics,Pi,Big Numbers[/tags]

Compute the largest known prime, from a .signature file

Okay, most of the ones of these I’ve written have been at least a little obscure or obfuscated. This one is entirely straightforward, and is further unremarkable because you need to have the gnu bignum library to make it work. Shrug. It’s still kind of fun, and it demonstrates just how straightforward the library is to use.

Here’s the source code.

I found that I had to set my process limits up (apparently the print routines allocate memory on the stack, and that causes problems when your number has almost 10 million digits). In csh, that means “limit stacksize unlimited”. I had space to include that in the comment.

If you want something REALLY clever, try Fabrice Bellard’s obfuscated program to do the same thing. It’s a little too large for a .signature file, but it requires no additional libraries, and is positively diabolical. I must admit that I had a tiny bit of problems compiling this one, because the LL qualifier appearing on the second line seems to parse badly when it is broken up onto two lines. Still, very neat (and very fast too).

[tags]Prime Numbers,Mathematics[/tags]

Recreational Math: The Kruskal Count

This is the kind of paper I read when I have a lunch hour by myself at the local sushi bar.

[math/0110143] The Kruskal Count

The Kruskal Count is a card trick invented by Martin J. Kruskal in which a magician “guesses” a card selected by a subject according to a certain counting procedure. With high probability the magician can correctly “guess” the card. The success of the trick is based on a mathematical principle related to coupling methods for Markov chains. This paper analyzes in detail two simplified variants of the trick and estimates the probability of success. The model predictions are compared with simulation data for several variants of the actual trick.

[tags]Mathematics[/tags]

SeisMac

Through some convergence of factors (namely, my experience trying to read the accelerometers in the Wii remote, last night’s earthquake, and this mornings blear eyed checking of the Make Blog feed) I found the application below, which turns your Macbook or Macbook Pro into a seismograph by reading the accelerometer inside. I tried it on my budget Macbook. It works. Silly me, I though only the pros had accelerometers. Great, now I have something else to play with.

Suitable Systems / SeisMac

Fun computing mersenne primes…

sieve completed... 0.000000 user, 0.000000 system
2**3 - 1 is prime 0.000000 user, 0.000000 system
2**5 - 1 is prime 0.000000 user, 0.000000 system
2**7 - 1 is prime 0.000000 user, 0.000000 system
2**13 - 1 is prime 0.000000 user, 0.000000 system 
2**17 - 1 is prime 0.000000 user, 0.000000 system 
2**19 - 1 is prime 0.000000 user, 0.000000 system
2**31 - 1 is prime 0.000000 user, 0.000000 system
2**61 - 1 is prime 0.000000 user, 0.000000 system
2**89 - 1 is prime 0.000000 user, 0.000000 system
2**107 - 1 is prime 0.000000 user, 0.000000 system 
2**127 - 1 is prime 0.000000 user, 0.000000 system 
2**521 - 1 is prime 0.012000 user, 0.000000 system
2**607 - 1 is prime 0.020001 user, 0.000000 system
2**1279 - 1 is prime 0.192012 user, 0.000000 system 
2**2203 - 1 is prime 1.092068 user, 0.000000 system 
2**2281 - 1 is prime 1.240077 user, 0.000000 system
2**3217 - 1 is prime 3.972248 user, 0.000000 system
2**4253 - 1 is prime 10.808675 user, 0.044002 system 
2**4423 - 1 is prime 12.324770 user, 0.044002 system 
2**9689 - 1 is prime 204.052752 user, 0.712044 system 
2**9941 - 1 is prime 225.430088 user, 0.744046 system 
2**11213 - 1 is prime 339.633225 user, 1.136071 system
2**19937 - 1 is prime 2574.836917 user, 8.732545 system
2611.599u 8.828s 1:27:19.73 50.0%       0+0k 0+0io 0pf+0w

Addendum: Sorry, I was too tired by the time I finished this last night to really comment. I wrote up a simple C program using the GNU multiprecision arithmetic library that used a simple sieve to find all numbers < 20000 which are prime, and then tested each one using the Lucas-Lehmer test to determine if it was, in fact, actually prime. It spews out the total runtime needed each time it finds one. You can see that it took 2611 seconds (43 minutes or so? my math might be off) of runtime (I was running another number cruncher at the same time, so the elapsed time was twice as long). The highest Mersenne prime I checked (2^19937 -1) was discovered in 1971. That means that in 43 minutes I was able to duplicate every computation on Mersenne primes done throughout human history up to 1971 myself. If I get some time later, I'm going to try to use the numbers generated to provide projections on how long it would take me to compute larger, more absurd primes using only my machine.