0% found this document useful (0 votes)
11 views

150 Problem Set 2

Uploaded by

mail
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

150 Problem Set 2

Uploaded by

mail
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

CS103 Handout 15

Winter 2018 January 19, 2018

Problem Set 2
This second problem set explores mathematical logic. We've chosen the questions here to help you
get a more nuanced understanding for what frsttorder logic statements mean (and, importantly,
what they don't mean) and to give you a chance to practice your proofwriting. By the time you've
completed this problem set, we hope that you have a much better grasp of mathematical logic and
how it can help improve your proofwriting structure.
Because of the Dr. Martin Luther King, Jr. holiday, there are a few problems on this problem set
that reference concepts we will cover in Monday’s lecture. Those questions are clearly marked as
such, and anything that doesn’t explicitly warn about this can be completed purely using the material
up to and including the lecture when this problem set is released. If you’d like to get an early jump
on the remaining problems, visit the course website and check out the Guide to Negations and
Guide to FirsttOrder Translations, which will provide an overview of the relevant skills.
Before attempting this problem set, we recommend that you do the following:
• Familiarize yourself with the online Truth Table Tool and play around with it a bit to get a
feel for the propositional connectives.
• Read the online “Guide to Negations” and “Guide to FirsttOrder Translations” (either on
Monday, or when this problem set goes out if you want to get a jump on things).
• Read Handout #14, “FirsttOrder Translation Checklist,” to get a better sense for common
errors in frsttorder logic translations and how to avoid them. We will be running these
checklists on your translations, so please be sure to double-check your work before sub-
mitting!

Checkpoint Questions Due Monday, January 22nd at 2:30PM.


Remaining Questions Due Friday, January 26th at 2:30PM.
2 / 11

This week’s checkpoint problem comes in the shape of a Google Form, which you can fnd online using
this link. Unlike the other assignments for this quarter, you will not submit this assignment on Gradet
Scope, and you’ll get feedback about incorrect answers as you go.

Checkpoint Problem: Interpersonal Dynamics (2 Points if Submitted)


The diagram to the right represents a set of people named A, B, C,
D, E, and F. If there's an arrow from a person x to a person y, then
person x loves person y. We'll denote this by writing Loves(x, y). A
For example, in this picture, we have Loves(C, D) and Loves(E, E),
but not Loves(D, A).
There are no “implied” arrows anywhere in this diagram. For ext
ample, even though A loves C and C loves E, the statement B C D
Loves(A, E) is false because there's no direct arrow from A to E.
Similarly, even though C loves D, the statement Loves(D, C) is
false because there's no arrow from D to C.
At the linked Google Form, you’ll fnd a series of frsttorder logic E F
formulas about this particular group of people. For each of those
formulas, determine whether it’s true or false about this group. No
justifcation is necessary.
3 / 11

The remainder of these problems should be completed and


submitted through GradeScope by Friday at 2:30PM.
Problem One: Implies and False
Although propositional logic has many diferent connectives, it turns out that any formula in propositional
logic can be rewritten as an equivalent propositional formula that uses only the ¬, ∧, and ⊤ connectives.
(You don't need to prove this). In this problem, you will prove a diferent result: every formula in proposit
tional logic can be rewritten as an equivalent logical formula purely using the → and ⊥ connectives.
i. Find a formula that's logically equivalent to ¬p that uses only the variable p and the → and ⊥ cont
nectives. No justifcation is necessary.
ii. Find a formula that's logically equivalent to ⊤ that uses only the → and ⊥ connectives. No justift
cation is necessary.
iii. Find a formula that's logically equivalent to p ∧ q that uses only the variables p and q and the →
and ⊥ connectives. No justifcation is necessary.
As a hint, what happens if you negate an implication?
Since you can express ¬, ∧, and ⊤ using just → and ⊥, every possible formula in propositional logic can
be expressed using purely the → and ⊥ connectives. Nifty!

Problem Two: Ternary Conditionals


Many programming languages support a ternary conditional operator. For example, in C, C++, and Java,
the expression x ? y : z means “evaluate the boolean expression x. If it's true, the entire expression evalut
ates to y. If it's false, the entire expression evaluates to z.”
In the context of propositional logic, we can introduce a new ternary connective ?: such that p ? q : r
means “if p is true, the connective evaluates to the truth value of q, and otherwise it evaluates to the truth
value of r.”
i. Based on this description, write a truth table for the ?: connective.
ii. Find a propositional formula equivalent to p ? q : r that does not use the ?: connective. Justify
your answer by providing a truth table for your new formula.
It turns out that it's possible to rewrite any formula in propositional logic using only ?:, ⊤, and ⊥. The
rest of this question will ask you to show this.
iii. Find a formula equivalent to ¬p that does not use any connectives besides ?:, ⊤, and ⊥. No justift
cation is necessary.
iv. Find a formula equivalent to p → q that does not use any connectives besides ?:, ⊤, and ⊥. No
justifcation is necessary.
Since all remaining connectives can be written purely in terms of ¬ and →, any propositional formula ust
ing the seven standard connectives can be rewritten using only the three connectives ?:, ⊤, and ⊥.
The fact that all propositional formulas can be written purely in terms of ?:, ⊤, and ⊥ forms the basis for
the binary decision diagram, a data structure for compactly encoding propositional formulas. Binary decit
sion diagrams have applications in program optimization, graph algorithms, and computational complext
ity theory. Take CS166 or CS243 for more info!
4 / 11

Problem Three: Executable Logic


There’s a great quote from Douglas Adams about programming a computer:
“[I]f you really want to understand something, the best way is to try and explain it to
someone else. That forces you to sort it out in your mind. [… T]hat's really the essence of
programming. By the time you've sorted out a complicated idea into little steps that even a
stupid machine can deal with, you've learned something about it yourself.”
To help you get a better feeling for what frsttorder logic formulas mean – and, importantly, what they
don’t mean – we’d like you to write a series of short programs that determine whether particular frsttort
der logic formulas are true about specifc worlds. Visit the CS103 website and download the starter
project for Problem Set Two. Open ExecutableLogic.cpp, where you’ll fnd six function stubs. The
frsttorder formulas in this problem deal with sets of people who may or may not be happy and who may
or may not love one another. Each person is represented as an object of type Person, and we’ve provided
the following predicates functions to you:
bool happy(Person p)
bool loves(Person p1, Person p2)
These functions are written in lowertcase, since that’s the established C++ convention. The starter fles
contain a program that visualizes diferent groups of people and shows how each of your functions evalut
ates. We strongly recommend using this to check your work as you go.
i. Consider the following frsttorder logic formula, where P is a set of people:
∃x ∈ P. Happy(x)
Write C++ code for a function
bool isFormulaTrueFor_partI(std::set<Person> P)
that accepts as input a set of people P and returns whether the above formula is true for that part
ticular set of people.
ii. Repeat the above exercise with this frsttorder logic formula:
∀x ∈ P. Happy(x)
iii. Repeat the above exercise with this frsttorder logic formula:
∃x ∈ P. (Happy(x) ∧ Loves(x, x))
iv. Repeat the above exercise with this frsttorder logic formula:
∀x ∈ P. (Happy(x) → Loves(x, x))
v. Repeat the above exercise with this frsttorder logic formula:
∀x ∈ P. (Happy(x) →
∃y ∈ P. (Happy(y) ∧ ¬Loves(x, y))
)
It’s a lot easier to write code for this one if you use a helper function.
vi. Repeat the above exercise with this frsttorder logic formula:
∃x ∈ P. (Happy(x) ↔
∀y ∈ P. (Loves(x, y))
)
As in Problem Set One, you’re welcome to submit your answers to this question as many times as you’d
like. To submit your work for this problem, upload the fle ExecutableLogic.cpp.
5 / 11

Problem Four: First-Order Negations


(We will cover the material necessary to solve this problem on Monday. You can also read over the Guide to
Negations, which covers all the skills you’ll need.)
For each of the frsttorder logic formulas below, fnd a frsttorder logic formula that is the negation of the
original statement. Your fnal formula must not have any negations in it except for direct negations of
predicates. For example, the negation of the formula ∀x. (P(x) → ∃y. (Q(x) ∧ R(y))) could be found by
pushing the negation in from the outside inward as follows:
¬(∀x. (P(x) → ∃y. (Q(x) ∧ R(y))))
∃x. ¬(P(x) → ∃y. (Q(x) ∧ R(y)))
∃x. (P(x) ∧ ¬∃y. (Q(x) ∧ R(y)))
∃x. (P(x) ∧ ∀y. ¬(Q(x) ∧ R(y)))
∃x. (P(x) ∧ ∀y. (Q(x) → ¬R(y)))
Show every step of the process of pushing the negation into the formula (along the lines of what is done
above), and please preserve the indentation from the original formula as you go. You don't need to fort
mally prove that your negations are correct.
We strongly recommend reading over the Guide to Negations before starting this problem.
i. ∃p. (Problem(p) ∧
∀g. (Program(g) → ¬Solves(g, p))
)
ii. ∀x ∈ ℝ. ∀y ∈ ℝ. (x < y →
∃q ∈ ℚ. (x < q ∧ q < y)
)
iii. (∀x. ∀y. ∀z. (R(x, y) ∧ R(y, z) → R(x, z))) → (∀x. ∀y. ∀z. (R(y, x) ∧ R(z, y) → R(z, x)))
iv. ∀x. ∃S. (Set(S) ∧
∀z. (z ∈ S ↔ z = x)
)
v. ∀k. (SixClique(k) →
∃t. (Triangle(t, k) ∧
(∀e. (Edge(e, t) → Red(e)) ∨ ∀e. (Edge(e, t) → Blue(e)))
)
)
6 / 11

Problem Five: Vacuous Truths


(We will cover the material necessary to solve this problem on Monday. You can also read over the Guide to
Negations, which covers all the skills you’ll need.)
A statement is called vacuously true if either
• it’s an implication of the form P → Q where P is false,
• it’s a universallytquantifed implication ∀x. (P(x) → Q(x)) where P(x) is never true, or
• it’s a universallytquantifed implication ∀x ∈ S. Q(x) where S is the empty set.
These statements are true by defnition. In the frst case, the truth table for the → connective says the imt
plication is true when the antecedent is false, and in the second and third cases we just defne these sorts
of statements to be true.
You might be wondering why exactly this is the case.
i. Negate the propositional formula P → Q and push the negations as deep as possible. Now, look at
the resulting formula. Explain why when P → Q is vacuously true, its negation is false.
ii. Negate the frsttorder formula ∀x. (P(x) → Q(x)) and push the negations as deep as possible. Now,
look at the resulting formula. Explain why if the original formula is vacuously true, then its negat
tion is false.
iii. Negate the frsttorder formula ∀x ∈ S. Q(x) and push the negations as deep as possible. Now, look
at the resulting formula. Explain why if the original formula is vacuously true, then its negation is
false.
Your answers to parts (i), (ii), and (iii) of this problem give another justifcation for vacuous truths. The
three classes of statements given above have false negations in the indicated cases, and therefore to keep
everything consistent we choose to defne them as true.
iv. Now, look back over the code you wrote for parts (ii), (iv), and (v) of the Executable Logic probt
lem. In the course of writing those functions, you should not have needed to handle vacuous truths
by adding in extra code to specifcally check whether the group in question is empty. (If you did,
see if you can go back and remove it!) Briefy explain why it’s not necessary to handle these cases
explicitly and why your code will correctly handle empty inputs without singling this case out.
Your answer to part (iv) of this problem gives a diferent intuition for why statements would be vacuously
true – vacuous truth naturally follows from how we might think about checking whether a universallyt
quantifed formula would be true.
7 / 11

Problem Six: This, But Not That


(We will cover the material necessary to solve this problem on Monday. You can also read over the Guide to
Negations, which covers all the skills you’ll need.)
Below is a series of pairs of statements about a group of people. For each pair, come up with a single
group of people where the frst statement is true about that group of people and the second statement is
false about that group of people. To submit your answers, edit the fles ThisButNotThatI.people,
ThisButNotThatII.people, etc. in the res/ directory of the starter fles for this assignment with a det
scription of those groups. There’s a description in each of those fles of how to specify a group of people.
The starter fle ThisButNotThat.cpp we’ve provided you contain stubs of ten functions representing the
ten statements here (the fve “this” statements and the fve “that” statements). You may optionally implet
ment those functions in the course of solving this problem so that you can test your worlds, but you are
not required to do so. You’ll just be graded on the groups you submit.
Make this statement true… … and this statement false.
i. ∀y ∈ P. ∃x ∈ P. Loves(x, y) ∃x ∈ P. ∀y ∈ P. Loves(x, y)
ii. ∀x ∈ P. (Happy(x) ∨ Loves(x, x)) (∀x ∈ P. Happy(x)) ∨ (∀x ∈ P. Loves(x, x))
iii. (∃x ∈ P. Happy(x)) ∧ (∃x ∈ P. Loves(x, x)) ∃x ∈ P. (Happy(x) ∧ Loves(x, x))
iv. (∀x ∈ P. Happy(x)) → (∀y ∈ P. Loves(y, y)) ∀x ∈ P. ∀y ∈ P. (Happy(x) → Loves(y, y))
v. ∃x ∈ P. (Loves(x, x) → (∀x ∈ P. Loves(x, x)) ∨ (∀x ∈ P. ¬Loves(x, x))
∀y ∈ P. (Loves(y, y))
)
As a hint, if you want to make a statement false, make its negation true.
To submit your answer, upload the fve .people fles you edited in the course of solving this problem to
GradeScope, and don’t forget to also include the ExecutableLogic.cpp fle from earlier in this problem
set!
8 / 11

Problem Seven: Translating into Logic


(We will cover the material necessary to solve this problem on Monday. You can also read over the Guide to
First-Order Translations, which covers all the skills you’ll need.)
In each of the following, write a statement in frsttorder logic that expresses the indicated sentence. Your
statement may use any frsttorder construct (equality, connectives, quantifers, etc.), but you must only use
the predicates, functions, and constants provided. You do not need to provide the simplest formula possit
ble, though we'd appreciate it if you made an efort to do so. ☺ We highly recommend reading the Guide
to FirsttOrder Logic Translations before starting this problem.
i. Given the predicate
Natural(x), which states that x is an natural number
and the functions
x + y, which represents the sum of x and y, and
x · y, which represents the product of x and y
write a statement in frsttorder logic that says “for any n ∈ ℕ, n is even if and only if n2 is even.”
Try translating this statement assuming you have a predicate Even(x). Then, rewrite your solution without
using Even(x). Numbers aren’t a part of FOL, so you can’t use the number 2 in your solution.
ii. Given the predicates
Person(p), which states that p is a person;
Kitten(k), which states that k is a kitten; and
HasPet(o, p), which states that o has p as a pet,
write an FOL statement that says “someone has exactly two pet kittens and no other pets.”
Make sure your formula requires that the person have exactly two pet kittens; look at the lecture example of
uniqueness as a starting point. Good questions to ask – is your formula false if everyone has exactly one pet
kitten? Is it false if everyone has exactly three pet kittens?
iii. The axiom of pairing is the following statement: given any two distinct objects x and y, there's a
set containing x and y and nothing else. Given the predicates
x ∈ y, which states that x is an element of y, and
Set(S), which states that S is a set,
write a statement in frsttorder logic that expresses the axiom of pairing.
iv. Given the predicates
x ∈ y, which states that x is an element of y, and
Set(S), which states that S is a set,
write a statement in frsttorder logic that says “every set has a power set.”
As a warm-up, solve this problem assuming you have a predicate X ⊆ Y that says that X is a subset of Y.
Once you have that working, see if you can solve the full version of this problem.
v. Given the predicates
Lady(x), which states that x is a lady;
Glitters(x), which states that x glitters;
SureIsGold(x, y), which states that x is sure that y is gold;
Buying(x, y), which states that x buys y; and
StairwayToHeaven(x), which states that x is a Stairway to Heaven;
write a statement in frsttorder logic that says “there's a lady who's sure all that glitters is gold, and
she's buying a Stairway to Heaven.”
9 / 11

Problem Eight: Hereditary Sets


Let’s begin with a fun little defnition:
A set S is called a hereditary set if all its elements are hereditary sets.
This defnition might seem strange because it's selftreferential – it defnes hereditary sets in terms of other
hereditary sets! However, it turns out that this is a perfectly reasonable defnition to work with, and in this
problem you'll explore some properties of these types of sets.
i. Given the selftreferential nature of the defnition of hereditary sets, it's not even clear that heredit
tary sets even exist at all! As a starting point, prove that there is at least one hereditary set.
ii. Prove that if S is a hereditary set, then ℘(S) is also a hereditary set.

After you’ve written up a draft of your proofs, take a minute to read over them and apply the criteria from
the Proofwriting Checklist. Here are a few specifc things to watch out for:
• If you want to prove in part (ii) that a set T is a hereditary set, you need to prove the statement “ev -
ery element of T is a hereditary set.” That’s a universally-quantifed statement. If you’re proving it
via a direct proof, you’ll probably need to pick some arbitrary element x ∈ T, then prove that x is a
hereditary set by making specifc claims about the variable x. Read over your proof and make sure
that (1) you’ve introduced a new variable to refer to some arbitrarily-chosen element of T and that
(2) you’re making specifc claims about the variable x, rather than talking in general about how ele -
ments of T behave. You may need to introduce multiple variables in the course of your proofs.
• A common mistake we see people make when they’re just getting started is to restate defnitions in
the abstract in the middle of a proof. For example, we commonly see people say something like
“since A ⊆ B, we know that every element of A is an element of B.” When you’re writing a proof,
you can assume that whoever is reading your proof is familiar with the defnitions of relevant
terms, so statements like the one here that just restate a defnition aren’t necessary. Instead of restat -
ing defnitions, try to apply those defnitions. A better sentence would be something to the efect of
“Since x ∈ A and A ⊆ B, we see that x ∈ B,” which uses the defnition to conclude something about a
specifc variable rather than just restating the defnition.
• Although we’ve just introduced frst-order logic as a tool for formalizing defnitions and reasoning
about mathematical structures, the convention is to not use frst-order logic notation (connectives,
quantifers, etc.) in written proofs. In a sense, you can think of frst-order logic as the stage crew in
the theater piece that is a proof – it works behind the scenes to make everything come together, but
it’s not supposed to be in front of the audience. Make sure that you’re still writing in complete sen -
tences, that you’re not using symbols like ∀ or → in place of words like “for any” or “therefore,” etc.
10 / 11

Problem Nine: Symmetric Latin Squares


A Latin square is an n × n grid flled with the numbers 1, 2, 3, …, n such that every number appears in
every row and every column exactly once. For example, the following are Latin squares:
1 3 5 2 4
4 2 1 3
1 2 3 2 4 1 3 5
1 3 2 4
3 1 2 3 5 2 4 1
3 1 4 2
2 3 1 4 1 3 5 2
2 4 3 1
5 2 4 1 3

A symmetric Latin square is a Latin square that is symmetric across the main diagonal (the one from the
uppertleft corner to the lowertright corner). That is, the elements at positions (i, j) and (j, i) are always the
same. For example:
1 2 3 4 5
4 2 3 1
1 2 3 2 4 5 3 1
2 3 1 4
2 3 1 3 5 2 1 4
3 1 4 2
3 1 2 4 3 1 5 2
1 4 2 3
5 1 4 2 3

Prove that in any n × n symmetric Latin square where n is odd, every number 1, 2, 3, …, n must appear at
least once on the main diagonal.
As a hint: split the Latin square into three regions – the main diagonal and the two regions above and below
the main diagonal. Then think about how often each element appears in each group.
Once you’ve written up a draft of your proof for this problem, try out the following exercise as a way of
checking your work. If you look at the sample Latin squares shown above, you can see that the result given
above is not true in the case where the Latin square isn’t symmetric, and it’s also not true in the case where
the square has even size. As a result, if your proof does not specifcally use the fact that the Latin square is
symmetric and does not specifcally use the fact that the Latin square has odd size, it has to contain an error
somewhere. Otherwise, you could change the setup to the problem and end up with a proof of an incorrect
result. (Do you see why this is?) So go back over your proof and ask yourself – where, specifcally, am I
making reference to the fact that the Latin square is symmetric? Where, specifcally, am I making reference
to the fact that the Latin square has odd size? And why would my proof break down if I eliminated either
of those references?
Going forward, this approach to checking your proofs – perturbing the starting assumptions and seeing
where your logic breaks down – is an excellent way to smoke out any underlying logic errors.
11 / 11

Problem Ten: Tournament Winners


Here’s one more problem to help you practice your proofwriting. It’s a classic CS103 problem, and we
hope that you enjoy it!
A tournament is a contest among n players. Each player plays a game against
B
each other player, and either wins or loses the game (let's assume that there are
A
no draws). We can visually represent a tournament by drawing a circle for each
player and drawing arrows between pairs of players to indicate who won each
C game. For example, in the tournament to the left, player A beat player E, but
lost to players B, C, and D.
E A tournament winner is a player in a tournament who, for each other player,
D either won her game against that player, or won a game against a player who in
turn won his game against that player (or both). For example, in the graph on
the left, players B, C, and E are tournament winners. However, player D is not a tournament winner, bet
cause he neither beat player C, nor beat anyone who in turn beat player C. Although player D won against
player E, who in turn won against player B, who then won against player C, under our defnition player D
is not a tournament winner. (Make sure you understand why!)
i. Let T be an arbitrary tournament and p be any player in that tournament. Prove the following
statement: if p won more games than anyone else in T or is tied for winning the greatest number
of games, then p is a tournament winner in T.
This problem is a lot easier to solve if you draw the right picture. Something to think about: what happens if
a player p isn’t a winner in a tournament? What would that mean about player p? And fnally, be careful
not to make broad claims about tournaments or tournament structures without frst proving them!
A corollary of the result you proved in part (i) is that every tournament with at least one player must have
at least one tournament winner – you can always pick someone who won the most games or is tied for
winning the most games. However, note that you can win a tournament without necessarily winning the
most games – for example, player E in the above example tournament is a winner, though player E only
won a single game!
Whenever you prove a new mathematical result (in this case, every tournament with at least one player
has at least one winner), it’s useful to ask how “resilient” that result is. In other words, if we relax our deft
nition of a tournament a little bit, can we still necessarily guarantee that we can always fnd a winner? The
answer is no, and in fact, even slightly weakening the defnition of a tournament invalidates this result.
Let’s introduce one more defnition. A pseudotournament is like a tournament, except that exactly one
pair of people don’t play a game against one another.
ii. Prove that for any n ≥ 2, there’s a pseudotournament P with n players and no tournament winners.
Think about the structure of what you’re being asked to prove here. There’s both a universal and an existen-
tial component to this statement. How do you prove an existential statement?

Optional Fun Problem: Insufficient Connectives (1 Point Extra Credit)


On some of the earlier problems on this problem set, you that every propositional logic formula could be
written in terms of just the ¬, ∧, and ⊤. You also saw that you could use just → and ⊥, or alternatively
that you could just use ?:, ⊤, and ⊥. Interestingly, you cannot express every possible propositional logic
formula using just the ↔ and ⊥ connectives. Prove why not.

You might also like