* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Worksheet Boolean Algebra
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
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)