Category Archives: Soapbox

This category contains posts where I push my opinions on others.

Happy Birthday, Bob Ross!

Today would be Bob Ross‘s 70th birthday. 

For those of you who aren’t familiar with Bob Ross, he was an artist who’s best known for his PBS show, The Joy of Painting.  I’d say that Bob Ross informed a LOT of my creative processes growing up. I’d watch this show religiously even though my family would never have been able to afford oil paints or canvas.   For a short while, I tried to reproduce his techniques with poster paint and notebook paper, but without much success.

According to the wikipedia article, Bob spent time in the Air Force before dedicating himself to painting.  It’s hard to imagine the painter in a military environment… but apparently, he got quite a lot of the inspirations for his famous landscapes from where he was stationed in Alaska.

Happy Birthday, Bob.  Thank you for being such an inspiration.

 

When is Math.abs(x) < 0?

I was monitoring a long running Hadoop job yesterday at work when I began noticing one of the tasks which make up that job began failing for an odd reason: Illegal Partition.

For those of you not familiar with Hadoop jobs, part of it involves splitting up massive amounts of data into smaller, more manageable pieces; or partitioning the data.  The goal of partitioning is to get N roughly equal chunks where N is generally pretty big.

The specific illegal partition value that was coming up was negative. “But that’s not possible!” I thought to myself! The expression I was using to choose partitions used Math.abs(x), or the Absolute value of x.  Specifically:

partition = Math.abs(x) % N

Ok, now at a glance, you tell me how that could be negative… It turns out though, that for at least a critical value of x, Math.abs(x) will return negative: Integer.MIN_VALUE.

As it turns out, Integer.MIN_VALUE is the smallest value that a 32-bit number can hold in java: -2,147,483,648. and if you try to Math.abs(Integer.MIN_VALUE), the result is STILL Integer.MIN_VALUE.  Is this a bug? It turns out that it’s not.  If you read the javadoc for Math.abs(), it points out that:

“Note that if the argument is equal to the value of Long.MIN_VALUE, the most negative representable long value, the result is that same value, which is negative.”

Now, exactly why is that the case?  Well, for you to get the absolute value of Integer.MIN_VALUE, you’ve got to be able to represent the result as a 32-bit integer too… which is impossible, as the largest integer you could possibly represent is 2,147,483,647 which is one smaller than we need it to be.  Maybe this was coded so that the Integer.MIN_VALUE would be preserved?  I decided to look at the source.

So … here’s the implementation:

public static int abs(int a) {
    return (a < 0) ? -a : a;
}

Okay… that’s a much simpler than what I thought it’d be, however it does point out that it’s not just Math.abs(x) that has this problem… it’s any negation of Integer.MIN_VALUE.  Anotherwords, the following must be a true expression:

Integer.MIN_VALUE == -Integer.MIN_VALUE

Give it a shot if you don’t believe me, fire up eclipse and try it out!  In fact, eclipse will highlight the expression with a warning that says “Comparison of identical expressions”.

Okay… I’m not sure how i feel about this.  so WWCD? (What would C do?) … so I gave it a shot… Here’s a C program that exercises this exact question:

int main(int argc, char *argv[]) {
    int x = -2147483648;
    int y = -2147483647;
    printf("X: %d %d\n", x, abs(x));
    printf("Y: %d %d\n", y, abs(y));
}

What do you think the answer is?  It actually surprised me a little:

X: -2147483648 -2147483648
Y: -2147483647 2147483647

It seems like C behaves the same way.  Apparently this isn’t just a Java problem.  Bottom line? watch and test around -2,147,483,648. It’s a critical value.

Evil Robots – It’s all in the LEDs

By picking up machine learning and micro-controllers, I’ve found myself at a juncture.  A natural spot where these two hobbies naturally coincide.  Robots.

I can honestly say that I’ve never really thought much about Asimov or his three laws of Robotics until this point.  So… what are these three laws? and what the hell do they do?

  1. A robot may not injure a human being or, through inaction, allow a human being to come to harm.
  2. A robot must obey the orders given to it by human beings, except where such orders would conflict with the First Law.
  3. A robot must protect its own existence as long as such protection does not conflict with the First or Second Laws.

They make perfect sense right? These laws make it clear that robots shouldn’t harm humans.  The thing is, though… that a huge body of sci-fi exists which totally disregard putting the three laws.  Seriously.  I bet you could name at least three evil robots.  Why didn’t their creators program in the 3 laws?  Well, primarily, it’d make for a pretty boring plot… but I actually think that in real life, we won’t see robots programmed with the three laws because well… these laws are hard to code! I mean, how do you even begin to go about coding them?  I have a more obvious and far easier way of preventing evil robots from taking over — DON’T USE RED LEDS!

Let’s take a look at some well known evil robots and let’s see if we can identify a common characteristic. Ok?

Probably the first evil AI that comes to mind is the HAL 9000.  This lovable computer from Arthur C. Clarke’s 2001 attempts to kill the entire crew of the spacecraft, Discovery.  It would have succeeded too, if it wasn’t for a meddling kid named Dave Bowman.

I’m not a huge Kubrick fan, but I must admit that he did an excellent job of making HAL seem very creepy.  You’ll note that the camera mysteriously has a bright red LED glowing right smack in the middle.  I’m not really sure how a camera can operate with light bring projected through its aperture, but meh. It’s the future… oh wait… it should have happened 11 years ago… but that’s a tangent. Bottom line. Evil AI. Red LED.

 

The second Robot AI I’d like to point out came into being about a decade after 2001: A Space Odyssey, the Cylon.  You will notice the scanning visual thingy on this robot? Yes. Red LED. It marks an entire race of sentient AIs whose entire purpose is to eradicate humanity from the cosmos.  Okay. I know what you’re thinking… didn’t KITT also have a Red LED sensor? KITT wasn’t evil! Hah.  The original version of that AI was KARR which WAS evil. KITT is just pretending to be good to piss off it’s evil twin.

Skipping forward to the 80s, we come across The Terminator. This robot is doubly evil.  It’s totally got not one but TWO red LEDs.  The Terminator is the progeny of an AI who tricked the superpowers of earth into engaging in nuclear war.  That’s not just evil… it’s totally passive aggressive too.  I’m pretty sure that SkyNET had red LEDs all over it.

Need more convincing? Okay. Let’s go.

Here are the “Squiddies” from the Matrix.  These AIs are all about rending humans limb from limb. They are basically ruthless killing machines.  Note the sheer number of red lights. I rest my case.

Red LEDs = EVIL

So like, what the hell? Why use Red LEDs at all?  It probably has to do with power. I mean, power corrupts right?  Let’s take a look at one more example.  This should hammer home the corruptive power of the red LED.

Otto Octavius, a mild mannered scientist creates an 8-limbed exoskeleton that’ll revolutionize the world.  He uses red LEDs for their power… but cancels it out by building a rather fragile looking anti-evil circuit into the suit.  Learn from Otto’s mistake. If you make yourself some kinda futuristic, armored, super-powered exoskeleton? DON’T MAKE THE ANTI-EVIL CIRCUIT THE MOST FRAGILE PART!

So okay.  What happens if we don’t use red LEDs? Are there any example of powerful robots who don’t have them? Maybe we *NEED* to use red LEDs… I’ll leave you with one final image.  You come to your own conclusions.