# A Brief Guide to Logic for Programmers.

In this, the second of three Parts, I intend to discuss the concept of the Venn Diagram, which is used in the mathematical area of Set Theory.

The Venn Diagram and the Universal Set

The Venn Diagram is used to represent in a picture the sets and combinations of sets to which we may wish to refer. A set is simply any combination of objects or ideas. Firstly, we define a Universal Set. The Universal Set contains absolutely everything in the whole universe and we represent it by all the points within a rectangular box, U, i.e.

Mathematicians also wish to refer to a set that contains absolutely nothing at all - the empty set - and given the symbol 'ø'.

The Venn Diagrams of Sets

We now represent a set to which we may wish to refer by a circular in the box. Let us suppose we wish to refer to all red objects and call this set A. The Venn Diagram for this is:-

We say that the set of all red objects is contained within the Universal Set, or is a subset of U, the Universal Set.

Let us introduce a second set of all Vauxhall cars and call it B. The Venn diagram for this is:-

The Venn Diagrams of Combinations of Sets

Having defined the sets A and B, we can define the 'intersection' of A and B as the set of objects contained within both A and B. This is the set of all red Vauxhall cars and corresponds to the shaded area in the Venn diagram below.

Note that there are some red objects (e.g. the planet Mars) that are not Vauxhall cars and some Vauxhall cars that are not red. Also note that if we had defined A as the set of all red objects and B the set of all blue objects, then the intersection would have been the empty set, ø.

Also we can represent the 'union' of A and B, that is the set of all objects in A or B (or both), as the shaded area in the Venn Diagram below:-

We can now represent complicated combinations of sets. For example, consider the set A, but not B, or B, but not A. This is the shaded area in the Venn Diagram below:-

Demonstration of the use Venn Diagrams to prove one of De Morgan's Laws If we consider the Venn diagram for the set of objects both in set A and set B:-

The negation of any set is everything in the Universal Set outside of the set in question. So the Venn Diagram for the negation of A and B is as below:-

But if we consider the Venn Diagram for the negation of the set A:-

And the Venn Diagram for the negation of the set B:-

Then if we form the set all objects in the negation of A or the negation of B, the Venn Diagram is:-

Which is the same diagram as given above for the negation of all objects both in A and B, or we have proved that 'not (A and B)' is '(not A) or (not B)'.

In the third part of these articles, I intend to describe the Karnaugh Map. This is a special type of Venn Diagram that can be used to work out the particular logical expression that a programmer might need in C in 'if', 'while' or 'do ... while' statements (In BBC BASIC 'IF', 'WHILE' or 'REPEAT').