% \section{Regular languages}

% \definition{}
% A language is called \textit{regular} if it is recognized by some $DFA$.
% \end{definition}

% \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{}
% \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{}
% \part{a} Check that the pumping lemma holds for the language recognized by the automaton C from Figure 3 and pumping length $p=2$.

% \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{}
% 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.

% \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}

% \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}

% \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.

% 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.

% \begin{figure}[h]
% \begin{center}
% \includegraphics[width = 0.5\linewidth]{Alphabet.png}
% \caption{Tiles forming a finite word}
% \end{center}
% \end{figure}

% 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)$.

% \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}


% \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}

% \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?
%

% \problem{} Same questions if the length of finite runs of $a$'s is asked to be odd.

% \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}~\\

% \includegraphics[width = 0.9\linewidth]{Patterns1.png}

% See the continuation at the next page

% \includegraphics[width = 0.9\linewidth]{Patterns2.png}
% \end{solution}

% % \section{DFAs from NFAs}

% % \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}

% % \section{Regular expressions}

% % \com{TD}{Prove that regular expressions give regular languages and vice versa}
