\documentclass[11pt]{amsart}

\usepackage{amsmath,amsthm,amssymb}
\usepackage{stmaryrd}

\usepackage{fancyhdr} % Allows customization of verbatim environments

\usepackage{xcolor}

%\usepackage[textheight=8.5in, margin=1.6in]{geometry}
\usepackage[
  hmarginratio={1:1},     % equal left and right margins
%  vmarginratio={1:1},     % equal top and bottom margins
  %textwidth=400pt,        % new text width
  heightrounded,          % always useful
  %bindingcorrection=5mm,  % binding correction
  total={6in,8in}
]{geometry}
\headheight=13pt
\footskip=13pt

\usepackage{needspace}  % <-- to prevent bad pagebreak over environment titles
% Use:  \Needspace{3\baselineskip} before opening an environment

\usepackage{graphicx}

% Tikz stuff.
\usepackage{tikz}
%\usepackage{tkz-graph}
\usepackage{pgfplots}
%\usepackage{tikz-3dplot}
\pgfplotsset{compat=newest}
%\usepgfplotslibrary{fillbetween}
%\usetikzlibrary{cd}
%\usetikzlibrary{positioning}
%\usetikzlibrary{decorations.pathmorphing}    
%\usetikzlibrary{decorations.pathreplacing}
%\usetikzlibrary{arrows.meta,calc}
%\usetikzlibrary{bending}
%\usetikzlibrary{decorations.markings,shapes.geometric}
%\tikzset{->-/.style={decoration={markings, mark=at position #1 with
%  {\arrow{>}}},postaction={decorate}}}
%\tikzset{-|-/.style={decoration={markings, mark=at position #1 with
%  {\arrow{stealth}}},postaction={decorate}}}
%\tikzset{movearrow/.style 2 args ={
%        decoration={markings,
%	  mark= at position {#1} with {\arrow{#2}} ,
%        },
%        postaction={decorate}
%    }
%}
%\tikzset{<--/.style={decoration={markings, mark=at position #1 with
%  {\arrow{<}}},postaction={decorate}}}
\tikzstyle{ball} = [circle,shading=ball, ball color=black,
    minimum size=1mm,inner sep=1.3pt]
%\tikzstyle{bball} = [circle,shading=ball, ball color=blue,
%    minimum size=1mm,inner sep=1.3pt]
%\tikzstyle{miniball} = [circle,shading=ball, ball color=black,
%    minimum size=1mm,inner sep=0.5pt]
%\tikzstyle{redminiball} = [circle,shading=ball, ball color=red,
%    minimum size=1mm,inner sep=0.5pt]
%\tikzstyle{mminiball} = [circle,shading=ball, ball color=black,
%    minimum size=0.6mm,inner sep=0.1pt]
%\tikzstyle{mycircle} = [draw,circle, minimum size=1mm,inner sep=1.3pt]
%\newcommand*{\DashedArrow}[1][]{\mathbin{\tikz [baseline=-0.25ex,-latex, dashed,#1] \draw [#1] (0pt,0.5ex) -- (1.3em,0.5ex);}}%

%%%% tikz style for finite automata
\usetikzlibrary{automata, positioning, arrows}
\tikzset{fa/.style={
    ->, % makes the edges directed
    >=stealth, % makes the arrow heads bold
    node distance=3cm, % specifies the minimum distance between two nodes. Change if necessary.
    every state/.style={thick, fill=gray!10}, % sets the properties for each ’state’ node
    initial text=$ $, % sets the text that appears on the start arrow
}}
%%%%

\usepackage{needspace}  % <-- to prevent bad pagebreak over environment titles
% Use:  \Needspace{3\baselineskip} before opening an environment

\usepackage[shortlabels]{enumitem}
\setlist[enumerate]{itemsep=4pt,leftmargin=*,label={(\alph*)}}
%\setlist[enumerate]{itemsep=2pt,label={\arabic*.}}

\usepackage[T1]{fontenc}
\renewcommand{\labelitemi}{\guillemotright}

\allowdisplaybreaks

\usepackage[colorlinks=true,citecolor=black,linkcolor=black,urlcolor=blue]{hyperref}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\W}{\mathbb{W}}
\newcommand{\KK}{\Bbbk}
\newcommand{\ve}{\varepsilon}
\newcommand{\scribe}{
  \begin{center}%
    Scribe~$=$ \rule{7cm}{0.15mm}%
  \end{center}%
  \medskip%
}
\DeclareMathOperator{\im}{\mathrm{im}}
\DeclareMathOperator{\id}{\mathrm{id}}
\DeclareMathOperator{\glb}{\mathrm{glb}}
\DeclareMathOperator{\lub}{\mathrm{lub}}

\newcounter{problem}
\renewcommand \thesection {\theproblem}
\newenvironment{prob}[1][]
{
\refstepcounter{problem}\par\medskip
\def\myArg{#1}
  \ifx\myArg\empty
    \noindent \textsc{Problem~\theproblem.} \rmfamily
  \else
    \noindent \textsc{Problem~\theproblem\ (\textnormal{#1}).} \rmfamily
  \fi
}
{
\medskip

}

\newenvironment{sol}
{\emph{Solution.}
}
{
  \medskip

}

\parskip = 0.05in
\parindent = 0.0in

%\pagestyle{empty}
%\pagenumbering{gobble}

\fancypagestyle{firststyle}
{
\fancyhead[L,LO]{
\textit{\small Math 387 Group problems, Monday Week 2}
}
\renewcommand{\headrulewidth}{0pt}
}

\begin{document}
\thispagestyle{firststyle}

\begin{prob}
  For each of the following, prove either that the language is regular or that
  it is not regular.  In all cases $\Sigma=\{0.1\}$.
  \begin{enumerate}[topsep=5pt]
    \item $L_{1}=\{w: w \text{ contains an equal number of $0$s and $1$s}\}$.
    \item $L_{2}=\{1^{k}w: w\in \Sigma^{*}, k\geq 1, \text{ the number of $1$s
      in $w$ is at least $k$}\}$.
    \item $L_{3}=\{1^{k}w: w\in \Sigma^{*}, k\geq 1, \text{ the number of $1$s
      in $w$ is at most $k$}\}$.  
  \end{enumerate}
\end{prob}

\begin{prob}
  Consider the context-free grammar $G$
  \begin{align*}
    S &\to RR\\
    R &\to 0R1\mid \varepsilon.
  \end{align*}
  \begin{enumerate}
    \item Which of the following are in $L(G)$?  For each that is, give a
      left-most derivation making one substitution at each step.
      \begin{enumerate}[label=(\roman*)]
	\item $001101$
        \item $000111$.
	\item $1010$.
	\item $\varepsilon$.
      \end{enumerate}
    \item Succinctly describe the language $L(G)$.  Explain your reasoning.
    \item Is $L(G)$ regular?  Provide a proof.
  \end{enumerate}
\end{prob}

\begin{sol}
  \begin{enumerate}
    \item
      \begin{enumerate}[label=(\roman*)]
	\item $001101\in L(G)$:
	  \[
	    S\to RR \to 0R1R \to 00R11R \to 0011R \to 00110R1 \to 001101.
	  \]
	\item $000111\in L(G)$:
	  \[
	    S \to R R\to R \to 0R1 \to 00R11 \to 000R111.
	  \]
	\item $1010\not\in L(G)$.
	\item $\varepsilon\in L(G)$:
	  \[
	    S \to RR \to R \to \varepsilon.
	  \]
      \end{enumerate}
    \item The language produced by the CFG
      \begin{align*}
	S &\to R\\
	R &\to 0R1 | \varepsilon
      \end{align*}
      is $A:=\{0^{k}1^{k}:k\geq 0\}$.  The production $S \to RR$ in~$G$ then
      says that~$L(G)= A^2=AA:=\{ww: w\in A\}$.
    \item The language $L(G)$ is not regular.  We prove this by contradiction.
      If it we regular, then take a pumping length~$p$ and consider the word
      $0^{p}1^{p}\in L(G)$.  By the pumping lemma $0^{p}1^{p}=xyz$ where
      $|xy|\leq p$, $|y|>0$, and $xy^{i}z\in L(G)$ for all $i\geq0$.  Then~$y$
      consists of all $0$s, and pumping it would produce words in $L(G)$ that
      have more $0$s than $1$s, which is not possible.
  \end{enumerate}
\end{sol}

\begin{prob}
  Let $A$ be the language of all words in $\Sigma=\{0,1\}$ that contain the same
  number of occurrences of $01$ as occurrences of $10$.  Is $A$ regular?
  Provide a proof.
\end{prob}

\begin{sol}
  The language $A$ is regular.  In fact, $A$ is given by the regular expression
  $(0^{+}1^{+}0^{+})^{*}\cup(1^{+}0^{+}1^{+})^{*}$.
\end{sol}

\begin{prob}
  Let $A$ be the NFA pictured below:
  \begin{center}
    \begin{tikzpicture}[fa,baseline={([yshift=-1em] current bounding box.north)}]
      \node[state, initial] (q1) {$q_1$};
      \node[state, right of=q1] (q2) {$q_{2}$};
      \node[state, right of=q2] (q3) {$q_3$};
      \node[state, accepting, right of=q3] (q4) {$q_4$};
      \draw (q1) edge[loop above] node{$a$} (q1);
      \draw (q1) edge[above, bend left] node{$a$} (q2);
      \draw (q2) edge[above, bend left] node{$b$} (q1);
      \draw (q2) edge[above] node{$b$} (q3);
      \draw (q3) edge[above] node{$a$,$\varepsilon$} (q4);
    \end{tikzpicture}
  \end{center}
  \begin{enumerate}
    \item Create a CFG $G$ such that~$L(A)=L(G)$.
    \item Give a derivation of the word $aabab$ making one substitution at each
      step.
  \end{enumerate}
\end{prob}

\begin{prob} 
   Let $P=\left\{0^{q}: q \text{ is a prime number}\right\}$.  Prove or disprove
   that $P$ is regular.
\end{prob}

\begin{prob} (Bonus)
Our goal in this problem is to show that the representation of objects can
affect whether or not a given set can be recognized by a machine. Consider a
set~$A$ of natural numbers. Let $B_k(A)$ be the set of strings that represent
numbers from~$A$ in base~$k$ (with no leading zeros). For example, if $A = \{3,
5\}$ then $B_2(A) = \{11, 101\}$ and $B_3(A) = \{10, 12\}$. We can think of
$B_k(A)$ as a language with a $k$-symbol alphabet. Give a set~$A$ for which
$B_2(A)$ is regular but $B_3(A)$ is not (and prove it).
\end{prob}
\end{document}
