\documentclass[12pt]{article}
\usepackage{ntnu}
\usepackage{ntnu-math}

\author{Øystein Tveit}
\title{MA0301 Exercise 12}

\usetikzlibrary{automata, positioning, arrows.meta}

\begin{document}
  \ntnuTitle{}
  \break{}

  \begin{excs}

  \exc{}

  \[ r = \{a,b\}^* a \{a,b\}^* a \{a,b\}^* a \{a,b\}^* \]

  \exc{}
  \begin{subexcs}
    \subexc{}
    \[ \{ab\} \{ab\}^* \]

    \subexc{}
    \[ a (a | \lambda) b (b | \lambda)\]

  \end{subexcs}

  \exc{}

  \[ M = (Q, \Sigma, \delta, s, F) \]

  \begin{align*}
    Q      &= \{ s_0, s_1, s_2 \} \\
    \Sigma &= \{a, b\} \\
    \delta &= \begin{Bmatrix} 
                 s_0 \xrightarrow{b} s_1, \\
                 s_0 \xrightarrow{a} s_2, \\
                 s_1 \xrightarrow{a,b} s_1, \\
                 s_2 \xrightarrow{a} s_1, \\
                 s_2 \xrightarrow{b} s_2
              \end{Bmatrix} \\
    s      &= s_0 \\
    F      &= \{ s_2 \}
  \end{align*}

  \includeDiagram[scale=1.6, width=10cm]{diagrams/ex3.tex}

  \exc{}

  The words $L$ can be described by the regular expression $r$ where

  \[ r = a^* b b^* a \{a,b\}^* \]

  \exc{}

  The words in $L$ can be described by the regular expression $r$ where

  \[ r = (a^* b)^3 \{ (a^* b)^4 \} \]

  \exc{}
  \begin{subexcs}
    \subexc{}
    \begin{align*}
      s_0 &\xrightarrow{a, 0} s_0 \\
      s_0 &\xrightarrow{a, 0} s_0 \\
      s_0 &\xrightarrow{b, 1} s_3 \\
      s_3 &\xrightarrow{b, 0} s_3 \\
      s_3 &\xrightarrow{c, 1} s_0 \\
      s_0 &\xrightarrow{c, 1} s_2
    \end{align*}

    The output would be $001011$

    \subexc{}
    \includeDiagram[scale=1.2, width=13cm]{diagrams/ex6_b.tex}

  \end{subexcs}

  \exc{}
  \begin{subexcs}
    \subexc{}
    Suppose we have $a \in A, b \in B$

    \begin{align*}
      AB^* &= \{a, ab, ab^2, ab^3, \ldots \} \\
           &= \{a\} \cup \{ab, ab^2, ab^3, \ldots \} \\
           &= A \cup \{ab, ab^2, ab^3, \ldots \} \\
           &\Rightarrow A \subseteq AB^*
    \end{align*}
    \qed

    \subexc{}
    Since $A \subseteq B$, we can rewrite $B$ as $A \cup \overline{A}$ where $\overline{A} = \{b \mid b \in B, b \notin A \}$

    \begin{align*}
      B^* &= (A \cup \overline{A})^* \\
          &= A^* \cap \overline{A}^* \cap B_1, \qquad B_1 = \{(B^*\ a\ B^*\ a_1\ B^*) \vee (B^*\ a_1\ B^*\ a\ B^*) \mid a \in A, a_1 \in \overline{A}\} \\
          &\Rightarrow A^* \subseteq B^*
    \end{align*}
    \qed
    

  \end{subexcs}



  \end{excs}
\end{document}