CPSC 121: Models of Computation Assignment #3, due Thursday

CPSC 121: Models of Computation
Assignment #3, due Thursday March 2nd at 16:00
1
The Case of the Missing Nuts [27 marks]
Imagine you have the following predicates:
ˆ Stole(x, o):
person
x
stole object
o
ˆ PersonClaim(x, y, o):
people
x
and
ˆ PersonOrder(x, y, o):
person
x
actually saw object o before person y
ˆ ObjectClaim(n, o, x):
person
x
claims she saw object
ˆ ObjectOrder(n, o, x):
person
x
actually saw object n before object o
ˆ Caught(x):
person
x
y
claim that
x
saw object
n
o
before
before object
y
o
was caught stealing
Here are the domains:
ˆ P
Squirrel Girl (SG for short), Chipmunk Hunk (CH), Koi Boy (KB),
Tippy Toe (TT). (Well, TT is technically a squirrel, but that has no impact on this question. Also,
is the set of people, including
and
she's a
ˆ O
very capable squirrel.)
is the set of objects, including the
stick, rope, pipe,
and
gum.
1.1 English to Logic [9 marks]
Translate the following statements into predicate logic using the domains and predicates above.
1. Squirrel Girl and Chipmunk Hunk claim to have seen a pair of objects in opposite orders. (So, SG
claims to have seen the pair of objects in one order, and CH claims to have seen them in the other
order.)
2. No one actually saw any other object after the one they stole.
3. Anyone who was caught claimed they saw an object they stole before some other object.
1.2 Logic to English [9 marks]
Translate the following predicate logic statements into English. Do your best to make the translations clear,
concise, and accurate.
1.
∼ ∃p ∈ P, Stole(p, gum) ∧ Caught(p)
2.
∀p ∈ P, (∃o ∈ O, Stole(p, o)∧ ∼ ∃n ∈ O, n 6= o ∧ Stole(p, n)) ∧ (∀p2 ∈ P, Stole(p2 , o) → p = p2 )
3.
∀p ∈ P, ∼ Caught(p) → ∃p2 ∈ P, ∃o ∈ O, p 6= p2 ∧ Stole(p, o) ∧ PersonClaim(p, p2 , o)
1
1.3 Dening Predicates [3 marks]
Dene a new predicate
Lied(p)
that is true exactly when
p
made a claim that was not true (whether as
part of a pair of people in a claim about their order seeing an object or a single person in a claim about
the order they saw two objects).
1.4 Proving Statements [6 marks]
Translate the following argument into predicate logic and provide a formal proof of its validity. (That is,
your proof should proceed through numbered steps, with each line justied by a rule from Dave's Awesome
Handout. You may also use universal instantiation. That is, given
conclude
∀x ∈ D, P (x)
for a
d ∈ D,
you may
P (d).)
Everyone who stole an object was caught.
Anyone who was caught saw the gum and the pipe.
Squirrel Girl didn't see the gum.
Therefore, Squirrel girl did not steal anything.
Note: to say that someone saw an object, you can say that they saw it either before or after something.
(We don't have a predicate that just lets you say someone saw an object without a comparison to another
object.) We recommend dening a new saw predicate in terms of the existing ones, as it will make writing
your solution easier. That's what we did!
2
Odd Shapes [9 marks]
Consider the following theorem:
Theorem:
The area of any rectangle whose side lengths are both odd integers is the dierence
of two perfect squares.
1. Express this theorem in predicate logic using the following sets, functions, and predicates:
ˆ R
is the set of rectangles
ˆ s1 (r)
takes a rectangle with integral side length and produces its rst side length (the smaller of
the two, if they dier); its signature is
ˆ s2 (r)
s1 : R → N
takes a rectangle and produces its second side length; its signature is
ˆ Odd(x) takes an integer and indicates whether it is odd.
Note that
s2 : R → N
Odd(x) ≡ ∃k ∈ Z, x = 2k −1.
Remember that a perfect square is the square of an integer.
2. Now, prove the theorem is true. Your proof should be informal (in natural language), but it must
proceed with proof steps described in our proof strategies reference or Dave's Awesome Handout (or
very clearly described and very clearly correct steps that we can easily read beyond those, but
aware that we will deduct marks if we disagree with these caveats!). Signicant credit goes
with
be
to clear, step-by-step layout of your proof approach. The remainder goes for the correctness of your
proof.
Hint:
(a2 − b2 ) = (a + b)(a − b).
Notice that
a
is exactly in the middle between
2
a+b
and
a − b.
3
Extra Problems
These problems are
not
for marks but are good practice!
We supply sample solution for them on the
subsequent page. Don't look until you've tried them!
3.1 The Case of the Missing Nuts
1. Translate to predicate logic: Everyone who claimed to see the rope rst stole some other object. (This
is a tricky one!)
2. Translate to English:
3. Dene a predicate
saw after
n
o.
was
∼ ∃p ∈ P, ∃p2 ∈ P, ∃o ∈ O, Stole(p, o) ∧ PersonOrder(p, p2 , o)
Next(n, o, p),
meaning that the (immediately) next object that person
p
actually
(Note that this is a tricky one!)
4. Translate into predicate logic and prove formally:
Only people who saw the rope after Koi Boy were caught.
Tippy Toe did not see the rope after Koi Boy.
No one saw the same object both before and after someone.
Therefore, Tippy Toe didn't get caught.
3.2 Big O
We're comparing two algorithms' running times. One algorithm takes
g(n) = n! seconds to run.
n! = n ∗ (n − 1) ∗ (n − 2) ∗ · · · ∗ 3 ∗ 2 ∗ 1.
f (n) = 10n2
seconds to run. The
other algorithm takes
(Remember that
n! = n ∗ (n − 1)!,
More formally,
0! = 1
and for
n > 0,
but the informal denition will probably be more useful here.)
∃c ∈ R+ , ∃n0 ∈ N, ∀n ∈ N, n ≥ n0 → f (n) ≤ cg(n).
and N is the set of natural numbers.
Prove that the following statement is true:
Recall that
R+
is the set of real numbers
Your proof should be informal (in natural language), but it must proceed with proof steps described in
very clearly described and very clearly
correct steps that we can easily read beyond those, but be aware that we will deduct marks if we disagree
our proof strategies reference or Dave's Awesome Handout (or with
with these caveats!).
3
3.3 Sample Solutions
These can be very helpful to you, but at least give a brief try to each problem before you look at its sample
solution!
3.3.1 The Case of the Missing Nuts
1. Translate to predicate logic: Everyone who claimed to see the rope rst (among the objects they saw)
stole some other object.
Sample solution:
We have the set of people but not the set of people who claimed to see the rope
rst. So, we'll want to restrict the domain of the universal over people to just those who claimed to
see the rope rst.
But, how do we say someone claimed to see the rope
rst.
That's a bit unclear. We can only say
that they claimed to see an object before another object. There's two reasonable ways to approach
seeing it rst. We could say they didn't claim to see anything else before it, or we could say they
did claim to see everything else after it.
We could do either or both, but perhaps the best design would be to wrap this choice up in a predicate
so we can revisit it later without messing with everything else we want to express.
So, we'll go with a version of both statements ( p didn't claim to see anything else before, and
anything else they did made a claim about seeing, they claimed came after) and put them in a new
ClaimedFirst
predicate we dene in terms of our existing predicates.
To do that, we can rst say
they claimed to see something else before the rope. Then, we can negate that. Here we go with
p
claimed to see something else before the rope:
practice, we probably don't need the
o2 6= rope
∃o2 ∈ O, o2 6= rope ∧ ObjectClaim(o2 , rope, p).
In
part, since that's just to avoid claiming to see the
rope before the rope (which we probably also shouldn't do when claiming to see the rope rst!).
We also need claiming that anything else they made a claim about seeing they claim came after:
∀o3 ∈ O, (o3 6= rope∧(∃o4 ∈ O, ObjectClaim(o3 , o4 , p)∨ObjectClaim(o4 , o3 , p))) → ObjectClaim(rope, o3 , p).
Now, we're set for p did not claim to see anything else before and claimed everything else they saw
was after. To make the new predicate, we'll generalize from the rope specically to any object:
ClaimedFirst(p, o) ≡(∼ ∃o2 ∈ O, ObjectClaim(o2 , o, p))∧
(∀o3 ∈ O, (o3 6= o ∧ (ObjectClaim(o3 , o4 , p) ∨ ObjectClaim(o4 , o3 , p))) →
ObjectClaim(rope, o3 , p))
Having dened that, we can now do the domain restriction to everyone who claimed to see the rope
rst:
∀p ∈ P, ClaimedFirst(p, rope) → . . ..
Finally, we need
p
to steal some other object.
∀p ∈ P, ClaimedFirst(p, rope) → ∃o2 ∈ O, o2 6= rope ∧ Stole(p, o2 )
This does not do a good job of handling the possibility that we make no claims about having seen
anything, but the predicates we were provided just don't do a great job with that, sadly!
2. Translate to English:
Sample solution:
∼ ∃p ∈ P, ∃p2 ∈ P, ∃o ∈ O, Stole(p, o) ∧ PersonOrder(p, p2 , o)
We'll translate it without the negation rst and then add the negation at the end.
Literally, it says there's a person
p
and
Let's massage that into clearer English.
p2
p
and an object
stole
after the person who stole it did.
4
o
and
p2
o
such that
saw
o
after
p
p.
stole
o
and
p
saw
o
before
p2 .
So, somebody saw an object
That's pretty good. Let's negate it: No one actually saw any stolen object after the person who stole
it.
3. Dene a predicate
saw after
n
was
o.
Sample solution:
Next(n, o, p),
meaning that the (immediately) next object that person
p
actually
(Note that this is a tricky one!)
What does it mean to see an object next? It sounds like it means one sees the
object after the one in question but sees nothing else between the two. Let's state the positive version
p sees some object between n and o. So, p
o: ObjectOrder(n, o2 , p) ∧ ObjectOrder(o2 , o, p). Let's make that
rst, then we can negate it. So, we want to say that
sees
n
before
o2
and sees
o2
before
a predicate, and then we can use it conveniently:
ObjectBetween(n, o2 , o, p) ≡ ObjectOrder(n, o2 , p) ∧ ObjectOrder(o2 , o, p)
(We could use dierent parameter names than
n, o2 , o,
and
p;
if we were dening this for general use,
we probably should, since this is a strange set of names to use and makes the denition a bit less
clear. But, since it's only for this one use, we'll leave it.)
Now, we just want to say that
p
sees
n
before
o
and nothing between them:
Next(n, o, p) ≡ ObjectOrder(n, o, p)∧ ∼ ∃o2 ∈ O, ObjectBetween(n, o2 , o, p)
4. Translate into predicate logic and prove formally:
Only people who saw the rope after Koi Boy were caught.
Tippy Toe saw the rope before Koi Boy.
No one saw the same object both before and after someone.
Therefore, Tippy Toe didn't get caught.
Sample solution:
The only use here is a bit tricky. What does only [these people] were caught
really mean? It doesn't mean all of them were caught. Instead, it means nobody else was caught. So,
we want to say that everyone who did
not see the rope after Koi Boy was not caught.
We need the people who did not see the rope after Koi Boi. That's domain restriction:
∀p ∈ P, ∼
PersonOrder(KB, p, rope) → . . ..
Now, we want to say those people weren't caught:
Premise #1:
∀p ∈ P, ∼ PersonOrder(KB, p, rope) →∼ Caught(p)
The next statement is pretty straightforward.
Premise #2:
PersonOrder(TT, KB, rope)
Next, we want to say that it is not the case that someone saw an object both before and after someone
else. That's not
Premise #3:
too complex.
∼ ∃p1 ∈ P, ∃p2 ∈ P, ∃o ∈ O, PersonOrder(p1 , p2 , o) ∧ PersonOrder(p2 , p1 , o)
The conclusion is just:
∼ Caught(TT).
Now, let's work out and then write up our proof.
We'd like to be able to say TT wasn't caught. To do that, we want her in the class of people that
wasn't caught. That means we need that she didn't see the rope after KB. We have that she saw the
rope before KB. We can use the third premise to conclude from that that she didn't see the rope after
him. Together, that ought to do it. Let's see. . . we'll also want to make that big negated existential
in the third premise into a universal so we can instantiate it for TT, KB, and the rope.
Note: we'll do generalized DM steps one-by-one instead of going across multiple quantiers at once,
but you can just go across a collection of side-by-side quantiers all at once.
emphasize that these really are individual steps in the process. That said, we
three variables in our triple-universal in one step. :)
5
We just wanted to
did just instantiate all
1.
2.
3.
4.
∀p ∈ P, ∼ PersonOrder(KB, p, rope) →∼ Caught(p)
PersonOrder(TT, KB, rope)
∼ ∃p1 ∈ P, ∃p2 ∈ P, ∃o ∈ O, PersonOrder(p1 , p2 , o) ∧ PersonOrder(p2 , p1 , o)
∀p1 ∈ P, ∼ ∃p2 ∈ P, ∃o ∈ O, PersonOrder(p1 , p2 , o) ∧ PersonOrder(p2 , p1 , o)
premise
premise
premise
generalized DM
on 3
(AKA, quantiers)
5.
6.
7.
∀p1 ∈ P, ∀p2 ∈ P, ∼ ∃o ∈ O, PersonOrder(p1 , p2 , o) ∧ PersonOrder(p2 , p1 , o)
∀p1 ∈ P, ∀p2 ∈ P, ∀o ∈ O, ∼ (PersonOrder(p1 , p2 , o) ∧ PersonOrder(p2 , p1 , o))
∼ (PersonOrder(TT, KB, rope) ∧ PersonOrder(KB, TT, rope))
gen'l DM on 4
gen'l DM on 5
universal instantiation
on 6
8.
9.
10.
∼ PersonOrder(TT, KB, rope)∨ ∼ PersonOrder(KB, TT, rope)
∼ PersonOrder(KB, TT, rope)
∼ Caught(TT)
DM on 7
ELIM on 2 and 8
Universal MP
on 1 and 9
3.3.2 Big O
For
f (n) = 10n2
g(n) = n!, prove that ∃c ∈ R+ , ∃n0 ∈ N, ∀n ∈ N, n ≥ n0 → f (n) ≤ cg(n).
∃c ∈ R+ , ∃n0 ∈ N, ∀n ∈ N, n ≥ n0 → f (n) ≤ cg(n). As we work through the
and
Our theorem is
problem,
we'll put our proof in bullet-point form. When we're done, we'll write it out in full.
∃c ∈ R+ .
The outermost operator is
Looking at the proof strategies sheet, a witness proof sounds
promising. So, we'll start with:
ˆ
Let
c=
(a positive real number)
Then, we'll prove the body of the existential
∃n0 ∈ N, ∀n ∈ N, n ≥ n0 → f (n) ≤ cg(n).
Again, we have an existential as our outermost operator; so, we continue:
ˆ
Let
c=
ˆ
Let
n0 =
(a positive real number)
(a natural number)
Our remaining theorem is
∀n ∈ N, n ≥ n0 → f (n) ≤ cg(n).
To approach the universal that's the
outermost operator, we'll try a WLOG proof.
ˆ
Let
c=
ˆ
Let
n0 =
ˆ
(a positive real number)
WLOG, let
(a natural number)
n
be a natural number. (Do
not pick a value for n.
It's a natural number, but we don't
want to say which one or we're losing generality!)
That leaves us with just:
n ≥ n0 → f (n) ≤ cg(n).
The outermost operator is
→.
A natural way to go
is antecedent assumption:
ˆ
Let
c=
ˆ
Let
n0 =
ˆ
(a positive real number)
WLOG, let
(a natural number)
n
be a natural number. (Do
not pick a value for n.
want to say which one or we're losing generality!)
ˆ
Assume
n ≥ n0 .
6
It's a natural number, but we don't
Now, we have
f (n) ≤ cg(n)
remaining in our theorem. To prove an inequality, we'll want to work from
one side of the inequality to the other (much like proving a logical equivalence). At each step of this
≤
proof, we need to make sure the right side is at least as large as the left. (So, we can make it bigger but
never smaller.)
But, we can't do that until we do our scratchwork and gure out what we want
Let's try setting
f (n) = cg(n)
c
and
n0
to be.
to look for a crossing point for these two functions and see where it
gets us. Then, we might be able to choose values for
c
and
n0
and work out our inequality proof. As I go,
I'm going to feel comfortable taking some simplifying steps if it looks like they won't break my inequality.
WARNING: From this point forward, the scratch work becomes trickier and harder for you to recreate.
You should still strive to nish your proofs! However, we understand that some steps will be harder than
others and will try to assign partial credit to solutions in a reasonable way. (Here, for example, we very
much expect you to be able to do everything up to this point. We also expect that you'd recognize you need
to nd good values for
c
and
n0 .
Of course, we'd also like you to get to the end of the proof successfully,
but lots of partial credit will go into the earlier pieces!)
10n2 = cn!
maybe we can make
which is much more like
n2
n!
into just
and is at most
n!
n(n − 1),
for
n≥2
2
10n = cn(n − 1)
10n2 = cn2 − cn
NOTE:
(
Again, this is just scratchwork.
I'm saying
=
above just because it's comfortable to work
with, not because these really are equal!)
c = 10, we're almost there, but that −cn means that the left side will be
c or n0 bigger to get rid of that piece. I'll make n0 bigger. I already said
for n ≥ 2, n! ≥ n(n − 1). Now, I'll make n ≥ 4 and say n! ≥ n(n − 1)2. When n = 4, that's 4 × 3 × 2.
As n gets larger, I'm just using the two biggest terms and the term 2. The reason to do this is to give me
2
2
enough size on the right side to get to just n instead of n − n. Multiplying n − 1 by 2 should give us
something bigger than n. Indeed, I can say that 2(n − 1) > n anytime n > 1.
2
2
OK. So, I'll turn n! into n(n − 1)2 and then into n (by changing (n − 1)2 into n). That gives me cn
on the right, and I can just pick c = 10. I'm going to start from the cn! side because I'm nding that more
At that point, if we choose
too large. We can try making
complex, and it's usually easier to start from the more complex side. Here we go!
cn! = 10n!
because
≥ 10n(n − 1)2
c = 10
because
≥ 10n × n
because
(n − 1)2 ≥ n
for
n≥4
n>1
≥ 10n2
c = 10? Remember, I got to choose c since
quantied. So, I can just ll in the blank for c above with 10.
How do I know n ≥ 4 and n > 1? Well, if I know n ≥ 4, then n > 1 is no problem.
And, I get to choose n0 just like I got to choose c. So, I'll pick n0 = 4.
And that does it! Now, how did I know
I'm now ready for my full proof !
it was existentially
I assumed
n ≥ n0 .
Theorem: ∃c ∈ R+ , ∃n0 ∈ N, ∀n ∈ N, n ≥ n0 → f (n) ≤ cg(n), where f (n) = 10n2 and g(n) = n!
Proof: Let c = 10 and let n0 = 4. WLOG, let n be a natural number. Assume n ≥ n0 (in order to
prove
f (n) ≤ cg(n)).
Then:
7
cn! = 10n!
because
≥ 10n(n − 1)2
because
≥ 10n × n
≥ 10n
Therefore,
cn! ≥ 10n2
c = 10
because
(n − 1)2 ≥ n
for
2
and so
cg(n) ≥ f (n),
which completes the proof.
8
QED
n≥4
n>1