\documentclass{xlondon} %\usepackage{url} \usepackage{tikz} \newcommand{\MN}{{\rm MN}} \newcommand{\Z}{{\sf Z}} \newcommand{\N}{{\sf N}} \newcommand{\Q}{{\sf Q}} \newcommand{\R}{{\sf R}} \newcommand{\st}{\mathrel{:}} \newcommand{\es}{\emptyset} \newcommand{\ceil}[1]{\left\lceil {#1}\right\rceil} \newtheorem{theoremfoo}{Theorem}[section] %by chapter in report style \newenvironment{theorem}{\pagebreak[1]\begin{theoremfoo}}{\end{theoremfoo}} \newtheorem{nttn}[theoremfoo]{Notation} \newenvironment{notation}{\pagebreak[1]\begin{nttn}\rm}{\end{nttn}} \newtheorem{dfntn}[theoremfoo]{Def} \newenvironment{definition}{\pagebreak[1]\begin{dfntn}\rm}{\end{dfntn}} \newtheorem{lemmafoo}[theoremfoo]{Lemma} \newenvironment{lemma}{\pagebreak[1]\begin{lemmafoo}}{\end{lemmafoo}} \newtheorem{notefoo}[theoremfoo]{Note} \newenvironment{note}{\pagebreak[1]\begin{notefoo}\rm}{\end{notefoo}} \newtheorem{corollaryfoo}[theoremfoo]{Corollary} \newenvironment{corollary}{\pagebreak[1]\begin{corollaryfoo}}{\end{corollaryfoo}} \begin{document} \newcommand{\LOOP}{{\rm LOOP}} \title{Small NFA's for Cofinite Unary Languages} \addauthor{William Gasarch}{University of Maryland} \addauthor{Erik Metz}{University of Maryland} \addauthor{Zan Xu}{University of Maryland} \addauthor{Yuang Shen}{University of Maryland} \addauthor{Sam Zbarsky}{Princeton University} \jyear{2020} \authorrunning{Gasarch, Metz, Xu, Shen, \& Zbarsky} \titlerunning{Small NFA's for Cofinite Unary Languages} \maketitle \newcommand{\Ot}{\widetilde{O}} %\keywords{whatever} \begin{abstract} For all $n$ there is a DFA for $\{ a^i \st i\ne n\}$ of size $n+2$; however there is no smaller DFA. What about NFA's? We show that there is an NFA for $\{ a^i \st i\ne n\}$ of size $\sqrt{n} + \Ot(1)$. We also find small NFA's for many other cofinite unary sets. How small can we go? We show that any NFA for $\{ a^i \st i\ne n\}$ must have at least $\sqrt{n}$ states. \end{abstract} \section{Introduction} Consider the language $$\MN(n)=\{ a^i \st i\ne n \}.$$ ($\MN$ stands for {\it Missing Number}.) It is easy to show that (1) there is a DFA for $\MN(n)$ with $n+2$ states, and (2) any DFA for $\MN(n)$ has at least $n+2$ states. What about an NFA for $\MN(n)$? We show that there is an NFA for $\MN(n)$ that has substantially fewer than $n$ states. We also obtain small NFA's for many other cofinite unary languages. \begin{notation} $\N$ is $\{0,1,2,\ldots\}$ (that is, we include 0). \end{notation} \begin{definition} If $A\subseteq \N$ then $$\MN(A) = \{ a^i \st i \notin A\}.$$ We will only use this definition when $A$ is finite. We will write $\MN(a,b,c)$ instead of the formally correct $\MN(\{a,b,c\})$. \end{definition} \begin{notation} If $f$ and $g$ are functions then, informally, $f\le \Ot(g)$ means that $f$ is less than $g$ if we ignore polylog factors. Formally it means that $$(\exists n_0)(\exists c)(\forall n\ge n_0)[f(n) \le c(\log n)^c g(n)].$$ \end{notation} \begin{enumerate} \item In Section~\ref{se:n} we show that (1) there is an NFA for $\MN(100)$ on 29 states, and (2) for all $n$ there is an NFA for $\MN(n)$ with $\le n^{1/2} + \Ot(1)$ states. \item In Section~\ref{se:A} we show that (1) there is an NFA for $\MN(998,999,1000)$ on 104 states, (2) for any $A\subseteq \{998,999,1000\}$ there is an NFA for $\MN(A)$ on 104 states, (3) for all $n$, for all $0<\delta<1$ there is an NFA for $\MN(n-n^\delta,\ldots,n)$ on $5n^{\max\{1/2, \delta\}} + \Ot(1)$ states, and (4) for any $A\subseteq \{n-n^\delta,\ldots,n\}$ there is an NFA for $\MN(A)$ on $5n^{\max\{1/2, \delta\}} + \Ot(1)$ states. \item In Section~\ref{se:alphan} we show that, for all $n$, for all $0<\alpha<1$ such that $\alpha n\in\N$, there is an NFA for $\MN(\alpha n,n)$ on $2n^{1/2}\ln(n) + \Ot(1)$ states. \item In Section~\ref{se:gap} we prove a general theorem about unary sets with big gaps. We obtain the following corollary: for all $0<\delta<1$ there is an NFA for $\MN(n^\delta,n)$ on $n^{1/2} + n^\delta + \Ot(1)$ states. \item In Section~\ref{se:lower} we show that any NFA for $\MN(n)$ requires at least $n^{1/2}$ states. \item In Section~\ref{se:emp} we discuss our empirical results. \item In Section~\ref{se:open} we state open problems. \end{enumerate} \begin{definition} A set $X$ has a {\it small NFA} if there is an NFA that accepts it that is much smaller than any DFA for it. We do not define the term {\it much smaller} rigorously. However, all of our results are about small NFA's. \end{definition} All of our general results are asymptotic; however, we will present empirical evidence that indicates the results hold for small $n$ as well. \section{Needed Lemma} The following problem is attributed to Frobenius: \bigskip \noindent {\it Given a set of relatively prime positive integers $\{a_1,\ldots,a_m\}$ find the set \\$\{ \sum_{i=1}^n a_ix_i \st x_1,\ldots,x_m\in\N \}$.} \bigskip It is known that this set is always cofinite. The $m=2$ case was solved by James Joseph Sylvester in 1884: \begin{lemma}\label{le:syl} Let $c,d\in\N$ be relatively prime. \begin{enumerate} \item For all $i\ge cd-c-d+1$ there exists $x,y\in\N$ such that $i=cx+dy$. \item There is no $x,y\in\N$ such that $cd-c-d=cx+dy$. \item There is no $x,y,C,D\in\N$ such that $cd-c-d-Cc-Dd=cx+dy$. (If there was then $cd-c-d= (C+x)c + (D+y)d$.) We use this part in Section~\ref{se:A}. \end{enumerate} \end{lemma} \section{Small NFA's for \texorpdfstring{$\MN(100)$}{MN(100)} and \texorpdfstring{$\MN(n)$}{MN(n)}}\label{se:n} \subsection{Small NFA for \texorpdfstring{$\MN(100)$}{MN(100)}} \begin{theorem}\label{th:100}~ \begin{enumerate} \item For all $i\ge 96$ there exists $x,y\in \N$ such that $i=13x+9y$. \item There does not exist $x,y\in \N$ such that $95=13x+9y$. \item For all $i\ge 101$ there exists $x,y\in \N$ such that $i=13x+9y+5$. \item There does not exist $x,y\in \N$ such that $100=13x+9y+5$. \item There exists an NFA $M$ such that the following are true: \begin{enumerate} \item For all $i\ge 101$, $M$ accepts $a^i$. \item $M$ rejects $a^{100}$. \item We have no comment on the behavior of $M$ on other $a^i$. \item $M$ has 13 states. \end{enumerate} \item There exists an NFA on 29 states that accepts $\MN(100)$. \end{enumerate} \end{theorem} \begin{proof} \noindent 1,2) These follow from Lemma~\ref{le:syl}, though they can be proven directly by an easy induction. \noindent 3,4) These follow from Parts 1 and 2 \noindent 5) The NFA is constructed as follows: (also see Figure~\ref{nfa:good}, the caption will be explained later). \begin{itemize} \item $M$ has states $0,\ldots,12$, 0 is the start state, and 5 is the only final state. For $0\le j \le 12$, $\delta(j,a)=j+1 \pmod {13}$. ($\delta$ is not fully defined yet.) \item If we go no further then $M$ accepts $\{ a^{13x+5} \st x\in\N\}.$ \item We put in an $e$-transition from state 5 to state 9. Now $M$ accepts $$\{ a^{13x+9y+5} \st x,y\in\N\}.$$ (The $9y$ is not because the $e$-transition went to state 9. It is because the distance from state 9 back to state 5 is 9.) \end{itemize} \begin{figure}[htp] \centering \tikz{ \draw [->] (0.3, 0) -- (1.4366479857089982, 0); \draw (1.9366479857089984, -2.0270493529100753e-16) arc (0:360:0.2); \draw [->] (1.758082538723345, 0.26551458207263445) .. controls (1.7847454210056686,0.3961180176791278) .. (1.8218310541023663, 0.5241524759379792); \draw (2.1262424787833005, 0.769215096001155) arc (0:360:0.2); \draw [->] (2.068612611711708, 0.9943554491279956) .. controls (2.152915864364736,1.097608188926705) .. (2.245254141228331, 1.1937425184333006); \draw (2.651592144504216, 1.3622122835552706) arc (0:360:0.2); \draw [->] (2.6822825756388817, 1.4954014660703405) .. controls (2.8049133394441372,1.5476495517037883) .. (2.9313506736420476, 1.589860536112429); \draw (3.392345705604882, 1.6431430533845108) arc (0:360:0.2); \draw [->] (3.4585080372939285, 1.6538690286772584) .. controls (3.5913730821245378,1.6431430533845108) .. (3.7229442041270797, 1.6217606648646847); \draw (4.178805448285282, 1.5476495517037883) arc (0:360:0.2); \draw [->] (4.219465097942566, 1.4334551280966594) .. controls (4.332126643225204,1.3622122835552701) .. (4.438690194585503, 1.2821349696311535); \draw (4.830802923364684, 1.0976081889267055) arc (0:360:0.2);\draw (4.800802923364683, 1.0976081889267055) arc (0:360:0.17); \draw [->] (4.7908276655169, 0.8846539326761033) .. controls (4.8574763089461195,0.7692150960011549) .. (4.91461986427754, 0.6487876042565155); \draw (5.198973366723751, 0.3961180176791281) arc (0:360:0.2); \draw [->] (5.041703461451032, 0.13318918251506998) .. controls (5.047070802020421,-3.296516558006644e-16) .. (5.041703461451032, -0.1331891825150699); \draw (5.198973366723751, -0.39611801767912724) arc (0:360:0.2); \draw [->] (4.91461986427754, -0.6487876042565155) .. controls (4.8574763089461195,-0.7692150960011556) .. (4.7908276655169, -0.8846539326761031); \draw (4.830802923364683, -1.0976081889267053) arc (0:360:0.2); \draw [->] (4.438690194585502, -1.2821349696311535) .. controls (4.332126643225204,-1.3622122835552701) .. (4.219465097942566, -1.433455128096659); \draw (4.178805448285283, -1.5476495517037878) arc (0:360:0.2); \draw [->] (3.7229442041270797, -1.6217606648646847) .. controls (3.591373082124539,-1.6431430533845108) .. (3.4585080372939285, -1.6538690286772584); \draw (3.3923457056048814, -1.6431430533845108) arc (0:360:0.2); \draw [->] (2.931350673642047, -1.5898605361124285) .. controls (2.8049133394441372,-1.5476495517037883) .. (2.682282575638881, -1.4954014660703403); \draw (2.651592144504216, -1.3622122835552706) arc (0:360:0.2); \draw [->] (2.24525414122833, -1.1937425184333) .. controls (2.152915864364736,-1.0976081889267049) .. (2.0686126117117074, -0.9943554491279959); \draw (2.1262424787833005, -0.769215096001155) arc (0:360:0.2); \draw [->] (1.8218310541023663, -0.5241524759379792) .. controls (1.7847454210056686,-0.3961180176791283) .. (1.758082538723345, -0.26551458207263556); \draw [->] (4.443675236321908, 0.9318275243665066) .. controls (4,0) .. (3.8759700310429475, -1.2764948413250177); \draw (4, 0) node[anchor=east] {$\varepsilon$}; }\\ \caption{LOOP(9,13,5) Case 1} \label{nfa:good} \end{figure} By Parts 3,4 $M$ satisfies 5a and 5b. $M$ clearly has 13 states, so it satisfies 5d. \bigskip \noindent 6) Let $Q=\{3,5,7\}$. Note that $3\times 5\times 7 = 105>100$. For each $p\in Q$ let $M_p$ be the DFA that accepts $\{ a^i \st i\not\equiv 100 \pmod p\}$. The NFA is constructed as follows: (see also Figure~\ref{nfa:100}) \begin{enumerate} \item The NFA $M$ is part of our new NFA. We create a new start state, and then put an e-transition from this new state to $M$'s original start state. Note that $M$ (a) accepts all $a^i$ with $i\ge 101$ (it also accepts other strings), (b) rejects $a^{100}$, and (c) has 13 states. \item For each $p\in Q$ put an $e$-transition from our new start state to the start state of $M_p$. Note that $M_p$ (a) accepts all $a^i$ with $i\not\equiv 100 \pmod p$, (b) rejects $a^{100}$, and (c) has $p$ states. \end{enumerate} Clearly the NFA has $13+3+5+7+1=29$ states and rejects $a^{100}$. We show that it accepts everything else. Let $a^i$ be rejected by this NFA. \begin{itemize} \item Since the $M$ part rejects $a^i$, $i\le 100$ (note, hence $i\le 3\times 5\times 7=105$). \item Since the $M_3$ part rejects $a^i$, $i\equiv 100\pmod 3$ \item Since the $M_5$ part rejects $a^i$, $i\equiv 100\pmod 5$ \item Since the $M_7$ part rejects $a^i$, $i\equiv 100\pmod 7$ \end{itemize} By the Chinese Remainder Theorem there is a unique number $0\le z\le 3\times 5\times 7=105$ such that, for every $p\in \{3,5,7\}$, $z\equiv 100 \pmod p$. Since both $i$ and $100$ satisfies these criteria, $i=n$. \end{proof} \begin{figure}[htp] \centering \tikz{ \draw (0.2, 0) arc (0:360:0.2); \draw [->] (0.3, 0) .. controls (1.4366479857089982,0) .. (1.4366479857089982, 0); \draw (0.7183239928544991, 0) node[anchor=south] {$\varepsilon$}; \draw [->] (1.83697019872103e-17, -0.3) .. controls (3.3394912204729587e-17,-0.5453803043943841) .. (3.3394912204729587e-17, -0.5453803043943841); \draw (0, 0.5) node[anchor=west] {$\varepsilon$}; \draw [->] (-0.3, -3.67394039744206e-17) .. controls (-0.7236338406573068,-8.861958667156766e-17) .. (-0.7236338406573068, -8.861958667156766e-17); \draw (-0.3618169203286534, 4.430979333578383e-17) node[anchor=south] {$\varepsilon$}; \draw [->] (-5.510910596163089e-17, 0.3) .. controls (-1.6567402340051424e-16,0.9018873769202297) .. (-1.6567402340051424e-16, 0.9018873769202297); \draw (0, -0.4355781548856767) node[anchor=west] {$\varepsilon$}; \draw (1.9366479857089984, -2.0270493529100753e-16) arc (0:360:0.2); \draw [->] (1.758082538723345, 0.26551458207263445) .. controls (1.7847454210056686,0.3961180176791278) .. (1.8218310541023663, 0.5241524759379792); \draw (2.1262424787833005, 0.769215096001155) arc (0:360:0.2); \draw [->] (2.068612611711708, 0.9943554491279956) .. controls (2.152915864364736,1.097608188926705) .. (2.245254141228331, 1.1937425184333006); \draw (2.651592144504216, 1.3622122835552706) arc (0:360:0.2); \draw [->] (2.6822825756388817, 1.4954014660703405) .. controls (2.8049133394441372,1.5476495517037883) .. (2.9313506736420476, 1.589860536112429); \draw (3.392345705604882, 1.6431430533845108) arc (0:360:0.2); \draw [->] (3.4585080372939285, 1.6538690286772584) .. controls (3.5913730821245378,1.6431430533845108) .. (3.7229442041270797, 1.6217606648646847); \draw (4.178805448285282, 1.5476495517037883) arc (0:360:0.2); \draw [->] (4.219465097942566, 1.4334551280966594) .. controls (4.332126643225204,1.3622122835552701) .. (4.438690194585503, 1.2821349696311535); \draw (4.830802923364684, 1.0976081889267055) arc (0:360:0.2);\draw (4.800802923364683, 1.0976081889267055) arc (0:360:0.17); \draw [->] (4.7908276655169, 0.8846539326761033) .. controls (4.8574763089461195,0.7692150960011549) .. (4.91461986427754, 0.6487876042565155); \draw (5.198973366723751, 0.3961180176791281) arc (0:360:0.2); \draw [->] (5.041703461451032, 0.13318918251506998) .. controls (5.047070802020421,-3.296516558006644e-16) .. (5.041703461451032, -0.1331891825150699); \draw (5.198973366723751, -0.39611801767912724) arc (0:360:0.2); \draw [->] (4.91461986427754, -0.6487876042565155) .. controls (4.8574763089461195,-0.7692150960011556) .. (4.7908276655169, -0.8846539326761031); \draw (4.830802923364683, -1.0976081889267053) arc (0:360:0.2); \draw [->] (4.438690194585502, -1.2821349696311535) .. controls (4.332126643225204,-1.3622122835552701) .. (4.219465097942566, -1.433455128096659); \draw (4.178805448285283, -1.5476495517037878) arc (0:360:0.2); \draw [->] (3.7229442041270797, -1.6217606648646847) .. controls (3.591373082124539,-1.6431430533845108) .. (3.4585080372939285, -1.6538690286772584); \draw (3.3923457056048814, -1.6431430533845108) arc (0:360:0.2); \draw [->] (2.931350673642047, -1.5898605361124285) .. controls (2.8049133394441372,-1.5476495517037883) .. (2.682282575638881, -1.4954014660703403); \draw (2.651592144504216, -1.3622122835552706) arc (0:360:0.2); \draw [->] (2.24525414122833, -1.1937425184333) .. controls (2.152915864364736,-1.0976081889267049) .. (2.0686126117117074, -0.9943554491279959); \draw (2.1262424787833005, -0.769215096001155) arc (0:360:0.2); \draw [->] (1.8218310541023663, -0.5241524759379792) .. controls (1.7847454210056686,-0.3961180176791283) .. (1.758082538723345, -0.26551458207263556); \draw [->] (4.443675236321908, 0.9318275243665066) .. controls (4,0) .. (3.8759700310429475, -1.2764948413250177); \draw (4, 0) node[anchor=east] {$\varepsilon$}; \draw (0.2, -0.8453803043943842) arc (0:360:0.2);\draw (0.17, -0.8453803043943842) arc (0:360:0.17); \draw [->] (0.24552678105560788, -0.9347447444138203) .. controls (0.3307973372530754,-1.0363662361046584) .. (0.3761688525290769, -1.161023449811913); \draw (0.5307973372530754, -1.4183380995252075) arc (0:360:0.2); \draw [->] (0.13064207147346907, -1.5862883092190658) .. controls (1.453207381724049e-16,-1.609324031235482) .. (-0.13064207147346862, -1.5862883092190658); \draw (-0.130797337253075, -1.4183380995252077) arc (0:360:0.2);\draw (-0.160797337253075, -1.4183380995252077) arc (0:360:0.17); \draw [->] (-0.3761688525290767, -1.1610234498119134) .. controls (-0.33079733725307525,-1.036366236104659) .. (-0.24552678105560802, -0.9347447444138206); \draw (-0.8236338406573068, -4.739555399560076e-17) arc (0:360:0.2); \draw [->] (-1.0786725117330176, -0.2589365891284701) .. controls (-1.1452173982244043,-0.3741957135154557) .. (-1.23427183872053, -0.4731006896315648); \draw (-1.2635272844081948, -0.6054613829125257) arc (0:360:0.2);\draw (-1.2935272844081949, -0.6054613829125257) arc (0:360:0.17); \draw [->] (-1.7267984995162744, -0.633132302643926) .. controls (-1.856979941641581,-0.6054613829125259) .. (-1.9785634992086785, -0.5513288954217924); \draw (-1.9752898278253719, -0.37419571351545605) arc (0:360:0.2);\draw (-2.0052898278253717, -0.37419571351545605) arc (0:360:0.17); \draw [->] (-2.2829617159459397, -0.13236069328096123) .. controls (-2.2968733853924697,-4.372127372475383e-16) .. (-2.2829617159459397, 0.13236069328096037); \draw (-1.975289827825372, 0.3741957135154552) arc (0:360:0.2);\draw (-2.005289827825372, 0.3741957135154552) arc (0:360:0.17); \draw [->] (-1.9785634992086791, 0.5513288954217916) .. controls (-1.8569799416415815,0.6054613829125253) .. (-1.7267984995162753, 0.6331323026439255); \draw (-1.2635272844081953, 0.6054613829125255) arc (0:360:0.2);\draw (-1.2935272844081953, 0.6054613829125255) arc (0:360:0.17); \draw [->] (-1.2342718387205307, 0.47310068963156476) .. controls (-1.1452173982244045,0.3741957135154557) .. (-1.0786725117330176, 0.25893658912847); \draw (0.1999999999999999, 1.2018873769202296) arc (0:360:0.2);\draw (0.1699999999999999, 1.2018873769202296) arc (0:360:0.17); \draw [->] (-0.26270576085269126, 1.24148389929453) .. controls (-0.38670655412342103,1.2901506244028016) .. (-0.5020689619883784, 1.356755141637998); \draw (-0.4968211325580484, 1.537458748208902) arc (0:360:0.2);\draw (-0.5268211325580484, 1.537458748208902) arc (0:360:0.17); \draw [->] (-0.8296576875507629, 1.7675384105587006) .. controls (-0.8689217397391918,1.8948293413836366) .. (-0.8887755161117993, 2.0265505409996467); \draw (-0.6689217397391919, 2.29148077508605) arc (0:360:0.2); \draw [->] (-0.7718604535905095, 2.53878889889215) .. controls (-0.6968211325580487,2.6488513682607846) .. (-0.6062159788865009, 2.7465005003239504); \draw (-0.18670655412342144, 2.8961594920668854) arc (0:360:0.2);\draw (-0.21670655412342144, 2.8961594920668854) arc (0:360:0.17); \draw [->] (-0.1328365549927154, 2.9744680159369277) .. controls (-6.573783746043151e-16,2.9844227395494576) .. (0.13283655499271382, 2.9744680159369277); \draw (0.5867065541234203, 2.896159492066886) arc (0:360:0.2);\draw (0.5567065541234203, 2.896159492066886) arc (0:360:0.17); \draw [->] (0.6062159788864995, 2.746500500323951) .. controls (0.6968211325580476,2.6488513682607855) .. (0.7718604535905084, 2.538788898892151); \draw (1.068921739739191, 2.291480775086051) arc (0:360:0.2);\draw (1.038921739739191, 2.291480775086051) arc (0:360:0.17); \draw [->] (0.8887755161117985, 2.026550540999647) .. controls (0.8689217397391911,1.8948293413836375) .. (0.8296576875507625, 1.7675384105587018); \draw (0.8968211325580479, 1.5374587482089024) arc (0:360:0.2);\draw (0.8668211325580478, 1.5374587482089024) arc (0:360:0.17); \draw [->] (0.5020689619883778, 1.3567551416379986) .. controls (0.38670655412342103,1.2901506244028018) .. (0.26270576085269154, 1.2414838992945303); } \caption{NFA for $\MN(100)$} \label{nfa:100} \end{figure} \subsection{Small NFA for \texorpdfstring{$\MN(n)$}{MN(n)}} We generalize the construction of a small NFA for $\MN(100)$ to get a small NFA for $\MN(n)$. \begin{definition}\label{de:loop} Let $c,d,e\in\N$ be such that $c] (-3.7, 0) -- (-3.4, 0); \draw (-2.9, 0) arc (0:360:0.2); \draw [->] (-2.8, 0) -- (-2.5, 0); \draw (-2, 0) arc (0:360:0.2); \draw [->] (-1.9, 0) -- (-1.6, 0); \draw (-1.1, 0) arc (0:360:0.2); \draw [->] (-1, 0) -- (-0.7, 0); \draw (-0.2, 0) arc (0:360:0.2); \draw [->] (-0.1, 0) -- (0.2, 0); \draw (0.7, 0) arc (0:360:0.2); \draw [->] (0.8, 0) -- (1.45, 0); \draw (1.9366479857089984, -2.0270493529100753e-16) arc (0:360:0.2); \draw [->] (1.758082538723345, 0.26551458207263445) .. controls (1.7847454210056686,0.3961180176791278) .. (1.8218310541023663, 0.5241524759379792); \draw (2.1262424787833005, 0.769215096001155) arc (0:360:0.2); \draw [->] (2.068612611711708, 0.9943554491279956) .. controls (2.152915864364736,1.097608188926705) .. (2.245254141228331, 1.1937425184333006); \draw (2.651592144504216, 1.3622122835552706) arc (0:360:0.2); \draw [->] (2.6822825756388817, 1.4954014660703405) .. controls (2.8049133394441372,1.5476495517037883) .. (2.9313506736420476, 1.589860536112429); \draw (3.392345705604882, 1.6431430533845108) arc (0:360:0.2); \draw [->] (3.4585080372939285, 1.6538690286772584) .. controls (3.5913730821245378,1.6431430533845108) .. (3.7229442041270797, 1.6217606648646847); \draw (4.178805448285282, 1.5476495517037883) arc (0:360:0.2); \draw [->] (4.219465097942566, 1.4334551280966594) .. controls (4.332126643225204,1.3622122835552701) .. (4.438690194585503, 1.2821349696311535); \draw (4.830802923364684, 1.0976081889267055) arc (0:360:0.2);\draw (4.800802923364683, 1.0976081889267055) arc (0:360:0.17); \draw [->] (4.7908276655169, 0.8846539326761033) .. controls (4.8574763089461195,0.7692150960011549) .. (4.91461986427754, 0.6487876042565155); \draw (5.198973366723751, 0.3961180176791281) arc (0:360:0.2); \draw [->] (5.041703461451032, 0.13318918251506998) .. controls (5.047070802020421,-3.296516558006644e-16) .. (5.041703461451032, -0.1331891825150699); \draw (5.198973366723751, -0.39611801767912724) arc (0:360:0.2); \draw [->] (4.91461986427754, -0.6487876042565155) .. controls (4.8574763089461195,-0.7692150960011556) .. (4.7908276655169, -0.8846539326761031); \draw (4.830802923364683, -1.0976081889267053) arc (0:360:0.2); \draw [->] (4.438690194585502, -1.2821349696311535) .. controls (4.332126643225204,-1.3622122835552701) .. (4.219465097942566, -1.433455128096659); \draw (4.178805448285283, -1.5476495517037878) arc (0:360:0.2); \draw [->] (3.7229442041270797, -1.6217606648646847) .. controls (3.591373082124539,-1.6431430533845108) .. (3.4585080372939285, -1.6538690286772584); \draw (3.3923457056048814, -1.6431430533845108) arc (0:360:0.2); \draw [->] (2.931350673642047, -1.5898605361124285) .. controls (2.8049133394441372,-1.5476495517037883) .. (2.682282575638881, -1.4954014660703403); \draw (2.651592144504216, -1.3622122835552706) arc (0:360:0.2); \draw [->] (2.24525414122833, -1.1937425184333) .. controls (2.152915864364736,-1.0976081889267049) .. (2.0686126117117074, -0.9943554491279959); \draw (2.1262424787833005, -0.769215096001155) arc (0:360:0.2); \draw [->] (1.8218310541023663, -0.5241524759379792) .. controls (1.7847454210056686,-0.3961180176791283) .. (1.758082538723345, -0.26551458207263556); \draw [->] (4.443675236321908, 0.9318275243665066) .. controls (4,0) .. (3.8759700310429475, -1.2764948413250177); \draw (4, 0) node[anchor=east] {$\varepsilon$}; } \caption{NFA LOOP(9,13,17) Case 2} \label{nfa:bad} \end{figure} The following is clear: \begin{lemma}\label{le:loop} Let $c,d,e\in\N$ be such that $e,c1066$ (That is not a typo. We really do mean to multiply by 3. We chose 3 because $|\{998,999,1000\}|=3$. We chose $\{5,7,11\}$ since none of them divide 3 and the product $3\times 5\times 7\times 11>1066$. The fact that 3 is a prime is not important.) For each $p \in Q$ let $M_{3p}$ be the DFA that accepts $$\{ a^i \st i\not\equiv 998,999,1000 \pmod {3p} \} $$ Note that $\mathrm{LCM}(3\times 5, 3\times 7,3\times 11)=3\times 5\times 7\times 11=105>100$. The NFA is constructed as follows: \begin{enumerate} \item The NFA $M$ is part of our new NFA. We create a new start state, and then put an e-transition from this new state to $M$'s original start state. Note that $M$ (1) accepts all $a^i$ with $i\ge 1067$ (it also accepts other strings), (2) rejects any of $a^i$ with $i\in \{998,999,1000\}$, and (3) has 34 states. \item For each $p\in Q$, there is an $e$-transition from our new start state to the start state of $M_{3p}$. Note that $M_{3p}$ (1) accepts $a^i$ when $i\not\equiv 998,999,1000 \pmod {3p}$, (2) rejects any $a^i$ with $i\in \{998,999,1000\}$, and (3) has $3p$ states. \end{enumerate} This NFA has $34+3(5+7+11) + 1= 104$ states and rejects any $a^i$ with $i\notin \{998,999,1000\}$. We show that it accepts everything else. Let $a^i$ be rejected by this NFA. \begin{itemize} \item Since the $M$ part rejects $a^i$, $i\le 1066$ (note, hence $i\le 3\times 5\times 7\times 11=1155$). \item For all $p\in Q$, since the $M_{3p}$ part rejects $a^i$, there exists $x\in\{998,999,1000\}$ such that $i\equiv x\pmod {3p}$. \end{itemize} We cannot use the Chinese Remainder Theorem (yet) since it is possible that, say $i\equiv 998 \pmod {3\times 7}$ but $i\equiv 1000 \pmod {3\times 11}$. We need that $i$ is equivalent to the same $x$ with all of those mods. Let $i\equiv x \pmod 3$ where $x\in \{998,999,1000\}$. Note that $x$ is unique. Let $p\in Q$. Let $y\in \{998,999,1000\}$ be such that $i\equiv y\pmod {3p}$. Note that $y$ is unique since $3<3p$. We show that $x=y$. Since $i\equiv x \pmod 3$ there exists $a\in \Z$ such that $$\hbox{Eq 1 } i=x+3a.$$ Since $i\equiv y \pmod {3p}$ there a $b\in \Z$ such that $$\hbox{Eq 2 } i=y+3pb.$$ By subtracting Eq 2 from Eq 1 we get $$x-y=3pb-3a\equiv 0 \pmod 3$$ Since $x,y\in \{998,999,1000\}$ and $x\equiv y \pmod 3$, $x=y$. To recap we now have that there exists $x\in \{998,999,1000\}$ such that, for all $p\in Q$, $i\equiv x \pmod {3p}$. By the Chinese Remainder Theorem there is a unique number $0\le z\le \mathrm{LCM}(3\times 5,3\times 7,3\times 11)=1155$ such that, for all $p\in Q$, $z\equiv x \pmod {3p}$. Since both $i$ and $x$ satisfy those criteria, $i=x$. \bigskip \noindent 3) We look at $\MN(998,1000)$ as an example. The construction is similar to the one for $\MN(998,1000)$ except that, at the end, use the DFA for $\{a^i \st i\not\equiv 998,1000\pmod {3p}\}$ instead of $\{a^i \st i\not\equiv 998,999,1000\pmod {3p}\}$. The other cases are similar. \end{proof} \begin{theorem}\label{th:A} Let $0 < \delta <1$. Let $n\in\N$. (We will assume $n^\delta\in\N$ and leave it to the reader to adjust the statement and the proof for when $n^\delta\notin\N$.) Assume $n=c^2+f$ where $0\le f\le 2c$. \begin{enumerate} \item There exists an NFA $M$ such that the following are true: \begin{enumerate} \item For all $i\ge n+ n^{1/2+\delta} + n^{2\delta} +1$, $M$ accepts $a^i$. \item For all $i\in \{ n-n^\delta, n-n^\delta+1,\ldots,n\}$, $M$ rejects $a^i$. \item We have no comment on the behavior of $M$ for other $a^i$'s. \item $M$ has $\le 5n^{\max\{1/2,\delta\}}+O(1)$ states. \end{enumerate} \item There exists an NFA on $$\le 5n^{\max\{1/2,\delta\}} + \Ot(1)\hbox{ states }$$ that accepts $\MN(n-n^\delta,n-\delta+1,\ldots,n)$. \item Let $A\subseteq \{ n-n^\delta,\ldots,n\}$. There exists an NFA on $$5n^{\max\{1/2,\delta\}} + \Ot(1)\hbox{ states }$$ that accepts $\MN(A)$. (For $A=\es$ this is trivial.) \end{enumerate} \end{theorem} \begin{proof} 1) Let $M$ be the NFA $\LOOP(c+k,c+k+1,f+1+x(k))$ where we determine $k$ and $x(k)$ later. \noindent {\bf Claim:} \begin{enumerate} \item If $M$ rejects $a^{n + n^\delta(c+k)}$ then, for $i=n-n^\delta,\ldots,n$, $M$ rejects $a^i$. \item If $x(k) = n^\delta(c+k) - k^2 - 2c k + c + k$ then $M$ rejects $a^{n + n^\delta(c+k)}$. \item If $x(k) = n^\delta(c+k) - k^2 - 2c k + c + k$ then, for $i=n-n^\delta,\ldots,n$, $M$ rejects $a^i$ (this follows from parts 1 and 2). \end{enumerate} \noindent {\bf Proof of Claim:} \noindent 1) Assume $M$ rejects $n + n^\delta(c+k)$. Then it also rejects everything of the form $$n + n^\delta(c+k) - (c+k)C - (c+k+1)D = n + n^\delta(c+k) -(C+D)(c+k) - D$$ (since otherwise $M$ would accept $n+n^\delta(c+k) - (c+k)C - (c+k+1)D + (c+k)C + (c+k+1)D= n+n^\delta(c+k)$). We set $(C,D)$ as follows: \begin{itemize} \item If $(C,D)=(n^\delta,0)$ then we get $n+n^\delta (c+k) - n^\delta (c+k) -0 = n$. \item If $(C,D)=(n^\delta-1,1)$ then we get $n+n^\delta (c+k) - n^\delta (c+k) -1 = n-1$. \item $\qquad \vdots$ \item If $(C,D)=(0,n^\delta)$ then we get $n+n^\delta (c+k) - n^\delta (c+k) -n^\delta = n-n^\delta$. \end{itemize} \noindent 2) For $k\in\N$ we need $x(k)\in\N$ such that $\LOOP(c+k,c+k+1,f+1+x(k))$ rejects $n + n^\delta(c+k)$. Note that this NFA rejects \[(c+k)(c+k+1) - (c+k) - (c+k+1) + f + 1 + x(k)\] \[= c^2 + k^2 + 2ck + c + k - 2c - 2k - 1 + f + 1 + x(k) \] \[= n + k^2 + 2ck - c - k + x(k)\] Hence we find $x(k)$ via: \[n + k^2 + 2ck - c - k + x(k) = n + n^\delta(c+k)\] or equivalently \[x(k) = n^\delta(c+k) - k^2 - 2c k + c + k\] \noindent {\bf End of Proof of Claim} We choose $k$ such that the max of $\{c+k+1,f+1+x(k)\}$ is small. We look at what happens to $x(k)$ for $k\in \{0,\ldots,n^\delta\}$. We consider only when $n \ge 9$, with smaller $n$ being expressed within the $O(1)$ term. Note that \begin{itemize} \item $x(0)=n^\delta c + c > 0$. \item $x(n^\delta)=n^{2\delta }+ n^\delta c -n^{2\delta} - 2c n^\delta + c + n^\delta =c+n^\delta - cn^\delta<0$ (since $n\ge 9$). \item there exists $k_o$ such that $x(k_o)\ge 0$ and $x(k_o+1)\le 0$ (this follows from the first two points). \end{itemize} Note that $$x(k_o) \le x(k_o) - x(k_o+1) \le |-2c +n^\delta - 2k_o| \le 2c+n^\delta.$$ Let $M=\LOOP(c+k_o,c+k_o,f+1+x(k_o))$. Since $c\le n^{1/2}$, $f\le 2n^{1/2}$, $k_o \le n^\delta$, and $x(k_o)\le 2c + n^\delta \le 3n^{\max\{1/2,\delta\}}$. $e = x(k_o) + f + 1$ has $\le 5n^{\max\{1/2,\delta\}} + O(1)$ states, while $c+k_o+1$ has $\le 3n^{\max\{1/2,\delta\}} + O(1)$ states, so $M$ must have $\le 5n^{\max\{1/2,\delta\}} + O(1)$ states overall. $M$ satisfies conditions of what to reject and how many states it has. We now consider what it accepts. Note that $x(k)$ was chosen so that the largest number $M$ (with $k=k_o$) rejects is $a^{n+n^\delta(c+k_o)}$. We need to estimate this. $$n+n^\delta(c+k_o)\le n+n^\delta(n^{1/2}+n^\delta) \le n+ n^{1/2+\delta} + n^{2\delta}.$$ By Lemma~\ref{le:loop} $M$ accepts what it should. \noindent 2) To simplify the algebra we just use that the NFA in Part 1 accepts $\{ a^i \st i\ge n^2\}$. By Lemma~\ref{le:primes} there is a set of primes $Q'$ such that (1) $\prod_{p\in Q'} p \ge n^2$, (2) $\sum_{p\in Q'} p \le \Ot(1)$. We form $Q$ as follows: (1) remove from $Q'$ all of the primes that divide $n^\delta$, (2) add in the smallest primes possible that do not divide $n^\delta$ so that $n^\delta\prod_{p\in Q}p\ge n^2$. One can show that $\sum_{p\in Q} p\le O(\sum_{p\in Q'} p) \le \Ot(1)$. Hence we have a set $Q$ such that (1) $n^\delta \prod_{p\in Q} p \ge n^2$ (2) $\sum_{p\in Q} p \le \Ot(1)$, and (3) for all $p\in Q$, $p$ does not divide $n^\delta$. For each $p\in Q$ let $M_{n^\delta p}$ be the DFA that accepts $\{a^i \st i\not\equiv n\pmod {n^\delta p}\}$. Note that the $\mathrm{LCM}\{ n^\delta p \st p\in Q\} = n^\delta\prod_{p\in Q} p \ge n$. The NFA is constructed as follows: \begin{enumerate} \item The NFA $M$ is part of our new NFA . We create a new start state, and then put an e-transition from this new state to $M$'s original start state. Note that $M$ (1) accepts all $a^i$ with $i\ge n^2$ (it also accepts other strings), (2) rejects any of $a^i$ with $i\in \{n-n^\delta,\ldots,n\}$, and (3) has $\le 5n^{\max\{1/2,\delta\}}+O(1)$ states. \item For each $p\in Q$ put an $e$-transition from our new start state to the start state of $M_{n^\delta p}$. Note that $M_{n^\delta p}$ (1) accepts $a^i$ with $i\not\equiv n-n^\delta,\ldots,n \pmod {n^\delta p}$, (2) rejects any of $a^i$ with $i\in \{n-n^\delta,\ldots,n\}$, and (3) has $n^\delta p$ states. \end{enumerate} This NFA has $5n^{\max\{1/2,\delta\}} + \Ot(1)$ states and rejects any $a^i$ with $i\in \{n-n^\delta,\ldots,n\}$. We show that it accepts everything else. Let $a^i$ be rejected by this NFA. \begin{itemize} \item Since the $M$ part rejects $a^i$, $i\le n^2$ (note, hence $i\le n^\delta\prod_{p\in Q} p$). \item For each $p\in Q$, since the $M_{n^\delta p}$ part rejects $a^i$, there exists $x\in \{n-n^\delta,\ldots,n\}$ such that $i\equiv x\pmod {n^\delta p}$. \end{itemize} We cannot use the Chinese Remainder Theorem (yet) since it is possible that, say $i\equiv 95 \pmod {n^\delta\times 7}$ but $i\equiv 92 \pmod {n^\delta\times 11}$. We need that $a^i$ is equivalent to the same $n^\delta p$ with all those mods. Let $i\equiv x \pmod {n^\delta}$ where $x\in \{n-n^\delta,\ldots,n\}$. Note that $x$ is unique. Let $n^\delta p\in n^\delta Q$. Let $y\in \{n-n^\delta,\ldots,n\}$ be such that $i\equiv y \pmod n^\delta p$. Note that $y$ is unique since $n^\delta < n^\delta p$. We show that $x=y$. Since $i\equiv x \pmod {n^\delta}$ there exists $a\in\Z$ such that: $$\hbox{Eq 1 } i=x+n^\delta a.$$ Since $i\equiv y\pmod {n^\delta}$ there exists a $b\in \Z$ such that $$\hbox{Eq 2 } i=y+n^\delta p b.$$ By subtracting Eq 2 from Eq 1 we get $$x-y=n^\delta pb-n^\delta a\equiv 0 \pmod {n^\delta}$$ Since $x,y\in \{n-\delta,\ldots,n\}$ and $x\equiv y \pmod {n^\delta}$, $x=y$. To recap we now have that there exists $x\in \{n-\delta,\ldots,n\}$ such that, for all $n^\delta p\in Q$, $i\equiv x \pmod {n^\delta p}$. By the Chinese Remainder Theorem there is a unique number $0\le z\le \mathrm{LCM}\{ n^\delta p \st p\in Q\}\ge n$ such that, for all $p\in Q$, $z\equiv x \pmod {n^\delta p}$. Since both $i$ and $x$ satisfy those criteria, $i=x$. \bigskip \noindent 3) This is an easy modification of Part 2 which we leave to the reader. \end{proof} \section{Small NFA's for \texorpdfstring{$\MN(\alpha n,n)$}{MN(alpha n, n)}}\label{se:alphan} \begin{lemma}\label{le:zero} Let $x,x',y,y',c\in \N$ with $c\ge 1$ be such that the following hold. \begin{enumerate} \item $c(x-x') + (c+1)(y-y')=0$. \item $|x-x'|\le c$. \end{enumerate} Then $x=x'$ and $y=y'$. \end{lemma} \begin{proof} Since $c+1$ divides $c(x-x')$ and $c+1$ is rel prime to $c$ we have that $c+1$ divides $x-x'$. Since $|x-x'|\le c$, $x=x'$. Hence $y=y'$. \end{proof} \begin{theorem}\label{th:alphan} Let $n\in\N$ and $0<\alpha<1$ be such that $\alpha n\in \N$. \begin{enumerate} \item There exists an NFA $M$ such that the following are true: \begin{enumerate} \item For all $i\ge 2n\ln n$, $M$ accepts $a^i$. \item For all $i\in \{\alpha n, n\}$, $M$ rejects $a^i$. \item We have no comment on the behavior of $M$ for any other $a^i$'s. \item $M$ has $\le 2n^{1/2}\ln n +\Ot(1)$ states. \end{enumerate} \item There exists an NFA on $\le 2n^{1/2}\ln n+\Ot(1)$ states that accepts $\MN(\alpha n, n)$. \end{enumerate} \end{theorem} \begin{proof} Let $c=\ceil{n^{1/2}}+1$ and $e=n+1 \pmod c$. Note that $e\le c$. \noindent 1) Let $M'$ be $\LOOP(c,c+1,e)$. By the proof of Theorem~\ref{th:n} we have: \begin{enumerate} \item %%%%%%%%% this used to say sqrt(n) %%%%%%%%%%%%%%%%% For all $i\ge n+2\ceil{n^{1/2}}$, $M'$ accepts $a^i$. Note that for all $i\ge 2n\ln n$, $M'$ accepts $a^i$. \item $M'$ rejects $a^n$. \item We have no comment on the behavior of $M'$ on other $a^i$. \item $M'$ has $\le n^{1/2}+O(1)$ states. \end{enumerate} \noindent {\bf Case 1:} $M'$ rejects $a^{\alpha n}$. Then take $M$ to be $M'$. \noindent {\bf Case 2:} $M'$ accepts $a^{\alpha n}$. We use the very acceptance of $a^{\alpha n}$ to find an NFA $M$ that satisfies the theorem. \noindent {\bf Claim 1:} There exists a unique $x,y$, such that $cx + (c+1)y+e=\alpha n$. Both $x,y$ are $\le c-1\le n^{1/2}$. \noindent {\bf Proof of Claim:} Since $M'$ accepts $a^{\alpha n}$ there is at least one such $x,y$ such that: $$\hbox{Eq 1 } cx + (c+1)y+e=\alpha n$$ $x\le c-1$ since otherwise Eq 1 implies: $$\alpha n = cx + (c+1)y+e\ge c^2 + (c+1)y+e \ge c^2 = n.$$ \noindent $y\le c-1$ by a similar argument. Assume that $x',y'$ also works. $$\hbox{Eq 2 } cx' + (c+1)y'+e=\alpha n$$ By the same reasoning that $x\le c-1$, we have $x'\le c-1$, so $|x-x'|\le c-1$. Subtract the second equation from the first to obtain: $$c(x-x') + (c+1)(y-y')=0$$ By Lemma~\ref{le:zero}, $x=x'$ and $y=y'$. \noindent {\bf End of Proof of Claim 1} Let $p$ be the least prime that does not divide $yc$ (hence does not divide $y$ or $c$). Since $y\le c^{1/2}$ and $c=\ceil{n^{1/2}}+1$, $yc\le n+n^{1/2}+O(1)$. By Lemma~\ref{le:primes}.3, $p \le (1+o(1))\ln(n+n^{1/2}+O(1)) \le 2\ln(n) + O(1)$. Let $M$ be $\LOOP(c,p(c+1),e)$. Note that $M$ has $\le 2n^{1/2}\ln n + \Ot(1)$ states. We need to show that (1) for all $i\ge n\ln n$, $M$ accepts $a^i$, and (2) $M$ rejects $a^{\alpha n}$ and $a^n$. Note that $$cp(c+1) - c - cp - p + e = c^2p + cp - c - cp - p + e = c^2p - c - p + e \le 2n\ln n-1$$ By Lemma~\ref{le:loop} \begin{itemize} \item For all $i\ge 2n\ln n$, $M$ accepts $a^i$. \item For all $C,D$, $M$ rejects $a^i$ where $i=c^2p - c - p + e -Cc - D(p(c+1))$. (We will not be using this.) \end{itemize} \noindent {\bf Claim 2:} $M$ rejects $a^{\alpha n}$. \noindent {\bf Proof of Claim 2:} Assume, by way of contradiction, that $M$ accepts $\alpha n$. Then there exists $x',y'$ such that $$\hbox{Eq 1 } \alpha n= cx'+ (c+1)y' + e$$ Recall that from Claim 1 there exists unique $x,y$ such that $$\hbox{Eq 2 } \alpha n = cx + (c+1)y+e.$$ Hence $x=x'$ and $y=y'p$. This contradicts that $p$ does not divide $y$. \noindent {\bf End of Proof of Claim 2} \noindent {\bf Claim 3:} $M$ rejects $a^{n}$. \noindent {\bf Proof of Claim 3:} Assume, by way of contradiction, that $M$ accepts $n$. Then there exists $x',y'$ such that $$n= cx' + p(c+1)y' + e$$ Then $a^n$ is accepted by $\LOOP(c,c+1,e)$, which is a contradiction. \noindent {\bf End of Proof of Claim 3} \bigskip \noindent 2) This proof is similar to that of Theorem~\ref{th:A}.2. \end{proof} \section{Small NFA's for \texorpdfstring{$\MN(A)$ where $A$}{MN(A) where A} has large gaps}\label{se:gap} \begin{theorem}\label{th:gap} Let $A\subseteq \N$ with maximum element $n'$. Let $n'