0% found this document useful (0 votes)
8 views9 pages

Practice Prob5 With Sol

The document is a practice problem set for CS 228M: Logic for Computer Science, Spring 2025, containing various exercises on natural deduction proofs and first-order logic (FOL). It includes problems that require proving the validity of sequents, identifying correct terms and formulas in FOL, and expressing syntactically incorrect formulas in a correct form. Additionally, it discusses predicates that are true for infinitely many or all but finitely many natural numbers.

Uploaded by

Mayur Jambhulkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views9 pages

Practice Prob5 With Sol

The document is a practice problem set for CS 228M: Logic for Computer Science, Spring 2025, containing various exercises on natural deduction proofs and first-order logic (FOL). It includes problems that require proving the validity of sequents, identifying correct terms and formulas in FOL, and expressing syntactically incorrect formulas in a correct form. Additionally, it discusses predicates that are true for infinitely many or all but finitely many natural numbers.

Uploaded by

Mayur Jambhulkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

CS 228M : Logic for Computer Science Spring 2025

Practice Problem Set 5


Instructions:
• The following problems are meant for you to practice, so that your understanding of the
topic improves.

• You must solve all problems to get the maximum benefit from practice problems.

• You must not submit your solutions to these problems. These are not going to be graded.

• Discussion among students is strongly encouraged in order to understand different perspec-


tives.

1. Naturally deduced
Prove that the following sequents are valid. In other words, show the following syntactic
entailments using natural deduction proof rules for propositional logic:
(a) ⊢ ((a ∨ (¬a ∧ b) → (a ∨ b))

Solution:
1. (a ∨ (¬a ∧ b)) assumption
2. a assumption
3. a∨b ∨i 2
4. ¬a ∧ b assumption
5. b ∧e 4
6. a∨b ∨i 5
7. a∨b ∨e 1, 2-3, 4-6
8. (a ∨ (¬a ∧ b)) → (a ∨ b) →i 1-7

(b) ⊢ (¬((a ∨ b) ∧ (¬a ∨ ¬b)) → (¬a ∨ b) ∧ (a ∨ ¬b))

Solution: Note: A shorter proof may be possible.

CS 228M Page 1 of 9 PSet 5


1. ¬((a ∨ b) ∧ (¬a ∨ ¬b)) assume
2. ¬(¬a ∨ b) assume
3. ¬a assume
4. ¬a ∨ b ∨i 2
5. ⊥ ¬e 2, 4
6. ¬¬a ¬i 3-5
7. a ¬¬e 6
8. ¬(¬(a ∨ b) ∨ ¬(¬a ∨ ¬b)) assume
9. ¬(a ∨ b) assume
10. ¬(a ∨ b) ∨ ¬(¬a ∨ ¬b) ∨i 9
11. ⊥ ¬e 8, 10
12. ¬¬(a ∨ b) ¬i 9-11
13. (a ∨ b) ¬¬e 12
14. ¬(¬a ∨ ¬b) assume
15. ¬(a ∨ b) ∨ ¬(¬a ∨ ¬b) ∨i 14
16. ⊥ ¬e 8, 15
17. ¬¬(¬a ∨ ¬b) ¬i 14 − 16
18. ¬a ∨ ¬b ¬¬e 17
19. (a ∨ b) ∧ (¬a ∨ ¬b) ∧i 13, 18
20. ⊥ ¬e 1, 19
21. ¬¬(¬(a ∨ b) ∨ ¬(¬a ∨ ¬b)) ¬i 8-20
22. (¬(a ∨ b) ∨ ¬(¬a ∨ ¬b)) ¬¬e 21
23. ¬(a ∨ b) assume
24. a assume
25. a∨b ∨i 24
26. ⊥ ¬e 23, 25
27. ¬a ¬i 24-26
28. ⊥ ¬e 7, 27
29. b ⊥e 28
30. ¬(a ∨ b) → b →i 23-29
31. ¬(¬a ∨ ¬b) assume
32. ¬b assume
33. ¬a ∨ ¬b ∨i 32
34. ⊥ ¬e 31, 33
35. ¬¬b ¬i 32-34
36. b ¬¬e 35
37. ¬(¬a ∨ ¬b) → b →i 31-36
38. b →e 2, 37
39. ¬a ∨ b ∨i 38
40. ⊥ ¬e 2, 39
41. ¬¬(¬a ∨ b) ¬i 31
42. (¬a ∨ b) ¬¬e 41
43. (a ∨ ¬b) Proof similar to 2-42
44. (¬a ∨ b) ∧ (a ∨ ¬b) ∧i 42, 43
45. (¬((a ∨ b) ∧ (¬a ∨ ¬b)) → ((¬a ∨ b) ∧ (a ∨ ¬b)) →i 1, 44

(c) ⊢ ((a → (b → c)) → ((a ∧ b) → c))

CS 228M Page 2 of 9 PSet 5


Solution:
1. a assume
2. b→c assume
3. a∧b assume
4. b ∧e 3
5. c →e 2, 4
6. (a ∧ b) → c →i 3 − 5
7. (b → c) → ((a ∧ b) → c) →i 2-6
8. (a → (b → c)) → ((a ∧ b) → c) →i 1-7

(d) a → b, b → c, c → ¬a ⊢ ¬a

Solution:
1. a→b (Premise)
2. b→c (Premise)
3. c → ¬a (Premise)
4. a assume
5. b →e 4,1
6. c →e 5,2
7. ¬a →e 6,3
8. ⊥ ¬e 4, 7
9. ¬a ¬i 4-8

2. Syntactically speaking ...


Let us define a FOL (F , P ), where F represents function symbols and P represents
predicate symbols (Note that for propositional logic F = ∅). For this problem, let F =
{f1 /1, f2 /2, c/0} and P = {>/2}. Here (F/P )/n represents a function/predicate of arity
n. Throughout the problem we allow the following syntactic relaxations : +(t1 , t2 ) ≡ t1 +t2
and >(t1 , t2 ) ≡ t1 > t2 , where t1 and t2 are terms.
(a) Identify the correct term(s) in this FOL.
i. f1 (x, y)
ii. f2 (x, y)
iii. f2 (x, 0)
iv. f2 (y, f1 (c))
v. x > c

Solution: (ii) and (iv)

f1 has arity 1 so (i) is wrong. ‘0’ is not a term so it cannot be a function/predicate


argument in (iii), so, it is wrong. x > c is a formula not a term, so, (v) is also
wrong.

(b) Identify the syntactically correct FOL formula(s), also give reason(s) why each of
them is correct/incorrect.
i. f1 (x)
ii. ∀xf1 (x)
iii. ∃yf2 (x, c) > c
iv. ∀xf2 (x, c) > 0
v. ∃x>c f1 (x) > y

CS 228M Page 3 of 9 PSet 5


Solution:

i. Incorrect. f1 (x) is a term. You need to input term(s) into predicate(s) to


get a formula.

ii. Correct.

iii. Correct. Note that a variable does not have to be used for it to be quantified
over.

iv. Incorrect. ‘0’ is not a term.

v. Incorrect. The quantifiers are over variables and variables only, that is, you
cannot use formulae or non-variable terms. Here x > c is a FOL formula.

(c) Express the FOL formula in (b)-v a syntactically correct form, ensuring that it has
the same ‘meaning’.

Solution:
∃x((x > c) ∧ (f1 (x) > y))
The above statement means that ‘there exists x such that f1 (x) > y and x > c’.
Which is same as saying ‘there exists x > c such that f1 (x) > y’.

(d) Express the following syntactically incorrect FOL formula in a syntactically correct
form, ensuring that it has the same ‘meaning’.
∀x>c f1 (x) > y

Solution: The intent here was to say that ”for all x > c, f1 (x) > y holds”. How-
ever, we can’t write x > c along with a quantifier in first-order logic. Remember,
the syntax of quantifiers allows us to only write ∀x (or ∃x) for a variable x. Hence,
we have to express our intent as follows:

∀x((x > c) → (f1 (x) > y))

(e) Identify the free variables in each of the following formulae.


i. ∀x((f1 (x) > c) → (f1 (y) > f1 (x)))
ii. (f2 (x, x) > 0) ∨ (∃x(f1 (x) > y))
iii. (∀x(∃y(f2 (x, x) > 0))) ∨ (f1 (x) > y)
iv. (∃y(∀x(f2 (x, y) > c))) ∧ (f1 (x) > f (z)) ∧ ∀z(f1 (z) > 0)

Solution:

i. Free variable: y.
 
free f1 (x) > c = {x}, free f1 (y) > f1 (x) = {x,
 y}.
Therefore, free (f1 (x) > c) → (f1 (y) > f1 (x)) = {x, y}.
And finally, free ∀x((f1 (x) > c) → (f1 (y) > f1 (x))) = {x, y} \ {x} = {y}.
Note that since the quantifier on x applies to all the occurrences of x, x is a
bound variable. y does not any quantifier, so, it is free.

CS 228M Page 4 of 9 PSet 5


ii. Free variables: x, y.
 
free (f2 (x, x) > 0) = {x}, free (f 1 (x) > y) = {x, y}.
Therefore, free ∃x(f1 (x) > y) = {x, y} \ {x} = {y}. 
And finally, free (f2 (x, x) > 0) ∨ (∃x(f1 (x) > y)) = {x} ∪ {y} = {x, y}.
Note that the set of free and bound variables need not be disjoint! Here x is
in the set of free variables of one sub-formula, and also in the set of bound
variables of another sub-formula. y does not have any quantifier, so, it is free
in any case.

iii. Free variables: x, y.



free f2 (x, x) > 0 = {x}. 
Therefore, free ∃y(f2 (x, x) > 0) = {x} \ {y} = {x}.
Hence, free ∀x(∃y(f2 (x, x) > 0)) = {x} \ {x} = ∅.
Also, free f1 (x) > y = {x, y}. 
So finally, free (∀x(∃y(f2 (x, x) > 0))) ∨ (f1 (x) > y) = ∅ ∪ {x, y} = {x, y}.
Note that x is bound at one place and free at one place. Note also that the
scope of the quantifier ∃y does not capture f1 (x) > y.

iv. Free variables: x, z.



free f2 (x, y) > c = {x, y}. 
Therefore, free ∀x(f2 (x, y) > c) = {x, y} \ {x} = {y}.
Hence, free ∃y(∀x(f2 (x, y) > c)) = {y} \ {y} = ∅. 
Also, free f1 (x) > f (z) = {x, z} and free f1 (z) > 0 = {z}.
Therefore, free ∀z(f1 (z) > 0) = {z} \ {z} = ∅. 
Finally, free (∃y(∀x(f2 (x, y) > c))) ∧ (f1 (x) > f (z)) ∧ ∀z(f1 (z) > 0) = ∅ ∪
{x, z} ∪ ∅ = {x, z}.
Note that y only occurs in bound form. In contrast, x and z are bound in
some sub-formula and free in some other sub-formula.

3. Oh, the infinite!


Let the Universe for a First Order Logic formula be U = N, the set of natural numbers.
The vocabulary V = {>, P }, where > is our usual binary predicate ‘greater than’, and P
is an unknown unary predicate. Write an FOL sentence which is true if and only if
(a) P (x) is true for infinitely many x
(b) P (x) is true for all but finitely many x i.e. P (x) is false for only finitely many x
Some example predicates P for (a) are prime numbers, even numbers, number which are
divisible by the first 100 natural numbers.
Some example predicates P for (b) are numbers greater than 10100 , numbers which are
either odd or composite, numbers which are bigger than the square of the sum of their
digits.
Can we conclude anything about whether a P satisfies (a) implies it satisfies (b), or the
other way around?

Solution: We can use the fact that for natural numbers, a set is finite if and only if it
has an upper bound. So a predicate is true for infinitely numbers can be thought of as:
for all numbers, there’s is a bigger number for which the predicate is true. Similarly for
the second part, we can think of the statement as: there is a bound above which for all

CS 228M Page 5 of 9 PSet 5


numbers the predicate is true.
(a) For every upper bound x, there must be a y above the bound for which P (y) is
true.
∀x ∃y [(y > x) ∧ P (y)]

(b) There must be a bound x, above which for every number y, P (y) is true i.e if a
number y is bigger than the bound, P (y) must be true.

∃x ∀y [(y > x) → P (y)]

It is true that P satisfying (b) implies P satisfies (a). If P (x) is false for finitely many
x, it has to be true for infinitely many x, as both the sets where P (x) is true and P (x)
is false put together constitute the set of natural numbers which is infinite.
(a) implies (b) is false, just because there are infinitely many x for which P (x) is true,
doesn’t mean there are only finitely many x for which P (x) is false. For example there
are infinitely many even numbers, but there are also infinitely many numbers which are
not even.

4. Writing English statements in logic


In this question, we wish to write first-order logic formulas that express certain statements
about students, courses and professors in a university. You can use the following predicates
in your formulas. Assume that the vocabulary consists of the predicates given below and
the ”=” predicate; there are no functions or constants in the vocabulary.
• Students S(x): True iff x is a student.
• Courses C(y): True iff y is a course.
• Professors P (z): True iff z is a professor.
• Enrolled (x, y): True iff x is a student who has enrolled in course y.
• Teaches (z, y): True iff z is a professor who teaches course y.
• Passed (x, y): True iff x is a student who has passed a course y.
• Prereq (y, w): True iff y and w are courses, and course y has a prerequisite course
w.
Express the following natural language (English) statements using first-order logic for-
mulas:
1. Every student is enrolled in at least one course.
2. A student can enroll in a course only if he/she/they have passed all prerequisites of
the course.
3. No professor teaches more than three courses.
4. Every course has at least one professor teaching it.
5. If a student has passed a course, some professor certainly teaches the course.
6. There is at least one student and at least one professor, such that the student has
not been taught by the professor.

Solution:

1. Every student is enrolled in at least one course.

∀x (S(x) → ∃y (C(y) ∧ Enrolled(x, y)))

CS 228M Page 6 of 9 PSet 5


2. A student can enroll in a course only if he/she/they have passed all
prerequisites of the course.

∀x ∀y S(x) ∧ C(y) ∧ Enrolled(x, y) → ∀w (Prereq(y, w) → Passed(x, w))

3. No professor teaches more than three courses.

∀z (P (z) → ¬∃y1 ∃y2 ∃y3 ∃y4 (C(y1 ) ∧ C(y2 ) ∧ C(y3 ) ∧ C(y4 ) ∧ y1 ̸= y2

∧y1 ̸= y3 ∧ y1 ̸= y4 ∧ y2 ̸= y3 ∧ y2 ̸= y4 ∧ y3 ̸= y4 ∧
Teaches(z, y1 ) ∧ Teaches(z, y2 ) ∧ Teaches(z, y3 ) ∧ Teaches(z, y4 )))

4. Every course has at least one professor teaching it.

∀y (C(y) → ∃z (P (z) ∧ Teaches(z, y)))

5. If a student has passed a course, some professor certainly teaches the


course.

∀x ∀y S(x) ∧ C(y) ∧ Passed(x, y) → ∃z (P (z) ∧ Teaches(z, y))

6. There is at least one student and at least one professor, such that the
student has not been taught by the professor.

∃x ∃z S(x) ∧ P (z) ∧ ∀y (Teaches(z, y) → ¬Enrolled(x, y))

5. Reasoning with contradictions


If a contradiction can be derived from a set of sentences, then the set is inconsistent.
Else, it is consistent. Let F be an inconsistent set. For each G ∈ F, let FG be the set
obtained by removing G. Prove that FG ⊢ ¬G.

Solution: First, we will prove a useful fact: If a contradiction can be derived from
a set of sentences, then any formula can be derived from that set (Bertrand Russell
famously used a result similar to this to prove he was the Pope, when questioned by a
student to derive the statement ”I am the Pope”, from the premise ”1=0”).

Statement Justification
F ⊢ (F ∧ ¬F ) Premise
F ⊢F ∧-Elimination
F ⊢ (F ∨ G) ∨-Introduction
F ⊢ (¬F →− G) →
− -Definition
F ⊢ (¬F ) ∧-Elimination
F ⊢G ∨-Modus Ponens

Having proven this, we proceed with proving the main claim:

CS 228M Page 7 of 9 PSet 5


Statement Justification
FG ∪ {G} ⊢ (F ∧ ¬F ) Definition of inconsistent
FG ∪ {G} ⊢ ¬G By the above subclaim
FG ∪ {¬G} ⊢ ¬G Assumption
FG ⊢ ¬G Proof by Cases

6. Logic and Equivalence Relations


Let VE be the vocabulary {E} consisting of one binary relation. Consider the conjunction
of the following sentences:
∀xE(x, x)
∀x∀y(E(x, y) =⇒ E(y, x))
∀x∀y∀z(E(x, y) ∧ E(y, z) →
− E(x, z))
All three sentences together define E as an equivalence relation. By demonstrating models
for the pairwise conjunction of two of these sentences which do not interpret E as an
equivalence relation, conclude that all 3 statements are necessary to define an equivalence
relation.

Solution: For the conjunction of the first two sentences, simply take the structure
with Z as the Universe and E as the set of all ordered pairs of adjacent integers. For
the conjunction of the second two sentences, let the relation E be empty on some non-
empty Universe, thus not satisfying reflexivity. For the conjunction of sentences 1 and
3, consider E as the ≤ relation on the real numbers.

7. Graphs and first-order logic


In this question, we wish to write properties of (undirected) graphs using first-order
logic sentences (i.e. formulas with no free variables). In each of the following sentences,
assume that the variables take values from a (possibly infinite) set of graph nodes, and
the edge relation E(x, y) evaluates to true iff there is an undirected edge between the
nodes represented by variables x and y.
For each subquestion, you are required to draw a small graph (no more than 5 nodes)
such that the given sentence evaluates to true over your graph.
(a) ∀x ∀y ¬(x = y) ↔ E(x, y)

(b) ∀x (∃y E(x, y)) ∧ (∃y ¬E(x, y))
(c) ∃x ∀y ¬E(x, y)

Solution:
(a) The condition enforced by this sentence is that there is an edge between every pair
of distinct nodes, and there is no self-loop. Hence, the sentence evaluates to true
over a complete graph over the graph nodes.

CS 228M Page 8 of 9 PSet 5


(b) This formula requires that for every vertex x, there is a vertex y that is not
connected to x by an edge, and there is a (possibly different) vertex y that is
connected to x by an edge. Note that the y in ∃y E(x, y) and the y in ∃y ¬E(x, y)
are under different quantifier scopes; hence they are different bound variables (and
could even be re-named differently, to say ∃y E(x, y) and ∃z ¬E(x, z)). Therefore,
it is ok to use one vertex y as a witness for E(x, y), and another vertex y (or z) as
a witness for ¬E(x, y) (or ¬E(x, z)). For n graph nodes, the condition enforced is
therefore that the degree of each node should be > 0 and < n. The same graph as
above works since
∀x ¬E(x, x) =⇒ ∀x ∃y ¬E(x, y)
and clearly ∀x ∃y E(x, y).

(c) The condition is that there should be atleast some node which is not connected to
any other node (including itself).

CS 228M Page 9 of 9 PSet 5

You might also like