Models of Computation Assignment 
Purpose  To improve and consolidate your understanding of regular and contextfree languages, finitestate and pushdown automata. To develop skills in analysis and formal reasoning about complex concepts, and to practise writing down formal arguments.
Challenge 1  This challenge is to design eight finite relations and submit them via Grok. Let D = {1, 2, 3}. We can think of a binary relation on D as a subset of D × D. For example, the identity relation is {(1, 1),(2, 2),(3, 3)}. There are 9 elements in D×D, so there are 2^{9} = 512 different binary relations on D.
Construct eight of these, r_{0}, . . . , r_{7}, satisfying the criteria given in the table below. Each relation should be presented as a Haskell list of pairs, that is, an expression of type [(Int, Int)]. For full marks, each relation has to be as small as it can be.

Reflexive

Symmetric

Transitive

r_{0}

no

no

no

r_{1}

no

no

yes

r_{2}

no

yes

no

r_{3}

no

yes

Yes

r_{4}

yes

no

no

r_{5}

yes

no

Yes

r_{6}

yes

yes

no

r_{7}

yes

yes

Yes

Challenge 2  This challenge is to design three DFAs and a regular expression and submit them via Grok. An expression such as (01 ∪ 1)* ∩ (0*11)* is not a regular expression, since ∩ is not a regular operation. Nevertheless, the expression denotes a regular language.
a. Give a 3state DFA D_{a} for (01 ∪ 1)*.
b. Give a 4state DFA D_{b} for (0∗11)*.
c. In tute exercise 61 we constructed "product" automata for the intersection of languages. Now find a minimal DFA D_{c} for (01 ∪ 1)* ∩ (0∗11)*. You can build the DFA that is the "product" of D_{a} and D_{b}, but be aware that the result may not be minimal, so you may have to apply minimisation.
d. Use the NFAtoregularexpression translation shown in Lecture 12, to turn D_{c} into a regular expression r for (01 ∪ 1)* ∩ (0*11)*.
Challenge 3  This challenge is to complete, on Grok, some Haskell functions that will allow us to test for membership of languages given as regular expressions. You have probably used regular expression features in your favourite programming language, and this challenge will help you understand how such features are implemented.
Let us call a language A volatile iff ε ∈ A. For example, L(10 ∪ (11)*) is volatile, but L((0 ∪ 1)(11)*) is not. Another useful concept is that of a derivative of a language with respect to a (finite) string. The derivative of A with respect to s,
d(A, s) = {w  sw ∈ A}
For example, if A = {0, 02, 102, 111, 1102} then d(A, 11) = {1, 02}. For another example, if B is the language given by the regular expression (00)* then d(B, 0) = L((00)*0) = L(0(00)*).
We can extend the definition of "volatile" to regular expressions r: We say that r is volatile iff ε ∈ L(r). Similarly we extend d so that the function takes, and produces, regular expressions. Let us first handle the case where the string s is of length 1, that is, s is a single symbol x. We define
d_{1}(∈, x) = ∅
d_{1}(∅, x) = ∅
d_{1}(y, x) = ∅ if y is a symbol and y ≠ x
d_{1}(x, x) = ∈
d_{1}(r_{1} ∪ r_{2}, x) = d_{1}(r_{1}, x) ∪ d_{1}(r_{2}, x)
d_{1}(r_{1} r_{2}, x) = d_{1}(r_{1}, x) r_{2} ∪ d_{1}(r_{2}, x) if r_{1} is volatile
d_{1}(r_{1} r_{2}, x) = d_{1}(r_{1}, x) r_{2} if r_{1} is not volatile
d_{1}(r*, x) = d_{1}(r, x) r*
Now we can define the general case, that is, the derivative of r with respect to an arbitrary string s. We define d(r, ∈) = r and, for k ≥ 1: d(r, x_{1}x_{2} · · · x_{k}) = d_{1}((. . . d_{1}(d_{1}(r, x_{1}), x_{2}), . . .), x_{k})
You should think about why the above recursive definitions are correct, before you complete their Haskell implementations on Grok. On Grok you will find a Haskell type RegExp for regular expressions.
a. Write a Haskell function volatile :: RegExp > Bool that determines whether a regular expression is volatile.
b. Complete a Haskell function derivative :: RegExp > String > RegExp so that you can use Haskell to calculate derivatives of regular expressions.
c. Write a function contains :: RegExp > String > Bool which takes a regular expression r and a string w and decides whether w ∈ L(r). This function must use the functions volatile and derivative.
Challenge 4  Let Σ be a finite nonempty alphabet and let x ∈ Σ be a symbol. For every w ∈ Σ* and x ∈ Σ, let omit(x, w) be the string w with all occurrences of x removed. For example, if Σ = {a, b, c} and w = baabca then omit(a, w) = bbc. Similarly, omit(b, bb) = ∈.
We now "lift" this function to languages: To "drop" a symbol from a language L will mean to "omit" it from every string in L. That is, for L ⊆ Σ*, define
drop(x, L) = {omit(x, w)  w ∈ L}.
For example, if L = {aa, baabca, bbaac, bbc} then drop(a, L) = {∈, bbc} and drop(b, L) = {aa, aac, aaca, c}.
a. Show that if R is a regular language then drop(a, R) is a regular language.
b. Assuming {a, b} ⊆ Σ, provide a language L such that drop(a, L) is contextfree and nonregular, while drop(b, L) is regular.
Challenge 5  Every regular language can be recognised by a pushdown automaton which has only three states, q_{I} , q_{R}, and q_{A}. Show in detail how to systematically translate an arbitrary DFA to a PDA with only three states. Try to answer this question precisely, that is, make use of the formal definitions of DFAs and PDAs. So, given an arbitrary DFA (Q, Σ, δ, q_{0}, F), define precisely each component of the corresponding PDA (Q′, Σ′, Γ, δ′, q′_{0}, F′).
Hints: (a) A PDA does not have to have an empty stack in order to accept a string; (b) its stack alphabet Γ can be whatever (finite) set of symbols you choose; and (c) we named the states q_{I}, q_{R}, and q_{A} for a reason.
Challenge 6  Let us fix the alphabet Σ = {0, 1}. Define a substring of w ∈ Σ* to be any string x ∈ Σ* such that w = uxv for some u, v ∈ Σ*. Now consider the language
A = {w ∈ Σ* 001 is not a substring of w}
For example, ∈, 01, 1111, 10101, and 0111010101 are in A, but 10001 and 11001011 are not.
Consider the contextfree grammar G = ({S}, Σ, R, S), where the rules R are: S → ∈
 S 0
 1 S
 0 1 S
Show that L(G) = A.
Hint: Show L(G) ⊆ A using structural induction and show A ⊆ L(G) by induction on the length of strings in A.
Attachment: Assignment File.rar