Assignment 5

Nils Anders Danielsson

Consider the following language over the alphabet Σ = {a, b}: M = {aibi + j | i, j ∈ }.

  1. (0p) Give an ambiguous context-free grammar G = ({S}, ΣPS) for M. Note that the grammar should have exactly one nonterminal, S.

    (There are no points for this exercise. In the following three exercises you are asked to prove that your answer is correct.)

  2. (1p) Prove that G is ambiguous.

  3. (3p) Prove i, j ∈ S ⇒* aibi + j.

    You are allowed to make use of the following property without providing a proof for it: α, α′, β, β′ ∈ {Sab}*. (α ⇒* α′ ∧ β ⇒* β′) ⇒ (αβ ⇒* αβ′).

  4. (3p) Prove w ∈ L(GS). w ∈ M, where L(_, _) is the inductive construction introduced in the eleventh lecture under the heading of “Recursive inference”.

  5. (3p) Give an unambiguous context-free grammar G for M.

    You are not obligated to provide a proof. However, note that (for a typical model of computation) there is no algorithm for checking whether two arbitrary context-free grammars implement the same language,1 or whether an arbitrary context-free grammar is unambiguous. You should give enough explanation so that the person correcting your submission can easily see that your answer is correct.

The exercises above are loosely based on exercises from a previous version of this course, given by Ana Bove.


  1. Bonus exercise (hard, 0p): Is there an algorithm for checking whether an arbitrary context-free grammar implements the language M?