Introduction to Boolean Logic |
Written by Mike James | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Tuesday, 11 March 2025 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Page 2 of 7
Truth TablesThe rules for combining expressions are usually written down as tables listing all of the possible outcomes. These are called truth tables and for the three fundamental operators these are:
Notice that while the Boolean AND is the same as the English use of the term, the Boolean OR is a little different. When you are asked would you like tea OR coffee you are not expected to say yes to both! In the Boolean case, however, “OR” most certainly includes both. When P is true and Q is true the combined expression (P OR Q) is also true. There is a Boolean operator that corresponds to the English use of the term “or” and it is called the “Exclusive OR” written as XOR or EOR. Its truth table is:
and this one really would stop you having both the tea and the coffee at the same time (notice the last line is True XOR True = False). Practical truth tablesAll this seems very easy but what value does it have? It most certainly isn’t a model for everyday reasoning except at the most trivial “tea or coffee” level. We do use Boolean logic in our thinking, but only at the most trivially obvious level. However, if you start to design machines that have to respond to the outside world in even a reasonably complex way then you quickly discover that Boolean logic is a great help. For example, suppose you want to build a security system which only works at night and responds to a door being opened. If you have a light sensor you can treat this as giving off a signal that indicates the truth of the statement: P = It is daytime. Clearly NOT(P) is true at night and we have our first practical use for Boolean logic! Similarly the door opening sensor can be considered to correspond to true if the door is open: Q = door open What we really want is something that works out the truth of the statement: R = burglary in progress in terms of P and Q. A little thought soon leads to the solution: R = NOT(P) AND Q
That is, the truth of “burglary in progress” is given by:
From this you should be able to see that the alarm only goes off when it is night-time and a window opens. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Last Updated ( Tuesday, 11 March 2025 ) |