Logic: It's a beautiful thing. It's not everyday, however, that I get to implement it so explicitly as I did today.
One of the hallmarks of mathematical logic are some rules set out by Augustus De Morgan called, appropriately, De Morgan's Laws. They go something like this: Take two (or more) statements A and B. These can be things like "The sky is blue" and "We are on Earth." These statements have complements, namely, "The sky is not blue" and "We are not on Earth."
De Morgan gives an equivalence between the relation of these statements' complements and the complement of the relation of these statements. In (better) English, we could say that the complement of A and B is the complement of A or the complement of B. So, in our example, De Morgan tells us that the complement of "The sky is blue AND we are on Earth" is the same thing as saying "The sky is not blue OR we are not on Earth." Confused? Try out the formal statements for a bit of clarification:
where we read "c" as complement,
and
Why would this ever arise in practice, you might ask? In fact, just today I wanted to add a stopping condition to a WHILE loop I had in a program. A WHILE loop runs (loops) for as long as a given statement is true. My loop ran for as long as the variable called FLAG was true. Essentially, I wanted to cheat a little and add a different stopping criterion that would bounce out of the loop if a different variable hadn't been changing for a while.
So in my head, the loop should run while FLAG was true, and it should stop when COUNTER was bigger than 20 and W(COUNTER)==W(COUNTER-20). But, just my luck, you can't really tell a WHILE loop when not to run, you have to tell it when it has to run. But guess, what? These conditions are complements! Enter De Morgan.
My situation was that I want to stop the loop when
is true. Which means that I want to NOT stop (i.e. run) when
is true.
Bonus! We get to use both flavors of De Morgan. First apply the first equation from up top, then apply the second to the B parentheses. After all is said and complemented, I want to run my WHILE loop while FLAG is true AND (COUNTER is less than 20 OR W(COUNTER)~=W(COUNTER-20)). Cool huh?
Stay Logical.
These seem to depend on absolutes being absolutely true. I don't know of any absolutely true and indisputable things in nature except that we humans are constantly trying to define things by their opposites. Day is day because it is not night, etc. The While Loop must only exist and have no variables inherent in it or it cannot have a complement. Does this ever exist in nature? Seems to me that day is day when we declare it so or blue only blue by common acceptance but cannot be actually defined as blue at just one given point; there are infinite shades of it. I know it is splitting hairs, but that's what logic really leads to. Interesting study.
ReplyDelete