EXERCISE 1: REGULAR EXPRESSIONS
Question 1. Let R1 = a((b*c*) + a)b and R2 = a* ((bc) + a*)b* be two regular expressions.
(a) Give two words ω1 and ω2 such that {ω1 ω2} ⊆ L(R1) ∩ L(R2). Please type each word on a new line.
(b) Give two words ω3 and ω4 such that (ω3, ω4) ⊆ L(R1) \ L(R2). Please type each word on a new line.
(c) Give two words ω5 and ω6 such that {ω5, ω6} ⊆ L(R2) \ L(R1). Please type each word on a new line.
(d) Give a regular expression R3 such that L(R3) = L(R1) U L(R2).
(e) Give a regular expression R4 such that L(R4) = L(R1) ∩ L(R2).
Question 2. Give regular expressions for the following languages.
(a) L1 = {anbm | n ≥ 3, m is even}.
(b) L2 = L1' (where L' stands for the complement of L).
(c) L3 = {abnω | n > 3, ω ∈ {a, b}*}.
(d) L4 = {ωanω | n > 0, ω ∈ {a, b}*} ∩ {bωb | ∈ {a, c}*}.
Question 3. Let R1 and R2 be regular expressions over a non-empty alphabet E.
(a) Determine, formally, whether L(R1(R1 + R2)*) = L((R1 + R2)*). That is, if it is true, provide a proof; otherwise provide a counter example.
(b) Prove that L(R1R2)Τ = L(RΤ2, R2)*) where if represents the reverse of regular expression R. For example, if abb ∈ L(R), then bba ∈ L(R'). Similarly, if X is a set of words, then XΤ = {ω|ωr ∈ X}.
EXERCISE 2: GRAMMARS
Question 4. In this exercise, we use operator R# to denote one or more repetitions of R, that is, R# is a compact way of writing RR' (remember we used + for alternation). Let L1 and L2 be the following two languages over alphabet {a, b, c}:
L1 = {anb2cm a2+n+m | n,m ≥ 1};
L2 = L(((a + b)*b(b + (c + a) (b + a)* )#.
(a) Give a grammar G1 such that L(G1) = L1.
(b) Give a grammar G2 such that L(G2) = L2.
(c) Provide a grammar G3 such that L(G3) = L1 U L2.
(d) Prove formally that L1 ∩ L2 = L1
Question 5. Let G = ({S, A}, {a, b}, Γ, S) be a grammar, where the set of rules r is defined as follows:
S -> aSbS
S -> bSaS
S -> ∈
(a) Is G an ambiguous grammar? Explain your answer.
(b) Is there a relationship between the number of a's and b's in L(G)?
(c) Does there exist a regular expression R such that L(R) = L(G)? If it exists, provide such R; otherwise, briefly explain the reason for its nonexistence.
(d) Does there exist a regular expression, DFA, or PDA over the alphabet Σ = {a, b} which is equivalent to the language L1 = L(G) ∩ L(a*b*)? For each, briefly explain why not or provide the expression/automaton.
EXERCISE 3: AUTOMATA
Question 6. Answer the following questions based on the finite state automaton M1 present in the JFLAP file DFA-3.6.jff available in Course Material section of the course website.
(a) Give four strings of length 3 accepted by M1. Please type each string on a new line.
(b) Give four strings of length 3 rejected by M1. Please type each string on a new line.
(c) Do you think M1 has more states than required to express its language? Explain briefly.
(d) Give the language of this machine M1 as a regular expression.
(e) Create an automaton M2 such that it accepts the language L2 where L2 = L(M1) ∩ L(a*c*(c+ b)*). Your machine should not accept words not in this language.
Question 7. Let M3 = ({q0, q1, q2, q3}, {a, b} , δ, q0, {q3}) be a deterministic finite state machine as shown below. Prove that if w is a string in L(M3), then the number of a's in ω is na,(ω) mod 3 = O.
Question 8. Consider the pushdown automaton M4 over the alphabet Σ = {a, b, c} as shown below.
Notation x, A/X means a transition where X is the input symbol being read, A is the symbol on top of the stack that is popped, and X is the symbol pushed onto the stack. The symbol ∈ stands for the "empty" string. Acceptance is by final state and empty stack.
(a) Give 4 strings of length 6 over Σ that are accepted by PDA M4.
(b) Give 4 strings of length 6 over Σ that are rejected by PDA M4.
(c) Give the language of M4 in set notation.
(d) Let M5 be a PDA obtained from M4 by removing the transitions δ(q4, ∈, ∈) = (q5, ∈), δ(q5, a, B) = (q5, ∈) and δ(q5, a, C) = (q5, ∈), adding transition δ(q4, a, B) = (q4, ∈), removing state q5 and making state q4 a final state. Give the language of M5 in set notation.
(e) Is there a relation between the language of M4 and M5. Explain briefly.
(f) It is a well known result that every PDA with acceptance condition of an empty stack and reachability of a final state can be transformed to an equivalent PDA with acceptance condition requiring only reachability of a final state. Transform the PDA M4 to an equivalent PDA with acceptance requiring only reachability of a final state.