1. Home
  2. Computing & Technology
  3. Visual Basic
Symbolic Logic
Part 5: Visualize Symbolic Logic
 More of this Feature
• Part 1: Symbolic Logic
• Part 2: The Basics of Symbolic Logic
• Part 3: Mapping Out Symbolic Logic
• Part 4: Going Behind the Symbolic Logic Mask
 
 Join the Discussion
Is this the kind of article that helps you?
Let us know!
 
 Related Resources
• Calculating a Contrasting Color Code
The first article in the series. • The Imp Logical Operator
• VB .NET New Logical Operators AndAlso and OrElse
 
 Elsewhere on the Web
• Association for Symbolic Logic
• Karnaugh Maps
• A game for understanding Venn Diagrams
 

Venn Diagrams

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:

  • Retail or Commercial
  • Current or Past Due
  • In State or Out of State

You could visualize the possible combinations of accounts with a Venn Diagram that looks like this:

Venn Diagram

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 Maps

Karnaugh 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 - Retail or Commercial
  • B - Current or Past Due
  • C - In State or Out Of State
  • D - More or Less Than Five Years Old

A Karnaugh Map of this condition would look like this:

Karnaugh Map

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
Explore Visual Basic
By Category
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2009 About.com, a part of The New York Times Company.

All rights reserved.