Cleaned up DFA handout
This commit is contained in:
parent
95965cde82
commit
9406121c62
@ -16,6 +16,6 @@
|
||||
|
||||
|
||||
\input{parts/0 DFA.tex}
|
||||
%\input{parts/1 regular.tex}
|
||||
\input{parts/1 regular.tex}
|
||||
|
||||
\end{document}
|
@ -111,7 +111,7 @@ Which of the following strings are accepted by $B$:
|
||||
|
||||
|
||||
|
||||
\problem{}
|
||||
\problem{}<SameStartAndEnd>
|
||||
Describe the strings accepted by $B$.
|
||||
|
||||
\begin{solution}
|
||||
@ -122,38 +122,7 @@ Describe the strings accepted by $B$.
|
||||
\pagebreak
|
||||
|
||||
|
||||
|
||||
|
||||
\definition{}
|
||||
An \textit{alphabet} is a finite set of symbols. \par
|
||||
|
||||
\definition{}
|
||||
A \textit{string} over an alphabet $Q$ is a finite sequence of symbols from $Q$. \par
|
||||
We denote the empty string $\varepsilon$. \par
|
||||
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
$Q^*$ is the set of all possible strings over $Q$. \par
|
||||
For example, $\{\texttt{0}, \texttt{1}\}^*$ is the set $\{\varepsilon, \texttt{0}, \texttt{1}, \texttt{00}, \texttt{01}, \texttt{10}, \texttt{11}, \texttt{000},... \}$ \par
|
||||
Note that this set contains the empty string.
|
||||
|
||||
\definition{}
|
||||
A \textit{language} over an alphabet $Q$ is a subset of $Q^*$. \\
|
||||
For example, the language \say{strings of length 2} over $\{\texttt{0}, \texttt{1}\}$ is $\{\texttt{00}, \texttt{01}, \texttt{10}, \texttt{11}\}$
|
||||
|
||||
\definition{}
|
||||
We say a language $L$ is \textit{recognized} by a DFA if that DFA accepts a string $w$ if and only if $w \in L$.
|
||||
|
||||
|
||||
%\begin{remark}
|
||||
%A machine, such as DFA or Turing machine, may accept several strings, but it always recognizes only one language. If the machine %accepts no strings, it still recognizes one language — namely, the empty language $\emptyset$.
|
||||
%\end{remark}
|
||||
|
||||
|
||||
\vspace{8mm}
|
||||
|
||||
\problem{}
|
||||
\problem{}<fibonacci>
|
||||
How many strings of length $n$ are accepted by the automaton $C$?
|
||||
|
||||
\begin{center}
|
||||
@ -186,6 +155,28 @@ How many strings of length $n$ are accepted by the automaton $C$?
|
||||
%\end{remark}
|
||||
|
||||
\vfill
|
||||
|
||||
\definition{}
|
||||
An \textit{alphabet} is a finite set of symbols. \par
|
||||
|
||||
\definition{}
|
||||
A \textit{string} over an alphabet $Q$ is a finite sequence of symbols from $Q$. \par
|
||||
We denote the empty string $\varepsilon$. \par
|
||||
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
$Q^*$ is the set of all possible strings over $Q$. \par
|
||||
For example, $\{\texttt{0}, \texttt{1}\}^*$ is the set $\{\varepsilon, \texttt{0}, \texttt{1}, \texttt{00}, \texttt{01}, \texttt{10}, \texttt{11}, \texttt{000},... \}$ \par
|
||||
Note that this set contains the empty string.
|
||||
|
||||
\definition{}
|
||||
A \textit{language} over an alphabet $Q$ is a subset of $Q^*$. \\
|
||||
For example, the language \say{strings of length 2} over $\{\texttt{0}, \texttt{1}\}$ is $\{\texttt{00}, \texttt{01}, \texttt{10}, \texttt{11}\}$
|
||||
|
||||
\definition{}
|
||||
We say a language $L$ is \textit{recognized} by a DFA if that DFA accepts a string $w$ if and only if $w \in L$.
|
||||
|
||||
\pagebreak
|
||||
|
||||
\problem{}
|
||||
|
@ -1,177 +1,186 @@
|
||||
% \section{Regular languages}
|
||||
\section{Regular languages}
|
||||
|
||||
% \definition{}
|
||||
% A language is called \textit{regular} if it is recognized by some $DFA$.
|
||||
% \end{definition}
|
||||
\definition{}
|
||||
We say a language is \textit{regular} if it is recognized by some $DFA$.
|
||||
|
||||
% \problem{}
|
||||
% \part{a} Draw a DFA over an alphabet $\{A, B\}$ accepting strings which do not start and end with the same letter. \textit{Hint: the DFA from Fig. 2 does almost this.}
|
||||
% \part{b} Prove that for any regular language $L$ over an alphabet $Q$ its complement $\overline{L} = Q^*\setminus L$ is also regular.
|
||||
%
|
||||
% \begin{solution}
|
||||
% Invert accepting and rejecting states.
|
||||
% \end{solution}
|
||||
\problem{}
|
||||
Draw a DFA over $\{A, B\}$ that accepts strings which do not start and end with the same letter. \par
|
||||
\hint{Modify the DFA in \ref{SameStartAndEnd}.}
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Let $L$ be a regular language over an alphabet $Q$. \par
|
||||
Show that $Q^* - L$ is also regular. \par
|
||||
\hint{$Q^* - L$ is the set of objects in $Q^*$ but not in $L$. This is often called the \textit{complement} of $L$.}
|
||||
|
||||
\begin{solution}
|
||||
Invert accepting and rejecting states.
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
\pagebreak
|
||||
|
||||
|
||||
% \problem{}
|
||||
% \part{a} Draw a DFA over an alphabet $\{A, B\}$ accepting strings which do not start and end with the same letter AND have an even length.
|
||||
% \part{b} Prove that for any regular languages $L_1$, $L_2$ over an alphabet $Q$ their union and intersection are also regular.
|
||||
%
|
||||
% \begin{solution}
|
||||
% Consider a product of automatons where each state is a pair of states in the first and second automaton and every transition works if it was applied to both elements in pair.
|
||||
|
||||
% For union, we call the state $(s_1, s_2)$ accepting if $s_1$ OR $s_2$ is accepting in their respective automaton.
|
||||
|
||||
% For intersection, we call it accepting if $s_1$ AND $s_2$ are accepting in their respective automaton.
|
||||
% \end{solution}
|
||||
|
||||
|
||||
% However, not all languages are regular. You will later see that the language consisting of palindromes is not regular.
|
||||
|
||||
% Our technique for proving nonregularity stems from a theorem about regular
|
||||
% languages, traditionally called the pumping lemma. This theorem states that all regular languages have a special property. If we can show that a language does not have this property, we are guaranteed that it is not regular. The property states that all strings in the language can be “pumped” if they are at least as long as a certain special value, called \textit{the pumping length}. That means each such string contains a section that can be repeated any number of times with the resulting string remaining in the language.
|
||||
% \medskip
|
||||
|
||||
% \noindent \fbox{\begin{minipage}{\textwidth}
|
||||
% \begin{theorem}[Pumping lemma]
|
||||
% If $A$ is a regular language, then there is a number $p$ (the pumping length) where if $s$ is any string in $A$ of length at least $p$, then $s$ may be divided into three pieces, $s = xyz$, satisfying the following conditions:
|
||||
% \begin{enumerate}
|
||||
% \item for each $i \ge 0$, $xy^iz \in A$,
|
||||
% \item $|y| > 0$, and
|
||||
% \item $|xy| \le p$.
|
||||
% \end{enumerate}
|
||||
% \end{theorem}
|
||||
% \end{minipage}
|
||||
% }
|
||||
% \medskip
|
||||
|
||||
% Here $|s|$ represents the length of string $s$ (assuming $\varepsilon$ has length 0), $y^i$ means that $i$ copies of $y$ are concatenated together, and $y^0$ equals $\varepsilon$.
|
||||
% When $s$ is divided into $xyz$, either $x$ or $z$ may be $\varepsilon$, but condition 2 says that $y \ne \varepsilon$. Observe that without condition 2 the theorem would be trivially true.
|
||||
\problem{}
|
||||
Draw a DFA over the alphabet $\{A, B\}$ that accepts strings which have even length and do not start and end with the same letter. \par
|
||||
|
||||
|
||||
% \problem{}
|
||||
% \part{a} Check that the pumping lemma holds for the language recognized by the automaton C from Figure 3 and pumping length $p=2$.
|
||||
\vfill
|
||||
|
||||
% \part{b} Suppose that there is a regular language $L$ in the alphabet $\{a\}$. $L$ contains all strings of $a$'s whose length is some set $S$. Derive from the pumping lemma that if $S$ is infinite then it contains some arithmetic progression.
|
||||
\problem{}
|
||||
Let $L_1$, $L_2$ be two regular languages over an alphabet $Q$. \par
|
||||
Show that their union and intersection are also regular.
|
||||
|
||||
\begin{solution}
|
||||
Consider a product of automatons where each state is a pair of states in the first and second automaton and every transition works if it was applied to both elements in pair.
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
For union, we call the state $(s_1, s_2)$ accepting if $s_1$ OR $s_2$ is accepting in their respective automaton.
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
For intersection, we call it accepting if $s_1$ AND $s_2$ are accepting in their respective automaton.
|
||||
\end{solution}
|
||||
|
||||
|
||||
\vfill
|
||||
\pagebreak
|
||||
|
||||
|
||||
\theorem{Pumping Lemma}
|
||||
Let $A$ be a regular language. \par
|
||||
There then exists a number $p$, called the \textit{pumping length}, so that any string $s \in A$ of length at least $p$ may be divided into three pieces $s = xyz$ satisfying the following:
|
||||
|
||||
\begin{itemize}
|
||||
\item $|y| > 0$ \tab~\tab \hint{In other words, the segment $y$ is not the empty string.}
|
||||
\item $|xy| \leq p$. \tab~\tab \hint{$|s|$ is the length of a string.}
|
||||
\item $\forall i > 0$, $x y^i z \in A$ \tab \hint{$y^i$ means that $y$ is repeated $i$ times. $y^0$ is the empty string.}
|
||||
\end{itemize}
|
||||
|
||||
When $s$ is divided into $xyz$, either $x$ or $z$ may be the empty string, but $y$ must not be empty. \par
|
||||
Notice that without the first condition, this theorem is trivially true.
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
In english, the pumping lemma states that in any regular language, any string of sufficient length contains a substring that can be \say{pumped} (or repeated) to generate more strings in that language.
|
||||
|
||||
|
||||
\problem{}
|
||||
Check that the pumping lemma holds with $p = 3$ for the following DFA. \par
|
||||
\hint{This is the same DFA as in \ref{fibonacci}. What kind of strings does it accept?}
|
||||
|
||||
\begin{center}
|
||||
\begin{tikzpicture}
|
||||
\begin{scope}[layer = nodes]
|
||||
\node[main] (0) at (0, 0) {$\phantom{0}$};
|
||||
\node[accept] (1) at (3, 0) {$\phantom{0}$};
|
||||
\node[main] (2) at (5, 0) {$\phantom{0}$};
|
||||
\node[start] (s) at (-2, 0) {\texttt{start}};
|
||||
\end{scope}
|
||||
|
||||
\draw[->]
|
||||
(s) edge (0)
|
||||
(0) edge[loop above] node[label] {\texttt{b}} (0)
|
||||
(0) edge[bend left] node[label] {\texttt{a}} (1)
|
||||
(1) edge[bend left] node[label] {\texttt{b}} (0)
|
||||
(1) edge node[label] {\texttt{a}} (2)
|
||||
(2) edge[loop above] node[label] {\texttt{a,b}} (2)
|
||||
;
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
How can we use the pumping lemma to show that a language is \textbf{not} regular?
|
||||
\vfill
|
||||
|
||||
%\part{b} Suppose that there is a regular language $L$ in the alphabet $\{a\}$. $L$ contains all strings of $a$'s whose length is some set $S$. Derive from the pumping lemma that if $S$ is infinite then it contains some arithmetic progression.
|
||||
|
||||
% \part{c} Prove directly that if $S$ is infinite, than it contains some arithmetic progression. \textit{Hint: look at the first cycle in the DFA you get while reading $aaa\dots$.}
|
||||
|
||||
% \part{d} Prove the pumping lemma. \textit{Hint: look at the first cycle in the DFA you get while reading $s$.}
|
||||
%
|
||||
% \begin{solution}
|
||||
% Look at the first place where we come to an already visited state while reading the word. Say the first time we came to this state after reading $x$ and the second time after reading $xy$. Then $y$ doesn't move us from this state and we can omit it or repeat any number of times we want.
|
||||
% \end{solution}
|
||||
\problem{}
|
||||
Prove the pumping lemma. \par
|
||||
\hint{Look at the first cycle in the DFA you get while reading $s$.}
|
||||
|
||||
% \problem{}
|
||||
% Show that the following languages are not regular:\\
|
||||
% \part{a} $\{a^{n^2}\}$ -- the language of all strings over alphabet $\{a\}$ whose length is a perfect square;
|
||||
% \part{b} $\{0^n1^n| n \in \mathbb{N}_0\}$ over $\{0, 1\}$ (which is the shorthand for the set $\{\varepsilon, 01, 0011, \dots\}$);
|
||||
% \part{c} Language $ADD$ over the alphabet $\Sigma = \{0, 1, +, =\}$ where
|
||||
% $$ADD = \{"x=y+z"|~x, y, z\text{ are binary integers, and $x$ is the sum of $y$ and $z$}\};$$
|
||||
% \vspace{-2em}
|
||||
% \part{d} Language of all palindromes over the Latin alphabet.
|
||||
%
|
||||
% \begin{solution}
|
||||
% All of them are done by the pumping lemma.
|
||||
\begin{solution}
|
||||
Look at the first place where we come to an already visited state while reading the word. Say the first time we came to this state after reading $x$ and the second time after reading $xy$. Then $y$ doesn't move us from this state and we can omit it or repeat any number of times we want.
|
||||
\end{solution}
|
||||
|
||||
% \noindent\part{a} Follows from parts b-c of the previous problem;
|
||||
% \part{b} Assume the contrary and take the $p$ from the pumping lemma. Then the string $0^p1^p$ is accepted and so the string $0^{p-|y|}1^p$ (or $0^{p+|y|}1^p$) is also accepting;
|
||||
% \part{c} Pumping $10^{p+1}=10^p+10^p$;
|
||||
% \part{d} Pumping $a^pba^p$.
|
||||
% \end{solution}
|
||||
\vfill
|
||||
\pagebreak
|
||||
|
||||
% \problem{}
|
||||
% For a word $w$ over an alphabet $\{a, b\}$ denote by $|w|_a$ and $|w|_b$ the amount of letters $a$ and $b$, respectively, inside $w$.\\
|
||||
% \part{a} Prove that the language $L_p = \{w,\text{ s.t. $p$ divides } |w|_a - |w|_b\}$ is regular for any prime $p$.
|
||||
% \part{b} Prove that $L = \{w,\text{ s.t. } |w|_a - |w|_b = \pm1\}$ is not regular.
|
||||
% \part{c} Prove that there are infinitely many primes.
|
||||
%
|
||||
% \begin{solution}
|
||||
% \href{https://www.jstor.org/stable/48661886#metadata_info_tab_contents}{Link}
|
||||
% \end{solution}
|
||||
\problem{}
|
||||
Show that the following languages are not regular: \par
|
||||
|
||||
% \section{Tilings}
|
||||
% Tilings are all around us. Given a bunch of little pieces, it is human nature to wonder how they fit together. In the most general sense of the word, tiling is just a way of decomposing some space into lots of little pieces (tiles) that fit together without gaps or overlaps. Mathematicians study the structures emerging from the tilings of a plane or high-dimensional space wondering about their properties such as periodicity.
|
||||
\begin{enumerate}[itemsep=2mm]
|
||||
% \item $\{a^{n^2}\}$, the language of all strings over the alphabet $\{a\}$ which have a square length. \par
|
||||
% $\{a^{n^2}\} = \{ \varepsilon, \texttt{a}, \texttt{aaaa}, \texttt{aaaaaaaaa}, ... \}$
|
||||
|
||||
% Let us consider the one-dimensional tilings. {\em Tiles} can be seen as {\em letters} over a finite alphabet, and {\em tilings} as words infinite in both directions.
|
||||
\item $\{0^n1^n ~|~ n \in \mathbb{Z}^+_0\}$ over $\{0, 1\}$, which is the shorthand for the set $\{\varepsilon, 01, 0011, \dots\}$
|
||||
|
||||
% \begin{figure}[h]
|
||||
% \begin{center}
|
||||
% \includegraphics[width = 0.5\linewidth]{Alphabet.png}
|
||||
% \caption{Tiles forming a finite word}
|
||||
% \end{center}
|
||||
% \end{figure}
|
||||
\item The language ADD over the alphabet $\Sigma = \{0, 1, +, =\}$ where \par
|
||||
$\text{ADD} = \{ ~ \text{\say{x=y+z}} ~|~ x, y, z ~ \text{are binary integers, and $x$ is the sum of $y$ and $z$}\}$
|
||||
|
||||
% We call {\em pattern} of a word any of its finite subwords.
|
||||
% Letter are allowed to stay next to each other or not, and a common way to specify such constraints is to give a finite set of forbidden patterns.
|
||||
% For example, if $aa$ and $bb$ are forbidden, then the only infinite word that can be formed is "$\dots babab \dots$" -- the infinite periodic word with period $(ab)$.
|
||||
\item The language of all palindromes over the english alphabet
|
||||
|
||||
% \problem{}
|
||||
% Let us consider the set $S$ of infinite words in the alphabet $\{a,b\}$ which contain runs of $b$'s of length at most three.
|
||||
% Does there exist a finite set of forbidden words determining the $S$?
|
||||
%
|
||||
% \begin{solution}
|
||||
% Yes, we just prohibit the pattern $bbbb$.
|
||||
% \end{solution}
|
||||
|
||||
% \problem{} Count the minimal number of forbidden words to determine the following infinite words (given by its periods): \part{a} $(ab)$, \part{b} $(aab)$, \part{c*} $(aabaabab)$, \part{d*} $(aabaababaabaababaabab)$.
|
||||
%
|
||||
% \begin{solution}
|
||||
% \part{a} We can determine it by prohibiting 2 patterns -- $aa$ and $bb$. Moreover, we need to prohibit at least two patterns, because otherwise one of the words $(a)$ or $(b)$ would not be prohibited.
|
||||
|
||||
% \part{b} We can prohibit $aaa$, $bb$ and $bab$. After that $(aab)$ is determined uniquely. Moreover, we need to prohibit at least 3 patterns, since otherwise $(a)$, $(b)$ or $(ab)$ will not be prohibited.
|
||||
|
||||
% \part{c, d} We act analogously. You can see the generalized solution after the last problem.
|
||||
|
||||
% \end{solution}
|
||||
|
||||
% \problem{}
|
||||
% Consider the set of infinite words over the alphabet $\{a,b\}$ where the patterns (subword) $ba^nb$ are forbidden, for any $n>1$.
|
||||
% Can you find a finite set of forbidden patterns that defines the same set of words?
|
||||
%
|
||||
% \begin{solution}
|
||||
% No, since any pattern is finite, and if the maximal prohibited pattern has length $p$, there is no way of prohibiting two $b$'s on distance $>p$.
|
||||
% \end{solution}
|
||||
\end{enumerate}
|
||||
|
||||
|
||||
% \problem{}
|
||||
% What about the previous question if, in addition, you are now allowed to color letters (using finitely many different colors), that is, for example, to make a difference between a blue $a$ and a green $a$?
|
||||
%
|
||||
% \begin{solution}
|
||||
% Yes. Take two types of $a$ and prohibit patterns $bb$, $a_{blue}b$, $ba_{green}$, $a_{blue}a_{green}$ and $a_{green}a_{blue}$. Then words $(a)$ and $\dots aaabaaa \dots$ will be still possible (color everything left from $b$ green and right -- blue). But $ba^nb$ is impossible since all $a$'s between $b$ should have simultaneously blue and green color.
|
||||
% \end{solution}
|
||||
\begin{solution}
|
||||
% \textbf{Part A:} \par
|
||||
% Follows from parts b-c of the previous problem;
|
||||
% \vspace{2mm}
|
||||
|
||||
% \problem{} Let $S$ be the set of infinite words whose finite runs of $a$'s are all of the even length only.
|
||||
% Is it possible to determine the $S$ with some finite number of forbidden words?
|
||||
% And if we can color letters using finitely many different colors?
|
||||
%
|
||||
\textbf{Part A:} \par
|
||||
Assume this language is regular. Let $p$ be the pumping length. The string $0^p1^p$ must then be accepted, implying that the string $0^{p-|y|}1^p$ (or $0^{p+|y|}1^p$) is also accepted.
|
||||
|
||||
% \problem{} Same questions if the length of finite runs of $a$'s is asked to be odd.
|
||||
\vspace{2mm}
|
||||
|
||||
% \problem{} Let $u_0=a$, $u_1=ab$, $u_{n+2}=u_n u_{n+1}$.
|
||||
% Count the minimal number of necessary forbidden words to enforce infinite periodical words with period $u_n$.
|
||||
%
|
||||
% \begin{solution}~\\
|
||||
\textbf{Part B:} \par
|
||||
By pumping $10^{p+1}=10^p+10^p$
|
||||
|
||||
% \includegraphics[width = 0.9\linewidth]{Patterns1.png}
|
||||
\vspace{2mm}
|
||||
|
||||
% See the continuation at the next page
|
||||
\textbf{Part C:} \par
|
||||
By pumping $a^pba^p$
|
||||
|
||||
% \includegraphics[width = 0.9\linewidth]{Patterns2.png}
|
||||
% \end{solution}
|
||||
|
||||
% % \section{DFAs from NFAs}
|
||||
\end{solution}
|
||||
|
||||
% % \com{TD}{Show NFA==DFA}
|
||||
% % \com{TD}{Increasing number of states exponentially}
|
||||
|
||||
% % \problem{}[IOM 2016, P6]
|
||||
% % In a country with n cities, some pairs of cities are connected by oneway flights operated by one of two companies A and B. Two cities can be connected by more than one flight in either direction. An AB-word $w$ is called implementable if there is a sequence of connected flights whose companies’ names form the word $w$. Given that every AB-word of length $2^n$ is implementable, prove that every finite AB-word is implementable. (An AB-word of length $k$ is an arbitrary sequence of $k$ letters A or B; e.g. AABA is a word of length 4.)
|
||||
% %
|
||||
% % \begin{solution}
|
||||
% % \hyperlink{https://imomath.com/srb/zadaci/2016_metropolis_resenja_e.pdf}{Solution}
|
||||
% % \end{solution}
|
||||
\vfill
|
||||
\pagebreak
|
||||
|
||||
% % \section{Regular expressions}
|
||||
\definition{}
|
||||
Let $w$ be a string over an alphabet $A$. \par
|
||||
If $a \in A$, $|w|_a$ is the number of times the letter $a$ occurs in $w$.
|
||||
|
||||
% % \com{TD}{Prove that regular expressions give regular languages and vice versa}
|
||||
\vspace{2mm}
|
||||
|
||||
For the following problems, we will use the alphabet $\{a, b\}$.
|
||||
|
||||
\problem{}
|
||||
Show that the language $L_p = \Bigl\{w ~\Bigl|~ \text{$p$ divides } |w|_a - |w|_b \Bigr\}$ is regular for any prime $p$.
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Show that $L = \Bigl\{ w ~\Big|~ |w|_a - |w|_b = \pm 1 \Bigr\}$ is not regular.
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Prove that there are infinitely many primes.
|
||||
|
||||
\begin{solution}
|
||||
\texttt{https://www.jstor.org/stable/48661886}
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
\pagebreak
|
||||
|
Loading…
x
Reference in New Issue
Block a user