Wednesday, February 10, 2010

The Problem with Infinity (and Cantor's Theorem)

In this post I discuss my thoughts on infinity and math which acts upon it. I cover what infinity is and why it doesn't make sense to give it mathematical properties the way Cantor does.

Infinity is not a number, it's a concept. Most people agree with this easily and fail to understand the significance of this. What is a concept? Well, some examples of concepts are remorse and happiness. You can't point to them and it's difficult to argue their existence, but everyone has felt them before and knows that they exist. Then there are concepts like democracy and bigfoot. The existence of these two can be argued at length. Infinity is somewhere between happiness and bigfoot. It can't be pointed to, it can't be held, it can't even be felt like happiness can. Why is this important?

One reason this is important is because concepts are something for which everyone has a different idea of their exact meaning. For example, no two people in the world have the exact same understanding of what "happiness" means. So when talking about infinity, it's impossible for two people to have the same understanding of it. This makes it difficult to prove anything about it mathematically.

Additionally, when infinity is treated as a number, it results in inconsistency. Why is this important? Inconsistent things in life, logic, and mathematics are cause for concern and disbelief. Inconsistency in life is often called hipocrisy, like when a politician's motto is "family first" and he's later found to have multiple mistresses. In logic, inconsistency is called a fallacy. In math, it's called a contradiction.

Treating infinity as a number is a contradiction because it's not a number, it's a concept. Infinity + 1 = Infinity, and Infinity + 2 = infinity as well. Unfortunately, this means that
infinity + 1 = infinity + 2
Okay, so cross out the infinities and we're left with 1 = 2, a contradiction.

So why is it okay to say that "1 < infinity?" Well it's not. Giving infinity mathematical properties is like asking "What is Marxism divided by 2?"

Apparently, the mathematical community as a whole (for the most part), has accepted Cantor's theorem as something mathematical that can be proven (there is some debate here). In fact Cantor's theorem, and any other theorem that involves infinity, is not math at all. Ideas dealing with infinity are philosophy, not math, since what is being discussed is a concept.

Related links.
http://scienceblogs.com, Infinity is not a number.
http://en.wikibooks.org, Infinity is not a number.

Saturday, February 9, 2008

Java Threads and Exception Handling

Exception handling with threads seems to be a topic that can be confusing for people. So here I offer an example of how it can be done.

The "Callable" interface is provided exactly for this purpose. The code below creates a thread once without throwing an exception and creates a thread a second time in order to throw an exception. There isn't much to it really, once you see it done, but getting there can be difficult.

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

public class Main {

public static void main(String args[]) {
// create an executor service to execute our threads (tasks)
ExecutorService executor = Executors.newCachedThreadPool();

// create a new thread/task
FutureTask task = new FutureTask(new SomeThread(false));
executor.submit(task); // execute the thread
// we must shutdown the executor service in order to know when all
// submitted tasks have completed..
executor.shutdown();

try {
// wait a maximum of 5 seconds for the thread to terminate
// (normally or with an error).
executor.awaitTermination(5, TimeUnit.SECONDS);
// output whatever value the thread returned.
System.out.println("The task returned: " + task.get());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}

executor = Executors.newCachedThreadPool();
task = new FutureTask(new SomeThread(true));
executor.submit(task);

executor.shutdown();
try {
executor.awaitTermination(5, TimeUnit.SECONDS);
// The error is returned when we call the .get() method.
System.out.println("The task returned: " + task.get());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
} // end of main.

static class SomeThread implements Callable {
boolean throwAnError = false;

public SomeThread(boolean throwAnError) {
this.throwAnError = throwAnError;
}

public String call() throws Exception {
System.out.println("Sleeping...");
Thread.sleep(2000);
System.out.println("Done sleeping!");

if (throwAnError) {
throw new Exception("Oh no, an exception!");
}

return "some return value";
}
} // end of SomeThread.
}

Of course there are some intricacies, but this should get anyone started. If this gets you excited the next exciting thing may be a BlockingQueue.