FOUNDATIONS
OF
COMPUTATIONAL
THINKING AND PROGRAMMING
Problems with Boolean logic
Revising ideas from the previous
lesson
1. Write the Boolean expression Q = ¬((A ⊻ B) ∧ C)
using AND, OR, NOT and XOR instead of symbols.
2. Draw a truth table for the following circuit:
E
Q
B D
C
Revising ideas from the previous lesson
Inpu Inpu Inpu D = B E = A Q =
1. Write the Boolean expression tA tB tC C D E
Q = ¬((A ⊻ B) ∧ C) using 0 0 0 0 0 1
AND, OR, NOT and XOR 0 0 1 1 0 1
0 1 0 1 0 1
instead of symbols. Answer: 0 1 1 1 0 1
NOT ((A XOR B) AND C) 1 0 0 0 0 1
1 0 1 1 1 0
2. Draw a truth table for the 1 1 0 1 1 0
1 1 1 1 1 0
following circuit (answer on
the right)
Learning outcomes
1. In today’s session you will use the knowledge of Boolean operators
to understand how Boolean logic is different from regular algebra
2. You will learn the practical applications of applying Boolean logic to
solving problems
3. You will practise representing logic circuits using Boolean
expressions
Boolean logic
• In the previous session, we covered the
idea that Boolean logic works on three
main expressions: AND, OR and NOT
• Today we are going to see how we can
define problems using Boolean logic
• But first, we will start with a little history
of Boolean logic
Boolean algebra
• Up until 1800s logic belonged to the field of
philosophy where arguments were
expressed in words, not mathematical
symbols
• One of the pioneers of using symbolic logic
to express arguments was British
mathematician George Boole
• Boole wanted to see how logical arguments
could be solved using mathematics and in
1847 published an essay called
Mathematical Analysis of Logic
• Boole used three key operators AND, OR
and NOT to perform comparisons of sets George Boole, mathematician, 1815-1864
Unknown author; Unknown author, Public
domain, via Wikimedia Commons
Boolean algebra
• Boole published his most important work,
An investigation into the laws of thought
in 1854
• This was the first work to identify the
{0,1} set as a base for a consistent
algebraic language. His proposition was
that only two values were needed to solve
a logic equation: True or False
• Boolean algebra is significantly
different from the algebra we learn
at school
George Boole, mathematician, 1815-1864
Unknown author; Unknown author, Public
domain, via Wikimedia Commons
How Boolean algebra is different
• Consider the following two statements: “my
cat is fluffy” (A) and “my cat is white” (B)
• If a statement A is true, it has the value of 1
and if the statement B is true, it also has the
value of 1
• We saw from our exercises with the logic
gates that we could combine A and B and as
long as one of them is true, the outcome will
also be true. We would do this using OR:
“my cat is fluffy OR my cat is white”. In
Boolean algebra OR behaves like +: 1+0=0
• What happens if both of the statements are
true in above expression: 1+1=? George Boole, mathematician, 1815-1864
Unknown author; Unknown author, Public
domain, via Wikimedia Commons
How Boolean algebra is different
• Let’s see what happens when we use
AND : “my cat is fluffy AND my cat is
white”. In Boolean Algebra AND does
not behave like a + because both of
the statements need to be true for the
condition to be true.
What mathematical symbol could
be used to use replace AND?
(answer below)
• The answer is x or * (the sign for
multiplication) George Boole, mathematician, 1815-1864
Unknown author; Unknown author, Public
domain, via Wikimedia Commons
Limitations of Boolean algebra
• One major limitation of Boolean algebra is
its inability to express statements such as
‘for all A’ as it always takes another
condition to quantify A A B
• The easiest way to visualise this is
through Venn diagrams on the right A OR B
A B
A NOT B
Limitations of Boolean algebra
Task
On the right you can see the OR and NOT
operators as expressed by Venn diagrams
Produce Venn diagrams to express AND,
A B
XOR and NOT
A OR B
(Use fill background and fill to indicate
various areas)
A B
A NOT B
Boole’s legacy
• 70 years after Boole’s death an American
Engineer Claude Shannon used Boole’s
concepts to design the basis of the
contemporary computer circuits
• The foundation of codes used to program
computer software now are based on the logic
designed by Boole
• You should also know that all internet search
engines use Boolean logic to conduct searches
• For example a search for ‘computer mouse’
has an implied AND between the first and
second words which should limit if not
eliminate the number of times you might see
mouse, the animal, in the search results George Boole, mathematician, 1815-1864
Unknown author; Unknown author, Public
domain, via Wikimedia Commons
Defining problems using
Boolean logic
Solve the following problems using Boolean logic:
A garden centre has a climate monitoring system that gives warnings if the
temperature and humidity are not at suitable levels. The climate monitoring system
contains the following algorithm:
if humidity == 50 AND (temperature > 16 AND temperature < 25 ) then
print("Humidity and temperature at acceptable levels.")
elseif temperature <= 16 OR temperature >= 25 then
print("Warning - Please alter the temperature.")
else
print("Warning - Please alter the humidity.")
endif
1. What will be the output if temperature = 30 and humidity = 16
2. What will be the output if humidity = 30 and temperature = 20
Defining problems using
Boolean logic
Solve the following problems using Boolean logic:
A garden centre has a climate monitoring system that gives warnings if
the temperature and humidity are not at suitable levels. The climate
monitoring system contains the following algorithm:
if humidity == 50 AND (temperature > 16 AND temperature < 25 ) then
print("Humidity and temperature at acceptable levels.")
elseif temperature <= 16 OR temperature >= 25 then
print("Warning - Please alter the temperature.")
else
print("Warning - Please alter the humidity.")
endif
1. What will be the output if temperature = 30 and humidity = 16
2. Answer: Warning - Please alter the temperature.
3. What will be the output if humidity = 30 and temperature = 20
4. Answer: Warning - Please alter the humidity.
Defining problems using
Boolean logic
We can define and solve problems using
Input Binary Condition
Boolean logic
Temperature >=
Example problem: 1
100 C
T
A chemical process has a sensor to detect 0
Temperature
dangerous situation. When this happens, it <100 C
sounds an alarm (A). 1 Rotator ON
The alarm is sounded if: R
0 Rotator OFF
either temperature >= 100 C AND
rotator is OFF 1 PH > 6
or PH > 6 AND temperature < 100 C P
0 PH <= 6
Study the table on the right to see how this
relationship could be represented using
these conditions as Boolean values
Defining problems using
Boolean logic
Conditions on the right could be Input Binary Condition
written as follows:
1 Temperature >= 100 C
A = (T AND NOT R) OR (P AND T
NOT T) 0 Temperature <100 C
or as 1 Rotator ON
A = (T ∧ ¬R) ∨ (P ∧ ¬T) R
0 Rotator OFF
Task: Using logic gates and their
graphical representations, draw 1 PH > 6
the logic circuit for the above P
problem 0 PH <= 6
Defining problems using
Boolean logic
Input Binary Condition
A = (T ∧ ¬R) ∨ (P ∧ ¬T)
Temperature >=
1
The logic circuit for this problem T
100 C
could be expressed as follows: 0
Temperature <100
C
1 Rotator ON
R
R 0 Rotator OFF
1 PH > 6
P
T 0 PH <= 6
P
Learning outcomes
1. In today’s session you used the knowledge of Boolean operators
to understand how Boolean logic is different from regular algebra
2. You learned the practical applications of applying Boolean logic
to solving problems
3. You practised representing logic circuits using Boolean
expressions
Revising ideas from today
1. Explain how Boolean algebra is different from
regular algebra using examples
2. Explain how George Boole’s ideas influenced
the field of engineering and computer science
as result of Boolean algebra
3. Using a real-life example, explain how
Boolean algebra could help us solve problems
4. Draw a logic circuit for the following
expression: Q = A ⊻ B ∨ ¬B
Topics and key vocabulary from
today:
• Logic Gates
• Truth tables What questions do
• you have at the
Boolean expressions
end of this lesson?
• NOT gate
• OR gate
• NOR gate
• XOR gate
• NAND gate
• Logic circuit