Recall warm-up
- Why are TMs countable?
Stuck? Peek at 4.4 Encoding TMs, the universal TM, and the Church–Turing thesis
- ⟨M⟩: binary code of transitions (0ⁱ1 0ʲ1 0ᵏ1 0ˡ1 0ᵐ, separated by 11). TMs are countable.
- Universal TM U: simulates M on w; L(U) = {⟨M,w⟩ : M accepts w} is RE.
- Church–Turing thesis: algorithm ⇔ TM (thesis, not theorem).
- What is a bijection?
Stuck? Peek at 0.2.2 Functions, relations and equivalence classes
- Relation ⊆ A × B. Function: every input exactly one output. Partial function: some inputs have none.
- #functions A→B = |B|^|A|. #one-to-one (|A| ≤ |B|) = |B|·(|B|−1)···. #relations on n-set = 2^(n²).
- Equivalence = reflexive + symmetric + transitive. Classes partition the set; number of classes = index.
- Finer relation (refinement) ⇒ more classes; every fine class sits inside a coarse class.
- Shortlex order lists Σ* how?
Stuck? Peek at 0.3.2 Σᵏ, Σ*, Σ⁺ and languages
- |Σᵏ| = |Σ|ᵏ; Σ⁰ = {ε}; Σ* = ⋃ Σᵏ (k ≥ 0); Σ⁺ = Σ* − {ε}.
- #strings of length ≤ n over k symbols = (kⁿ⁺¹ − 1)/(k − 1); binary: 2ⁿ⁺¹ − 1.
- Language = any subset of Σ*. ∅ (no strings) ≠ {ε} (one string). Exactly r of one symbol in length n (binary): C(n, r).
- Shortlex order lists every string at a finite position.
The Hook
Here is the shortest proof that some problems have no algorithm: count. There are only countably many programs (each is a finite string), but uncountably many problems (sets of strings). More problems than programs — so most problems have no program at all. This lesson makes “countably many” and “uncountably many” precise, using Cantor’s diagonal trick, the same trick that proves the halting problem undecidable.
Predict First
Are there “more” even numbers than natural numbers, fewer, or the same number?
Core Concept
Prediction check
The same. n ↦ 2n pairs every natural number with exactly one even number (a bijection). For infinite sets, “same size” means “a bijection exists”, and a part can be as big as the whole.
| ℕ | 0 | 1 | 2 | 3 | 4 | … |
|---|---|---|---|---|---|---|
| even | 0 | 2 | 4 | 6 | 8 | … |
Countable sets
Countable: ℕ, the integers (0, 1, −1, 2, −2, …), pairs ℕ × ℕ (walk the diagonals), Σ* (shortlex order), the set of all TMs (list their codes), every language’s set of strings.
| position | 0 | 1 | 2 | 3 | 4 | 5 | 6 | … |
|---|---|---|---|---|---|---|---|---|
| string of {0,1}* | ε | 0 | 1 | 00 | 01 | 10 | 11 | … |
Uncountable sets and Cantor’s diagonal
Proof: suppose the languages could be listed L₁, L₂, …. Build D = { wᵢ : wᵢ ∉ Lᵢ } — for each i, D disagrees with Lᵢ about the string wᵢ. So D is not on the list, contradicting that the list was complete. ∎
More languages than machines
TMs are countable; languages are uncountable. Each TM recognizes one language, so only countably many languages are RE. Therefore uncountably many languages are not RE — in fact “almost all” languages have no recognizer, let alone a decider.
Diagonalization as a technique
Whenever a list claims to contain every object of some kind, build an object that differs from the i-th one at position i. If your object belongs to the kind, the list was incomplete. Next lesson aims this weapon at Turing machines themselves.
Putting it together
- Countable means listable; Σ* and the set of TMs are countable.
- The diagonal argument shows P(Σ*) is not.
- So almost all languages have no recognizer.
Visual
countable: ℕ ℤ ℚ ℕ×ℕ Σ* {all TMs} {all RE languages} {all regular languages}
uncountable: P(ℕ) ℝ P(Σ*) = {all languages} {infinite binary sequences}Worked Examples
Is the set of all regular languages countable?
Show the full solution
Yes: each is described by a finite DFA (or regex), and finite descriptions can be listed.
Is the set of all infinite binary sequences countable?
Show the full solution
No: it corresponds to P(ℕ) (positions of the 1s); the diagonal argument applies.
Which are countable? (i) set of all CFGs over {a,b} (ii) set of all languages over {a} (iii) set of all RE languages (iv) set of all finite subsets of ℕ
Show the full solution
(i) countable (finite descriptions). (ii) uncountable: P({a}*) and {a}* is countably infinite. (iii) countable. (iv) countable (list by sum of elements / size). Answer: (i), (iii), (iv).
GATE Traps
- Σ* is countable (infinite but listable); P(Σ*) is uncountable.
- Even a one-letter alphabet has uncountably many languages.
- Countably many TMs ⇒ only countably many RE languages ⇒ most languages are not RE.
- Finite subsets of ℕ: countable. All subsets of ℕ: uncountable.
Memory Hook
A hotel with numbered rooms holds every program, but the crowd of all problems never fits — the diagonal guest always finds no room.
Connect the Dots
Counting proves non-RE languages exist but names none. Next: diagonalize against TMs directly to get concrete ones — L_d, and then the most famous of all, the halting problem.
Self-Test
- MSQ
Which sets are countable?
- Σ*
- the set of all TMs
- the set of all languages over Σ
- ℕ × ℕ
- MCQ
The counting argument shows:
- every language is RE
- some languages are not RE
- the halting problem is RE
- Σ* is uncountable
- MCQ
Cantor’s diagonal language D = { wᵢ : wᵢ ∉ Lᵢ } differs from Lᵢ:
- nowhere
- at the string wᵢ
- at every string
- only on ε
- MCQ
The set of all languages over the alphabet {a} is:
- finite
- countably infinite
- uncountable
- empty
Rule Card
- Countable = finite or bijection with ℕ (listable). Σ*, ℕ×ℕ, TMs, RE, CFG, regular languages: countable.
- P(ℕ), P(Σ*) (all languages), infinite binary sequences, ℝ: uncountable (diagonal).
- Countably many TMs ⇒ most languages are not RE.
Concept Ledger
- countable set
- bijection with ℕ
- uncountable set
- Cantor’s diagonal argument
- diagonalization
- counting argument (non-RE languages exist)
Answer Vault
Reveal answers when you’re ready
Warm-up answers
- Each has a finite binary code, so they can be listed.
- A function that is one-to-one and onto.
- Shorter strings first, then dictionary order — every string at a finite position.
Self-test answers
- ABD — All listable.
- C: P(Σ*) is uncountable.
- B — Countable TMs vs uncountable languages.
- A: Opposite.
- C: True but not from counting.
- D: Σ* is countable.
- B — Built to disagree on the diagonal.
- A: It differs.
- C: Only one position is guaranteed.
- D: No.
- C — P of a countably infinite set.
- A: No.
- B: No.
- D: No.
Flashcards
- Is Σ* countable?
Reveal answer
Yes (shortlex). - Is the set of all languages over Σ countable?
Reveal answer
No — it is P(Σ*), uncountable. - Why must non-RE languages exist?
Reveal answer
TMs are countable; languages are uncountable.