Section 6 · Revision
Theory of Computation formula sheet
State counts, conversions, normal forms, closure tables and decidability facts for regular, context-free and Turing-recognisable languages on one page.
Regular expressions and finite automata
Conversions and state bounds
| From | To | States |
|---|---|---|
| NFA with states | DFA (subset construction) | at most , including |
| -NFA with states | NFA without | (same states) |
| Regex of length | -NFA (Thompson) | |
| DFAs with and states | DFA for (product) | at most |
| Complete DFA with states | DFA for complement | (swap accepting and non-accepting) |
| DFA with states | DFA for reversal | up to |
| Mealy with states, output alphabet | Moore | at most (plus 1 for the start) |
| Moore with states | Mealy |
- Swapping final states complements only a complete DFA, never an NFA.
- Moore output for input of length has length ; Mealy gives .
- Labelled DFAs with states, symbols, fixed start: .
Minimal complete DFA sizes (pattern with , alphabet , like with no self-overlap issues)
| Language | States | Dead state? |
|---|---|---|
| Length exactly | yes | |
| Length | yes | |
| Length | no | |
| -th symbol from the left is fixed | yes | |
| -th symbol from the right is fixed | no | |
| Starts with | yes | |
| Ends with | no | |
| Contains | no | |
| Does not contain | yes (counted) | |
| no | ||
| Length divisible by or by ( coprime) | no | |
| Binary, MSB first, value divisible by ( odd) | no | |
| Binary, LSB first, value divisible by odd | no |
- Partial DFA = complete DFA minus the dead state. Read whether the question counts it.
- Product states can merge after minimisation. Example: and ends in needs 4 states, not 6.
- Myhill-Nerode: number of classes = states of the minimal complete DFA. Infinite index means not regular.
- Minimisation: drop unreachable states first, then merge equivalent states (Moore table filling).
Regular expression identities
-
-
Shift rule:
-
, , , ,
-
(the right side misses )
-
Arden: gives ; gives (unique if ).
-
Binary strings of length with no : (2, 3, 5, 8, 13, 21 for ).
-
-closure of always contains .
Context-free grammars and PDAs
Normal forms and counts (string length )
| Quantity | Value |
|---|---|
| CNF derivation steps | |
| CNF parse tree: variable nodes / all nodes | / |
| CNF parse tree height (edges) | min , max |
| GNF derivation steps | |
| CYK table cells | |
| CYK time | |
| Parse trees of with operators in | Catalan : 1, 1, 2, 5, 14, 42, 132 |
| Strings of length from | |
| Balanced strings () of length |
- Simplification order: remove -productions, then unit productions, then useless symbols (non-generating first, then unreachable).
- Palindromes of length over : .
PDA facts
| Model | Accepts |
|---|---|
| NPDA, final state | CFL |
| NPDA, empty stack | CFL (same class) |
| DPDA, final state | DCFL |
| DPDA, empty stack | DCFLs with the prefix property |
| PDA with bounded stack | regular |
| PDA with 2 stacks / queue automaton | RE (same as TM) |
DCFL or not
| Deterministic CFL | CFL, not deterministic |
|---|---|
| , | |
| (inherently ambiguous) | |
| every regular language |
- Ambiguity is a property of a grammar; inherent ambiguity is a property of a language. Every DCFL and every regular language has an unambiguous grammar.
- Dangling else: is ambiguous ( has 2 trees).
Pumping lemma and closure properties
-
Regular, : , , for all .
-
CFL, : , , for all .
-
The lemma only proves non-membership. Passing it proves nothing.
-
-state DFA: non-empty iff it accepts a string of length ; infinite iff it accepts one of length in .
-
Unary CFLs are regular. So , , are not CFL.
-
For : pumping up gives length strictly between and .
If you see X, think Y
| Pattern | Class |
|---|---|
| , , equal counts of two symbols | CFL, not regular |
| , , | not CFL |
| with non-empty | regular (first symbol = last, length ) |
| , | CFL |
| Equal counts of and | regular ( or first symbol = last) |
| Bounded counter () | finite, so regular |
Closure table (Y closed, N not closed)
| Operation | Reg | DCFL | CFL | CSL | Rec | RE |
|---|---|---|---|---|---|---|
| Union | Y | N | Y | Y | Y | Y |
| Intersection | Y | N | N | Y | Y | Y |
| Intersection with regular | Y | Y | Y | Y | Y | Y |
| Complement | Y | Y | N | Y | Y | N |
| Difference | Y | N | N | Y | Y | N |
| Concatenation | Y | N | Y | Y | Y | Y |
| Kleene star | Y | N | Y | Y | Y | Y |
| Reversal | Y | N | Y | Y | Y | Y |
| Homomorphism | Y | N | Y | N | N | Y |
| -free homomorphism | Y | N | Y | Y | Y | Y |
| Inverse homomorphism | Y | Y | Y | Y | Y | Y |
| Right quotient with regular | Y | Y | Y | N | N | Y |
- Regular languages are closed under quotient with any language, and under prefix, suffix, half, , .
- regular does not make regular. A subset of a regular language need not be regular. An infinite union of regular languages need not be regular. regular does not make regular ( is regular).
- CFL regular is CFL: use it to expose a non-CFL core, e.g. .
Turing machines and undecidability
Hierarchy
| Type | Grammar | Machine | Language class |
|---|---|---|---|
| 3 | right-linear | DFA / NFA | regular |
| 2 | context-free | NPDA | CFL |
| 1 | context-sensitive | LBA | CSL (all recursive) |
| 0 | unrestricted | TM | RE |
Regular DCFL CFL CSL Recursive RE all languages.
- Same power as a TM: multi-tape ( simulation), nondeterministic (exponential simulation), two-way infinite tape, multi-head, 2-stack PDA, 2-counter machine, queue automaton.
- Weaker: single-stack PDA, LBA, read-only TM (regular).
Decidability (D decidable, U undecidable)
| Problem | DFA / regex | CFG | CSG | TM |
|---|---|---|---|---|
| Membership | D | D | D | U |
| Emptiness | D | D | U | U |
| Finiteness | D | D | U | U |
| D | U | U | U | |
| Equivalence | D | U | U | U |
| Containment | D | U | U | U |
| Intersection empty (two of the same type) | D | U | U | U |
| Ambiguity | U | |||
| Is regular? | D | U | U | U |
- DPDA equivalence is decidable. CFG DFA emptiness is decidable.
- PCP: undecidable for alphabets of size , decidable for a one-letter alphabet or when the solution length is bounded.
Standard sets
| Set | RE | co-RE |
|---|---|---|
| , , , "accepts " | Y | N |
| , , | N | Y |
| , , , , | N | N |
- and both RE recursive. RE but not recursive not RE.
- RE recursive is RE; it may or may not be recursive.
Rice's theorem
- Every non-trivial property of is undecidable.
- Applies only to properties of the language. Does not apply to: number of states, "halts within steps", "makes more than moves", "ever moves left on blank input". Those are about the machine; many are decidable.
- Trivial property (true for all RE languages or for none): decidable.
- If some has the property but a superset of does not (not monotone), the property is not even RE.
Reductions ()
-
decidable decidable; RE RE.
-
undecidable undecidable; not RE not RE.
-
Always .
-
Standard trick: from build that ignores its input and runs on . Then or . This gives and .
Countability
-
Countable: , TMs, regexes, RE languages, finite subsets of , .
-
Uncountable: (all languages), , functions , infinite subsets of .
-
Countably many TMs, uncountably many languages: non-RE languages exist.