CS 110 Fall 09 

Lab 4: Digital Logic

Due: Thursday, October 1st

 

In this lab you'll continue exploring logical notation, practice if statements, and, for extra credit, play around with a program that simulates digital circuits.

Part 1 - Simplify simplify

Simplify the following boolean expressions (labeled as Q) as much as possible.  That is, your task is to find the smallest expression that is equivalent to the stated expression.  You may want to write out a truth table to check your solutions.  The first two solutions are given, along with explanations, but you are not required to provide explanations for your answers.  For parts 1 through 3, submit your solutions as a text called logic.rtf.

1. Q = v false

Solution: Q = A (if A is true, Q is true, and if A is false, Q is false, and thus A and Q are the same)

2. Q = A ^ false

Solution: Q = false (regardless of whether A is true or false, Q is false)

3. Q = v true

Solution: Q =

4. Q = A ^ true

Solution: Q =

5. Q = A^ ¬A

Solution: Q =

6. Q = A v ¬A

Solution: Q =

7. Q = ¬(¬A)

Solution: Q =

8. Q = (v B) ^ (A v ¬B)

Solution: Q =

9. Q = ¬(¬v ¬B)

Solution: Q =

10. Q = ¬(¬A ^ ¬B)

Solution: Q =

Part 2 - Logical notation

Suppose we let the letters M, N, P and R represent the following statements: ‘monkeys are funny’, ‘ninjas are awesome’, ‘pirates are awesome’, ‘robots tend to cheat at poker’. Use boolean notation to symbolize the following:

1.  Monkeys are not funny, but robots do tend to cheat at poker.

2.  Neither ninjas nor pirates are awesome.

3.  Monkeys are funny, and at least one of ninjas and pirates are awesome.

4.  Either (a) robots do tend to cheat at poker and monkeys are funny, or (b) they don’t and ninjas are awesome.

Part 3 - Are these the same?

Indicate which of the following equations are correct for all truth values of A, B and C, and which are not.  Justify your answer.  To be clear, a justification that two expressions are different simply requires you to specify truth values for the variables such that the two expressions disagree.  A justification that they are the same requires you to create a complete truth table in which all entries for the two expressions match.

1. (v B) ^ ¬(A ^ B) = (A ^ ¬Bv (¬A ^ B)

2. (v B) ^ C = A ^ (v C)

Part 4 - Find the expression

For both problems, generate a boolean expression that matches the specified output.  Your solutions should be added to logic.rtf.

1.

A

B

?

T

T

T

T

F

T

F

T

F

F

F

T

2.

A

B

C

?

T

T

T

F

T

T

F

F

T

F

T

T

T

F

F

T

F

T

T

F

F

T

F

F

F

F

T

T

F

F

F

F

Part 5 - Practice with ifs

In Python, create three programs that perform the following tasks, with the specified name.

1. (GradeReport.py)     Write a full Python program (main() function definition with main() invocation) with the following functionality; prompt the user for their test grade.  If their grade is 90 or above, print "You got an A!"  If the grade is between 80 and 89, print "You got a B!"  If the grade is between 70 and 79, print "You got a C."  And if the grade is below 70, print "Uh oh... you should probably see me."  One and only one output should be printed for any particular value.  

2. (Divisible.py)    Write a full Python program that prompts the user to enter an integer.  Then report to the user whether that number is divisible by 2, 3 and 5.  For example, if the user enters 15, the output should be "15 is not divisible by 2, is divisible by 3, and is divisible by 5."  If the user enters 64, the output should be "15 is divisible by 2, is not divisible by 3, and is not divisible by 5."  Use only 3 if-statements.

3. (RoomSize.py)  Write a full Python program that prompts the user to enter an integer room width and length in feet.  If the area of the room is less than 100, print "The room is too small."  If the area is greater than 900, print "The room is too big."  If the area is in between, but either the width is more than three times the height or the height is more than three times the width, print "The room is a good size, but the shape is kinda stupid."  Finally, if none of these problems exist, print "Looks OK I guess... I'll take it."   

Part 6 - Extra Credit: Simple circuits

In Logisim, create circuits representing the following boolean expressions, and save them with the specified file name.  For each problem, check that the circuit behaves correctly on all possible inputs.

1. (5_1.circ)     (A v ¬B) ^ (¬v B)

2. (5_2.circ)     (A ^ B) v ¬(A v B)

3. (5_3.circ)     ((A ^ B) v (A ^ C) v (B ^ C)) ^ (¬A v ¬B v ¬C)

Part 7 - Extra Credit: Abacus

In Logisim, create circuits with the following properties, and save them with the specified file name.  Again, you'll want to check that your circuits have the desired properties.  You may find it helpful to explicitly construct the truth tables and boolean expressions for such a function before trying to build the circuits.

1. (pairity.circ)     A circuit with three inputs and one output that yields T if an odd number of inputs are T, and F otherwise.  (For those of you who need a reminder, 0 is most decidedly an even number.)

2. (majority.circ)    A circuit with three inputs and one output that yields T if the majority of the inputs are T, and F otherwise.

3. (adder.circ)     Use multiple copies of the two circuits above to create a 4-bit adder.  That is, you should have a circuit with 8 inputs (corresponding to two 4-bit input numbers, represented in binary) and 5 outputs (corresponding to a single 5-bit output number, represented in binary).  So we'll treat F as 0, and T as 1.  Given the two 4-bit binary inputs, the circuit should output the 5-bits representing the sum of those numbers in binary.  For example, if the inputs are given by 1001 (9 base 10) and 1011 (11 base 10) then the output should be 10100 (20 base 10).  If the inputs are 0001 (1 base 10) and 0010) (2 base 10) then the output should be 00011 (3 base 10).  I'll be talking more about binary representation and binary arithmetic on Friday and Monday, so you might want to wait on this one if this doesn't make sense yet.  Also, the "add circuit" option may be helpful; ask me for more details when you get this far.

Part 8 - Uploading your lab

Upload the assigned files to a folder named Lab04 in the Assignment Inbox.