Dis01c Sol
Dis01c Sol
Solution:
(a) True. Proof by contradiction. Suppose the set of irrationals is countable. From Lecture note
10 we know that the set Q is countable. Since union of two countable sets is countable, this
would imply that the set R is countable. But again from Lecture note 10 we know that this is
not true. Contradiction!
(b) False. Let S ⊂ R × R denote the set of all real solutions for the given equation. For any x′ ∈ R,
the pair (x′ , y′ ) ∈ S if and only if y′ = 1−x′ . Thus S = {(x, 1−x) : x ∈ R}. Besides, the mapping
x to (x, 1 − x) is a bijection from R to S. Since R is uncountable, we have that S is uncountable
too.
(c) True. Recall that a function h : A → B is injective iff a1 ̸= a2 =⇒ h(a1 ) ̸= h(a2 ) for all a1 , a2 ∈
A. Let x1 , x2 ∈ X be arbitrary such that x1 ̸= x2 . Since g is injective, we have g(x1 ) ̸= g(x2 ).
Now, since f is injective, we have f (g(x1 )) ̸= f (g(x2 )). Hence f ◦ g is injective.
(d) False. Recall that a function h : A → B is surjective iff ∀b ∈ B, ∃a ∈ A such that h(a) = b. Let
g : {0, 1} → {0, 1} be given by g(0) = g(1) = 0. Let f : {0, 1} → {0, 1} be given by f (0) = 0
and f (1) = 1. Then f ◦ g : {0, 1} → {0, 1} is given by ( f ◦ g)(0) = ( f ◦ g)(1) = 0. Here f is
surjective but f ◦ g is not surjective.
A1 × A2 × · · · × An
is countable.
Solution:
(a) As shown in lecture, N × N is countable by creating a zigzag map that enumerates through
the pairs: (0, 0), (1, 0), (0, 1), (2, 0), (1, 1), . . . . Since A and B are both countable, there exists a
bijection between each set and a subset of N. Thus we know that A × B is countable because
there is a bijection between a subset of N × N and A × B : f (i, j) = (Ai , B j ). We can enumerate
the pairs (a, b) similarly.
(b) Proceed by induction.
Base Case: n = 2. We showed in part (a) that A1 × A2 is countable since both A1 and A2 are
countable.
Induction Hypothesis: Assume that for some n ∈ N, A1 × A2 × · · · × An is countable.
Induction Step: Consider A1 ×· · ·×An ×An+1 . We know from our hypothesis that A1 ×· · ·×An
is countable, call it C = A1 × · · · × An . We proved in part (a) that since C is countable and An+1
are countable, C × An+1 is countable, which proves our claim.
3 Hello World!
Note 12 Determine the computability of the following tasks. If it’s not computable, write a reduction or
self-reference proof. If it is, write the program.
(a) You want to determine whether a program P on input x prints "Hello World!". Is there a
computer program that can perform this task? Justify your answer.
(b) You want to determine whether a program P prints "Hello World!" before running the kth line
in the program. Is there a computer program that can perform this task? Justify your answer.
(c) You want to determine whether a program P prints "Hello World!" in the first k steps of its
execution. Is there a computer program that can perform this task? Justify your answer.
Solution:
(c) Computable. You can simply run the program until k steps are executed. If P has printed
“Hello World!” by then, return true. Else, return false.
The reason that part (b) is uncomputable while part (c) is computable is that it’s not possible to
determine if we ever execute a specific line because this depends on the logic of the program,
but the number of computer instructions can be counted.
4 Code Reachability
Note 12 Consider triplets (M, x, L) where
• M is a Java program
• x is some input
• L is an integer
Program M reaches line 2 if and only if P(x) halted. Thus, we have implemented a solution to the
halting problem — contradiction.