\documentclass{report}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{automata, arrows.meta, positioning}



\setcounter{chapter}{+1}

\title{Language and Automata, Assignment 1}
\author{Krzysztof Rudnicki\\ Student number: 307585}
\date{\today}


\begin{document}
\maketitle

\section{Regular expression}
We are given following regular expression:
\[ a^* + ba^*b + bba^*\]

\section{Examples of accepted strings}
\begin{enumerate}
\item $ \varepsilon $
\item a
\item bab
\item bba
\item bb
\end{enumerate}

\section{Building NFA using Thompson construction algorithm}
\begin{figure}
\centering
\begin{tikzpicture} [node distance = 2cm, on grid, auto]

\node (q0) [state, initial, initial text = {}] {$q_0$};
\node (q1) [state, accepting, right = of q0] {$q_1$};

\path [-stealth, thick]
    (q0) edge node {$\varepsilon$}   (q1);
\end{tikzpicture}
\caption{Operator 'a'} \label{fig:operatorA}
\end{figure}

\begin{figure}
\centering
\begin{tikzpicture} [node distance = 2cm, on grid, auto]

\node (q0) [state, initial, initial text = {}] {$q_2$};
\node (q1) [state, accepting, right = of q0] {$q_3$};

\path [-stealth, thick]
    (q0) edge node {$\varepsilon$}   (q1);
\end{tikzpicture}
\caption{Operator 'b'} \label{fig:operatorB}
\end{figure}

\begin{figure}
\centering
\begin{tikzpicture} [node distance = 2cm, on grid, auto]

\node (q0) [state, initial, initial text = {}] {$q_4$};
\node (q1) [state, right = of q0] {$q_0$};
\node (q2) [state, right = of q1] {$q_1$};
\node (q3) [state, accepting, right = of q2] {$q_5$};

\path [-stealth, thick]
    (q0) edge node {$\varepsilon$}   (q1);
\path [-stealth, thick]
    (q0) edge [bend right] node[below left] {$\varepsilon$}   (q3);
\path [-stealth, thick]
    (q1) edge node {a}   (q2);
\path [-stealth, thick]
    (q2) [bend left] edge node {$\varepsilon$}   (q1);
\path [-stealth, thick]
    (q2) edge node {$\varepsilon$}   (q3);
\end{tikzpicture}
\caption{Operator '$a^*$'} \label{fig:operatorAstar}
\end{figure}

\begin{figure}
\centering
\begin{tikzpicture} [node distance = 2cm, on grid, auto]

\node (q6) [state, initial, initial text = {}] {$q_6$};
\node (q0) [state, right = of q6] {$q_4$};
\node (q1) [state, right = of q0] {$q_0$};
\node (q2) [state, right = of q1] {$q_1$};
\node (q3) [state, accepting, right = of q2] {$q_5$};

\path [-stealth, thick]
        (q6) edge node {$b$}   (q0);
\path [-stealth, thick]
    (q0) edge node {$\varepsilon$}   (q1);
\path [-stealth, thick]
    (q0) edge [bend right] node[below left] {$\varepsilon$}   (q3);
\path [-stealth, thick]
    (q1) edge node {a}   (q2);
\path [-stealth, thick]
    (q2) [bend left] edge node {$\varepsilon$}   (q1);
\path [-stealth, thick]
    (q2) edge node {$\varepsilon$}   (q3);
\end{tikzpicture}
\caption{Operator '$ba^*$'} \label{fig:operatorbastar}
\end{figure}

\begin{figure}
\centering
\begin{tikzpicture} [node distance = 2cm, on grid, auto]

\node (q6) [state, initial, initial text = {}] {$q_6$};
\node (q0) [state, right = of q6] {$q_4$};
\node (q1) [state, right = of q0] {$q_0$};
\node (q2) [state, right = of q1] {$q_1$};
\node (q3) [state, right = of q2] {$q_5$};
\node (q7) [state, accepting, right = of q3] {$q_7$};

\path [-stealth, thick]
        (q6) edge node {$b$}   (q0);
\path [-stealth, thick]
    (q0) edge node {$\varepsilon$}   (q1);
\path [-stealth, thick]
    (q0) edge [bend right] node[below left] {$\varepsilon$}   (q3);
\path [-stealth, thick]
    (q1) edge node {a}   (q2);
\path [-stealth, thick]
    (q2) [bend left] edge node {$\varepsilon$}   (q1);
\path [-stealth, thick]
    (q2) edge node {$\varepsilon$}   (q3);
\path [-stealth, thick]
    (q3) edge node {$b$}   (q7);

\end{tikzpicture}
\caption{Operator '$ba^*b$'} \label{fig:operatorbastarb}
\end{figure}

\begin{figure}
\centering
\begin{tikzpicture} [node distance = 2cm, on grid, auto]

\node (q8) [state, initial, initial text = {}] {$q_8$};
\node (q9) [state, right = of q8] {$q_9$};
\node (q4) [state, right = of q9] {$q_{4}$};

\path [-stealth, thick]
    (q8) edge node {$b$}   (q9);
\path [-stealth, thick]
    (q9) edge node {$b$}   (q4);


\end{tikzpicture}
\caption{Operator '$bb$'} \label{fig:operatorbb}
\end{figure}

\begin{figure}
\centering
\begin{tikzpicture} [node distance = 2cm, on grid, auto]

\node (q8) [state, initial, initial text = {}] {$q_8$};
\node (q9) [state, right = of q8] {$q_9$};
\node (q0) [state, right = of q9] {$q_4$};
\node (q1) [state, right = of q0] {$q_0$};
\node (q2) [state, right = of q1] {$q_1$};
\node (q3) [state, accepting, right = of q2] {$q_5$};

\path [-stealth, thick]
    (q0) edge node {$\varepsilon$}   (q1);
\path [-stealth, thick]
    (q0) edge [bend right] node[below left] {$\varepsilon$}   (q3);
\path [-stealth, thick]
    (q1) edge node {a}   (q2);
\path [-stealth, thick]
    (q2) [bend left] edge node {$\varepsilon$}   (q1);
\path [-stealth, thick]
    (q2) edge node {$\varepsilon$}   (q3);

\path [-stealth, thick]
    (q8) edge node {$b$}   (q9);
\path [-stealth, thick]
    (q9) edge node {$b$}   (q4);
\end{tikzpicture}
\caption{Operator '$bba^*$'} \label{fig:operatorbbastar}
\end{figure}

\begin{figure}
\centering
\begin{tikzpicture} [node distance = 2cm, on grid, auto]

\node (q10) [state, initial, initial text = {}] {$q_{10}$};
% a*

\node (q0) [state, above right = of q10] {$q_4$};
\node (q1) [state, right = of q0] {$q_0$};
\node (q2) [state, right = of q1] {$q_1$};
\node (q3) [state, right = of q2] {$q_5$};
% ba*b
\node (q4) [state, below right = of q10] {$q_6$};
\node (q5) [state, right = of q4] {$q_4$};
\node (q6) [state, right = of q5] {$q_0$};
\node (q7) [state, right = of q6] {$q_1$};
\node (q8) [state, right = of q7] {$q_5$};
\node (q9) [state, right = of q8] {$q_7$};

\node (q11) [state, accepting, above right = of q9] {$q_{11}$};



\path [-stealth, thick]
  (q10) edge node {$\varepsilon$}   (q0);

\path [-stealth, thick]
  (q10) edge node {$\varepsilon$}   (q4);

% a*
\path [-stealth, thick]
    (q0) edge node {$\varepsilon$}   (q1);
\path [-stealth, thick]
    (q0) edge [bend right] node[below left] {$\varepsilon$}   (q3);
\path [-stealth, thick]
    (q1) edge node {a}   (q2);
\path [-stealth, thick]
    (q2) [bend left] edge node {$\varepsilon$}   (q1);
\path [-stealth, thick]
    (q2) edge node {$\varepsilon$}   (q3);
\path [-stealth, thick]
  (q3) edge node {$\varepsilon$}   (q11);

% ba*b
\path [-stealth, thick]
        (q4) edge node {$b$}   (q5);
\path [-stealth, thick]
    (q5) edge node {$\varepsilon$}   (q6);
\path [-stealth, thick]
    (q5) edge [bend right] node[below left] {$\varepsilon$}   (q8);
\path [-stealth, thick]
    (q6) edge node {a}   (q7);
\path [-stealth, thick]
    (q7) [bend left] edge node {$\varepsilon$}   (q6);
\path [-stealth, thick]
    (q7) edge node {$\varepsilon$}   (q8);
\path [-stealth, thick]
    (q8) edge node {$b$}   (q9);
\path [-stealth, thick]
  (q9) edge node {$\varepsilon$}   (q11);
\end{tikzpicture}
\caption{Operator '$a^*+ba^*b$'} \label{fig:operatorastarOrbastarb}
\end{figure}

\begin{figure}
\begin{tikzpicture} [node distance = 1.5cm, on grid, auto]

\node (q12) [state, initial, initial text = {}] {$q_{12}$};

\node (q10) [state, above right = of q12] {$q_{10}$};
% a*

\node (q0) [state, above right = of q10] {$q_4$};
\node (q1) [state, right = of q0] {$q_0$};
\node (q2) [state, right = of q1] {$q_1$};
\node (q3) [state, right = of q2] {$q_5$};
% ba*b
\node (q4) [state, below right = of q10] {$q_6$};
\node (q5) [state, right = of q4] {$q_4$};
\node (q6) [state, right = of q5] {$q_0$};
\node (q7) [state, right = of q6] {$q_1$};
\node (q8) [state, right = of q7] {$q_5$};
\node (q9) [state, right = of q8] {$q_7$};

\node (q11) [state, above right = of q9] {$q_{11}$};

\node (q13) [state, accepting, below right = of q11] {$q_{13}$};


\path [-stealth, thick]
  (q12) edge node {$\varepsilon$}   (q10);

\path [-stealth, thick]
  (q10) edge node {$\varepsilon$}   (q0);

\path [-stealth, thick]
  (q10) edge node {$\varepsilon$}   (q4);

% a*
\path [-stealth, thick]
    (q0) edge node {$\varepsilon$}   (q1);
\path [-stealth, thick]
    (q0) edge [bend right] node[below left] {$\varepsilon$}   (q3);
\path [-stealth, thick]
    (q1) edge node {a}   (q2);
\path [-stealth, thick]
    (q2) [bend left] edge node {$\varepsilon$}   (q1);
\path [-stealth, thick]
    (q2) edge node {$\varepsilon$}   (q3);
\path [-stealth, thick]
  (q3) edge node {$\varepsilon$}   (q11);

% ba*b
\path [-stealth, thick]
        (q4) edge node {$b$}   (q5);
\path [-stealth, thick]
    (q5) edge node {$\varepsilon$}   (q6);
\path [-stealth, thick]
    (q5) edge [bend right] node[below left] {$\varepsilon$}   (q8);
\path [-stealth, thick]
    (q6) edge node {a}   (q7);
\path [-stealth, thick]
    (q7) [bend left] edge node {$\varepsilon$}   (q6);
\path [-stealth, thick]
    (q7) edge node {$\varepsilon$}   (q8);
\path [-stealth, thick]
    (q8) edge node {$b$}   (q9);
\path [-stealth, thick]
  (q9) edge node {$\varepsilon$}   (q11);
\path [-stealth, thick]
  (q11) edge node {$\varepsilon$}   (q13);

% bba*

\end{tikzpicture}
\caption{Operator '$a^*+ba^*b + bba^*$'} \label{fig:final}
\end{figure}


\section{Transforming NFA into DFA using subset algorithm}
\section{Constructing minimal state DFA}



\end{document}
