Thursday, September 23, 2010

Boundary Conditions

Inspired by http://msdn.microsoft.com/en-us/library/cx9s2sy4.aspx

19 - 3 = 16

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
1 2 3 4 5 6 7  8  9 10 11 12 13 14 15 16 17

But when the numbers are listed out, there are 17 items, not 16. Why?

Take the simplest example:

2 - 1 = 1
1 2

1 - 0 = 1
0 1

Both of these have at least 2 elements in the cardinality.
This may have something to do with the number of operands (Arity).

So take an example with arity 3 (Ternary):

19 - 3 - 5 = 11

[19 - 3]
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
1 2 3 4 5 6 7  8  9 10 11 12 13 14 15 16 17

[19 - 3 - 5]
8 9 10 11 12 13 14 15 16 17 18 19
1 2  3  4  5  6  7  8  9 10 11 12

It has nothing to do with arity.

It's counting the gaps between the numbers.

3 4 5 6 7 8 9 10 11 12 13  14  15  16  17  18  19
 1 2 3 4 5 6 7  8  9  10 11  12  13  14  15  16

If numbers represent physical things/items, then why does the subtraction operation count gaps?

1 2 3
3 - 2 = 1

1 2 3 4
4 - 2 = 2

c - b = a
minuend (c) - subtrahend (b) = difference (a)

In the second example, counting from the left starting at 1 going towards the right are the numbers included in the subtrahend, and the numbers from the minuend to the subtrahend (difference) goes from right to left (starting at 4 ending at 2). Both of these beasts want to gobble up 2. If the focus is set on the numbers in the subtrahend then 2 is gobbled up by it (1 2). If the focus is set on the numbers in the difference then 2 is gobbled up by IT (2 3 4). Logically speaking, 2 should be included in the subtrahend only because it is one of the numbers to be taken away by the subtraction, but the difference wants to gobble up the 2 because the 2 is a focal point of interest in the equation we are trying to speak and to get the difference is the goal of our speech. So logically the difference should only include (3 4) without the 2.

How does all this relate to the MSDN article? The for-loop runs from i = 3 to 19, which is 17 times, but 19 - 3 = 16. This is a situation where the subtraction operation yields the wrong result because the logical focus is actually on the difference rather than the subtrahend. So the 3 is taken by the for-loop in the code to run its contents, leaving the normal conventions of a subtraction operation blind & behind in the dust. This gap between math and code needs to be explored further. My gut feeling is that different levels of abstraction will rotate in and out of phase with code in sort of a yin yang duality kind of way. We'll see what happens, but for now, the train rolls on...

No comments:

Post a Comment