| Symbolic Logic | |||||||||||||||||||||
| Part 5: Visualize Symbolic Logic | |||||||||||||||||||||
Microsoft's second statement is a simple example of using compound logical expressions. These can be very difficult to analyze and understand when they become larger and more complex. There are a couple of visual techniques that can be used to analyze more complex logical expressions. One that we have already had a peek at is called Karnaugh Maps. Another is Venn Diagrams. Venn Diagrams are much more intuitive and visual (that is, easier to understand), but at the same time are less useful and more limited because they can only handle three independent variables and they don't really help you do more than visualize the problem. (Picky accuracy note: To be strictly correct, you can create Venn Diagrams for more than three variables, but the technique just loses it's visual value. See this reference for the proof.) Suppose you had were programming a problem that required the retrieval of accounts from a database where accounts could be:
You could visualize the possible combinations of accounts with a Venn Diagram that looks like this:
Notice that there are seven different compartments. There are eight possible binary combinations of three conditions. The "eighth compartment" is "none of the others". Karnaugh MapsKarnaugh Maps are a more analytical tool. Let's add one more variable to our list of conditions: "Accounts in force more than five years". This would rule out the use of Venn Diagrams. Suppose you need to search the database for all accounts that: Are commercial and current and out of state and over five years old or commercial and past due and out of state and over five years old or commercial and current and in state and over five years old or commercial and past due and in state and over five years old. Whew!!! First, let's assign letters to each of our conditions to make it easier to discuss and more abstract.
A Karnaugh Map of this condition would look like this:
There are a few changes in this diagram compared with previous ones. The left and top sides show you the logical state of the conditions and the right and bottom sides show the numeric values that could be assigned to them. In previous diagrams, we have seen these in a numeric sequence. In this case, however, they are in a sequence called Grey Code which makes some useful tricks possible in Karnaugh Maps. Grey Code specifies that only one bit changes between adjacent rows or columns. Notice the square colored light blue. This encloses the specific conditions for our example database search. It's easy to see in the Karnaugh Map now that only the condition (A And D) is really necessary. (Often, this is written using the mathematical shorthand: AD.) Columns, rectangles, basically anything with an even number of squares, can be visually reduced to a logically minimum condition. Karnaugh Maps are used a great deal as "scratch pad" visualization in logical circuit design and most of the information on the Web looks like it was written for an audience of electrical engineers. Nonetheless, they're also very useful for programmers for exactly the same reasons. In a future article, we'll take up the last leg of our series, number systems! First page > Symbolic Logic > Page 1, 2, 3, 4, 5 |
|||||||||||||||||||||

