You are on page 1of 8

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.

Solution : Yes, it is possible that Alice is a dragon. Because, if she is a dragon,


then Alice is telling the truth, so Bob is a dragon. Thus, Carol is lying by saying that
Alice is a troll, so Carol is a troll.
It is also possible that Alice is a troll. Because, if she is a troll, then she is lying; thus
Bob is a troll. So Bob is lying, and Carol is telling the truth (and is thus a dragon).
By the same logic, Bob may be a dragon or a troll.
Carol could be a dragon, because if she is telling the truth, then Alice is a troll (and
thus lying when she says that Bob is a dragon), meaning that both Alice and Bob
are trolls. Carol could also be a troll, meaning that she is lying about Alice, and thus
Alice and Bob are both dragons.
Yet, all eight assignments are not possible. For example, it cannot be the case that
Alice is a dragon and Bob is a troll, because then Alice would be lying about Bob
being a dragon.

[9] 2. A Short Mathematics Break



[6] a. Prove 3 5 6∈ Q.

Solution :

3
Assume 5 6∈ Q. (1)

3
⇒ 5 = a/b for a, b ∈ Z, where a, b share no common factors (2)
3 3
⇒ 5 = a /b (3)
3 3
⇒ 5b = a (4)
⇒ a3 is divisible by 5 (5)
⇒ a is divisible by 5 by the Fundamental Theorem of Arithmetic (6)
⇒ a = 5k for some k ∈ Z (7)
3 3
⇒ 5b = (5k) by (4), (7) (8)
3 3
⇒b =5·5·k (9)
3
⇒ b is divisible by 5 (10)
⇒ b is divisible by 5 by the Fundamental Theorem of Arithmetic  (11)

[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”.

Solution :

Assume 27 | n
⇒ n = 27k for some k ∈ Z
⇒n=9·3·k
⇒ n divides 9

[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

Solution :

p NAND p ≡∼ (p ∧ p) by def’n of NAND


≡∼ p∨ ∼ p by de Morgan’s
≡∼ p by Idempotency

[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.

Solution :

(p NAND q) NAND (p NAND q)



≡∼ ∼ (p ∧ q)∧ ∼ (p ∧ q) by def’n of NAND

≡∼ ∼ (p ∧ q) by Idempotency
≡ p ∧ q by Double Negation

[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.
1
See, e.g., Epp 4ed at 35, or Dave’s excellent formula sheet.
Solution :

≡ (p NAND p) NAND (q NAND q)

≡∼ ∼ (p ∧ p)∧ ∼ (q ∧ q) by def’n of NAND
≡∼∼ (p ∧ p)∨ ∼∼ (q ∧ q) by de Morgan’s
≡ (p ∧ p) ∨ (q ∧ q) by Double Negation
≡ p ∨ q by Idempotency

[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.

Solution : Because any truth table can be expressed in disjunctive normal


form (DNF), which is formulated using only conjunctions, disjunctions, and
negations.

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.
Solution : There is a problem (the circuit should output false) in precisely the four
times there is a cow with no cow beside it:

• x1 ∧ ∼ x2 (the cow in s1 is alone);


• ∼ x1 ∧ x2 ∧ ∼ x3 (the cow in s2 is alone);
• ∼ x2 ∧ x3 ∧ ∼ x4 ; (the cow in s3 is alone); or,
• ∼ x3 ∧ x4 (the cow in s4 is alone).

The circuit should output false if there is a cow-tastrophe, so the circuit can be a
negation of the disjunctive-normal form expression of the above four cases. That is,
the circuit can be expressed as:

∼ (x1 ∧ ∼ x2 ) ∨ (∼ x1 ∧ x2 ∧ ∼ x3 ) ∨ (∼ x2 ∧ x3 ∧ ∼ x4 ) ∨ (∼ x3 ∧ x4 )

We could rewrite the formula to find alternative forms, but it does not reduce the
number of gates used (there are still five). However, some people may find it easier
to read:

∼ (x1 ∧ ∼ x2 ) ∨ (∼ x1 ∧ x2 ∧ ∼ x3 ) ∨ (∼ x2 ∧ x3 ∧ ∼ x4 ) ∨ (∼ x3 ∧ x4 )
≡∼ (x1 ∧ ∼ x2 )∧ ∼ (∼ x1 ∧ x2 ∧ ∼ x3 )∧ ∼ (∼ x2 ∧ x3 ∧ ∼ x4 )∧ ∼ (∼ x3 ∧ x4 )
by de Morgan’s
≡ (∼ x1 ∨ ∼∼ x2 ) ∧ (∼∼ x1 ∨ ∼ x2 ∨ ∼∼ x3 ) ∧ (∼∼ x2 ∨ ∼ x3 ∨ ∼∼ x4 ) ∧ (∼∼ x3 ∨ ∼ x4 )
by de Morgan’s
≡ (∼ x1 ∨ x2 ) ∧ (x1 ∨ ∼ x2 ∨ x3 ) ∧ (x2 ∨ ∼ x3 ∨ x4 ) ∧ (x3 ∨ ∼ x4 )
by Double Negation

[15] 5. Everything is on the Table


[4] a. Write the truth table for:
     

a ∨ b ∧ ∼ ∼ (∼ b) ∨ b ∧ a∧c

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.

Solution : The truth table is as follows:

a b c a∨b ∼ (∼ (∼ b)) ∨ b a∧c ((a ∨ b) ∧ (∼ (∼ (∼ b)) ∨ b)) ∧ (a ∧ c)


0 0 0 0 1 0 0
0 0 1 0 1 0 0
0 1 0 1 1 0 0
0 1 1 1 1 0 0
1 0 0 1 1 0 0
1 0 1 1 1 1 1
1 1 0 1 1 0 0
1 1 1 1 1 1 1
[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.
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.
Solution :
[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.

Solution :
    

a ∨ b ∧ ∼ ∼ (∼ b) ∨ b ∧ a∧c
     
≡ a∨b ∧ ∼b∨b ∧ a ∧ c by Double Negation
    
≡ a ∨ b ∧ T ∧ a ∧ c by Negation
   
≡ a ∨ b ∧ a ∧ c by Identity
     
≡ a∧ a∧c ∨ b∧ a∧c by Distributivity
     
≡ a∧c ∨ b∧ a∧c by Idempotency
 
≡ a ∧ c by Absorption

[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.
3
See, e.g., Epp 4ed at 35, or Dave’s excellent formula sheet.
Solution :

You might also like