Did you know this about prime numbers?

By extension, once you have tested explicitly for 2 and 3, you only need check division by numbers congruent to 1 or 5 modulo 6, which you can do by incrementing two candidate divisors by 6 at each loop iteration. I implemented “isPrime()” / “nextPrime()” routines this way once - it’s a good bit more efficient than simply eliminating all the even candidates, skipping over 9, 15, etc.

By further extension, after checking 2, 3 and 5 one could use 8 candidates modulo 30 (congruent to 1, 7, 11, 13, 17, 19, 23, 29), but you start getting rather diminished returns for the added complexity.

I read up on the twin primes. This is very interesting. I am learning much from all of you.

Year ago, I had the idea that it might be significant to categorize the integers > 1 based on how many factors were in their prime factorizations. No doubt someone else has had the same idea, but I never checked the literature.

But what I realized was that the longest contiguous sequence with n prime factors would be 2[sup]n[/sup]-1, with the special exception of the 2,3 sequence for the primes. So I wrote a program to try to find the lowest such sequences for each n. I’ve put the results away, so I can’t give you them in detail, but for n=2 the first sequence is 33,34,35 and for n=3 it’s in the 200,000s. I didn’t find the sequence for any larger n.

The thing is, I wrote the program on an original Mac (I said this was years ago) and because it was so slow at division, I optimized it by creating a modulo counter for each prime number below about 1000, I think. Plus counters for the powers of the low primes. By incrementing all the counters every time I incremented the number, I kept track of the modulo of the number for all those primes. Once the modulo counter reached the prime it was for, that prime was a factor in the number and the counter was reset.

This may seem like a lot of work, but it actually made the program run faster. Of course, I was completely factoring all numbers, which is even more division-intensive than just finding primes.

Well, I’ve done a little playing with the first ten thousand digits of pi and The visual pattern of occurrence of some digits does seem to be more ordered than the occurence of the same digit in pseudo-random sequence, but it’s a little too early to decide if that is just coincidence or (more likely) wishful thinking…

Mangetout, what’s a good algorithm or source (online, preferrably) for the digits of pi? Given 65,536 of 'em, I can run them through the stuff I worked up last night, instead of the primes (see link above). That program creates the histograms and all automagically, so it’d be easy enough to just hand it a different input.

Here is some good pi stuff, DaveW, including algorithms.

Or not. Most of those links seem dead. Here is a better page with pi formulae. Yes, I checked this one.

Yeah, like I’ve got a math package that’ll handle those formulae out to 65536 decimal places, Q.E.D. :slight_smile: Actually, I looked at your previous offering, and did eventually find a page with the first million digits on it, so not all the links were dead. This should work fine. Dunno if I’ll have a page with pi spirals up tonight, but I’ll try.

Okay, here’s what I’ve done with pi so far.

Cool stuff, Dave. Good job with it.

Okay, I’ve seen the circular and square Ulam spirals, but how do triangular and hexagonal spirals look?

Also, what would a prime distribution appear if expressed in 3 dimensions, instead of just a 2-D spiral?

I wonder if Dave wants to do the same thing with e? My guess is the distribution would be similar to that of pi.

Nuts. I typed up a long post last night, but it didn’t go through. Here’s the abridged version:

Everything you’ve done so far has been really cool, Dave. You mentioned some strange property of the random dots you generated, and said it might just be bad luck–I think that’s probably right.

Some other spirals that might be interesting: even and odd digits of pi, primes mod 4, primes mod 6. If you get a chance.

Wow. Thanks, folks. A lot. I thought I might get a “neat-o,” but I never imagined a “cool,” and definitely not a “really cool.” :slight_smile:

Actually, what I really expected was for someone to say, “Hey, Dave, that looks just like what’s over on (insert URL of web site here).” I really can’t imagine that I’ve done anything that hasn’t been done before. Images like mine have gotta be out there, somewhere. (Perhaps in print?) Obviously, the Ulam spiral itself ain’t new, but I did histograms of differences between primes over 10 years ago (with millions of primes, not just thousands - 6 was still #1), and my dad, at the time, pointed out that that had been done ages before then.

“Pi as an Ulam Spiral” sounds far too much like an undergrad thesis title for it not to have been one already (several times), right?

Anyway, e should be a snap (if there’s a web site with the first million digits of it out there, too), now that all the routines for pi are in place and working (and I wouldn’t expect to see much of a difference). Even/odd digits of pi shouldn’t be too tough, either. And primes mod 4 or 6 shouldn’t be too much work.

I just realized, though, thinking about the code I’ve written, that both of my linearity-calculating routines are missing some of the visually-linear dots. So all of the scores are low. By how much, I can’t guess, but they should all be higher (and probably porportionally, so it won’t make a difference to the meaning of what’s up there already - it’s not going to raise the score of the random image more than it raises the score of the primes image).

And yeah, I’ve gotta work on re-running a bunch of random images (using the randomizer from the pi routines) to see if the one on my web page now was just a fluke.

I’m also thinking about going to a 1,000x1,000 spiral, to get the most out of that web page with the first million digits of pi on it, and I’ve re-written a quick-and-dirty prime-finder which has, in the last two hours, already stored the first 20 million primes (overkill, I know, but I’m going to let it go until it’s covered all primes in 32 bits or less - and I’m curious about the final histogram of all that, anyway).

My code right now spits out these spirals and histograms in about a second per, so going to a million digits/primes should only slow it down to 15 seconds per (if the speed is linearly related to the number of dots - not sure about that).

On second thought, going to a million digits/primes would require me to not have the big (and prettier) images (the ones which show each dot as four pixels instead of one), since 2,000x2,000 pixel bitmaps would be unweildy in a web browser (I figure lots of people have their displays at 1,024x768, anyway).

Any thoughts? Er… Any thoughts other than the obvious “do a 65,536x65,536 Ulam spiral with all those primes!” A 4-gigabyte bitmap file? I don’t think so, no. :slight_smile:

If you didn’t notice, Dave the e in my post is a link to formulae for generating it to arbitrary precision. :wink:

Good work DaveW.

I’ve been working on the pi thing and I thought I’d play around with making the spacing of each point on the spiral path proportional to the sqrt of the index, but it makes very little difference to the final appearance.

Long time listener, first time caller here.

There are no true patterns here. If there were “true patterns”, the gaps in the imagined “lines” could be explained. They can’t. No explanation? No patterns.
Know explanation, know patterns.

the gaps in the lines can be explained - as an artifact of the plottting method, the lines represent equations such as Euler’s formula; if we were to plot the entire set of results from Euler’s, we would see unbroken lines, but Euler’s only produces a high proportion of primes and it is only these we are plotting; the gaps are the non-prime results of the formulae.

Know great mystery.

If somebody comes up with an explanation, will there be a pattern?

Yes, Q.E.D., I did notice – but the same difficulty applies here as it did with pi. At least, I didn’t notice that any of the formulae could be continued past the precision of the math packages I have to work with (namely, what Visual C++ provides). So I can get e out to a handful of decimal places using what I’ve got, as far as I can tell. 80 bits’ worth, I believe.

Now I’ve played around with creating an arbitrary-precision floating-point package, myself, in order to have easy access not only to the far-right decimals, but also to huge integers, but I always seem to wind up getting bogged down on some point, and ditching the project for something else. While I once created a huge-integer package for looking for a subset of big prime numbers (thousands of digits was all I tested it with, but it could go as high as you could afford memory), it was too specialized to be generalized.

Through the links provided on that e page, I did locate the first 10,000 digits, but that’s too few for my tastes.