Monday, July 20, 2009

Prime Numbers

Prime numbers are the devil. Nothing is right about them, and nothing ever will be right about them. Simple laws that everybody can understand can easily be derived from them just by simple brainstorming.

For example:
Multiplying any two numbers (excluding 1) together gives a non-prime number.
Adding any two prime numbers (excluding 2) gives a non-prime number.

Those just came of the top of my head. The first one makes sense because if you have any equation a * b = c, the factors of c are always "1, a, b, c", along with any other factors of a or b. We have to exclude 1 because otherwise we get 1 * c = c, which is just multiplication's identity theorem.

The second takes a little more thought. Since we are excluding 2, that makes every other prime number an odd number. Given a and b as two prime numbers, they can be re-written as:

a = c + 1
b = d + 1

Where c and d are the even numbers directly before a and b, respectively. Now, if we add a and b together, using these new formulas, we get:

(c + 1) + (d + 1) = e
c + d + 2 = e

Because c and d are even, and they are being added with 2, an even number, this leaves e as an even number as well. And every even number is non-prime, with the exception of 2. However, no two prime numbers can add up to equal 2, so this is inconsequential.

However, the tricky part of prime numbers is trying to figure out whether the number is truly prime or not. By definition, a number is prime if and only if the only factors of the number are 1 and itself. So, surely the easiest way of determining whether a number is prime or not is simply to divide the number by every number between 1 and itself, noninclusive, and see if any of these numbers divide evenly into the test number. While yes, this does work, it takes linearly longer to do for each sequential number. By hand, this is very noticeable before you even hit 100. By computer, this is only noticeable when doing either a very large sample size of numbers, or testing for a very large number (such as the largest Mersenne Prime: 2^43112609 - 1).

So, there has to be a faster way of testing to see whether a number is prime or not. There are a few ways that I've thought of, or been shown, that help reduce the amount of time finding prime numbers.

First off, if the number is even, it's not prime. This may seem silly, but when you're checking to see how many prime numbers there are from 1 to 1000000000, it automatically cuts off half of your time.

Secondly, you don't have to check to see if there are any even factors to the number. For example, you don't need to check to see if 4 factors into 357, because 2 doesn't factor into this number, and if 2 doesn't factor in, 4, 8, or any other even number will not. Also, if any number doesn't factor in, any multiple of it also will not factor into the test number. However, this is harder to put into practice, because you essentially just start checking to see if the test value is prime by dividing it by prime numbers.

Finally, at least as far as I currently remember, the most helpful tool for finding primes by hand is to keep track of the results of dividing test factors. For example, say we are trying to find out if 25 is prime. Dividing 25 by 3 gives 8 1/3. Because of this, we never have to check factors higher than 8 1/3, because they are already ruled out. Let's do a real example with a real prime number:

Test number = 733

733/2 = 366.5
733/3 = 244.333
733/5 = 146.6
733/7 = 104.714
733/9 = 81.444
733/11 = 66.636
733/13 = 56.385
733/15 = 48.866
733/17 = 43.118
733/19 = 38.579
733/21 = 34.901
733/23 = 31.870
733/25 = 29.320
733/27 = 27.148
733/29 = 25.276

At this point, you can stop. To help clarify my previous paragraph, here's a generic formula:

test/x = y

Basically, if you are testing x sequentially, once y > x, you've already exhausted your options of factors. if you keep testing x higher than the first point at which y > x, y will always be some value between two previous x's. Alternatively, y will always be a non-integer value. Mind you, this holds true only if all of the previously tested x's gave a non-integer value for y.

I may rephrase paragraphs in this later if I feel I can explain things better. But for now, I think this is a good start.


Friday, July 10, 2009

Nightmares

So this morning, I wanted to wake up early to help with ROAD. Instead of actually waking up to my alarm, every time I hit the snooze button, I thought I was filing papers or something. After finally giving up with that, I fell back asleep and had a crazy nightmare.

Of course, by the time I'm writing this, I forget most of my nightmare, but damn was it weird/intense. For some reason, it started off with me and I think Penelope Cruz, then switched up to Nagisa and I, and then another guy was added in eventually, but I forget who that was.

The whole dream revolved around some book or something, and demons that would try to torment you, that only other people could see at the time. The book told of some story that made sense I would guess. And this one hallway that had a ton of doors on either side of it. For some reason we had to go into each of them to progress further into the hallway, and each one had a demon in it or something. But at some point in the hallway, something freaky happened and we were pushed back to the start of the hallway to start all over again.

In the dream, I swear it felt like I'd dreamed something like this before. Now, though, I'm not so sure.

Hopefully I have it again so I actually take notes on it right when I wake up.

Wednesday, June 17, 2009

On Dentists and Life.

So, today I went to the doctor's office for a checkup, then to the dentist's office to get my teeth checked on/cleaned. While at the dentist's, I noticed something weird: whenever she was poking around in my mouth, no matter how sharp the object was, my tongue was drawn to it like a magnet. Even forcing my tongue to the bottom of my mouth just resulted in my mind fighting to keep it from coming back up. I wonder why the tongue is drawn like that; maybe some evolutionary development to make sure we didn't choke or something? Who knows.

Anyways, my mind's also cycling between nostalgia and our purpose in life, essentially, because of this story:

Graduation Story

Not really wanting to think too in depth about it right now, both because I'd be in for a long night, and because I need to wake up early tomorrow for yet another doctor's appointment. Oh well, I'll just save it for another day.

Tuesday, June 16, 2009

First Post!

So, this is the start. Not really going to put much here, as sleep calls out to me. Expect more content soon-ish.

Slightly on that note, sleep is a weird sort of thing. There when you don't want it, hard to achieve when you do want it, and just all around annoying. Sure, you sometimes wake up feeling refreshed, but other times you just want to never wake up, and then half of your day is wasted. Why haven't we evolved to the point where we can function without sleeping ever, like sharks or something? Maybe we should just start breeding all the people together that can work with little sleep, and eventually get a race of humans that doesn't have to sleep. That'd be pretty interesting.

Well, now I must sleep.