CPSC 121, Winter 2017: Assignment 1

CPSC 121: Models of Computation
Assignment #1, due Tuesday 23 May 2017 at 16:00
[9] 1. An Island of Riddles
There is an island on which everyone is a dragon or a troll. Dragons, being noble,
always tell the truth. Trolls, being tricky, always lie. Alice, Bob, and Carol, all
inhabitants of the island, make the following statements.
Alice: “Bob is a dragon”
Bob: “Alice is a dragon”
Carol: “Alice is a troll”
[2] a. Is it possible that Alice is a dragon? Is it possible that Alice is a troll? Justify
each answer in no more than three sentences.
Hint: a full and complete justification will include more than just a truth table,
and will almost certainly include the word, “because” (with reference to what
the Alice, Bob, and Carol said).
[2] b. Is it possible that Bob is a dragon? Is it possible that Bob is a troll? Justify
each answer in no more than three sentences.
[2] c. Is it possible that Carol is a dragon? Is it possible that Carol is a troll? Justify
each answer in no more than three sentences.
[3] d. There are eight possible “assignments” of dragon or troll to Alice, Bob, and
Carol.
An “assignment” is a label of dragon or troll to each of Alice, Bob, and Carol,
regardless of whether it is correct or incorrect. For example, “Alice is a dragon,
Bob is a dragon, and Carol is a troll” is one of the eight possible assignments,
regardless of whether that assignment is correct or not.
Are all of the eight possible assignments potentially correct, based on what
Alice, Bob, and Carol said? Justify your answer. Your answer will be judged
on the brevity and preciseness of justifying why either “yes” or “no” is correct.
[9] 2. A Short Mathematics Break
√
[6] a. Prove 3 5 6∈ Q.
[3] b. Let n ∈ Z. Prove that if 27 | n, then 9 | n.
Hint: the notation “27 | n” should be read as “27 divides n”, or “27 is a factor of n”.
[12] 3. The Powerful NAND
In this question, you will prove that every truth table can be implemented using only
two-input NAND gates.
Hint: in your justifications, you are free to use the fact that:
a NAND b ≡∼ (a ∧ b)
by definition of NAND
[2] a. Show that ∼ can be simulated using a NAND gate. That is, design a circuit
whose only gate is a two-input NAND gate, that takes as input a signal p, and
whose output is ∼ p.
You must prove that your circuit accurately computes ∼ p by using equivalence
rules.1
[4] b. Show that ∧ can be simulated using NAND gates. That is, design a circuit
whose only gates are all two-input NAND gates, that takes as input two signals
p and q, and whose output is p ∧ q.
You must prove that your circuit accurately computes p∧q by using equivalence
rules.
[4] c. Show that ∨ can be simulated using NAND gates. That is, design a circuit
whose only gates are all two-input NAND gates, that takes as input two signals
p and q, and whose output is p ∨ q.
You must prove that your circuit accurately computes p∨q by using equivalence
rules.
[2] d. Why do the answers to the previous three questions prove that any truth table
can be implemented in a circuit that uses only NAND gates? Justify your
answer in no more than three sentences.
Did you know : you can do the same using only two-input NOR gates?
[6] 4. Not Udderly Alone
Ryan has a barn with four stalls, denoted s1 , s2 , s3 , and s4 . The stalls are arranged
side-by-side in a single row.
Unfortunately, being forgetful, Ryan has forgotten exactly how many of each type of
animal he is raising in the four-stall barn. But, he remembers that he has exactly
four animals, with each stall serving as home to exactly one animal. Additionally,
each animal is either a cow or a pig.
Ryan has a problem: namely, when cows are resting in their stalls, they never want
to be left without at least one cow in a stall beside them (so they can share cheese
recipes easily with at least one other cow).
Ryan has hired some CPSC 121 graduates to (over-)engineer a solution to his problem.
the graduates rig a sensor to each barn stall: the sensor for stall si produces output
xi , where xi = true if the animal in si is a cow, or false if the animal in si is not a
cow (i.e., if it is a pig).
Design a circuit that takes the four sensor outputs as inputs (x1 , x2 , x3 , and x4 ),
and outputs true if and only if no cow is standing in a stall without a cow beside it.
Should this circuit ever output false, Ryan will know to rearrange the animals to keep
the cows happy.
1
See, e.g., Epp 4ed at 35, or Dave’s excellent formula sheet.
[15] 5. Everything is on the Table
[4] a. Write the truth table for:
∧ a∧c
a ∨ b ∧ ∼ ∼ (∼ b) ∨ b
showing the intermediate values for each of:
i. a ∨ b;
ii. ∼ (∼ (∼ b)) ∨ b; and,
iii. a ∧ c.2
You may choose to include other intermediate values if you wish, so long as the
required three intermediate values and the final value are clearly indicated.
[4] b. Draw a circuit using nothing other than two-input AND and OR gates, and
single-input NEGATION gates (i.e., without XOR, NAND, NOR, and XNOR
gates) that implements the logical expression as it is written.
Note: this diagram will use more gates than strictly necessary, because there is
a simpler equivalent logical expression, as you will see below.
[6] c. Simplify the logical expression, using the logical equivalence laws,3 into its
simplest logical equivalent (i.e., the equivalent expression that uses the fewest
logical operations). Note: while the truth table from Part “a.” might help
you to verify your answer, you must use the equivalence laws to justify your
conclusion.
[1] d. Draw a circuit of the simplified equivalent expression, using nothing other than
two-input AND and OR gates, and single-input NEGATION gates.
2
The textbook, Epp 4ed, uses c to indicate a contradiction — something that must be false. You should
use 0 or F to indicate a false proposition, and 1 or T to indicate a true proposition, which are generally
what we will use in-class. Here, we use c as a variable name. Note the slightly different typeface between c
and c.
3
See, e.g., Epp 4ed at 35, or Dave’s excellent formula sheet.