|
| 1 | +\documentclass[12pt]{article} |
| 2 | +\usepackage[utf8]{inputenc} |
| 3 | +\usepackage{float} |
| 4 | +\usepackage{amsmath} |
| 5 | + |
| 6 | + |
| 7 | +\usepackage[hmargin=3cm,vmargin=6.0cm]{geometry} |
| 8 | +%\topmargin=0cm |
| 9 | +\topmargin=-2cm |
| 10 | +\addtolength{\textheight}{6.5cm} |
| 11 | +\addtolength{\textwidth}{2.0cm} |
| 12 | +%\setlength{\leftmargin}{-5cm} |
| 13 | +\setlength{\oddsidemargin}{0.0cm} |
| 14 | +\setlength{\evensidemargin}{0.0cm} |
| 15 | + |
| 16 | +%misc libraries goes here |
| 17 | +\usepackage{tikz} |
| 18 | +\usetikzlibrary{automata,positioning} |
| 19 | + |
| 20 | +\begin{document} |
| 21 | + |
| 22 | +\section*{Student Information } |
| 23 | +%Write your full name and id number between the colon and newline |
| 24 | +%Put one empty space character after colon and before newline |
| 25 | +Full Name : Kadir CETINKAYA \\ |
| 26 | +Id Number : 2036457 \\ |
| 27 | + |
| 28 | +% Write your answers below the section tags |
| 29 | +\section*{Answer 1} |
| 30 | + |
| 31 | +\subsection*{a.} |
| 32 | +%$a\{a,c\}^*b\{a,c\}^*b\{a,c\}^*cc$ |
| 33 | +$a(a+c)^*b(a+c)^*b(a+c)^*cc$ |
| 34 | + |
| 35 | +\subsection*{b.} |
| 36 | +%$\{(\{b,c\}\{b,c\})^*a\{b,c\}(\{b,c\}\{b,c\})^*\} \cup \{\{b,c\}(\{b,c\}\{b,c\})^*a(\{b,c\}\{b,c\})^*\}$ |
| 37 | +$(((b+c)(b+c))^*a(b+c)((b+c)(b+c))^*)+((b+c)((b+c)(b+c))^*a((b+c)(b+c))^*)$ |
| 38 | +\subsection*{c.} |
| 39 | +$a^*(b^*baa^*b^*baa^*)^*b^*$ |
| 40 | + |
| 41 | +\section*{Answer 2} |
| 42 | + |
| 43 | +\subsection*{a.} |
| 44 | +\begin{tikzpicture}[shorten >=1pt,node distance=3cm,on grid,auto] |
| 45 | +\node[state,initial] (q_0) {$q_0$}; |
| 46 | +\node[state,accepting] (q_1) [below=of q_0] {$q_1$}; |
| 47 | +\node[state] (q_2) [below right=of q_0] {$q_2$}; |
| 48 | +\node[state,accepting](q_3) [right=of q_2] {$q_3$}; |
| 49 | +\node[state,accepting](q_4) [right=of q_3] {$q_4$}; |
| 50 | +\path[->] |
| 51 | + (q_0) edge [bend left=20] node {a} (q_1) |
| 52 | + (q_0) edge [bend right=20] node {b} (q_1) |
| 53 | + (q_1) edge [bend left=40] node {b} (q_0) |
| 54 | + (q_1) edge [bend left=20] node {a} (q_2) |
| 55 | + (q_2) edge node {a} (q_3) |
| 56 | + (q_2) edge [bend left=20] node {b} (q_1) |
| 57 | + (q_3) edge node {a} (q_4) |
| 58 | + (q_3) edge node [swap] {b} (q_0) |
| 59 | + (q_4) edge [bend right] node [swap] {a} (q_3) |
| 60 | + (q_4) edge [bend left=40] node {b} (q_1); |
| 61 | +\end{tikzpicture} |
| 62 | + |
| 63 | +\subsection*{b.} |
| 64 | +\begin{tikzpicture}[shorten >=1pt,node distance=3cm,on grid,auto] |
| 65 | +\node[state,initial, accepting] (q_0) {$q_0$}; |
| 66 | +\node[state] (q_1) [right=of q_0] {$q_1$}; |
| 67 | +\node[state] (q_2) [right=of q_1] {$q_2$}; |
| 68 | +\path[->] |
| 69 | + (q_0) edge [loop below] node {b} () |
| 70 | + (q_0) edge node {a} (q_1) |
| 71 | + (q_1) edge [bend right=40] node [swap] {b} (q_0) |
| 72 | + (q_1) edge node {a} (q_2) |
| 73 | + (q_2) edge [bend left=20] node {b} (q_0); |
| 74 | +\end{tikzpicture} |
| 75 | + |
| 76 | +\section*{Answer 3} |
| 77 | +Let us examine the case where $L_i=\{a^ib^i\}, i\in N$ and the alphabet used is $\Sigma = \{a,b\}$. |
| 78 | +Clearly each $L_i$ is a regular language, since they only consist of one word. Their union is \\ |
| 79 | +$L=\cup_{i=0}^{\infty}L_i=\{a^ib^i|i\in N\}$. According to Pumping lemma $\exists p \ge 1$ s.t. |
| 80 | +$\forall w\in L, |w|\ge p$ can be written as $w=xyz$, with the following properties: |
| 81 | + |
| 82 | +\def\labelitemi{-} |
| 83 | +\begin{itemize} |
| 84 | + \item $|y|\ge 1$ |
| 85 | + \item $|xy|\le p$ |
| 86 | + \item $\forall i\ge 0, xy^iz\in L$ |
| 87 | +\end{itemize} |
| 88 | + |
| 89 | +So let us choose $w$ as $w=a^pb^p$, since that $p$ exists according to lemma, we can split the $w$ |
| 90 | +into three parts, since $|xy|\le p$ and $|y|\ge 1$ and $w$ contains $p$ $a$'s as prefix, $y$ |
| 91 | +contains at least one $a$. According to third property we should have $xy^0z\in L$, but that's |
| 92 | +clearly not true since $L$ contains only words containing same amount of $a$'s and $b$'s whereas $xy^0z$ |
| 93 | +contains absolutely less $a$'s then $b$'s. So, $L$ is not a regular language. Therefore, despite |
| 94 | +$L$ is countably infinite union of regular languages, itself is not a regular language so the claim |
| 95 | +is false. |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | +\section*{Answer 4} |
| 100 | +Let $L=\{a^ib^jc^{2j} | i\ge 0,j\ge 0\}$ and $w\in L$, according to pumping lemma $\exists p\ge 1$ s.t.\\ |
| 101 | +$\forall w\in L,\{a^ib^jc^{2j} | i\ge 0,j\ge 0\} |w|\ge p$ can be written as $w=xyz$, with the |
| 102 | +following properties: |
| 103 | +\def\labelitemi{-} |
| 104 | +\begin{itemize} |
| 105 | + \item $|y|\ge 1$ |
| 106 | + \item $|xy|\le p$ |
| 107 | + \item $\forall i\ge 0, xy^iz\in L$ |
| 108 | +\end{itemize} |
| 109 | + |
| 110 | +If $p=1$, it is clear that string $w=b^1c^2\in L$, when split into $w=xyz$, $xy=y=b$ by the pumping lemma |
| 111 | +and $xy^0z$ definitely would not be in $L$, since amount of $b$'s would be $0$ while amount of $c$'s is still $2$. |
| 112 | +Contradiction. |
| 113 | + |
| 114 | +If $p>1$ let us choose $w$ as $w=b^{j_0}c^{2j_0}$ where $j_0=p$ into $w=xyz$, since we assume $p>1$ and by |
| 115 | +the pumping lemma $y$ contains at least one $b$ and definitely no $c$. So, $xy^0z\notin L$ since amount of |
| 116 | +$b$'s is less than $j_0$ whereas there are exactly $2j_0$ of $c$'s. Contradiction. |
| 117 | + |
| 118 | +Since we got a contradiction for any choice of $p$, $L$ is not regular. |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | +\section*{Answer 5} |
| 123 | +Let us choose 2 regular languages $L_1$ and $L_2$, with correspoding deterministic finite automatas\\ |
| 124 | +$M_1=(Q_1, \Sigma_1, \Delta_1, s_1, F_1)$ and $M_2=(Q_2, \Sigma_2, \Delta_2, s_2, F_2)$.\\ |
| 125 | +Now let us create a new finite automata $M=(Q, \Sigma, \Delta, s, F)$, where $Q=(Q_1\times Q_2)$, |
| 126 | +$\Sigma =\Sigma_1 \cup \Sigma_2$,\\ |
| 127 | +$\Delta =\{((q_1,q_2), \sigma, (q_1', q_2'))| \sigma \in \Sigma, (q_1,\sigma,q_1')\in \Delta_1, (q_2,\sigma,q_2')\in \Delta_2\}$, |
| 128 | +$s=(s_1,s_2)$,\\ $F=\{(q_1, q_2) | q_1\in F_1, q_2\in Q_2-F_2\}$. Now from that definition it is easy |
| 129 | +to see that $(p,q)$ is an accepting state for $M$ iff $p$ is an accepting state for $M_1$ and $q$ is |
| 130 | +a nonaccepting state for $M_2$. Also $(p,q)$ is an inital state iff $p$ is inital state of $M_1$ and |
| 131 | +$q$ is inital state of $M_2$. Also transitions are done for the first element of the state tuple |
| 132 | +according to $\Delta_1$ and for the second element of the state tuple according to $\Delta_2$. |
| 133 | + |
| 134 | +\begin{itemize} |
| 135 | + \item Claim I: $L(M)\subseteq L(M_1)-L(M_2)$\\ |
| 136 | + Let $x\in L(M)$, since DFA $M$ accepts that string, state must be of the form $(p,q)$ |
| 137 | + which implies by the construction of $M$, DFA $M_1$ would be in state $p$ and DFA $M_2$ |
| 138 | + would be in state $q$, also by the construction of $M$ we know that $p$ is an accepting |
| 139 | + state for $M_1$ whereas $q$ is not an accepting state for $M_2$. So, $M_1$ accepts $x$ |
| 140 | + but $M_2$ does not. Therefore $x\in L(M_1) \wedge x\notin L(M_2)\rightarrow x\in L(M_1)-L(M_2)$ |
| 141 | + So our claim holds. |
| 142 | + \item Claim II: $L(M_1)-L(M_2)\subseteq L(M)$\\ |
| 143 | + Let $x\in L(M_1)-L(M_2)\rightarrow x\in L(M_1) \wedge x\notin L(M_2)$, this implies $M_1$ |
| 144 | + accepts $x$ whereas $M_2$ does not. So $M_1$ must be in an accepting state say $p$ while |
| 145 | + $M_2$ must be in a nonaccepting state say $q$. So if we given $x$ to DFA $M$ it would be |
| 146 | + in state $(p,q)$ which is an accepting state for $M$ since $p$ is an accepting state for |
| 147 | + $M_1$ and $q$ is a nonaccepting state for $M_2$ by construction. Therefore |
| 148 | + $x\in L(M_1)-L(M_2)\rightarrow x\in L(M)$. So our claim holds. |
| 149 | + \item So by Claim I and II it is easy to see that $L(M)=L(M_1)-L(M_2)=L_1-L_2$ and since $M$ |
| 150 | + is a DFA, $L(M)$ is a regular language. Therefore regular languages are closed under set |
| 151 | + difference. |
| 152 | +\end{itemize} |
| 153 | + |
| 154 | +\section*{Answer 6} |
| 155 | +\begin{tikzpicture}[shorten >=1pt,node distance=3cm,on grid,auto] |
| 156 | + \node[state,initial] (q0) {$\{q_0\}$}; |
| 157 | + \node[state, accepting] (q1) [right=of q0] {$\{q_1,q_2\}$}; |
| 158 | + \node[state] (q2) [right=of q1] {$\{q_3\}$}; |
| 159 | + \node[state, accepting] (q3) [above=of q2] {$\{q_2\}$}; |
| 160 | + \node[state, accepting] (q4) [right=of q2] {$\{q_1,q_3\}$}; |
| 161 | + \node[state, accepting] (q5) [below=of q4] {$\{q_0,q_2\}$}; |
| 162 | + \node[state] (q6) [left=of q5] {$\{q_0,q_3\}$}; |
| 163 | + \node[state, accepting] (q7) [left=of q6] {$\{q_0,q_1,q_3\}$}; |
| 164 | + \node[state, accepting] (q8) [left=of q7] {$\{q_0,q_1,q_2\}$}; |
| 165 | + \node[state] (q9) [left=of q3] {$\{\}$}; |
| 166 | +\path[->] |
| 167 | + (q0) edge [loop above] node {b} () |
| 168 | + edge [bend left] node {a} (q1) |
| 169 | + (q1) edge node {b} (q2) |
| 170 | + edge [bend left] node {a} (q0) |
| 171 | + (q2) edge [bend left] node {a} (q3) |
| 172 | + edge node {b} (q4) |
| 173 | + (q3) edge [bend left] node {b} (q2) |
| 174 | + edge node {a} (q9) |
| 175 | + (q4) edge [loop above] node {b} () |
| 176 | + edge node {a} (q5) |
| 177 | + (q5) edge node {a} (q1) |
| 178 | + edge node {b} (q6) |
| 179 | + (q6) edge node {a} (q1) |
| 180 | + edge node {b} (q7) |
| 181 | + (q7) edge [out=330,in=300,looseness=8,loop] node [swap] {b} () |
| 182 | + edge node {a} (q8) |
| 183 | + (q8) edge [loop left] node {a} () |
| 184 | + edge [bend right=90] node [swap] {b} (q6) |
| 185 | + (q9) edge [loop below] node {a} () |
| 186 | + edge [loop above] node {b} (); |
| 187 | +\end{tikzpicture} |
| 188 | + |
| 189 | +The correspondence is shown in the node names, as they are subsets of the states of the |
| 190 | +given NFA. Also the constructed DFA is minimal, since for every state $q$ in it there exists |
| 191 | +a word $w$ such that $(\{q_0\}, w) \vdash_M^* (q, e)$ which implies there is no unreachable |
| 192 | +state and also for every state pair $(p,q)$ there exists a word $w$ such that, |
| 193 | +$(p,w) \vdash_M^* (p',e)$, $(q,w) \vdash_M^* (q',e)$ where $(p'$ is an accepting state and |
| 194 | +$q'$ is a nonaccepting state $)$ or $(p'$ is a nonaccepting state and $q'$ is an accepting |
| 195 | +state $)$ which implies every two state is distinguishable from each other. |
| 196 | + |
| 197 | + |
| 198 | + |
| 199 | +\end{document} |
| 200 | + |
| 201 | + |
| 202 | + |
0 commit comments