The Parametric Frobenius Problem

Abstract: Given relatively prime positive integers a_1,...,a_n, the Frobenius number is the largest integer that cannot be written as a nonnegative integer combination of the a_i. We examine the parametric version of this problem: given a_i=a_i(t) as functions of t, compute the Frobenius number as a function of t. A function f is a quasi-polynomial if there exists a period m and polynomials f_0,...,f_{m-1} such that f(t)=f_{t mod m}(t) for all positive integers t. We conjecture that, if the a_i(t) are polynomials (or quasi-polynomials) in t, then the Frobenius number agrees with a quasi-polynomial, for sufficiently large t. We prove this in the case where the a_i(t) are linear functions, and also prove it in the case where n (the number of generators) is at most 3.

\section{Introduction}
Given positive integers $a_i$, $1\le i\le n$, let
\[\ideal{a_1,\ldots, a_n}=\setBuilder{\sum_{i=1}^n p_ia_i}{p_i\in\Z_{\ge 0}}\]
be the semigroup generated by the
$a_i$. If the $a_i$ are relatively prime, define the \emph{Frobenius
number} $F(a_1,\ldots,a_n)$ to be the largest integer not in
$\ideal{a_1,\ldots, a_n}$. The \emph{Frobenius problem} of determining $F(a_1,\ldots,a_n)$ has a long history --- Sylvester proved \cite{Sylvester84} in 1884 that $F(a,b)=ab-a-b$, and see Ram{\'{\i}}rez Alfons{\'{\i}}n's book \cite{RA05} for many subsequent results.

It will be convenient to also define $F(a_1,\ldots,a_n)$ in the case where the $a_i$ are not relatively prime, so that there is no largest integer not in the semigroup. A reasonable definition seems to be the largest integer in the group $\Z a_1+\cdots+\Z a_n$ that is not in the semigroup $\ideal{a_1,\ldots, a_n}$. That is, if $d$ is the greatest common divisor of $a_1,\ldots,a_n$, then $F(a_1,\ldots,a_n)=dF(\frac{a_1}{d},\ldots,\frac{a_n}{d})$. Sylvester's identity then becomes $F(a,b)=\lcm(a,b)-a-b$.

The \emph{parametric Frobenius problem} is, given functions $a_i:\Z_+\rightarrow\Z_+$ to determine $F\big(a_1(t),\ldots,a_n(t)\big)$ as a function of $t$. For example, using Sylvester's identity,
\[F(t,t+2)=\begin{cases}t(t+2)-t-(t+2) & \text{if $t$ is odd,}\\\frac{t(t+2)}{2} - t -(t+2) & \text{if $t$ is even.}\end{cases}\]

We see that $F(t,t+2)$ is a \emph{quasi-polynomial}; a function $f:\Z_+\rightarrow\Z$ is a quasi-polynomial if
there exist an $m\in\Z_+$ and polynomials $f_0,\ldots,f_{m-1}\in\Q[t]$
such that $f(t)=f_{t\bmod m}(t)$ for all $t\in\Z_+$. Here $m$ is a
\emph{period} of $f$ and the $f_i$ are \emph{components} of $f$. We will assume that all of our functions are integer-valued, but note that the $F(t,t+2)$ example shows that we may need polynomials with rational coefficients.

In general, our functions may misbehave for small $t$. We say that a property is \emph{eventually} true if it is true for all sufficiently large $t$. We say that  $f(t)\in\eqp$ (short for \emph{eventual quasi-polynomial}) if $f(t)$ eventually agrees with a quasi-polynomial. We say that the \emph{degree} of $f\in\eqp$ is the maximum degree of its components.

 We conjecture that, if $a_i(t)\in\eqp$, then $F\big(a_1(t),\ldots,a_n(t)\big)\in\eqp$. We prove this for the special case where the $a_i(t)$ are linear functions and for the special case where $n\le 3$.

\begin{conj}
Suppose that $a_i(t)\in\eqp$, $1\le i\le n$, are eventually positive. Then $F\big(a_1(t),\ldots,a_n(t)\big)\in\eqp$.
\end{conj}

\begin{theorem}
\label{thm:main}
Suppose that $a_i(t)\in\eqp$, $1\le i\le n$, are eventually positive and have degree at most 1. Then $F\big(a_1(t),\ldots,a_n(t)\big)\in\eqp$, with degree at most 2.
\end{theorem}

\begin{theorem}
\label{thm:3gens}
Suppose that $a_i(t)\in\eqp$, $1\le i\le n$, are eventually positive, with $n\le 3$. Then $F\big(a_1(t),\ldots,a_n(t)\big)\in\eqp$.

\end{theorem}

These results are examples of so-called ``unreasonable'' appearances of qua\-si-po\-ly\-no\-mi\-als, as discussed by Woods \cite{Woods14}. ``Reasonable'' appearances trace back to Ehrhart's classical result \cite{Ehrhart62} that, if $P\subseteq\R^n$ is a polytope with rational vertices, then $f(t)=\#(tP\cap\Z^n)$ is a quasi-polynomial. Note that if $P$ is defined with linear inequalities $\mathbf b_i\cdot \mathbf x\le c_i$, then $tP$ is defined with linear inequalities $\mathbf b_i\cdot \mathbf x\le c_it$. As $t$ changes, these linear inequalities move, but their normal vectors ($\mathbf b_i$) remain the same. Indeed, Woods proved \cite{Woods15} that any example over the integers defined with linear inequalities, boolean operations (and, or, not), and quantifiers ($\forall$, $\exists$) has this quasi-polynomial behavior. This is true even if there is more than one parameter; for example,
\[\#\setBuilder{(x,y)\in\Z^2_{\ge 0}}{2x\le t,\, 3y\le s} = \bigg(\floor{\frac{t}{2}+1}\bigg)\bigg(\floor{\frac{s}{3}+1}\bigg)\]
is a quasi-polynomial of period 2 in $t$ and period 3 in $s$.

If we look at the parametric Frobenius problem, however, we see that it does not fit this pattern. For example, if we want to ask whether $u\in\ideal{t,t+1,t+2}$, we are asking whether the polytope
\[\setBuilder{(x,y,z)\in\R^3_{\ge 0}}{u=tx + (t+1)y+(t+2)z}\]
contains any integer points. For a fixed $t$, this is a 2-dimensional triangle in $\R^3$; as $t$ changes, this triangle ``twists'' (the normal vector changes). Examples such as this were categorized in \cite{Woods14} as ``unreasonable'', though they are conjectured to still lead to eventual quasi-polynomial behavior.

This paper adds a third example to the list of recent  results demonstrating this phenomenon; previously Chen, Li, and Sam \cite{CLS12} showed that the number of integer points in a polytope whose vertices are rational functions of $t$ is in $\eqp$,  and Calegari and Walker \cite{CW11} showed that the vertices of the integer hull of such a polytope have coordinates in $\eqp$. A critical tool used in all of these results is that the division algorithm and the gcd of polynomials has quasi-polynomial behavior (cf. Lemma \ref{lemma:tools}); for example, the Euclidean algorithm yields
\[\gcd(2t+1, 5t+6)=\gcd(t+4, 2t+1)=\gcd(7,t+4)=\begin{cases}7& \text{if $t\equiv 3\bmod 7$,}\\1&\text{otherwise.}\end{cases}\]

Note that unlike in the ``reasonable'' case, these results only hold with one parameter variable. For example $F(s,t)=\lcm(s,t)-s-t$ is not a quasi-polynomial in $s$ and $t$.

The original inspiration for this paper comes from a conjecture of Wagon \cite{W15} (see \cite[Section 17]{ELSW07}) that, for any fixed $M$ and residue class $j$ of $t\bmod M^2$, there exist (usually positive) integers $c_{M,j}$ and $d_{M,j}$ such that eventually
\[F(t,t+1^2,t+2^2,\ldots,t+M^2)=\frac{1}{M^2}\left(t^2+c_{M,j}t\right)-d_{M,j}.\]
Using the proof of Theorem \ref{thm:main}, we can prove that there is indeed quasi-polynomial behavior with period $M^2$. In fact, such a result holds in greater generality:

\begin{cor}
\label{cor:wagon}
Suppose $b_1<b_2<b_3<\cdots<b_n$ are integers. Then $F(t+b_1, t+b_2,\ldots,t+b_n)\in\eqp$ with period $b_n-b_1$.
\end{cor}

When the $b_i$ form an arithmetic sequence, a precise quasi-polynomial formula was previously given by Roberts \cite{Roberts56}:
\[F(t,t+d,\ldots,t+sd)=\left(\floor{\frac{t-2}{s}}+1\right)t+(d-1)(t-1)-1.\]

In Section 2, we work through the example
\[F(t,t+1,t+2)=\left(\floor{\frac{t-2}{2}}+1\right)t-1=\begin{cases} \frac{t^2}{2} & \text{if $t$ even,}\\ \frac{t^2}{2}-\frac{t}{2}-1 & \text{if $t$ odd,}\end{cases}\]
which will give a flavor of our general proof. In Section 3, we prove Theorem \ref{thm:main}. In Section 4, we prove the various lemmas needed. In Section 5, we prove Corollary \ref{cor:wagon}. In Section 6, we prove Theorem \ref{thm:3gens}, using R\o dseth's algorithm \cite{Rodseth78} for the 3 generator Frobenius problem.

The proof of Theorem \ref{thm:main} relies on the fact that semigroups with only two generators are much easier to deal with. Indeed, we have the following definition and lemma:

\begin{definition}
\label{def:canon}
Let $a,b\in\Z_+$ be relatively prime, and let $c\in\Z$. The \emph{canonical form} for $c$ is given by $c=pa+qb$ with $p,q\in \Z$ and $0\le p<b$.
\end{definition}

\begin{lemma}
\label{lemma:canon}
Let $a,b\in\Z_+$ be relatively prime, and let $c\in\Z$.

\begin{enumerate}
\item The canonical form for $c$ exists and is unique. In particular, if $c=p'a+q'b$ is any form with $p',q'\in \Z$,  and if $k$ and $r$ are the quotient and remainder when $p'$ is divided by $b$, then the canonical form for $c$ is $ra+(q'+ka)b$.
\item If $c=pa+qb$  is in canonical form, $c\in\ideal{a,b}$ if and only if $q\ge 0$.
\end{enumerate}
\end{lemma}

\section{An Example}
In this example, we compute $F(t,t+1,t+2)$. Let $a=t$, $b=t+1$, and $c=t+2$ be our three generators, let $S=\ideal{a,b,c}$, and let $T=\ideal{a,c}$. Notice that $2b=a+c$. This implies that $S=T\cup (b+T)$, as follows: if $pa+qb+rc$ is a representation of an element of $S$, with $p,q,r\in\Z_{\ge 0}$ and $q\ge 2$, then $(p+1)a+(q-2)b+(r+1)c$ is also a representation, so we may assume without loss of generality that $q$ is $0$ or $1$ (cf. Lemma \ref{lemma:decomp}). Next, we run the extended Euclidean algorithm on the integers $a$ and $c$, and get
\[\gcd(a,c)=\gcd(t,t+2)=\gcd(2,t)\]
(cf. Lemma \ref{lemma:tools}). The next division step in the algorithm depends on the parity of $t$, and rather than end up with the messy $\floor{t/2}$, we divide into two cases.

\bigskip

\proofCase{t \text{ is odd}} Let $t=2s+1$, so that $a=2s+1$, $b=2s+2$, and $c=2s+3$. Now
\[\gcd(a,c)=\gcd(2,2s+1)=\gcd(1,2)=1,\]
and the extended Euclidean algorithm yields $1=(s+1)a-sc$. Let $u\in \Z$, and we are wondering whether $u\notin S$, that is, $u\notin T$ and $u\notin b+T$. Suppose that
\[u=pa+qc\]
 is the canonical form for $u$ (see Definition \ref{def:canon}). Lemma \ref{lemma:canon}(2) tells us that $u \in T$ if and only if $q\ge 0$. Since we are looking for $u\notin T$, we may assume from here on out that $q<0$. To characterize when $u\in b+T$ (that is, $u-b\in T$) we must find the canonical form for $u-b$.

First we compute the canonical form for $b$. Multiplying the equation $1=(s+1)a-sc$ by $b=2s+2$ yields \emph{some} form for $b$:
\[b=(2s+2)(s+1)a-(2s+2)sc.\]
By Lemma \ref{lemma:canon}(1), we may find the canonical form by dividing $(2s+2)(s+1)$ by $c=2s+3$: the quotient is $s$ with remainder $s+2$, giving the canonical form for $b$ as
\[b=(s+2)a-sc.\] Note that we got a little lucky here: our remainder of $s+2$ is clearly less than $c=2s+3$; if our remainder had instead been $s+7$, say, then we would only have the canonical form for sufficiently large $s$.

Now we have that \emph{some} form for $u-b$ is
\[u-b=(p-s-2)a+(q+s)c.\]
Is this the canonical form? There are two cases:

If $p\ge s+2$, then $0\le p-s-2\le p<c$, and this is in canonical form. Therefore, to have $u-b\in T$, we must have $q+s\ge 0$ (again using Lemma \ref{lemma:canon}(2)), that is, $q\ge -s$.

 If $p<s+2$, then the canonical form is
\[u-b=(p-s-2+c)a+(q+s-a)c=(p+s+1)a+(q-s-1)c\]
(to check that this is canonical, note that $p\ge 0$ and $s+2<c$ imply $p-s-2+c\ge 0$, and $p<s+2$ implies $p-s-2+c<c$). In this case, to have $u-b\in T$, we must have $q\ge s+1$. This implies that $q\ge 0$, but we have assumed $q< 0$ (so that $u\notin T$). Therefore this case never has $u-b\in T$.

\begin{figure}
\begin{center}
\includegraphics[width=2in]{example.pdf}
\caption{The $t=5$ case of the example. We have $T=\ideal{5,7}$ and $S=\ideal{5,6,7}=T\cup(6+T)$. Points $(p,q)\in\Z^2$ with $0\le p<7$ are the canonical forms for $u=5p+7q\in \Z$. Then $q\ge 0$ corresponds to $u\in T$, $(p,q)\ge (4,-2)$ corresponds to $u\in 6+T$, and positive $u$ such that $u\notin S$ are labelled beside their corresponding $(p,q)$. The ``corners'' $u=8$ and $u=9$ are candidates for the Frobenius number, and so $F(5,6,7)=\max\{8,9\}=9$.}
\label{fig:ex}
\end{center}
\end{figure}

To summarize across both cases, if $u=pa+qc$, with $0\le p < c=2s+3$ in the canonical form, then $u\notin S$ if and only if
\[ \text{not}(q\ge 0)\quad\text{and}\quad\text{not}\big((p,q)\ge(s+2,-s)\big)\]
(cf. Lemma \ref{lemma:oneh}).
The set of such $(p,q)$ has a ``stairstep'' shape, as can be seen in Figure \ref{fig:ex} for $t=5$. In particular, the set of such $(p,q)$ can be rewritten as $p\ge 0$ and
\[\big(p\le s+1\quad\text{and}\quad q\le -1\big)\quad\text{or}\quad\big(p\le 2s+2\quad\text{and}\quad q\le-s-1\big)\]
(cf. proof of Lemma \ref{lemma:finish}, $d=1$ case). The two ``corners'' in this picture, where both inequalities of one of these two  conjunctions are tight, give our candidates for the largest $u\notin S$: it must be either
\[(s+1)a-1c=2s^2+s-2 \quad\text{or}\quad (2s+2)a+(-s-1)c=2s^2+s-1.\]
The latter is always larger (in general, one might only be eventually larger than the other), and so we have
\[F(t,t+1,t+2)=2s^2+s-1=\frac{t^2}{2}-\frac{t}{2}-1,\]
in this case where $t=2s+1$ is odd.

\bigskip

\proofCase{t\text{ is even}} Let $t=2s$, so that $a=2s$, $b=2s+1$, and $c=2s+2$.
To have $u\notin S$ we must have both $u\notin T=\ideal{a,c}$ and $u\notin b+T$. Note that every element in $T$ is even and every element of $b+T$ is odd. Therefore the largest even integer not in S is the largest even integer not in $T$, which since $T$ has only 2 generators is simply $\lcm(a,c)-a-c=2s^2-2s-2$ (we're getting lucky here that we didn't have to do an analysis similar to the $t$ is odd case). Similarly the largest odd integer not in $S$ is the largest odd integer not in $b+T$, which is $b+(2s^2-2s-2)=2s^2-1$. The largest integer not in $S$ is then the maximum of these two candidates, so $F(t,t+1,t+2)=2s^2-1=\frac{t^2}{2}-1$ (cf. proof of Lemma \ref{lemma:finish}, $d>1$ case), in this case where $t$ is even.

\bigskip

Combining the even and odd case, we have proved that
\[F(t,t+1,t+2)=\begin{cases} \frac{t^2}{2} & \text{if $t$ even,}\\ \frac{t^2}{2}-\frac{t}{2}-1 & \text{if $t$ odd.}\end{cases}\]

\section{Proof of Theorem \ref{thm:main}}
This first lemma gives us the basic tools we need:
\begin{lemma}
\label{lemma:tools} Given $f,g\in \eqp$,
\begin{enumerate}
\item There exists an $m\in\Z_+$ such that, for each $0\le j< m$, $f(ms+j)$ eventually agrees with a polynomial in $\Z[s]$.
\item If $\deg(g)>0$, there exists $q,r\in\eqp$ such that $f(t)=q(t)g(t)+r(t)$ and $\deg(r)<\deg(g)$. Note that this is the analogue of the traditional division algorithm over $\Q[t]$.
\item If $g(t)$ is eventually positive, there exists $q,r\in\eqp$ such that $f(t)=q(t)g(t)+r(t)$ and eventually $0\le r(t)<g(t)$. Furthermore, $\deg(r)\le \deg(g)$. Note that this is the analogue of the traditional division algorithm over $\Z$.
\item There exists $p,q,d\in\eqp$ such that $\gcd\big(f(t),g(t)\big)=d(t)$ and $d(t)=p(t)f(t)+q(t)g(t)$.
\item We have $\max\big(f(t),g(t)\big)\in\eqp$.
\end{enumerate}
\end{lemma}

These are proved in Section 4 of \cite{CLS12} (and also in \cite{CW11}), so in Section 4 we merely give an outline of the important steps.

\begin{remark}
\label{remark:wlog}
Lemma \ref{lemma:tools}(1) will allow us to often simply say ``without loss of generality, $f\in\Z[t]$'': we may analyze $f(ms+j)$ for each $j$, recognize that statements may be false for small $s$, and then convert back to $t$ using $s=(t-j)/m$.
\end{remark}

Using this remark, we may assume that the $a_i(t)$ are polynomials in $\Z[t]$. Since they are of degree at most 1 and eventually positive, we have that
\[a_i(t)=\alpha_i t + \beta_i,\]
 with either $\alpha_i\in\Z_{+}$,
$\beta_i\in\Z$ or $\alpha_i=0$, $\beta_i\in\Z_+$.
Furthermore, without loss of generality, we may assume that they are \emph{ordered} so that
\[\beta_i\alpha_j\le \beta_j\alpha_i\]
for $i\le j$, that is (for $\alpha_i\ne 0$),
\[
\frac{\beta_1}{\alpha_1} \le
\frac{\beta_2}{\alpha_2} \le
\cdots \le \frac{\beta_n}{\alpha_n}.
\]
We first consider a degenerate case, where
$\beta_i\alpha_j=\beta_j\alpha_i$, for all $i,j$.

\begin{lemma}
\label{lemma:degen}
If $\beta_i\alpha_j=\beta_j\alpha_i$, for all $i,j$, then there are $\alpha_0, \beta_0\in\Z_{\ge 0}$ such that, for all $i$,  $\alpha_i=\gamma_i\alpha_0$ and $\beta_i=\gamma_i\beta_0$ (for some $\gamma_i\in\Z_+$). Therefore
\[F\big(a_1(t),\ldots,a_n(t)\big)=F(\gamma_1,\ldots,\gamma_n)\cdot(\alpha_0t+\beta_0)\]
is a polynomial of degree at most 1.
\end{lemma}

Therefore, we can assume that $\beta_1\alpha_n<\beta_n\alpha_1$. In particular, the polynomials $a_1$ and $a_n$ do not share a linear factor, and so if $d(t)=\gcd\big(a_1(t),a_n(t)\big)$, then $d(t)\in\eqp$ is of degree 0, that is, $d(t)$ is eventually a periodic function. Let
$S(t)=\ideal{a_1(t),\ldots,a_n(t)}$, and let $T(t)=\ideal{
a_1(t),a_n(t)}$. $T(t)$ is a semigroup with only two generators, so
it is much easier to analyze. The following lemma allows us to cover $S(t)$
with a finite number of translated copies of $T(t)$.

\begin{lemma}
\label{lemma:decomp}
For $a_i(t)=\alpha_it+\beta_i$ as described above,  there exists a finite set $H$
of integer-valued polynomials of degree at most 1 such that
\[
\ideal{a_1(t),\ldots,a_n(t)}=\bigcup_{h\in H}
\Big(h(t) + \ideal{a_1(t),a_n(t)} \Big)
\]
(for $t$ sufficiently large so that $a_i(t)>0, \forall i$).
Furthermore, $0\in H$ and the other $h\in H$ are eventually positive.
\end{lemma}

Assume for the moment that $a_1(t)$ and $a_n(t)$ are relatively prime. By Lemma \ref{lemma:canon}(2), the set of all integers not in $T$ will be in bijection to the set
\[\setBuilder{(p,q)\in\Z^2}{0\le p< a_n(t),\, q<0},\]
under the bijection $(p,q)\mapsto pa_1(t)+qa_n(t)$. By Lemma \ref{lemma:decomp}, integers not in $S$ must also not be in $h(t)+T$, for all $h\in H$. The following lemma gives an easy way to check this.

\begin{lemma}
\label{lemma:oneh}
Let $f,g,h\in\eqp$, with $f(t)$ and $g(t)$ relatively prime for all $t$ and with $f(t),g(t),h(t)$ eventually positive. There exists $r,s\in\eqp$ such that, given $p,q\in\Z$ with $0\le p< g(t)$ and $q<0$,
\[pf(t)+qg(t)\in h(t)+\ideal{f(t),g(t)}\quad\text{if and only if}\quad (p,q)\ge \big(r(t),s(t)\big)\]
component-wise. Furthermore, $\deg(r)\le\deg(g)$ and $\deg(s)\le\max\{\deg(f),\deg(h)-\deg(g)\}$,
\end{lemma}

In our case, this gives $r,s$ of degree at most 1. If $a_1(t)$ and $a_n(t)$ are relatively prime, all that remains is to follow the implications of Lemmas \ref{lemma:decomp} and Lemma \ref{lemma:oneh}, which will give us a staircase-shaped set such as in Figure \ref{fig:ex}. If $a_1(t)$ and $a_n(t)$ are not relatively prime, we must reduce to the case where they are. Both of these are accomplished in the following lemma, which (combined with Lemma \ref{lemma:decomp} and the fact that $d(t)=\gcd\big(f(t),g(t)\big)$ is of degree 0) proves our theorem.

\begin{lemma}
\label{lemma:finish}
Let $f(t), g(t)\in \eqp$, and let $d(t)=\gcd\big(f(t),g(t)\big)$ be of degree 0, let $H\subseteq\eqp$ be a finite set, and let
\[S(t)=\bigcup_{h\in H} \big(h(t)+\ideal{f(t),g(t)}\big).\]
The function $F(t)$ giving the largest integer not in $S(t)$ is in $\eqp$, with degree at most $\max\{\deg(f)+\deg(g),\deg(h)\}$.
\end{lemma}

In our case, this gives that $F$ is of degree at most 2.

\section{Proofs of Lemmas}
\begin{proof}[Proof of Lemma \ref{lemma:canon}]
Part 1 is a standard result, using the extended Euclidean algorithm and the fact that if $c=p'a+q'b$ is one solution, then all solutions are given by $c=(p'-kb)a+(q'+ka)b$ for $k\in\Z$.

For part 2, we have $c=pa+qb$ with $0\le p <b$. The reverse implication is immediate: if $q\ge 0$, then we have written $c=pa+qb$ with $p,q\in \Z_{\ge 0}$, proving that $c\in\ideal{a,b}$. Conversely, suppose $c\in \ideal{a,b}$ so that $c=p'a+q'b$ with $p',q'\in\Z_{\ge 0}$. By part 1, if $k$ and $r$ are the quotient and remainder when $p'$ is divided by $b$, then
\[c=ra+(q'+ka)b\]
is the canonical form for c, with $q=q'+ka\ge 0$.
\end{proof}

\begin{proof}[Proof of Lemma \ref{lemma:tools}]
As these are proved in Section 4 of \cite{CLS12}, we simply give an outline here.

For part 1, this is mostly obvious: simply take component polynomials of the quasi-polynomial. The main subtlety, as seen in the example from Section 2, is that integer-valued polynomials may have non-integral coefficients. In this case, let $m$ be the least common multiple of the denominators of the coefficients. Examining $f(ms+i)$, we see that all coefficients of $s^k$ must be integral, except possibly the constant coefficient; since the function is integer-valued, the constant coefficient must also be integral.

For part 2, simply perform polynomial division. The main subtlety is the following: Suppose, for example, that $f(t)= t^2+3t$ and $g(t)= 2t+1$. Then the leading coefficient of $g$ does not divide the leading coefficient of $f$, and the traditional polynomial division algorithm would produce quotients that are not integer-valued. Instead, we look separately at each residue class of $t$ modulo  the leading coefficient of $g$; for example, if $t$ is odd, then $t=2s+1$ for some $s\in\Z_{\ge 0}$, so substituting gives $f(2s+1)=4s^2+10s+3$ and $g(2s+1)=4s+3$, and now the leading term does divide evenly.

For part 3, first perform the polynomial division algorithm for part 2. For example, suppose $f(t)= 2t-3$ and $g(t)= t$, yielding $f=2g+ -3$. For part 3, however, we want the integer division algorithm: $f(t)=1g(t)+(t-3)$, and the remainder $t-3$ is between 0 and $g$ as long as $t\ge 3$. In other words, if we have found $f=q'g+r'$ with $\deg(r')<\deg(g)$, but we eventually have $r'(t)<0$, then we should use quotient $q= q'-1$ and remainder $r= g+r'$ instead, as eventually $0\le g(t)+r'(t)<g(t)$.

For part 4, run the extended Euclidean algorithm, repeatedly performing the division algorithm of part 2.

For part 5, note that given two polynomials, one eventually dominates the other.
\end{proof}

\begin{proof}[Proof of Lemma \ref{lemma:degen}]
For each $i$, let $\gamma_i=\gcd(\alpha_i, \beta_i)\in\Z_+$, let $\alpha'_i=\alpha_i/\gamma_i$, and let $\beta'_i=\beta_i/\gamma_i$, with $\alpha'_i$ and $\beta'_i$ relatively prime. Dividing $\beta_i\alpha_j=\beta_i\alpha_i$ by $\gamma_i\gamma_j$ yields $\beta'_i\alpha'_j=\beta'_j\alpha'_i$. Since $\alpha'_j$ divides $\beta'_j\alpha'_i$ and is relatively prime to $\beta'_j$, we have that $\alpha'_j$ divides $\alpha'_i$. Similarly, $\alpha'_i$ divides $\alpha'_j$, and so $\alpha'_i=\alpha'_j$. Similarly, $\beta'_i=\beta'_j$. Taking $\alpha_0$ to be the common $\alpha'_i$ (equal for all $i$) and $\beta_0$ to be the common $\beta'_i$, the proof follows.
\end{proof}

\begin{proof}[Proof of Lemma \ref{lemma:decomp}]

Let $r=\beta_n\alpha_1-\beta_1\alpha_n$. We are given that $r>0$ and that $\beta_j\alpha_i-\beta_i\alpha_j\ge 0$ for all $i\le j$. Let
\[H=\setBuilder{\lambda_2a_2+\cdots+\lambda_{n-1}a_{n-1}}{\lambda_i\in\Z_{\ge 0},\,\lambda_i<r}.\]
We will prove that $H$ has the required properties; certainly every element of $H$ is of degree at most 1. We must show that, if $u\in \ideal{a_1(t),\ldots,a_n(t)}$, then there
exists a $\lambda\in\Z_{\ge 0}^n$ such that $u=\lambda_1a_1(t)+\cdots+\lambda_na_n(t)$ and $\lambda_i<r$ for
$2\le i\le n-1$.

By definition of the semigroup, there exists a $\lambda\in\Z_{\ge 0}^n$ such that
$u=\lambda_1a_1(t)+\cdots+\lambda_na_n(t)$. Suppose that $\lambda_i\geq r$ for some $i$ with
$2\le i\le n-1$.  Let
$p=\beta_n\alpha_i-\beta_i\alpha_n$ and $q=\beta_i\alpha_1-\beta_1\alpha_i$ and observe that $p,q\ge0$.
Then
\begin{align*}
pa_1(t)+qa_n(t) &=
(\beta_n\alpha_i-\beta_i\alpha_n)(\alpha_1 t + \beta_1) +
  (\beta_i\alpha_1-\beta_1\alpha_i)(\alpha_n t + \beta_n) \\ &=
\beta_n\alpha_i\alpha_1t - \beta_i\alpha_n\beta_1 +
  \beta_i\alpha_1\beta_n - \beta_1\alpha_i\alpha_nt \\&=
(\beta_n\alpha_1-\beta_1\alpha_n)(\alpha_it+\beta_i)\\
&= ra_i(t).
\end{align*}
Now define $\lambda'$ by $\lambda'_1=\lambda_1+p$, $\lambda'_i=\lambda_i-r$, $\lambda'_n=\lambda_n+q$, and $\lambda'_j=\lambda_j$ for all other $j$. Then $$u=\lambda'_1a_1(t)+\cdots+\lambda'_na_n(t)$$
is a new representation of $u$. Repeating this
process eventually yields a representation with $\lambda_i<r$ for $2\le i\le n-1$.
\end{proof}

\begin{proof}[Proof of Lemma \ref{lemma:oneh}]
Assume $0\le p< g(t)$ and $q<0$. We need conditions on $p,q$ for which $pf(t)+qg(t)-h(t)\in\ideal{f(t),g(t)}$. By Lemma \ref{lemma:tools}(4) and the fact that $f(t)$ and $g(t)$ are relatively prime, we may write $1=r'(t)f(t)+s'(t)g(t)$, where $r',s'\in\eqp$. Multiplying this equation by $h(t)$ yields
\[h(t)=\big(h(t)r'(t)\big)f(t)+\big(h(t)s'(t)\big)g(t).\]
If we let $k(t)$ and $r(t)$ be the quotient and remainder when $h(t)r'(t)$ is divided by $g(t)$, using Lemma \ref{lemma:tools}(3), and let $s(t)=h(t)s'(t)+k(t)f(t)$, then we have
\[h(t)=r(t)f(t)+s(t)g(t),\]
with $0\le r(t)<g(t)$. In particular, this gives us that $\deg(r)\le \deg(g)$ and therefore $\deg(s)\le\max\{\deg(f),\deg(h)-\deg(g)\}$.
We have
\begin{equation}\label{eqn:canon}pf(t)+qg(t)-h(t)=\big(p-r(t)\big)f(t)+\big(q-s(t)\big)g(t).\end{equation}

\proofCase{p\ge r(t)} Then $0\le p-r(t)< g(t)$, and (\ref{eqn:canon}) is in canonical form. Then $pf(t)+qg(t)-h(t)\in\ideal{f(t),g(t)}$ if and only if $q-s(t)\ge 0$, by Lemma \ref{lemma:canon}(2).

\proofCase{p<r(t)} Then the canonical form for $pf(t)+qg(t)-h(t)$ will be
\begin{equation}\label{eqn:canon2} \big(p-r(t)+g(t)\big)f(t)+\big(q-s(t)-f(t)\big)g(t), \end{equation}
since $0\leq p<r(t)$ and $r(t)<g(t)$ imply that
\[ 0 < p-r(t)+g(t) < g(t). \]
Since $h(t)$, $r(t)$, $f(t)$, and $g(t)$ are eventually positive and $r(t)<g(t)$, we eventually have
\[0<h(t)=r(t)f(t)+s(t)g(t)<g(t)\big(f(t)+s(t)\big),\]
and so eventually $f(t)+s(t)>0$. Since we are assuming that $q<0$, eventually $q-s(t)-f(t)<0$. Therefore the canonical form  (\ref{eqn:canon2}) shows that $pf(t)+qg(t)-h(t)\notin \ideal{f(t),g(t)}$, by Lemma \ref{lemma:canon}(2).

Combining the two cases, we see that $pf(t)+qg(t)\in h(t)+\ideal{f(t),g(t)}$ exactly when $p\ge r(t)$ and $q\ge s(t)$, as desired.
\end{proof}

\begin{proof}[Proof of Lemma \ref{lemma:finish}]
Since $d(t)\in\eqp$ is of degree zero, it is eventually a periodic function. By Remark \ref{remark:wlog}, we may focus on a component of $d(t)$ and assume that $d(t)=d$ is a constant.

\proofCase{d=1}
We assume, without loss of generality, that $0\in H$ and the other functions in $H$ are eventually positive: if not, let $h_0(t)$ be the eventually minimal polynomial in $H$, and find the largest integer $F'(t)$ not in
\[S'(t)=\bigcup_{h\in H}\bigg(\big(h(t)-h_0(t)\big)+\ideal{f(t),g(t)}\bigg);\]
then $F(t)=F'(t)+h_0(t)$.

We wish to describe the set $U(t)$ of $(p,q)$ corresponding to canonical forms $u=pf(t)+qg(t)$ such that $u\notin S$. Canonical implies that $0\le p<g(t)$, and $u\notin \left(0+\ideal{f(t),g(t)}\right)$ implies that $q<0$, by Lemma \ref{lemma:canon}(2). Each $h\in H\setminus\{0\}$ gives the condition ``$p<r_h(t)$ or $q<s_h(t)$'', by Lemma \ref{lemma:oneh}. Then the set $U(t)$ has a ``stairstep'' shape as in Figure \ref{fig:ex}. To be precise, order the $\big(r_h(t),s_h(t)\big)$ such that $r_1(t)\le r_2(t)\le\cdots\le r_m(t)$ (eventually). Notice that if $r_i(t)\le r_j(t)$, then we may assume without loss of generality that $s_i(t)>s_j(t)$ (eventually), or else the condition ``$p<r_j(t)$ or $q<s_j(t)$'' would be redundant. Further include $\big(r_0(t),s_0(t)\big)=(0,0)$ (corresponding to $u\notin 0+\ideal{f(t),g(t)}$) and $\big(r_{m+1}(t),s_{m+1}(t)\big)= \big(g(t),-f(t)\big)$ (corresponding to $(p,q)$ being canonical). Finally, for $0\le i\le m$, let $\big(\alpha_i(t),\beta_i(t)\big)=\big(r_{i+1}(t)-1,s_i(t)-1\big)$. Then the set of $(p,q)\in U(t)$ is exactly the set such that $0\le p$ and
\[(p,q)\le \big(\alpha_0(t),\beta_0(t)\big)\quad\text{or}\quad\cdots\quad\text{or}\quad(p,q)\le \big(\alpha_m(t),\beta_m(t)\big).\]
Since if $(p,q)\le\big(\alpha_i(t),\beta_i(t)\big)$, then $pf(t)+qg(t)\le \alpha_i(t)f(t)+\beta_i(t)g(t)$, our candidates for the largest integer not in $S(t)$ are the $\alpha_i(t)f(t)+\beta_i(t)g(t)$, $0\le i\le m$. Then our final answer is
\[\max_{0\le i\le m} \alpha_i(t)f(t)+\beta_i(t)g(t),\]
which is in $\eqp$, by Lemma \ref{lemma:tools}(5). Furthermore, using that $\deg(\alpha_i)=\deg(r_i)\le \deg(g)$ and $\deg(\beta_i)=\deg(s_i)\le\max\{\deg(f),\deg(h)-\deg(g)\}$, by Lemma \ref{lemma:oneh}, we have that our final degree is at most
$\max\{\deg(f)+\deg(g),\deg(h)\}$.

\proofCase{d> 1}
Let $H_j(t)=\setBuilder{h\in H}{h(t)\equiv
  j\bmod d}$. The remainder when a given $h(t)$ is divided by $d$ is a periodic function, by Lemma \ref{lemma:tools}(3); applying Remark \ref{remark:wlog} as necessary, we may assume that these remainders are constant, that is, that $H_j=H_j(t)$  does not depend on $t$. Let $S_j(t)=\setBuilder{u\in
  S(t)}{u\equiv j\bmod d}$. Since $d$ divides every element of $\ideal{f(t),g(t)}$,
  \[
S_j(t) = \bigcup_{h\in H_j}\bigg(h(t) + \ideal{f(t),g(t)}\bigg)
.\]
Let $F_j(t)$ be the largest integer not in
\[
\frac{1}{d}(S_j(t)-j) =
\bigcup_{h\in H_j}
\left(\frac{h(t)-j}{d}+\left\langle\frac{f(t)}{d},\frac{g(t)}{d}\right\rangle\right)
.\]
By the case $d=1$ proved above, $F_j(t)$ is in $\eqp$. Since $dF_j(t)+j$ is the maximum $u\in j+d\Z$ such
that $u\notin S_j(t)$, we get that
$F(t)=\max_{j}\left(dF_j(t)+j\right)$. Lemma \ref{lemma:tools}(5) then implies that
$F(t)$ is in $\eqp$.
\end{proof}

\section{Proof of Corollary \ref{cor:wagon}}
Without loss of generality, we may assume that $b_1=0$ (substituting $s=t-b_1$, if necessary). For a fixed $j\in\Z$, look at all $t\equiv j\bmod b_n$, and let $s$ be such that  $t=b_ns+j$. Let $a_i(s)= t+b_i=b_ns+j+b_i$. We must prove that $F\big(a_1(s),\ldots,a_n(s)\big)$ is a \emph{polynomial} in $s$. We follow the proof of Theorem \ref{thm:main} and of the lemmas, looking for places where periodicity might be introduced.  Note that the $a_i(s)$ are correctly ordered (as defined before the statement of Lemma \ref{lemma:degen}) so that Lemma \ref{lemma:decomp} gives us
\[S=\bigcup_{h\in H}\big(h(s)+\ideal{a_1(s),a_n(s)}\big).\]

Following the proof of Lemma \ref{lemma:decomp}, note that each $h\in H$ is a nonnegative integer combination of $a_2(s),\ldots,a_{n-1}(s)$. In particular, each $h\in H$ has the form $kb_ns+\ell$ for some integers $k$ and $\ell$.

Focus on a specific $h=kb_ns+\ell$. Let
\[d(s)=\gcd\big(a_1(s),a_n(s)\big)=\gcd(b_ns+j,b_ns+j+b_n)=\gcd(b_n,b_ns+j)=\gcd(j,b_n),\]
which is a constant. Finding $p$ and $q$ with $pj+qb_n=d$ gives us
\[d=(ps-q+p)a_1(s)-(ps-q)a_n(s).\]
Assume for the moment that $d=1$. We next examine the proof of Lemma \ref{lemma:oneh}. The first step is to take
\begin{align*}
h&=h\cdot 1=h\cdot\big((ps-q+p)a_1(s)-(ps-q)a_n(s)\big)\\
&=\big((kb_ns+\ell)(ps-q+p)\big)a_1(s) - \big((kb_ns+\ell)(ps-q+p)\big)a_n(s),
\end{align*}
and write it in canonical form. This involves taking the remainder when dividing
\[(kb_ns+\ell)(ps-q+p)=kpb_ns^2+(\ell p-kb_nq+kb_np)s+(-\ell q+\ell p)\]
by $a_n(s)=b_ns+j+b_n$. The first step of polynomial long division works over the integers, because the leading coefficient, $b_n$, of $a_n(s)$ divides into the leading coefficient, $kpb_n$, of the dividend. This leaves a remainder that is linear in $s$. One more step of long division (dividing a linear in $s$ function by a linear in $s$ function and taking the linear in $s$ remainder) will then lead to the final answer, without introducing extra periodicity.

No other steps in the entire proof have a possibility of adding periodicity, so we are done, in the case $d=1$.

If $d>1$, following the proof of Lemma \ref{lemma:finish} in the $d>1$ case, let $b'_n=b_n/d$, $j'=j/d$, and $\ell'=\floor{\ell/d}$ be integers. Then the reduction to the $d=1$ case gives that we must examine,
\[\floor{\frac{h(s)}{d}}+\ideal{\frac{a_1(s)}{d},\frac{a_n(s)}{d}}=(kb'_ns+\ell')+\ideal{b'_ns+j',b'_ns+j'+b'_n},\]
and we have reduced to the $d=1$ case.

\section{Proof of Theorem \ref{thm:3gens}}
The $n=1$ case is trivial: $F\big(a_1(t)\big)=-a_1(t)$ is the usual interpretation.

The $n=2$ case follows from Sylvester's formula:
\[F\big(a_1(t),a_2(t)\big)=\lcm\big(a_1(t),a_2(t)\big)-a_1(t)-a_2(t)=\frac{a_1(t)a_2(t)}{\gcd\big(a_1(t),a_2(t)\big)}-a_1(t)-a_2(t),\]
and the gcd can be computed using Lemma \ref{lemma:tools}.

For the $n=3$ case, we show that the steps of R\o dseth's algorithm \cite{Rodseth78} can be performed on eventual quasi-polynomials. We enumerate the steps of the algorithm as described for integers, and follow each step with a comment on how it works with elements of $\eqp$.

\begin{enumerate}
\item[(1)] If $d(t)=\gcd\big(a_1(t),a_2(t),a_3(t)\big)\ne 1$, then use that
\[F\big(a_1(t),a_2(t),a_3(t)\big)=d(t)F\left(\frac{a_1(t)}{d(t)},\frac{a_2(t)}{d(t)},\frac{a_3(t)}{d(t)}\right).\]
\end{enumerate}

For elements of $\eqp$, Lemma \ref{lemma:tools}(4) allows us to compute this gcd.

\begin{enumerate}
\item[(2)] We may assume that $a_1(t), a_2(t),a_3(t)$ are relatively prime where $a_1(t),a_2(t),a_3(t)\in\eqp$. If $e(t)= \gcd\big(a_1(t),a_2(t)\big)\ne 1$, then use that
\[F\big(a_1(t),a_2(t),a_3(t)\big)=e(t)F\left(\frac{a_1(t)}{e(t)},\frac{a_2(t)}{e(t)},a_3(t)\right)+a_3(t)\big(e(t)-1\big).\]
\end{enumerate}
\noindent This can again be done using Lemma \ref{lemma:tools}(4).

\begin{enumerate}
\item[(3)] We may assume that $a_1(t)$ and $a_2(t)$ are relatively prime.
Compute $s_0(t)\in\eqp$ such that $a_2(t)s_0(t)\equiv a_3(t)\bmod{a_1(t)}$ and $0\le s_0(t)< a_1(t)$.
\end{enumerate}
\noindent To do this for elements of $\eqp$, first use Lemma \ref{lemma:tools}(4) to find $p,q\in\eqp$ such that $1=p(t)a_1(t)+q(t)a_2(t)$. Then
\[a_2(t)\big(a_3(t)q(t)\big)=a_3(t)\big(q(t)a_2(t)\big)\equiv a_3(t)\cdot 1\bmod{a_1(t)}.\]
Now let $s_0(t)$ be the remainder when $a_3(t)q(t)$ is divided by $a_1(t)$, using Lemma \ref{lemma:tools}(3). This is the desired $s_0(t)$.

\begin{enumerate}
\item[(4)] If $s_0(t)=0$, then $a_3(t)$ is a multiple of $a_1(t)$, and the Frobenius problem reduces to the $n=2$ case.
\end{enumerate}
\noindent If some of the components of $s_0(t)\in\eqp$ are zero, we will have to split into cases, one for each component.

\begin{enumerate}
\item[(5)] Compute $q_1,s_1\in\eqp$ such that
\[a_1(t)=q_1(t)s_0(t)-s_1(t),\quad 0\le s_1(t)<s_0(t).\]
\end{enumerate}
\noindent If $\deg(s_0)=0$, this is a slight variant of the usual integer division algorithm. If $\deg(s_0)>0$, use Lemma \ref{lemma:tools}(2) to compute $a_1(t)=q(t)s_0(t)+r(t)$, with $\deg(r) <\deg(s_0)$. If $r(t)$ is eventually negative or zero, simply set $q_1(t)=q(t)$ and $s_1(t)=-r(t)$, and we have that eventually $0\le s_1(t)<s_0(t)$. If $r(t)$ is eventually positive, set $q_1(t)=q(t)+1$ and $s_1(t)=s_0(t)-r(t)$, which will eventually satisfy the bounds.

\begin{enumerate}
\item[(6)] Continue computing
\begin{align*}
s_0(t)&=q_2(t)s_1(t)-s_2(t), \quad0\le s_2(t)<s_1(t),\\
s_1(t)&=q_3(t)s_2(t)-s_3(t), \quad 0\le s_3(t)<s_2(t),\\
\ &\ \, \vdots\\
s_{m-2}(t)&=q_{m}(t)s_{m-1}(t)-s_m(t), \quad 0\le s_m(t)<s_{m-1}(t),\\
s_{m-1}(t)&=q_{m+1}(t)s_m(t)+s_{m+1},\quad s_{m+1}=0.
\end{align*}
\end{enumerate}
\noindent This is simply repeating the process from Step 5. We must establish that it terminates. It suffices to show that, if $\deg(s_i)>0$, then $\deg(s_{i+2})<\deg(s_i)$ (and then once $\deg(s_i)=0$, the integers $s_i$ strictly decrease, so this will eventually terminate). Indeed, as described in Step 5, Lemma \ref{lemma:tools}(2) gives us $s_{i-1}(t)=q(t)s_i(t)+r(t)$, with $\deg(r) <\deg(s_i)$. If $r(t)$ is eventually negative or zero, we have $s_{i+1}(t)=-r(t)$, and the degree has decreased. If $r(t)$ is eventually positive, we have $s_{i+1}(t)=s_{i}(t)-r(t)$, which still have the same degree as $s_i$. But in the next step, $s_{i+1}(t)=1\cdot s_i(t)-r(t)$, and so $s_{i+2}(t)=r(t)$ has lower degree. Of course, different components of the eventual quasi-polynomials may terminate at different $m$, and we  must analyze each separately.

\begin{enumerate}
\item[(7)] Define $s_{-1}(t)=a_1(t)$, $P_{-1}(t)=0$, $P_0(t)=1$, and recursively $P_{i+1}(t)=q_{i+1}(t)P_i(t)-P_{i-1}(t)$. Then
\[0=\frac{s_{m+1}(t)}{P_{m+1}(t)}<\frac{s_m(t)}{P_m(t)}<\cdots<\frac{s_0(t)}{P_0(t)}<\frac{s_{-1}(t)}{P_{-1}(t)}=\infty.\]
Determine the unique index $i$ such that
\[\frac{s_{i+1}(t)}{P_{i+1}(t)}\le \frac{a_3(t)}{a_2(t)}<\frac{s_i(t)}{P_i(t)}.\]
\end{enumerate}
\noindent Restricting to a fixed residue class modulo the period of the quasi-polynomials, such an index $i$ exists, since each $s_i(t)/P_i(t)$ is a rational function, so is eventually greater than, eventually less than, or eventually equal to $a_3(t)/a_2(t)$.

\begin{enumerate}
\item[(8)] Then
\begin{align*}
F\big(a_1(t),a_2(t),a_3(t)\big)=-a_1&(t)+a_2(t)\left(s_i(t)-1\right)+a_3(t)\big(P_{i+1}(t)-1\big)\\
& - \min\big\{a_2(t)s_{i+1}(t),a_3(t)P_i(t)\big\}.
\end{align*}
\end{enumerate}
\noindent This is in $\eqp$, by Lemma \ref{lemma:tools}(5).

Combinatorics (math.CO); Number Theory (math.NT)

The Parametric Frobenius Problem


Linear extension numbers of $n$-element posets

Abstract: We address the following natural but hitherto unstudied question: what are the possible linear extension numbers of an $n$-element poset? Let $\mathbf{LE}(n)$ denote the set of all positive integers that arise as the number of linear extensions of some $n$-element poset. We show that $\mathbf{LE}(n)$ skews towards the "small" end of the interval $[1,n!]$. More specifically, $\mathbf{LE}(n)$ contains all of the positive integers up to $\exp\left(c\frac{n}{\log n}\right)$ for some absolute constant $c$, and $|\mathbf{LE}(n) \cap ((n-1)!,n!]|<(n-3)!$. The proof of the former statement involves some intermediate number-theoretic results about the Stern-Brocot tree that are of independent interest.

\section{Introduction}\label{sec:introduction}

\subsection{Background and main question}

A \textit{partially ordered set} (or \textit{poset}) consists of a ground set $P$ together with a transitive, antisymmetric, and reflexive binary relation $\leq_P$ on $P$.  Posets arise naturally in many areas of math and have been studied extensively.  In this paper, we concern ourselves with posets where the base set has a finite number of elements.
\\

A \textit{linear extension} of the poset $(P,\leq_P)$ is a total ordering $\leq^{\ast}$ on $P$ which ``extends'' the relation $\leq_P$ in the sense that $x \leq_P y$ necessarily implies $x \leq^{\ast} y$.  Throughout this paper, we let $\ext(P)$ denote the number of linear extensions of the poset $P$ (with $\leq_P$ implicit).  The problem of computing $\ext(P)$ for particular posets $P$ has received significant attention in a variety of contexts; see, e.g., \cite{atkinson1985extensions,bjorner1991permutation,brightwell2003number,felsner2015linear}.  Linear extension numbers have also been studied in relation to comparability graphs, convex polytopes, and other combinatorial objects in \cite{edelman1989recurrence,stachowiak1989relation,stanley1986two}.
\\

The following straightforward recursive algorithm generates all linear extensions of a poset $P$: for each minimal element $x \in P$ (i.e., an element $x$ such that there is no $y<_P x$), take $x \leq^{\ast} z$ for all $z \in P$ and then find all linear extensions of the poset induced by $\leq_P$ on the set $P \setminus \{x\}$.  One could also proceed by choosing any pair of incomparable elements $(x,y)$ and (recursively) finding all linear extensions of the two posets obtained by adding either the relation $x \leq_P y$ or the relation $y \leq_P x$.
\\

The computation of linear extension numbers is quite difficult in general.  For instance, Brightwell and Winkler \cite{brightwell1991counting} showed that the problem of computing $\ext(P)$ for arbitrary $P$ is NP-complete.  See \cite{dittmer2018counting} for a more recent perspective.
\\

Until now, there has not been a comparable interest in the natural inverse question for linear extension numbers: for fixed $n$, which positive integers can appear as $\ext(P)$, where $|P|=n$?  In this paper, we investigate the properties of the set
\[\LE(n)=\{\ext(P): |P|=n\}\]
for various values of $n$.
\\

Trivially, $1 \leq \ext(P)\leq n!$.  As $P$ ranges over all $n$-element posets, one would expect $\ext(P)$ to take on small values more readily than large ones.  For instance, it is easy to find posets with $\ext(P)=k$ for all $1 \leq k \leq n$ (by taking $P$ to have a chain of length $n-1$), whereas we can never have $\frac{n!}{2}<\ext(P)<n!$ (since the existence of even a single nontrivial relation forces $\ext(P)\leq \frac{n!}{2}$).  Note also that $\LE(n)\subseteq\LE(n+1)$ since we can simply add an element that is smaller than all other elements.

\subsection{Main results}

Heuristically speaking, we strengthen the above observations into a nontrivial description of how $\LE(n)$ skews towards small elements of the interval $[1, n!]$. Our main result is that $n$-element posets achieve all small linear extension numbers in the following sense.

\begin{theorem}[Small linear extension numbers]\label{thm:small}
There is an absolute constant $c$ such that for all sufficiently large $n$, the set $\LE(n)$ contains all positive integers up to $\exp\left(c\frac{n}{\log n}\right)$.
\end{theorem}

We prove this theorem by recursively constructing a family of width-$2$ posets whose linear extension numbers are related to the entries of the Stern-Brocot tree.  We then control the appearance of these entries by relating this phenomenon to certain properties of the Euclidean algorithm. We mention the following intermediate result here because it is of independent number-theoretic interest.

\begin{theorem}\label{thm:number-theoretic}
There is an absolute constant $c$ such that the following holds: for every $n\ge 2$, there exists some $1\le d\le n - 1$ relatively prime to $n$ such that when the Euclidean algorithm is run on the pair $(n, d)$, the sum of the quotients obtained is at most $c\frac{n}{\phi(n)}\log n\log\log n$, where $\phi$ denotes Euler's totient function.
\end{theorem}
We conjecture that the factor of $\frac{n}{\phi(n)}\log\log n$ can be removed.
\\

We complement Theorem~\ref{thm:small} by showing that $n$-element posets avoid most large linear extension numbers in the following sense.

\begin{theorem}[Large linear extension numbers]\label{thm:large}
For all $n\geq 8$, we have $|\LE(n) \cap ((n-1)!,n!]|<(n-3)!$.
\end{theorem}
We prove this theorem by analyzing the connected components of Hasse diagrams.  The key insight is that an $n$-element poset with a connected Hasse diagram has at most $(n-1)!$ linear extensions.
\\

\subsection{Structure of the paper}

In Section~\ref{sec:general-constructions}, we describe general constructions for manipulating the linear extension counts of posets.  In Section~\ref{sec:nice-family}, we use these ideas to construct a specific family of posets whose linear extension numbers are connected to the Stern-Brocot tree. In Section~\ref{sec:correspondence}, we use known facts about the Stern-Brocot tree to reduce Theorem~\ref{thm:small} to Theorem~\ref{thm:number-theoretic}, which we prove in Section~\ref{sec:proofs}.  In Section~\ref{sec:large}, we prove Theorem~\ref{thm:large} and related results.  Finally, we pose some conjectures and questions in Section~\ref{sec:conclusion}.

\subsection{Conventions and notation}\label{sec:conventions}
Throughout this paper, the set of natural numbers is $\mathbb{N} = \{1, 2, \ldots\}$, and $\mathbb{N}^\ast$ denotes the set of all (possibly empty) finite sequences of natural numbers. Logarithms are natural unless otherwise specified, and $\phi$ always denotes Euler's totient function.
\\

Two elements $x$ and $y$ in a poset $P$ are \textit{comparable} if either $x \leq_P y$ or $y \leq_P x$; otherwise, these elements are \textit{incomparable}.  A \textit{chain} in a poset $P$ is a subset in which any two elements are comparable, and an \textit{antichain} is a subset in which no two distinct elements are comparable.  We write $\textbf{1}$ for the \textit{singleton} poset whose base set consists of only a single element.  For $x, y \in P$, we write $x<_P y$ if $x \leq_P y$ and $x \neq y$.  We say that $y$ \textit{covers} $x$ if $y>_P x$ and there is no $z \in P$ such that $y>_P z>_P x$.
\\

The \textit{Hasse diagram} is a useful way to visualize a poset $P$.  The Hasse diagram of $P$ consists of points corresponding to the elements of $P$, where $y$ is placed higher than $x$ whenever $y>_P x$.  If $y$ covers $x$, then we also connect the points $x$ and $y$ with a line segment.

\section{Some general poset constructions}\label{sec:general-constructions}
There are several natural ways to build larger posets out of smaller posets such that the linear extension numbers of the larger posets can be understood in terms of the linear extension numbers of the smaller posets.
\\

Given posets $(P, \leq_P)$ and $(Q, \leq_Q)$, the \textit{disjoint sum} of $P$ and $Q$, written $P+Q$, is the poset on the base set $P \cup Q$, where $x\leq_{P+Q}y$ if and only if one of the following holds:
\begin{enumerate}
    \item $x,y \in P$ and $x\leq_P y$
    \item $x,y \in Q$ and $x\leq_Q y$.
\end{enumerate}
The Hasse diagram of $P+Q$ is obtained by placing the Hasse diagrams of $P$ and $Q$ side-by-side.  It is clear that $$\ext(P+Q)=\binom{|P|+|Q|}{|P|}\ext(P)\ext(Q).$$ This is the most basic way to combine two posets.
\\

The \textit{direct sum} of $(P, \leq_P)$ and $(Q, \leq_Q)$, written $P \oplus Q$, is the poset on the base set $P \cup Q$, where $x\leq_{P \oplus Q}y$ if and only if one of the following holds:
\begin{enumerate}
    \item $x,y \in P$ and $x\leq_P y$
    \item $x,y \in Q$ and $x\leq_Q y$
    \item $x \in P$ and $y \in Q$.
\end{enumerate}
The Hasse diagram of $P \oplus Q$ is obtained by placing the Hasse diagram of $Q$ above the Hasse diagram of $P$ and connecting each maximal element of $P$ to each minimal element of $Q$.  It is clear that $$\ext(P \oplus Q)=\ext(P)\ext(Q).$$  This property is useful for constructing small posets with large composite linear extension numbers.
\\

For any two incomparable elements $x$ and $y$ of a poset $P$, let $P[x<y]$ denote the poset that is obtained from $P$ by adding the relation $x<y$.  Then, as noted above,
$$\ext(P)=\ext(P[x<y])+\ext(P[y<x]).$$
In particular, suppose $M$ is a maximal element of the poset $P$ and $m$ is a minimal element of the poset $Q$.  Then we define the $(M,m)$\textit{-direct sum} of $P$ and $Q$, written $P \oplus_{M,m} Q$, to be the poset obtained from $P \oplus Q$ by deleting the relation $M<m$.  We can now compute the number of linear extensions of this new poset:
\begin{align*}
\ext(P \oplus_{M,m} Q)&=\ext((P \oplus_{M,m} Q)[M<m])+\ext((P \oplus_{M,m} Q)[m<M])\\
 &=\ext(P \oplus Q)+\ext((P\setminus \{M\})\oplus \{m\} \oplus \{M\} \oplus (Q \setminus \{m\}))\\
  &=\ext(P)\ext(Q)+\ext(P\setminus \{M\})+\ext(Q\setminus \{m\}),
\end{align*}
where $P\setminus \{x\}$ is the restriction of the poset $(P,\leq_P)$ to the set $P \setminus \{x\}$.

\section{A nice family of posets}\label{sec:nice-family}
We now use the $(M,m)$-direct sum to construct a large family of width-$2$ posets whose linear extension numbers we can control.  We will write this family as $\{P_b\}$, where $b$ ranges over the dyadic rationals in the interval $[0,1)$.  (In this section, all decimals are in base $2$.)  We construct this family recursively based on the number of digits needed to express $b$.  If $b$ requires $n$ digits (including the digit before the decimal point), then $|P_b|=n$.

\subsection{The construction}
For $n\geq 2$, each poset $P_b$ in the $n$-th stage gives rise to the posets $P_{b-2^{-n}}$ and $P_{b+2^{-n}}$ in the $n+1$-th stage.  Each of these posets is obtained from $P_b$ as the $(M,m)$-direct sum of the singleton poset $\textbf{1}$ with $P_b$ .  So each new poset looks like a copy of $P_b$ with a new minimal element added to one of the chains.
\\

For each $P_b$, we keep track of which elements are in which chain.  We will let $L_b$ and $R_b$ denote the minimal elements of the left and right chains, respectively.  We present each step of the construction ``in symbols'' and then ``in words.''
\\

The $n=1$ stage consists of just the poset $P_0$, which we define to be the singleton
$$P_0=\{R_0\}.$$
Note that there is no $L_0$ since $P_0$ contains only one element.
\\

The $n=2$ stage consists of just the poset $P_{0.1}$, which we define to be
$$P_{0.1}=\{L_{0.1}, R_{0.1}\}, \quad \text{with} \quad L_{0.1}<R_{0.1}.$$
Note that even though $P_{0.1}$ is itself a chain, we have identified the two non-maximal chains $\{L_{0.1}\}$ and $\{R_{0.1}\}$.
\\

We now explain the recursive part of the construction.  For $n \geq 2$, fix any $P_b$ in the $n$-th stage of the construction.  Define
$$P_{b-2^{-n}}=\{x\} \oplus_{x, L_b} P_b,$$
and re-label $x$ as $R_{b-2^{-n}}$ and $L_b$ as $L_{b-2^{-n}}$.  In words: we add a new minimal element to $P_b$ below $R_b$ which is smaller than everything except $L_b$.
\\

In order to construct $P_{b+2^{-n}}$, we consider two cases for $b$.  If $b$ is not of the form $2^{1-n}$, then (just as before) define
$$P_{b+2^{-n}}=\{x\} \oplus_{x, R_b} P_b,$$
and re-label $x$ as $L_{b+2^{-n}}$ and $R_b$ as $R_{b+2^{-n}}$.  In words: we add a new minimal element to $P_b$ below $L_b$ which is smaller than everything except $R_b$.  If $b=2^{1-n}$, then this construction does not work because $R_b$ is not minimal and the $(x, R_b)$-direct sum is not defined.  In this case, we define the analogous construction manually: let
$$P_{b+2^{-n}}=\{x\} \oplus P_b,$$
and re-label $x$ as $L_{b+2^{-n}}$ and $R_b$ as $R_{b+2^{-n}}$.  In words: we try to add a new minimal element to $P_b$ below $L_b$ which is smaller than everything except $R_b$, but this new element is automatically smaller than $R_b$ because $R_b$ was not minimal.  Figure~\ref{fig:big} shows the first few stages of this construction.
\\

\begin{figure}[p]
\begin{center}
\includegraphics[height=17.5cm]{bigfigure7.pdf}
\end{center}
\caption{The first $5$ stages of the construction of the posets $\{P_b\}$ (above) and the corresponding section of the Stern-Brocot tree (below).  Each $\ext(P_b)$ is written as the difference of the denominator and numerator of the corresponding entry in the Stern-Brocot tree.  We indicate where $P_1$ would fit if it were defined.  In order to emphasize the width-$2$ nature of these posets, we include more edges than are, strictly speaking, required for the Hasse diagrams.}
\label{fig:big}
\end{figure}

We remark that $P_{0.1}$ can be obtained from $P_0$ as
$$P_{0.1}=\{x\} \oplus P_0,$$
after re-labeling $x$ as $L_{0.1}$ and $R_0$ as $R_{0.1}$.  We included $P_{0.1}$ in the base case because $P_0$ does not give rise to a second poset in the $n=2$ stage.

\subsection{Tree structure}
The following lemma relates the linear extension numbers of posets in later stages to the linear extension numbers of posets in earlier stages.

\begin{proposition}\label{prop:recursion}
Let $b$ be a dyadic rational in the range $(0,1)$.  If $P_b$ first appears in the $n$-th stage, i.e., $b=0.b_2b_3\cdots b_{n-1}1$, then
$$\ext(P_b)=\ext(P_{b-2^{1-n}})+\ext(P_{b+2^{1-n}}),$$
where we convene to let $\ext(P_1)=0$.
\end{proposition}

It is easy to convince oneself of the truth of this statement by scrutinizing Figure~\ref{fig:big}: for a given poset $P_b$, consider the two cases that arise from adding a relation between $L_b$ and $R_b$, then follow the recurrence ``up'' the tree by eliminating new minimal elements one-by-one.  For the sake of completeness, we provide a technical, symbol-heavy proof as well.

\begin{proof}
Consider the following four cases for $b$:
\begin{enumerate}
    \item $b=0.11\cdots 1=1-2^{1-n}$.
     \item $b=0.b_2 \cdots b_{n-k-1}011 \cdots 1$ (where $b$ ends with $k\geq 2$ $1$'s, preceded by a $0$).
     \item $b=0.00\cdots 01=2^{1-n}$.
    \item $b=0.b_2 \cdots b_{n-k-2}100\cdots 01$ (where $b$ ends with a $1$, preceded by exactly $1 \leq k \leq n-3$ $0$'s).
\end{enumerate}

First, consider $b=0.1\cdots 1=1-2^{1-n}$.  By easy induction on $n$, we have
$$P_{1-2^{1-n}}=\{a_1\} \oplus \cdots \oplus \{a_n\},$$
which immediately implies that
$$\ext(P_{1-2^{1-n}})=1$$
for all $n \geq 1$.  Finally, for all $n \geq 2$, we have
$$\ext(P_{b-2^{1-n}})+\ext(P_{b+2^{1-n}})=\ext(P_{1-2^{2-n}})+\ext(P_1)=1+0=\ext(P_b),$$
as desired.
\\

Second, consider $b=0.b_2 \cdots b_{n-k-1}011 \cdots 1$ (where $b$ ends with $k\geq 2$ $1$'s, preceded by a $0$).  We proceed by induction on $k$.  We begin with the base case $k=2$, i.e., $b=0.b_2 \cdots b_{n-3}011$.  Let $b''=b+2^{1-n}=0.b_2 \cdots b_{n-3}1$.  In the recursive construction, $P_{b''}$ gives rise to $P_{b'}$, where $b'=b''-2^{2-n}=0.b_2 \cdots b_{n-3}01$, via
$$P_{b'}=\{R_{b'}\} \oplus_{R_{b'}, L_{b''}} P_{b''}.$$
In turn, $P_{b'}$ gives rise to $P_b$, where $b=b'+2^{1-n}$, via
$$P_{b}=\{L_{b}\} \oplus_{L_{b}, R_{b'}} P_{b'}.$$
We now compute
\begin{align*}
    \ext(P_b) &=\ext(\{L_{b}\})\ext(P_{b'})+\ext(\emptyset)\ext(P_{b'} \setminus \{R_{b'}\})\\
     &=\ext(P_{b'})+\ext(P_{b''})\\
     &=\ext(P_{b-2^{1-n}})+\ext(P_{b+2^{1-n}}),
\end{align*}
as desired.  Next, we perform the induction step.  Consider $b=0.b_2 \cdots b_{n-k-1}011 \cdots 1$, where now $k \geq 3$.  Let $b'=b-2^{1-n}$ (deleting the last $1$ in the decimal expansion of $b$) and $b''=b'-2^{2-n}$ (deleting the penultimate $1$, as well).  As before,
$$P_{b'}=\{L_{b'}\} \oplus_{L_{b'}, R_{b''}} P_{b''}$$
gives
$$\ext(P_{b'})=\ext(P_{b''})+\ext(P_{b''}\setminus \{R_{b''}\}).$$
By the induction hypothesis, we also have
$$\ext(P_{b'})=\ext(P_{b''})+\ext(P_{b'+2^{2-n}}),$$
so that
\begin{equation}\label{eq:tree}
    \ext(P_{b''}\setminus \{R_{b''}\})=\ext(P_{b'+2^{2-n}}).
\end{equation}
Next, consider
$$P_{b}=\{L_{b}\} \oplus_{L_{b}, R_{b'}} P_{b'},$$
which gives
$$\ext(P_{b})=\ext(P_{b'})+\ext(P_{b'}\setminus \{R_{b'}\}).$$
Recall that in $P_{b'}$, the element $L_{b'}$ is smaller than everything except for $R_{b'}$ (which is identified with $R_{b''}$ in $P_{b''}$).  Thus, we see that
$$P_{b'}\setminus \{R_{b'}\}=\{L_{b'}\} \oplus (P_{b''}\setminus \{R_{b''}\}),$$
which of course means that
$$\ext(P_{b'}\setminus \{R_{b'}\})=\ext(P_{b''}\setminus \{R_{b''}\}).$$
Finally, substituting from \eqref{eq:tree} gives
$$\ext(P_{b})=\ext(P_{b'})+\ext(P_{b'+2^{2-n}}).$$
This is the desired expression once one recalls that $b'=b-2^{1-n}$ and $b'+2^{2-n}=b+2^{1-n}$.
\\

The remaining two cases are completely analogous to the second case.
\end{proof}

\section{From posets to the Euclidean algorithm and back}\label{sec:correspondence}

At this point, the reader may recognize the structure of the (left half of the) Stern-Brocot tree in Figure~\ref{fig:big}.  We will exploit this connection in order to apply number-theoretic results about the Stern-Brocot tree to our problem about linear extension numbers.

\subsection{The appearance of denominators in the Stern-Brocot tree}
The Stern-Brocot tree is a complete binary plane tree that contains each positive rational exactly once: the rationals less than $1$ appear on the left half, and the rationals greater than $1$ appear on the right half.  (The entry $\frac{1}{0}$, representing infinity, also appears in the right half.)  The Stern-Brocot tree is closely related to the Calkin-Wilf tree, Stern's diatomic array, and Farey sequences: for instance, the Calkin-Wilf tree is obtained by permuting the entries in each layer of the Stern-Brocot tree \cite{calkin2000recounting}, and the denominators of the first $\ell$ layers of the left half of the Stern-Brocot tree are exactly the elements of the $\ell$-th line of Stern's diatomic array \cite{lehmer1929stern}.
\\

The entries of the left half of the Stern-Brocot tree can be parameterized in the obvious way by $\left\{ \frac{s_b}{t_b} \right\}$, where $b$ ranges over all dyadic rationals in $[0,1]$.  More precisely, the entries in the $\ell$-th layer are parametrized from left to right by the dyadic rationals in $[0,1]$ that require exactly $\ell$ digits in their decimal expansions.  This parameterization can be extended in the natural way to the entire Stern-Brocot tree by letting $b$ range over the dyadic rationals in $[0,2]$.
\\

It is well known \cite{aiylam2017generalized} that each layer of the Stern-Brocot tree is obtained by taking mediants of all consecutive terms of the entries in earlier layers; moreover, these mediants are already reduced fractions.  In other words, both the numerators and denominators in the Stern-Brocot tree individually follow the recursive structure of Proposition~\ref{prop:recursion}.  Since $\ext(P_0)=t_0-s_0$ and $\ext(P_1)=t_1-s_1$ (as defined), it then follows that $\ext(P_b)=t_b-s_b$ for all dyadic rationals $b$ in $[0,1]$.
\\

By the definition of the Calkin-Wilf tree (see \cite{calkin2000recounting}), each entry $\frac{s}{t}$ in the $\ell$-th layer has $\frac{s}{s+t}$ as its left child in the $\ell+1$-th layer.  Recall that the Calkin-Wilf and Stern-Brocot trees differ only in the ordering of elements within each layer.  These facts together imply that for every denominator $d$ in the $\ell$-th layer of the Stern-Brocot tree, there is some $\frac{s_b}{t_b}$ (with $s_b<t_b$, i.e., in the left half) in the $\ell+1$-th layer such that $t_b-s_b=d$.  In particular, every denominator $d$ in the $\ell-1$-th layer of the Stern-Brocot tree appears as the number of linear extensions of some $P_b$ on $\ell$ elements.
\\

It is also known \cite{lehmer1929stern} that any relatively prime positive integers $n,d$ appear consecutively somewhere in Stern's diatomic array.  In particular, the entries $n,d$ appear consecutively in the $\ell-1$-th line of Stern's diatomic array, where $\ell$ equals the sum of the quotients that appear in the expansion of $\frac{n}{d}$ as a continued fraction.  Recall that the sum of the quotients in the continued fraction expansion of $\frac{n}{d}$ is simply the sum of the quotients obtained in running the Euclidean algorithm on the pair $(n,d)$.  We summarize all of these observations in the following proposition.

\begin{proposition}\label{prop:connection}
Let $d<n$ be relatively prime positive integers, and let $\ell$ denote the sum of the quotients obtained when the Euclidean algorithm is run on the pair $(n,d)$.  Then there is some $P_b$ on at most $\ell$ elements with exactly $n$ linear extensions.
\end{proposition}

\subsection{Connecting Theorems \ref{thm:small} and \ref{thm:number-theoretic}}

We now use the ideas of the previous subsection to show how Theorem~\ref{thm:number-theoretic} (on sums of quotients in the Euclidean algorithm) implies Theorem~\ref{thm:small} (on small linear extension numbers).

\begin{proof}[Proof (Theorem~\ref{thm:number-theoretic} implies Theorem~\ref{thm:small})]
Recall that Theorem~\ref{thm:number-theoretic} asserts the existence of an absolute constant $c$ such that for every $n \geq 2$, there exists some $1 \leq d \leq n$ such that the sum of the quotients obtained in running the Euclidean algorithm on $(n,d)$ is at most $c \frac{n}{\phi(n)}\log n \log \log n$.  When $n=p$ is prime, we have $\frac{p}{\phi(p)}=\frac{p}{p-1}\leq 2$, so in this case the sum of quotients is at most $2c \log p \log \log p$.  Next, Proposition~\ref{prop:connection} tells us that for every prime $p$, there exists a poset $P_b$ of size at most $2c \log p \log \log p$ that has exactly $p$ linear extensions.
\\

Let $m \geq 2$ have prime factorization $m=p_1\ldots p_r$ (written with multiplicity).  For each $p_j$, let $P_{b_j}$ be the poset with exactly $p_j$ linear extensions from the previous paragraph.  Then the direct sum of the $p_j$'s has exactly $m$ linear extensions and size at most
$$\sum_{j=1}^r 2c \log p_j \log \log p_j \leq 2c\log \log m \sum_{j=1}^r \log p_j=2c\log \log m \log m.$$

Now, fix any positive integer $n$.  Every positive integer $m$ with $$2c\log m \log \log m\leq n$$ is obtained as the number of linear extensions of some poset on at most $n$ elements.  Moreover, because the sets $\{\LE(n)\}$ form an ascending chain (by taking the direct sum with a singleton), there is in fact an $n$-element poset that achieves each of these linear extension numbers $m$.  Finally, for $m \leq \exp(\frac{1}{4c} \frac{n}{\log n})$, we compute:
\begin{align*}
    2c\log m \log \log m &\leq 2c \left( \frac{1}{4c} \frac{n}{\log n} \right)\left( \log n-\log \log n-\log(4c) \right)\\
     &=\frac{n}{2}+O\left( \frac{n \log \log n}{\log n} \right).
\end{align*}
This quantity is smaller than $n$ for sufficiently large $n$, which suffices to establish Theorem~\ref{thm:small}.
\end{proof}

\section{Bounding the sum of quotients}\label{sec:proofs}
\subsection{Basic number-theoretic notions}\label{sec:basic-number-theory}
Given positive integers $n$ and $d$, the \emph{Euclidean algorithm} is defined as follows: let $a_0 = n$ and $a_1 = d$, then, for $k\ge 1$, recursively define $a_{k + 1}$ to be the remainder when $a_{k - 1}$ is divided by $a_k$, unless $a_k = 0$, in which case the algorithm terminates. As long as $a_{k+1}$ is defined, let $q_k$ be the unique positive integer which satisfies
\[a_{k - 1} = q_ka_k + a_{k + 1}.\]
It is well known that the Euclidean algorithm always terminates with some $a_\ell = 0$.  We now introduce some notation.
\begin{itemize}
    \item Let $\textbf{a}(n, d)$ denote the \textit{Euclidean sequence} $a_0, \ldots, a_{\ell - 1}$ of nonzero values generated by the Euclidean algorithm applied to $n$ and $d$.
    \item Let $\textbf{q}(n, d)$ denote the \textit{quotient sequence} $q_1, \ldots, q_{\ell - 1}$ generated by the Euclidean algorithm applied to $n$ and $d$. Note that $\textbf{q}(n, d)$ can be computed directly from $\textbf{a}(n, d)$ via $q_i=\left\lfloor\frac{a_{i-1}}{a_i}\right\rfloor$.
    \item Let $s(n, d)$ denote the sum of the elements of the sequence $\textbf{q}(n, d)$.
    \item For integers $1\le m\le n$, let $r(n, m)$ denote the total number of occurrences of $m$ in the sequences $\textbf{q}(n, d)$ as $d$ ranges over the elements of $\{1, \ldots, n - 1\}$ that are relatively prime to $n$.
\end{itemize}

Next, we define the function $X: \mathbb{N}^\ast\rightarrow\mathbb{N}$ by the following recursive rules:
\begin{align*}
X() &= 1,\\
X(q) &= q,\\
X(q_1, \ldots, q_t) &= q_1X(q_2, \ldots, q_t) + X(q_3, \ldots, q_t).
\end{align*}
We can easily see that, for any integers $q_1, \ldots, q_t$ all at least $1$, the following statements are equivalent: $\textbf{q}(n, d)=(q_1, \ldots, q_t)$ and $\textbf{a}(n, d)$ ends in $a_t=1$; and $n = X(q_1, \ldots, q_t)$ and $d = X(q_2, \ldots, q_t)$.  The pair $(n, d)$ can be used to reconstruct $(q_1, \ldots, q_t)$, so the map $\chi: \mathbb{N}^\ast\rightarrow\mathbb{N}^2$ defined via
\[\chi(q_1, \ldots, q_t) = (X(q_1, \ldots, q_t), X(q_2, \ldots, q_t))\]
is injective. It is well-known (see, e.g., the continued fractions interpretation in \cite[Chapter~4, Identity~109]{benjamin2003proofs}) that $X(q_1, \ldots, q_t) = X(q_t, \ldots, q_1)$. Thus, the map $\chi': \mathbb{N}^\ast\rightarrow\mathbb{N}^2$ defined by
\[\chi'(q_1, \ldots, q_t) = (X(q_1, \ldots, q_t), X(q_1, \ldots, q_{t - 1}))\]
is also injective. Note that the images of both $\chi$ and $\chi'$ consist of pairs of relatively prime positive integers.  Also, if $(y,x)$ is in the image of $\chi'$, then $y \geq x$.

\subsection{Proofs}\label{sec:main}
Before we prove Theorem~\ref{thm:number-theoretic} (on sums of quotients), we require a bound on the number of occurrences of large integers in the Euclidean sequences that start with $n$.
\begin{lemma}\label{lem:M-bound}
Fix any constant $K$. Then there is a constant $C = C(K)$ such that if $n\ge 2$ and $1\le M\le K(\log n)^2$, then
\[\sum_{m = M}^n r(n, m)\le\frac{Cn\log n}{M}.\]
\end{lemma}
\begin{proof}
Fix $n$ and $M$. Note that
\[\sum_{m = M}^n r(n, m)\]
counts the triples of positive integers $(a, b, d)$ where $\gcd(n, d) = 1$, $b$ and $a$ appear consecutively (in that order) in the Euclidean sequence $\textbf{a}(n, d)$, and $\frac{b}{a}\ge M$. Let $\mathcal{T}$ denote the set of these triples.  We will count the elements of $\mathcal{T}$ by looking at each possible pair $(a,b)$ separately and counting the values of $d$ such that $(a,b,d) \in \mathcal{T}$.  Note that any such pair $(a,b)$ satisfies $1 \leq a,b \leq n$ and $\frac{b}{a} \geq M$.  Moreover, $\gcd(a,b)=1$ since $\gcd(n,d)=1$.
\\

Fix a pair $(a, b)$ as described in the previous paragraph.  The choices for $d$ such that $(a, b, d)\in\mathcal{T}$ correspond exactly to the Euclidean sequences beginning with $n$ that contain $b$ and $a$ in consecutive positions. Write $b=a_t$ and $a=a_{t+1}$, for some $t \geq 0$.  Note that such a Euclidean sequence is completely determined past $b, a$ because it is simply the Euclidean sequence $\textbf{a}(b, a)$. Thus, each choice for $d$ corresponds to a choice for the Euclidean sequence between $n$ and $b$, which is in turn equivalent to choosing a sequence of quotients $q_1, \ldots, q_t$ within this range. Indeed, given such a sequence $q_1, \ldots, q_t$ with $t>0$, we can reconstruct the earlier terms of the Euclidean sequence by working backwards from $a=a_{t+1},b=a_t$ as follows:
\begin{align*}
    a_{t-1}&=q_tb+a\\
    a_{t-2}&=q_{t-1}(q_tb+a)+b\\
    \vdots \quad & \quad \quad \quad \vdots\\
    (d=)a_1&=q_2(\cdots)+(\cdots)\\
    (n=)a_0&=q_1(\cdots)+(\cdots).
\end{align*}
More explicitly,
$$a_i=X(q_{i+1},\ldots, q_t)b+X(q_{i+1}, \ldots, q_{t-1})a,$$
and, in particular, setting $i=0$ gives
\[n = X(q_1, \ldots, q_t)b + X(q_1, \ldots, q_{t - 1})a.\]
Note that $t = 0$ corresponds to the special case $n = b$ and $d = a$.
\\

Recall from Section~\ref{sec:basic-number-theory} that the map
\[\chi': (q_1, \ldots, q_t)\mapsto (X(q_1, \ldots, q_t), X(q_1, \ldots, q_{t - 1}))\]
is injective and that its range consists of pairs of relatively prime positive integers $(y,x)$, where $y \geq x$.  Thus, excluding the $t=0$ case, the number of choices for $d$ is at most than the number of ordered pairs $(y,x)\in\mathbb{N}^2$ such that
\[n = yb + xa,\]
subject to the additional constraints $\gcd(x, y) = 1$ and $y\ge x$.
\\

Taken together, all of the $t=0$ cases (which require $b=n$ and hence also $a \leq \frac{n}{M}$) contribute at most $\frac{n}{M}$ triples to $\mathcal{T}$.  So, putting everything together, we see that the quantity $\sum_{m = M}^n r(n, m)$ is at most $\frac{n}{M}$ greater than the size of the set
\[\{(a, b, x, y): 1\le a, b, x, y\le n; \frac{b}{a}\ge M; y\ge x; \gcd(a, b) = \gcd(x, y) = 1; n = yb + xa\}.\]
Note that the last condition is equivalent to
\begin{equation}\label{eq:linear}
(y - x)b + x(a + b) = n.
\end{equation}
We now bound the number of solutions to \eqref{eq:linear} (subject, of course, to the other conditions) by conditioning on the size of $b$.
\\

First, consider $b\le\sqrt{n\log n}$. We bound the number of solutions $(y,x)$ to \eqref{eq:linear} for each fixed pair $(a,b)$ with $a\le\frac{b}{M}$, then we sum over these values as $a$ and $b$ vary.  Fix a solution $(x_0,y_0)$ if one exists, and let $(x,y)$ be any solution.  Then $$(y_0-x_0)b+x_0(a+b)=n=(y-x)b+x(a+b),$$
so $$(x_0-x)(a+b)=(y-x-y_0+x_0)b.$$
Since $\gcd(b,a+b)=\gcd(b,a)=1$, we conclude that $x_0-x$ is divisible by $b$, i.e., $$x=x_0+bt$$ for some integer $t$.  Plugging in $x_0-x=-bt$ gives $$y-x=(y_0-x_0)-(a+b)t.$$  Since $0 \leq y-x <\frac{n}{b}$, there are at most $1+\frac{n}{b(a+b)}$ possible values for $t$.  Summing over $a$ and using $\frac{n}{b(a+b)}<\frac{n}{b^2}$, we get that there are at most $$\frac{b}{M}+\frac{n}{bM}$$ triples $(a,x,y)$ for each value of $b$.  Then summing over $b\leq \sqrt{n\log n}$ shows that there are at most
\[\frac{n\log n}{2M} + O\left(\frac{n\log\log n}{M}\right)\]
possible quadruples $(a,b,x,y)$ for $b$ in the desired range.
\\

Second, consider $b > \sqrt{n\log n}$. This time, we choose the pair $(y,x)$ first and then bound the number of possible pairs $(a, b)$. Fix any pair of relatively prime positive integers $(y, x)$ satisfying the above inequalities. We now count the possible pairs $(a, b)$.  The argument from the previous case shows that if $(a', b')$ is a solution to $yb+xa=n$, then every solution is expressible as $(a,b)=(a'+ys,b'-xs)$ for some integer $s$.  The inequality $\frac{b}{a}\ge M$ gives
\[0<(My + x)a\le yb + xa = n,\]
which implies that there are at most $$1+\frac{n}{y(My + x)}<1+\frac{n}{My^2}$$ possible values of $s$, i.e., solutions $(a,b)$.  We now sum over possible pairs $(y,x)$.  Note that \eqref{eq:linear}, in light of the bound on $b$, immediately gives both $y - x < \sqrt{\frac{n}{\log n}}$ and $x < \sqrt{\frac{n}{\log n}}$.  We compute that the number of solutions $(a,b,x,y)$ is bounded above by
\begin{align*}
    \sum_{x=1}^{\sqrt{\frac{n}{\log n}}}\sum_{y=x}^{x+\sqrt{\frac{n}{\log n}}}\left(1+\frac{n}{My^2} \right) &\leq \frac{n}{\log n}+ \frac{n}{M}\sum_{y=1}^{2\sqrt{\frac{n}{\log n}}}\sum_{x=1}^{y}\frac{1}{y^2}\\
     &\leq \frac{n}{\log n}+ \frac{n}{M}\sum_{y=1}^{2\sqrt{\frac{n}{\log n}}}\frac{1}{y}\\
     &=\frac{n}{\log n}+ \frac{n\log n}{2M}+O\left(\frac{n \log\log n}{M}\right).
\end{align*}
Combining the upper bounds from the above two cases for $b$ (and absorbing the $t=0$ case into the error term) gives a total of
\[\frac{n}{\log n}+ \frac{n\log n}{M} + O\left(\frac{n\log\log n}{M}\right).\]
Since $M\le K(\log n)^2$, this bound yields the desired result.
\end{proof}
We are ready to prove the main result of this section. The following is a restatement of Theorem~\ref{thm:number-theoretic} in the language of the previous subsection.

\begin{theorem}
There is an absolute constant $c$ such that the following holds: for every $n\ge 2$, there exists some $1\le d\le n - 1$ relatively prime to $n$ such that $s(n, d)\le c\frac{n}{\phi(n)}\log n\log\log n$.
\end{theorem}
\begin{proof}
Fix some $K$ and $C(K)$ as in Lemma~\ref{lem:M-bound}. Note that $10C\frac{n}{\phi(n)}\log n < K(\log n)^2$ for sufficiently large $n$; this follows from, for instance, the well-known fact \cite{hardy1979introduction} that
\begin{equation}\label{eq:euler-mascheroni}
    \liminf_{n\rightarrow\infty}\frac{\phi(n)}{\frac{n}{\log\log n}} = e^{-\gamma},
\end{equation}
where $\gamma$ is the Euler-Mascheroni constant. We now restrict our attention to this case of sufficiently large $n$, since the constant in the statement of the theorem can be adjusted to accommodate small $n$.
\\

Setting $M=10C\frac{n}{\phi(n)}\log n$ in Lemma~\ref{lem:M-bound} gives
\[\sum_{m = 10C\frac{n}{\phi(n)}\log n}^n r(n, m)\le\frac{\phi(n)}{10}.\]
Let $\mathcal{D}$ be the set of all $d\in\{1, \ldots, n - 1\}$ such that $\gcd(n, d) = 1$ and the elements of $\textbf{q}(n, d)$ are all at most $10C\frac{n}{\phi(n)}\log n$. Then we see that $|\mathcal{D}|\ge 0.9\phi(n)$.
\\

We can now compute:
\begin{align*}
\sum_{d\in\mathcal{D}} s(n, d)&\le\sum_{m = 1}^{10C\frac{n}{\phi(n)}\log n} mr(n, m)\\
&=\sum_{t = 1}^{10C\frac{n}{\phi(n)}\log n}\sum_{m = t}^{10C\frac{n}{\phi(n)}\log n} r(n, m)\\
&\le\sum_{t = 1}^{10C\frac{n}{\phi(n)}\log n}\frac{Cn\log n}{t}\\
&= Cn\log n\log\log n + O\left(n\log n\log\left(10C\frac{n}{\phi(n)}\right)
\right)\\
&= Cn\log n\log\log n + O\left(n\log n\log \log \log n \right),
\end{align*}
where we used Lemma~\ref{lem:M-bound} in the third line and \eqref{eq:euler-mascheroni} in the fifth line. Since $|\mathcal{D}|\ge 0.9\phi(n)$, we also have
\begin{align*}\min_{d\in\mathcal{D}} s(n, d)&\le\frac{C}{0.9}\frac{n}{\phi(n)}\log n\log\log n + O\left(\frac{n}{\phi(n)}\log n\log\log\log n\right),
\end{align*}
and the result immediately follows.
\end{proof}

\section{Large linear extension numbers}\label{sec:large}

The previous three sections have been devoted to showing that $\LE(n)$ contains many small elements.  In this section, we show that $\LE(n)$ does not contain very many large elements.  We begin with a straightforward lemma about posets whose Hasse diagrams (viewed as graphs) are connected.

\begin{lemma}\label{lem:connected}
Let $P$ be an $n$-element poset that cannot be expressed as the disjoint sum of nonempty posets.  Then $\ext(P)\leq (n-1)!$.
\end{lemma}

\begin{proof}
Note that the Hasse diagram of $P$, viewed as a graph, is connected.  Choose a spanning tree of this graph, and delete all other edges; the remaining graph is the Hasse diagram of some poset $P'$.  Clearly, $\ext(P)\leq \ext(P')$, so if suffices to show that $\ext(P')\leq (n-1)!$.
\\

We now proceed by induction on $n$, where the base case $n=1$ is trivial.  Choose an element $x \in P'$ that is a leaf of its Hasse diagram, so that the Hasse diagram of $P' \setminus \{x\}$ is connected.  By hypothesis, $\ext(P' \setminus \{x\}) \leq (n-2)!$.  Let $Q=(P' \setminus \{x\})+\{x\}$ be obtained from $P'$ by ``severing'' the element $x$ from the rest of the poset.  Then $$\ext(Q)=\binom{n}{1} \ext(P' \setminus \{x\}) \ext(\{x\}) \leq n(n-2)!.$$

Without loss of generality, $P'=Q[x<y]$ for some $y \in Q$.  (The case where the added relation is $x>y$ is completely symmetrical.)  We claim that in a uniformly chosen random linear extension of $Q$, the probability that $x<y$ is at most $\frac{n-1}{n}$.  To see this, consider all linear extensions with a fixed relative ordering of the elements other than $x$.  Even if $y$ is the largest of these $n-1$ elements, there is always at least $1$ way to insert $x$ (out of $n$ total ways) so that $x>y$.  Thus, $$\ext(P')\leq \left( \frac{n-1}{n} \right) \ext(Q) \leq (n-1)!,$$ as desired.
\end{proof}

We remark that equality is achieved for the posets $\{x_1\} \oplus (\{x_2\}+\cdots+\{x_n\})$ and $(\{x_2\}+\cdots+\{x_n\}) \oplus \{x_1\}$, the direct sum of a singleton and an antichain of length $n-1$.  The reader can easily verify from the proof of the lemma that these are the only equality cases.
\\

We will also make use of the following more general statement, which reduces to Lemma \ref{lem:connected} when $m=0$.

\begin{lemma}\label{lem:leupperbound}
Let $P=P_1+P_2+\cdots+P_k$, where no $P_i$ can be expressed as the disjoint sum of two smaller posets, be an $n$-element poset.  Suppose $P_k$ is the largest component and $P_1=P_2=\cdots=P_m=\textbf{1}$ are the only singletons among $P_1, \ldots, P_{k-1}$.  Then $\ext(P)\leq \frac{n!}{n-m}$.
\end{lemma}

\begin{proof}
We will prove that the $(n-m)$-element poset $Q=P_{m+1}+\cdots+P_k$ satisfies $\ext(Q) \leq (n-m-1)!$, then the statement follows from $$\ext(P)=(n-m+1)(n-m+2)\cdots (n) \ext(Q)\leq \frac{n!}{n-m}.$$

We proceed by induction on $k-m$, where the base case $k-m=1$ is Lemma \ref{lem:connected}.  For the induction step, we compute
\begin{align*}
\ext(Q) &=\binom{n-m}{|P_k|} \ext(P_{m+1}+\cdots+P_{k-1}) \ext(P_k)\\
 &\leq \binom{n-m}{|P_k|} \left( \frac{(n-m-|P_k|)!}{n-m-|P_k|} \right) (|P_k|-1)!\\
 &=\frac{(n-m)!}{|P_k|(n-m-|P_k|)},
\end{align*}
where the second line used the induction hypothesis.
\\

If $|P_k|=1$, then it must be the case that $P$ is antichain and $m=n-1$, so the statement is true by direct computation.  Otherwise, both $|P_k|\geq 2$ and $n-m-|P_k| \geq 2$ (since $Q \setminus P_k$ still has at least one connected component, which by construction must contain at least $2$ elements).  Thus, $|P_k|(n-m-|P_k|) \geq |P_k|+(n-m-|P_k|)=n-m$ establishes the claim and completes the proof.
\end{proof}

We now use these lemmas to obtain restrictions on possible large linear extension numbers.  In particular, we show that for near the top of the range $[1,n!]$,  $\LE(n)$ looks like a dilation of the large values of some suitable $\LE(n-r)$.

\begin{theorem}\label{thm:big}
For integers $r<n$, we have
$$\LE(n) \cap \left(\frac{n!}{r+1}, n!\right]=\left\{\left( \frac{n!}{r!}\right) \ell: \ell \in \LE(r) \cap \left(\frac{r!}{r+1}, r!\right] \right\}$$
as an equality of sets.
\end{theorem}

\begin{proof}
To see the first inclusion, let $P$ be any $n$-element poset satisfying $\ext(P)>\frac{n!}{r+1}$.  Decompose $P=P_1+P_2+\cdots+P_k$ and define $m$ as in Lemma \ref{lem:leupperbound}.  Then $\frac{n!}{n-m} \geq \ext(P) > \frac{n!}{r+1}$ implies that $r+1> n-m$ and  $m \geq n-r$.  Note that $Q=P_{n-r+1}+P_{n-r+2}+\cdots+P_k$ is an $r$-element poset.  Finally, we have $$\ext(P)=(r+1)(r+2)\cdots (n) \ext(Q)=\left( \frac{n!}{r!} \right) \ext(Q),$$ as desired.
\\

To see the other inclusion, let $Q$ be any $r$-element poset.  Then let $P$ be the disjoint sum of $Q$ and an antichain of size $n-r$, so that $\ext(P)=\left( \frac{n!}{r!} \right) \ext(Q)$, as above.
\end{proof}

This theorem tells us that the elements of $\LE(n)$ become sparser as one approaches the upper bound $n!$.  Note that the $r=2$ case recovers the obvious fact that the two largest elements of $\LE(n)$ are $n!$ and $\frac{n!}{2}$.  Similarly, the $r=3$ case tells us that the next largest element is $\frac{n!}{3}$, and so on.  The bound on $\LE(n) \cap ((n-1)!, n!]$ in Theorem~\ref{thm:large}, which we restate here as a corollary, follows immediately.

\begin{corollary}\label{cor:bigbound}
For all $n \geq 8$, we have $|\LE(n) \cap ((n-1)!,n!]|<(n-3)!$.
\end{corollary}

\begin{proof}
Let $N(n)=|\LE(n) \cap ((n-1)!,n!]|$.  For any $n \geq 2$, the $r=n-1$ case of Theorem \ref{thm:big} gives:
\begin{align*}
N(n) &=\left|\LE(n-1) \cap \left(\frac{(n-1)!}{n},(n-1)!\right]\right|\\
 &=\left|\LE(n-1) \cap \left(\frac{(n-1)!}{n},(n-2)!\right]\right|+|\LE(n-1) \cap ((n-2)!,(n-1)!]|\\
 &\leq \left\lceil (n-2)!-\frac{(n-1)!}{n} \right\rceil +N(n-1)\\
 &=\left\lceil \frac{(n-2)!}{n} \right\rceil +N(n-1).
\end{align*}
This inequality, together with $N(2)=1$, lets us compute  $N(3)\leq 2$, $N(4) \leq 3$, $N(5)\leq 5$, $N(6) \leq 9$, $N(7) \leq 27$, $N(8) \leq 117<5!$.  The corollary then follows (by induction) from the observation that for all $n \geq 9$, we have
\begin{align*}
\left\lceil \frac{(n-2)!}{n} \right\rceil +(n-4)! &< \frac{(n-2)!}{n}+1+(n-4)!\\
 &=(n-3)! \left\lbrack \frac{n-2}{n}+\frac{1}{(n-3)!}+\frac{1}{n-3} \right\rbrack\\
  &<(n-3)! \left\lbrack 1-\frac{2}{n}+\frac{1}{2n} +\frac{3}{2n} \right\rbrack\\
 &<(n-3)!.
\end{align*}
\end{proof}

\section{Conclusion}\label{sec:conclusion}

Theorems~\ref{thm:small} and \ref{thm:big} show a sense in which $\LE(n)$ contains small values ``more'' than it contains very large values.  We have, however, barely scratched the surface.  We present the following list of questions, problems, and conjectures about the structure of $\LE(n)$.

\begin{question}
Let $M(n)$ denote the smallest positive integer that is not in $\LE(n)$. We have shown that $M(n)$ grows as at least $\exp\left(O\left(\frac{n}{\log n}\right)\right)$. How much can this growth rate be improved?  What upper bounds can be established?
\end{question}
Note that any improvement to Theorem~\ref{thm:number-theoretic} immediately translates into a better lower bound on $M(n)$. In particular, we conjecture that Theorem~\ref{thm:number-theoretic} can be improved to what is clearly the best possible.
\begin{conjecture}\label{conj:euclidean}
There is an absolute constant $c$ such that the following holds: for every $n\ge 2$, there exists some $1\le d\le n - 1$ relatively prime to $n$ such that $s(n,d)\leq c\log n$.
\end{conjecture}
Conjecture~\ref{conj:euclidean} implies the lower bound on our conjectured growth rate for $M(n)$.
\begin{conjecture}\label{conj:extensions}
$M(n) = \exp(\Omega(n))$.
\end{conjecture}
Recall that the posets used in the proof of Theorem~\ref{thm:small} are all width-$2$.  Inspired by this fact, we conjecture that width-$2$ posets asymptotically achieve $M(n)$.
\begin{conjecture}
Let $M_2(n)$ be the smallest positive integer that is not the linear extension number of a width-$2$ poset. Then $M_2(n) = \exp(\Omega(n))$.
\end{conjecture}
It is easy to show that there are $\exp(O(n))$ width-$2$ posets of size $n$, each with $\exp(O(n))$ linear extensions.  As such, this conjecture is the best possible for width-$2$ posets (or, in fact,  any constant-width posets).
\\

We conclude with two more general problems for future research.
\begin{problem}
\textup{Estimate $|\LE(n)|$ and other statistics.}
\end{problem}
\begin{problem}
\textup{For fixed $c$, estimate the largest $R_c(n)$ such that $|\LE(n) \cap [1,R]| \geq cR$. In particular, is $R_c(n)$ quite different from $M(n)$ in terms of its asymptotic growth rate?}
\end{problem}

\bibliographystyle{plain}