Download Worksheet Boolean Algebra

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Foundations of mathematics wikipedia , lookup

Quantum logic wikipedia , lookup

Mathematical proof wikipedia , lookup

Propositional calculus wikipedia , lookup

Propositional formula wikipedia , lookup

Intuitionistic logic wikipedia , lookup

Law of thought wikipedia , lookup

Canonical normal form wikipedia , lookup

Laws of Form wikipedia , lookup

Transcript
Comp 3303 Elements of Computer Science
Workshop5
Boolean Algebra
[CBPrice. 24-02-15]
Color Coding for this Worksheet
Information
Hints for Portfolio
Instructed Learning
Autonomous Learning
Extension Activities
Portfolio
The activities in this worksheet contribute to ILO1
Activities
1
Finger Exercises 1: Reading a Proof
Each of the exercises below shows a proof of an identity. Your task is to identify which Boolean
β€œrule” is being used at each stage. Here’s an example. The column on the left shows the statement
of the identity, the middle column shows the stages in the proof and the right column is where you
write down which rule is being used.
Example:
𝐴. (𝐴 + 𝐴̅) = 𝐴
𝐴. 1
𝐴
complement
identity
1(a)
𝐴. (𝐴 + 𝐴̅) = 𝐴
𝐴. 𝐴 + 𝐴. 𝐴̅
𝐴 + 𝐴. 𝐴̅
𝐴+0
𝐴
𝐡̅ . (𝐴 + 𝐡) = 𝐡̅ . 𝐴
𝐡̅ . 𝐴 + 𝐡̅ . 𝐡
𝐡̅ . 𝐴 + 0
𝐡̅ . 𝐴
𝐴. (𝐴̅ + 𝐡) = 𝐴. 𝐡
𝐴. 𝐴̅ + 𝐴. 𝐡
0 + 𝐴. 𝐡
𝐴. 𝐡
1(b)
1(c)
2
Finger Exercises – 2: Writing a Proof
In these examples you are asked to write the algebra of a proof, line by line. To help you to do this
the rules you will need are listed in order in the rightmost column
2(a)
𝐴. (𝐴 + 𝐡) = 𝐴
distributive
idempotent
distributive (backwards)
identity
identity
𝐴. (𝐴 + 𝐡) = 𝐴
distributive
idempotent
absorption
2(b)
2(c)
(𝐴 + 𝐡). (𝐴 + 𝐡̅ ) = 𝐴
distributive
complement
identity
idempotent
distributive
complement
identity
idempotent
You may wish to include one or more of these examples in your portfolio
3
The House Alarm Problem
A house alarm has a sensor on the door (A) and a pressure pad inside the house (B). The logical
values of the sensors are
A = 1 means the door is closed, A = 0 means the door is open
B = 1 means someone is on the pressure pad, B = 0 means no-one is on the pressure pad
The alarm sounds when the door is open, or if someone is on the pressure pad, or both
(a) Write down the truth table for the alarm
(b) Write down the mini-terms using Boolean algebra for each line of the table where the output is
1
(c) Write down a boolean expression for the behaviour of the alarm by OR-ing your three miniterms.
(d) Use your expression to draw a circuit diagram for the alarm system
(e) The solution can be simplified using Boolean algebra, the proof is shown below. For each line
of the proof identify which β€œrule” is being used and make sure you understand how the rule works
Simplification Step
𝐴̅. 𝐡̅ + 𝐴. 𝐡̅ + 𝐴. 𝐡
𝐡̅ . (𝐴̅ + 𝐴) + 𝐴. 𝐡
𝐡̅ + 𝐴. 𝐡 + 𝐡̅ . 𝐴
𝐡̅ + 𝐴(𝐡 + 𝐡̅ )
𝐡̅ + 𝐴
Rule used
starting with mini-terms
(f) Either construct the digital logic circuit using a simulator OR use the Arduino template sketch
provided to test that the result of the simplification agrees with the required alarm behaviour.
Make sure you understand all elements of this activity. It would be really useful to have this in
your portfolio.
4.
A Very Strange Alarm System
An alarm manufacturer has installed an alarm according to a rather strange specification of the
customer. There are three switches A,B, and C which when pressed according to the following
rules will set off the alarm:
Rule1: A must be pressed
Rule2: A and B cannot be both pressed together
Rule3: Either B is pressed or C is not.
Rule4: Rule1 and Rule2 and Rule3 must all be true.
(a) Express each of the rules 1 to 3 using Boolean Algebra. You should get a separate mini-term for
each rule.
(b) Combine your mini-terms to express rule 4. You will obtain a Boolean expression for the
strange alarm system
(c) The expression you have obtained can be simplified using Boolean Algebra. The steps in the
simplification are shown below. You must indicate which β€œrule” is being used at each stage.
Μ…Μ…Μ…Μ…Μ…
𝐴. (𝐴.
𝐡 ). (𝐡 + 𝐢̅ )
𝐴. (𝐴̅ + 𝐡̅ . )(𝐡 + 𝐢̅ )
𝐴. (𝐴̅ . 𝐡 + 𝐴̅ . 𝐢̅ + 𝐡̅ . 𝐡 + 𝐡̅ . 𝐢̅ )
𝐴. (𝐴̅ . 𝐡 + 𝐴̅ . 𝐢̅ + 𝐡̅ . 𝐢̅ )
𝐴. 𝐴̅ . 𝐡 + 𝐴. 𝐴̅ . 𝐢̅ + 𝐴. 𝐡̅ . 𝐢̅
0 + 0 + 𝐴. 𝐡̅ . 𝐢̅
𝐴. 𝐡̅ . 𝐢̅
(d) Either construct the digital logic circuit using a simulator OR use the Arduino template sketch
provided to test that the result of the simplification agrees with the required alarm behaviour.
Useful for your portfolio, perhaps as an alternative to activity 3.
5.
Safety-Critical Systems
Some safety critical systems such as aircraft flight controllers use three computers which process
identical information, however it is understood that computers are not infallible and may fail. To
mitigate against this a voting system is often used where the output is used only if two or more
computers agree.
Let’s agree that the computers produce a logical output 0 or 1 and that logical 1 means a β€œcorrect”
output.
(a) Build a truth table for the voting system
A
0
0
0
0
1
1
1
1
B
0
0
1
1
0
0
1
1
C
0
1
0
1
0
1
0
1
(b) Construct mini-terms for each line of the table where the output is 1. You should find 4 such
mini-terms.
(c) Combine the mini-terms to produce a Boolean expression for the voting system
(d) Use Boolean Algebra to reduce the expression to 3 terms instead of 4.
(e) Either construct the digital logic circuit using a simulator OR use the Arduino template sketch
provided to test that the result of the simplification agrees with the required alarm behaviour.
6.
Simplification of a system expressed as a truth table
Here we are going to use Boolean Algebra to simplify a given logical problem expressed in the
following truth table
A
0
0
0
0
1
1
1
1
B
0
0
1
1
0
0
1
1
C
0
1
0
1
0
1
0
1
0
0
1
1
0
0
1
1
(a) Construct mini-terms for each line of the table where the output is 1.
(b) Combine the mini-terms to produce a Boolean expression
(c) Use Boolean Algebra to simplify the expression, making use of the hints below
𝐴̅. 𝐡. 𝐢̅ + 𝐴̅. 𝐡. 𝐢 + 𝐴. 𝐡. 𝐢̅ + 𝐴. 𝐡. 𝐢
𝐡
Starting expression
distributive (reverse)
complement
distributive (reverse)
complement
distributive (reverse)
complement
(d) Either construct the digital logic circuit using a simulator OR use the Arduino template sketch
provided to test that the result of the simplification agrees with the required alarm behaviour.
When you get this working (perhaps without Tutor support) make sure you understand how your
code works.
7.
A Complete Proof
Starting with the truth table shown below,
A
0
0
1
1
B
0
1
0
1
1
0
1
1
(a) Show that this table can be expressed as the Boolean expression 𝐴̅. 𝐡̅ + 𝐴. 𝐡̅ + 𝐴. 𝐡
(b) Use Boolean Algebra to simplify this expression to 𝐡̅ + 𝐴
(c) Check that these two expressions are indeed the same using a logic simulator or the Arduino
template sketch
Nice simple example for your portfolio
8.
Dr.C’s β€œNo-IF Conjecture”
I propose that all conditional statements like if( i < C) in computer code are un-necessary
and can be replaced by logic expressions based on Boolean algebra. Here C is a constant.
To outline my thinking here is an example. We shall see how to reduce the statement
if( i < 3) to the logical expression 𝐴̅. 𝐡̅ where A is the higher order bit of i and B is the
lower order bit, in other words i = 2*A + B where A and B are either 0 or 1 and + is interpreted as
addition.
First let’s look at how i is represented as bits. This is shown in the table below.
A
0
0
1
1
B
0
1
0
1
i
0
1
2
3
We now indicate which rows of this table correspond to the condition (i < 3) and we add a 1 to
each row so constructing a truth table.
A
0
0
1
1
B
0
1
0
1
i
0
1
2
3
o/p
1
1
1
0
Now we form the mini-terms as usual and end up with 𝐴̅. 𝐡̅ + 𝐴̅. 𝐡 + 𝐴. 𝐡̅. Finally we use Boolean
Algebra to simplify this expression and obtain 𝐴̅. 𝐡̅ .
We can test that the conjecture is correct by using the Arduino template provided and writing the
following two blocks of code (to be tested separately) which should produce the same output.
A = digitalRead(input1);
B = digitalRead(input2);
i = 2*A + B;
if(i<3) digitalWrite(output3,HIGH);
A = digitalRead(input1);
B = digitalRead(input2);
result = (!A) && (!B);
digitalWrite(output3,result);
This should prove the conjecture for this example.
(a) Prove that 𝐴̅. 𝐡̅ + 𝐴̅. 𝐡 + 𝐴. 𝐡̅ = 𝐴̅. 𝐡̅
(b) Test the Arduino code and verify the conjecture.
(c) Now test the conjecture for (i < 5)