Saturday, November 04, 2006

Mathematical? Thinking

I stopped reading the Java API for the String class to write this post at this sentence: "If two strings are different, then either they have different characters at some index that is a valid index for both strings, or their lengths are different, or both." There is nothing grammatically wrong with it, but logically, it caused me some very brief confusion. This statement implies that there are 3 possible differences between 2 strings: 1) at least one character is different, 2) the lengths are different, or 3) both 1 and 2. How is it possible for the lengths to be different while the individual characters are the same? It isn't--I thought about it for a while and proved to myself it just isn't.
Then I realized that that isn't what the API stated--it read, "different characters at some index that is a valid index for both strings."
"Oh," I said to myself, "Yeah."

That's not really important, but what it led me to think about is:

I think very much like I write programs. I'm not sure if this is how everyone thinks (though I doubt it), but I'm pretty sure I know several people that think in a similar manner. When I read and thought about the above statement, I set, in my brain somewhere,
condition1: at least two characters are different
condition2: the lengths are different
A flag sprang out somewhere above my left temple, and I wondered why the API didn't read: "If two strings are different, then either they have different characters at some index that is a valid index for both strings, or their lengths are different and [insert condition1]". Then I read over the actual wording for the first condition and realized that repeating it would almost double the length of the sentence.
"Oh," I said to myself, "Yeah," but this time someone else retorted: "They could have actually written, 'condition A."
"Maybe, but that's kinda vague. I'm not sure it would be clear to everyone," I said skeptically.
"It should be if they're thinking like they should be if they're reading the Java API."
My tumbling thoughts wrestled this one a bit before I realized I couldn't argue, but I wondered if thinking like that is common or if it has a name.
I thought about it some more, rid myself of the association to computers, and applied one to math. This manner of thinking is the reason I usually understand new mathematical concepts easily. For example:
In algebra: if x + y = 4 and x + 2y = 5, then y = 1 and x = 3. When I read this problem and start to figure it out, I see, in my mind's eye, two shapeless, colorless blobs, representing the variables x and y, which bounce around and interact to first isolate one and then substitute it back into the equation to find the other one. Sometimes blobs represent numbers or digits in a number or variables or anything, really.

Mostly, thinking about how I think made we wonder if other people think like I think and realize that I know people who I think think like I think. Any thoughts?

5 Comments:

Anonymous Anonymous said...

They could have just said "Two strings are different if they have different lengths or if they have at least one different character at the same valid index."

If they are different lengths, then they are obviously not the same. If they have the same length then any index which is valid for one must be valid for the other.

3:30 AM  
Anonymous Anonymous said...

A bit better:

If two strings are different, then either they have different lengths or they have different characters at some valid index.

3:40 AM  
Anonymous Anonymous said...

If the strings have the same length, then they have identical valid indices (this is part of the definition of string length). And invalid indices don't matter, so the word valid is unnecessary in the second condition.

It also seems that it would be a little clearer to define what makes strings identical.

Thus: Two strings are identical if their lengths are equal and corresponding indices have the same characters.

I took Engl 201C: Technical Writing when I was attending Penn State, and haven't been the same since.

That is also where I picked up a sever loathing for the pseudo-word "utilize."

4:06 AM  
Anonymous Anonymous said...

As for mathematical thinking check this out.

4:10 AM  
Blogger Unknown said...

The documentation is not well-worded, but its meaning is fine. Here is my interpretation, not knowing the internals of the Runtime Environments internal secrets.

First, it compares lengths. Invalid lengths immediately returns false.

Then, it checks characters. Values that do not match returns false.

Finally, the two conditions are false if the first condition fails. That part of the documentation is a bit strange. It seems a simple short circuit would work just fine therel no need for a third condition if both fail.

I suppose they just wanted to list all the ways it could fail. It probably could have been written better.

7:24 AM  

Post a Comment

<< Home