\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{enumerate}
\usepackage{color}

% dot graphs
\usepackage{dot2texi}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

% predefined styles
\newcommand{\wrong}[1]{{\color{red}\underline{\textbf{{#1}}}}}

\author{Sander van Veen (UvA ID: 6167969) \\ University of Amsterdam}
\title{Automata answers}

\begin{document}

\maketitle
\tableofcontents

\pagebreak

\section{Assignments part I}

\subsection*{Assignment 1}

\begin{enumerate}[(a)]
	\item
		\begin{dot2tex}[dot,options=-tmath --autosize --cache]
		digraph G {
			rankdir=LR;
			
			node [shape="none"]; start ;
			
			node [shape="box",color="blue"]; q_0;
			node [shape="circle",color="black"]; q_1 q_2 q_3;
			
			start -> q_0;
			
			q_0 -> q_1 [label="1"];
			q_1 -> q_0 [label="1"];
			
			q_1 -> q_2 [label="0"];
			q_2 -> q_1 [label="0"];
			
			q_2 -> q_3 [label="1"];
			q_3 -> q_2 [label="1"];
			
			q_3 -> q_0 [label="0"];
			q_0 -> q_3 [label="0"];
		}
		\end{dot2tex}
	\item
		\begin{dot2tex}[dot,options=-tmath --autosize --cache]
		digraph G {
			rankdir=LR;
			
			node [shape="circle",color="black"]; q_0;
			
			node [shape="none"]; start ;
			start -> q_0;
			
			q_0 -> q_0 [label="1"];
			
			node [shape="box",color="blue"]; q_1;
			
			q_0 -> q_1 [label="0"];
			
			q_1 -> q_0 [label="0, 1"];
		}
		\end{dot2tex}
	\item
		\begin{dot2tex}[dot,options=-tmath --autosize --cache]
		digraph G {
			rankdir=LR;
			
			node [shape="circle",color="black"]; q_0 q_1;
			
			node [shape="none"]; start ;
			start -> q_0;
			
			q_0 -> q_0 [label="1"];
			
			q_0 -> q_1 [label="0"];
			
			q_1 -> q_0 [label="1"];
			
			node [shape="box",color="blue"]; q_2;
			
			q_1 -> q_2 [label="0"];
			
			q_2 -> q_0 [label="1"];
			q_2 -> q_2 [label="0"];
		}
		\end{dot2tex}
	\item
		\begin{dot2tex}[dot,options=-tmath --autosize --cache]
		digraph G {
			rankdir=LR;
			
			node [shape="box",color="blue"]; q_0 q_1 q_2 q_3 q_4 q_6 q_7 q_8 q_9 q_10;
			node [shape="circle",color="black"]; q_5;
			
			q_0 -> q_1 [label="1"];
			q_1 -> q_2 [label="1"];
			q_2 -> q_3 [label="1"];
			q_3 -> q_4 [label="1"];
			q_4 -> q_5 [label="1"];
			q_5 -> q_5 [label="0, 1"];
			
			q_0 -> q_6 [label="0"];
			q_1 -> q_7 [label="0"];
			q_2 -> q_8 [label="0"];
			q_3 -> q_9 [label="0"];
			q_4 -> q_10 [label="0"];
			
			q_6 -> q_7 [label="0, 1"];
			q_7 -> q_8 [label="0, 1"];
			q_8 -> q_9 [label="0, 1"];
			q_9 -> q_10 [label="0, 1"];
			
			q_10 -> q_0 [label="0, 1"];
		}
		\end{dot2tex}
	\item
		\begin{dot2tex}[dot,options=-tmath --autosize --cache]
		digraph G {
			rankdir=LR
			
			node [shape="none"]; start ;
			
			node [shape="box",color="blue"]; q_0 q_1 q_2 q_3 q_4 q_5;
			node [shape="circle",color="black"]; q_6 q_7;
			
			start -> q_0;
			
			q_0 -> q_1 [label="0"];
			q_0 -> q_2 [label="1"];
			q_1 -> q_3 [label="0"];
			q_1 -> q_5 [label="1"];
			q_5 -> q_7 [label="0"];
			q_5 -> q_3 [label="1"];
			q_7 -> q_3 [label="0, 1"];
			q_2 -> q_4 [label="0"];
			q_2 -> q_3 [label="1"];
			q_4 -> q_3 [label="0"];
			q_4 -> q_6 [label="1"];
			q_6 -> q_3 [label="0, 1"];
			
			q_3 -> q_3 [label="0, 1"];
		}
		\end{dot2tex}
\end{enumerate}

\subsection*{Assignment 2}

Given $ A = ( Q, \Sigma, \delta, q_0, F ) $. \\
Then $ B = ( Q, \Sigma, \delta, q_0, Q \setminus F ) $. L(B) is the complement of L(A).

\subsection*{Assignment 3}

\begin{enumerate}[(a)]
	\item $ \{w \in \{a,b\}* | \, w $ ends with one $a$, followed by zero or more $b$'s$\} $
	\item $ \{w \in \{a,b\}* | \, w $ contains substring of two $a$'s, followed by one $b\} $
	\item $ \{w \in \{a,b\}* | \, w $ starts with one $a$, followed by one $b\} $
\end{enumerate}

\subsection*{Assignment 4}

\begin{dot2tex}[dot,options=-tmath --autosize --cache]
digraph G {
	rankdir=LR
	
	node [shape="none"]; start ;
	
	node [shape="box",color="blue"]; q_1 q_5;
	node [shape="circle",color="black"]; q_0 q_2 q_3 q_4;
	
	start -> q_0;
	
	q_0 -> q_1 [label="[0,9]"];
	q_1 -> q_1 [label="[0,9]"];
	q_1 -> q_2 [label="."];
	q_2 -> q_1 [label="[0,9]"];
	q_1 -> q_3 [label="E"];
	q_3 -> q_4 [label="-"];
	q_4 -> q_5 [label="[0,9]"];
	q_3 -> q_5 [label="[0,9]"];
	q_5 -> q_5 [label="[0,9]"];
}
\end{dot2tex}

\pagebreak

\subsection*{Assignment 5}

In order to draw a reasonable graph, the alphabet is limited to \{0,1,2\}.

\begin{dot2tex}[dot,options=-tmath --autosize --cache]
digraph G {
	rankdir=LR
	
	node [shape="none"]; start;
	
	node [shape="box",color="blue"]; q_1 q_2 q_4;
	node [shape="circle",color="black"]; q_0 q_3 q_6;
	
	node [shape="box",color="blue"]; q_5 q_7;
	node [shape="none",label="..."]; q_8 q_9;
	
	start -> q_0;
	
	q_0 -> q_1 [label="0"];
	q_0 -> q_8 [label="1"];
	q_0 -> q_9 [label="2"];
	
	q_1 -> q_2 [label="1"];
	q_2 -> q_3 [label="\{0,1\}"];
	q_2 -> q_4 [label="2"];
	q_3 -> q_4 [label="2"];
	q_3 -> q_3 [label="\{0,1\}"];
	
	q_1 -> q_5 [label="2"];
	q_5 -> q_6 [label="\{0,2\}"];
	q_5 -> q_7 [label="1"];
	q_6 -> q_7 [label="1"];
	q_6 -> q_6 [label="\{0,2\}"];
}
\end{dot2tex}

\section{Assignments part II}

\subsection*{Assignment 6}

\begin{enumerate}[(a)]
	\item
		\begin{dot2tex}[dot,options=-tmath --autosize --cache]
		digraph G {
			rankdir=LR
	
			node [shape="none"]; start ;
	
			node [shape="box",color="blue"]; q_1 q_2;
			node [shape="circle",color="black"]; q_0 q_3;
	
			start -> q_0;
	
			q_0 -> q_1 [label="a"];
			q_0 -> q_2 [label="b"];
			
			q_1 -> q_1 [label="a"];
			q_1 -> q_2 [label="b"];
			
			q_2 -> q_3 [label="\{a,b\}"];
			
			q_3 -> q_3 [label="\{a,b\}"];
		}
		\end{dot2tex}
	\item[(d)]
		\begin{dot2tex}[dot,options=-tmath --autosize --cache]
		digraph G {
			rankdir=LR
	
			node [shape="none"]; start ;
	
			node [shape="box",color="blue"]; q_0 q_1 q_2 q_3;
			node [shape="circle",color="black"]; q_4;
	
			start -> q_0;
	
			q_0 -> q_0 [label="b"];
			q_0 -> q_1 [label="a"];
			
			q_1 -> q_2 [label="a"];
			q_1 -> q_4 [label="b"];
			
			q_2 -> q_3 [label="b"];
			q_2 -> q_4 [label="a"];
			
			q_3 -> q_3 [label="\{a,b\}"];
		
			q_4 -> q_4 [label="a"];
			q_4 -> q_3 [label="b"];
		}
		\end{dot2tex}
\end{enumerate}

\subsection*{Assignment 7}

$ r = (ab + aa + baa)* $

\begin{center}
	\begin{tabular}{|l|l|l|l|l|l|}
		\hline
		$w$ & bbaaba & abaabaaabaa & aaaabaaaa & baaaaabaa & baaaaabaaaab \\
		\hline
		$w \in L(r)$ & no: \wrong{b}baaba & yes & yes & yes & no: baaaaabaaaa\wrong{b} \\
		\hline
	\end{tabular}
\end{center}

\subsection*{Assignment 9}

\begin{enumerate}[(a)]
	\item $(a+b)(a+b)$
	\item $(a+b)(a+b)(a+b)(a+b)*$
	\item $a(a+b)*a$
	\item $(a+b)*(a(bb+\epsilon)+b(aa+\epsilon)+(a+b)(a+b+aa+bb))*(a+b)*$
	\item $( \, (b+\epsilon) \, a \, (b+\epsilon) \, a \, (b+\epsilon) \, a \, (b+\epsilon) \, )*$
	\item  ?
	\item  $((a+b)*(a+b+ba))+\epsilon$
	\item  $b*(a+bb)*b*$
\end{enumerate}

\subsection*{Assignment 14}

\begin{enumerate}[(a)]
	\item 
		\begin{dot2tex}[dot,options=-tmath --autosize --cache]
		digraph G {
			rankdir=LR;
	
			node [shape="none"]; start ;
	
			node [shape="box",color="blue"]; q_2;
			node [shape="circle",color="black"]; q_0 q_1;
			
			start -> q_0;
			
			q_0 -> q_0 [label="a"];
			q_0 -> q_1 [label="b"];
			q_0 -> q_2 [label="c"];
			
			q_1 -> q_1 [label="a"];
			q_1 -> q_2 [label="\{b,c\}"];
			
			q_2 -> q_0 [label="c"];
			q_2 -> q_2 [label="\{a,b\}"];
		}
		\end{dot2tex}
	\item 
		\begin{dot2tex}[dot,options=-tmath --autosize --cache]
		digraph G {
			rankdir=LR;
	
			node [shape="none"]; start ;
	
			node [shape="box",color="blue"]; q_0 q_1 q_2 q_3 q_4;
			node [shape="circle",color="black"]; q_5;
			
			start -> q_0;
			
			q_0 -> q_5 [label="a"];
			q_0 -> q_1 [label="c"];
			q_0 -> q_2 [label="b"];
			
			q_1 -> q_5 [label="\{a,b,c\}"];
			
			q_2 -> q_0 [label="a"];
			q_2 -> q_3 [label="b"];
			q_2 -> q_4 [label="c"];
			
			q_3 -> q_5 [label="\{a,b,c\}"];
			
			q_4 -> q_4 [label="c"];
			q_4 -> q_0 [label="a"];
			q_4 -> q_3 [label="b"];
		
			q_5 -> q_5 [label="\{a,b,c\}"];
		}
		\end{dot2tex}
\end{enumerate}

\section{Assignments part III}

\subsection*{Assignment 16}

\begin{enumerate}[(a)]
	\item
		\begin{dot2tex}[dot,options=-tmath --autosize --cache]
		digraph G {
			rankdir=LR;
	
			node [shape="none"]; start ;
	
			node [shape="box",color="blue"]; q_1 q_2 q_3;
			node [shape="circle",color="black"]; q_0;
			
			start -> q_0;
			
			q_0 -> q_1 [label="a"];
			
			q_1 -> q_1 [label="a"];
			q_1 -> q_2 [label="b"];
			
			q_2 -> q_2 [label="a"];
			q_2 -> q_3 [label="b"];
			
			q_3 -> q_3 [label="b"];
		}
		\end{dot2tex}
	\item
		\begin{dot2tex}[dot,options=-tmath --autosize --cache]
		digraph G {
			rankdir=LR;
			
			node [shape="none"]; start ;
			
			node [shape="box",color="blue"]; q_3 q_4;
			node [shape="circle",color="black"]; q_0 q_1 q_2;
			
			start -> q_0;
			
			q_0 -> q_1 [label="a"];
			
			q_1 -> q_2 [label="b"];
			
			q_2 -> q_3 [label="a"];
			
			q_3 -> q_4 [label="a"];
			q_3 -> q_2 [label="b"];
			
			q_4 -> q_2 [label="\{a,b\}"];
		}
		\end{dot2tex}
\end{enumerate}



\subsection*{Assignment 19}

\textbf{Pumping lemma} If a language $L$ is regular, then there exists a number
$p \geq 1$ (the pumping length) such that every string $uwv$ in $L$ with 
$|w| \geq p$ can be written in the form $uwv = uxyzv$ with strings $x$, $y$ and
$z$ such that $|xy| \leq p, \; |y| \geq 1$ and $uxy^izv$ is in $L$ for every
integer $i \geq 0$. 

\begin{enumerate}[(a)]
	\item 
	\item 
	\item For example, use $w = a^n b^n, \; xy = a^n, \; z = b^n, \;
	      |y| >= 1$. \\
	      Pump $y$, so that $|xy| > |z|$. This will result in
	      $\#_a(w) \neq \#_b(w)$.
	\item

\end{enumerate}

%\subsection*{Assignment 20}

%\begin{enumerate}[(a)]
%	\item Regular, because $|v| = 2$ solves the ``counting problem'' for $v$. 
%	\item Regular, because the language is equivalent to 
%	      $\{g \; | \; g \in \{a,b\}^*\}$. 
%\end{enumerate}

% 16, 19abc, 20, 24ab, 26

\subsection*{Assignment 20}

If a regular expression $R$ has no occurrences of the empty language 
$\varnothing$, then it is not empty. If the regular expression $R$ contains an
occurrence of the empty language, it may or may not be empty. \\
\\
\textbf{Basis:} \{\} denotes the empty language ($\epsilon$ does not). \\
\\
\textbf{Induction:}

\begin{enumerate}
	\item $R = R_1 + R_2$ \\
     $L(R)$ is empty iff $R_1$ and $R_2$ is empty.

	\item $R = R_1 R_2$ \\
     $L(R)$ is empty iff $R_1$ or $R_2$ is empty.

	\item $R = R_1*$ \\
     $L(R)$ not empty, since it always includes $\epsilon$.

	\item $R = (R_1)$ \\
     $R$ empty iff $R_1$ is empty.

\end{enumerate}

\section{Assignments part IV}

\subsection*{Assignment 35}

\begin{table}[h]
\begin{tabular}{ll}

\begin{dot2tex}[dot,options=-tmath --autosize --cache]
	graph G {
		node [shape="none"]; S0 [label="S"] a0 [label="a"] ;
		S1 [label="S"] a1 [label="a"] S2 [label="S"] b;
		S3 [label="S"] e0 [label="\epsilon"] e1 [label="\epsilon"];
		
		S0 -> a0;
		S0 -> S1;

		S1 -> a1;
		S1 -> S2;
		S1 -> b;
		S1 -> S3;

		S2 -> e0;
		
		S3 -> e1;
	}
\end{dot2tex}

&

\begin{dot2tex}[dot,options=-tmath --autosize --cache]
	graph G {
		node [shape="none"]; S0 [label="S"] a0 [label="a"];
		S1 [label="S"] b S2 [label="S"] a1 [label="a"];
		S3 [label="S"] e0 [label="\epsilon"] e1 [label="\epsilon"];
		
		S0 -> a0;
		S0 -> S1;
		S0 -> b;
		S0 -> S2;

		S1 -> a1;
		S1 -> S3;

		S2 -> e0;

		S3 -> e1;
	}
\end{dot2tex}

\end{tabular}
\caption{Two parse trees for $w = aab$} 
\end{table}

Two leftmost derivations: \\
\\
$S \longrightarrow _{lm} aS \longrightarrow _{lm} aaSbS  \longrightarrow _{lm} 
aa \epsilon bS \longrightarrow _{lm} aa \epsilon b\epsilon \longrightarrow 
aab $ \\
$S \longrightarrow _{lm} aSbS \longrightarrow _{lm} aaSbS  \longrightarrow _{lm} 
aa \epsilon bS \longrightarrow _{lm} aa \epsilon b\epsilon \longrightarrow 
aab $ \\
\\
Two rightmost derivations: \\
\\
$S \longrightarrow _{rm} aS \longrightarrow _{rm} aaSbS \longrightarrow _{rm} 
aaSb \epsilon \longrightarrow _{rm} aa \epsilon b \epsilon \longrightarrow 
aab $ \\
$S \longrightarrow _{rm} aSbS \longrightarrow _{rm} aSb \epsilon 
\longrightarrow _{rm} aaSb \epsilon \longrightarrow _{rm} aa \epsilon b\epsilon
\longrightarrow aab $ 

\subsection*{Assignment 36}

Unambiguous grammar of `` $ S \longrightarrow aS \; | \; aSbS \; | 
\; \epsilon $ '': \\
\\
$ S \longrightarrow aST \; | \; \epsilon $ \\
$ T \longrightarrow bS \; | \; \epsilon $

\section*{Assignment 42}

\begin{enumerate}[1.]
	\item
	\item $P(G) = (\{q_0\}, \{a,b,s\}, \{a,b,s,A,S\}, \delta, q_0, S)$
\end{enumerate}

\end{document}
