Abstract:

Homework 04 for Computing and Complexity, covering an extension of content on context free grammars and regular expressions, and the user of deciders for validation.


Problem 01

Let . Show that is decidable.

To solve this problem, we will recall the reductions we can make when we know that:

  • A language when its complement is
  • That all DFAs are closed under the following complement:
  • That a DFA’s “emptiness” will be tested using a reachability check via graph, to test for

We can now use this decider to validate the input for :

  • We must validate encodes to a DFA as defined above ( )
    • if we cant, then we reject
  • We then construct the complement DFA as defined above ( )
  • Using this construction, we then test for the emptiness of this complement :
    • do a BFS/DFS search to find all reachable states from
    • if any of these reachable stats is in the such as an accepting state for the complement, then we know that , and we reject given that this also shows that is not in .
    • for any other case where no accept state is reachable for the complement, we can confirm that , and thus is in , and accept

Therefore we have shown that the procdure above ensures that is decidable as required


Problem 02

Let . Show that is decidable.

Recall the definition of a context free grammar :

Where:

  • variables
  • terminals
  • start variable
  • productions

We note that a given variable is considered nullable if and only if . Therefore:

We can then build a set of all nullable variables where , where we iterate until there is no more change.

The algorithm looks something like the following(very rough pseudocode):

With this we can now construct a decider for :

For input we:

  • ensure that the defintion above is a well behaved CFG, if not reject
  • compute nullable set using pseudocode procedure
  • ensure that if S is in NULL we accept, and if not we reject

Therefore thanks to this decider we know the procedure will always halt and correctly decide if generates as required


Problem 03

Consider the following context-free grammar:

\begin{align*} S &\to aA \mid Bb \mid C \ A &\to aa \mid B \mid C \ B &\to bb \mid A \mid C \ C &\to c \mid \epsilon \end{align*}

> > Recall that $A_{CFG}=\{ \langle G,w \rangle \mid \text{G is a CFG and G generates string w} \}$ 1. Is $\langle w, G \rangle \in A_{CFG}$? - **No**, because the inputs must be of a form like "$\langle G,w \rangle$". this input is inverted and produces incorrect terminals 2. Is $\langle G \rangle \in A_{CFG}$? - **No**, for the same reason as above, and the fact that there is no such string $w$ where it is with $G$ 3. Is $\langle G, abb \rangle \in A_{CFG}$? - **Yes**, below construction proves:

\begin{align*} S &\to aA \ &\to aB \quad \ - \text{due to AB} \ &\to a \ bb \quad - \text{due to Bbb} \end{align*}

4. Is $\langle G, \epsilon \rangle \in A_{CFG}$? - **Yes**, below construction proves:

\begin{align*} S &\to aA \ &\to \epsilon \quad - \text{due to C}\epsilon \end{align*}

5. Is $\langle G, abc \rangle\in A_{CFG}$? - **No**, because this cannot be created from any derivation 6. Is $\langle G, ac \rangle \in A_{CFG}$? - **Yes**, below construction proves:

\begin{align*} S &\to aA \ &\to aC \quad - \text{due to AC} \ &\to a \ c \quad -\text{due to Cc} \end{align*}

--- ## Problem 04 > Let $A=\{ \langle R,S \rangle \mid \text{R and S are regular expressions and }\mathcal{L}(R) \subseteq \mathcal{L}(S) \}$. Show that $A$ is decidable. To prove this we must construct a DFA to test for emptiness. We define emptiness with a reachability check. The following procedure proves $A$ is decidable: 1. First we validate that the given $R$ and $S$ are well behave regex over $\Sigma$ - **reject** if not 2. We can then convert these regex into their DFA equivelants using state elimination or another method. For this purpose, we will just use $A_{R}$ and $A_{S}$ where they are both DFAs that recognize exactly $\mathcal{L}(R)$ and $\mathcal{L}(S)$ 3. We then complement $A_{S}$ by swapping the accpeting and non-accepting states so that $A^C_{S}$ now recognizes $\Sigma / \mathcal{L}(S)$, adn so on. 4. Then we intersect $A_{R}$ wtih $A^C_{S}$ using the prod automation construction yielding a DFA that we will call $P$ that:

\mathcal{L}(P) = \mathcal{L}(R) \cap (\Sigma^* / \mathcal{L}(S))

5. we test for the emptiness of $P$ by doing a search, either BFS or DFS and finding all reachable states from the start state to see if any accepting state can be reached. - if there is no reachable accept state we **accept** as $\mathcal{L}(P)= \emptyset$ - if there is a reachable accept state, then we **reject** as $w \in \mathcal{L}(R) / \mathcal{L}(S)$