\documentclass[12pt,ifthen]{article} \usepackage{url} \usepackage{comment} \newif{\ifshowsoln} % \showsolntrue \newcommand{\und}{\_\_\_\_\_\_\_\_\_} \newcommand{\N}{\mathbb{N}} \newcommand{\Z}{\mathbb{Z}} \newcommand{\lf}{\left\lfloor} \newcommand{\rf}{\right\rfloor} \newcommand{\lc}{\left\lceil} \newcommand{\rc}{\right\rceil} \newcommand{\Ceil}[1]{\left\lceil {#1}\right\rceil} \newcommand{\ceil}[1]{\left\lceil {#1}\right\rceil} \newcommand{\floor}[1]{\left\lfloor{#1}\right\rfloor} \newcommand{\goes}{\rightarrow} \usepackage{amsmath} \usepackage{amssymb} % for \nmid \begin{document} \centerline{\bf HW 07 CMSC 452} \centerline{\bf Morally Due TUES March 25 11:00AM} \centerline{\bf Dead-Cat Due THU March 27 at 11:00AM} \begin{enumerate} \item (30 points) Let $G$ be the CFG below: $S\goes AABB$ $S\goes ABAB$ $A\goes AAA$ $B\goes BBB$ $A\goes a$ $B\goes b$. Recall that $L(G)$ is the set of all strings that are generated by $G$. \begin{enumerate} \item (15 points) Give an infinite number of strings that are NOT in $L(G)$. \newpage \item (15 points) RECALL that Chomsky Normal Form Grammars have rules of the form $X\goes YZ$ (for any NTs $X,Y,Z$) $A\goes \sigma$ (for any NT $A$ and any $\sigma\in \{a,b\}$. $S\goes e$ (this one you won't need). For this problem we also allow rules of the following form to make your life easier $X\goes Y$ (for any NTs $X,Y$). Give a Chomsky Normal Form Grammar $G'$ such that $L(G)=L(G')$. You should use the algorithm I discussed in class in the Feb 25,27 CFG lecture. \end{enumerate} \newpage \item (40 points) You can and should look on the web for the answer to Part $a$ of this question. Put it in you own words. Give a CLEAR explanation- since we are not testing your knowledge or cleverness we are testing how well you can express yourself. Make sure you understand the construction and COULD write a program to do it OR do it by hand. \begin{enumerate} \item (20 points) Give an algorithm that will, GIVEN a DFA $M=(Q,\Sigma,\delta,s,F)$ produce a CFG $G=(V,\Sigma,R,S)$ such that $L(M)=L(G)$. For the CFG you must specify \begin{itemize} \item $V$ The set of nonterminals. \item $S$ The Start nonterminal. \item $R$ The rules. \end{itemize} We want a DIRECT construction- DO NOT go from DFA to regex to CFG. \item (0 points but you need this for the next problem.) Write a DFA for $L=\{ w \colon \#_a(w)\equiv 0 \pmod 2 \wedge \#_b(w)\equiv 0 \pmod 2 \}$. (You can either give a diagram or a table.) \item (20 points) Give a CFG for $L$ by using the algorithm in part a on the DFA in part b. \item (0 points) THINK ABOUT but do not hand in: Let $L_n=\{ w \colon \#_a(w)\equiv 0 \pmod n \wedge \#_b(w)\equiv 0 \pmod n \}$. In a prior HW I asked how big a CFG for this problem would be. It was quite large since you went DFA to regex to CFG. NOW that we an go DFA to CFG, how large will the CFG for $L_n$ be? \end{enumerate} \newpage \item (30 points) In this problem we allow CNF grammars to have rules of the following types $A\goes BCD$ $A\goes BC$ $A\goes \sigma$ $A\goes e$ {\bf PREAMBLE} \begin{enumerate} \item (0 points but it gives the problem context) Fill in the blank. In class we showed that, for all $t$, the langage $$\{e,a,a^2,\ldots,a^{t^3-1}\}$$ has a CNFG with FILL IN nonterminals (you CANNOT use O-notation). \item (0 points but it gives the problem context) Fill in the blank. In class we showed that, for all $n$, the langage $$\{e,a,a^2,\ldots,a^n\}$$ has a CNFG with FILL IN nonterminals (you CAN use $O$-notation). \end{enumerate} \noindent {\bf END OF PREAMBLE} The acutal problem is on the next page. \begin{enumerate} \item Here is a CFG $E_0\goes a \mid e$ (so $L(E_0)=\{e,a\}$. $E_1\goes E_0E_0 \mid e$ (so $\{e,a^2\}\subseteq L(E_1)$). $E_2\goes E_1E_1 \mid e$ (so $\{e,a^4\}\subseteq L(E_2)$). $E_3\goes E_2E_2 \mid e$ (so $\{e,a^8\}\subseteq L(E_3)$). $E_4\goes E_3E_3 \mid e$ (so $\{e,a^{16}\}\subseteq L(E_4)$). $E_5\goes E_4E_4 \mid e$ (so $\{e,a^{32}\}\subseteq L(E_5)$). $E_6\goes E_5E_5 \mid e$ (so $\{e,a^{64}\}\subseteq L(E_6)$). $S\goes E_0E_1E_2E_3E_4E_5E_6$ \begin{enumerate} \item (10 points) Show that $L(G)=\{e, a, a^2,\ldots,a^{127}\}$ (Hint: Use that every number can be written in base 2.) \item (10 points) Convert the grammar to CNF. Just have to change the $S$ rule into a set of rules that do the same thing but are in CNF. How many nonterminals does it have? (We allow rules of the form $A\goes e$ so this is not strictly CNF.) \item (10 points) In the following statemeng FILL IN and prove it. Use the grammar above as a guide. {\it For all $t$ there exists a CNFG $G$ that generates $\{e, a, a^2,\ldots,a^{2^t-1}\}$ that has FILL IN number of nonterminals. You may use O-notation.} \item (0 points but its easy and finishes up this line of reasoning.) In the following statemeng FILL IN and prove it. Use the grammar above as a guide. {\it For all $n$ there exists a CNFG $G$ that generates $\{e, a, a^2,\ldots,a^n\}$ that has FILL IN number of nonterminals. You may use O-notation.} \end{enumerate} \end{enumerate} \end{enumerate} \end{document}