Limits of randomly grown graph sequences

Abstract: Motivated in part by various sequences of graphs growing under random rules (like internet models), convergent sequences of dense graphs and their limits were introduced by Borgs, Chayes, Lovász, Sós and Vesztergombi and by Lovász and Szegedy. In this paper we use this framework to study one of the motivating class of examples, namely randomly growing graphs. We prove the (almost sure) convergence of several such randomly growing graph sequences, and determine their limit. The analysis is not always straightforward: in some cases the cut distance from a limit object can be directly estimated, in other case densities of subgraphs can be shown to converge.

\section{Introduction}

Convergent graph sequences and their limits have been studied in
connection with internet models, statistical physics, extremal graph
theory, and more. In the context of dense graphs, a rather complete
theory has emerged. One can define a notion of convergence based on
the convergence of densities of subgraphs. An appropriate notion of
distance between two graphs, called their {\it cut distance}, can be
defined, so that convergent sequences are Cauchy in this metric and
vice versa. The completion of the metric space of graphs relative to
this metric can be described, and its elements, i.e., limit objects
for convergent graph sequences, can be characterized in various ways.
To mention one of these, limit objects can be described by 2-variable
symmetric measurable functions $[0,1]^2\to[0,1]$.

The goal of this paper is study in this framework one of the
motivating class of examples, namely randomly growing graphs.
Typically, such a sequence of graphs grows by every now and then
adding a new node, and then creating new edges (between the new node
and the old ones, or between two old nodes) randomly, from some
simple distribution determined by local conditions.

We will prove the (almost sure) convergence of several such randomly
growing graph sequences, and determine their limit. This analysis is
not always straightforward: in some cases the cut distance from a
limit object can be directly estimated, in other case densities of
subgraphs can be shown to converge.

\section{Preliminaries}

In this section we summarize those notions and results concerning
convergent graph sequences and their limits which are relevant for
the rest of the paper.

\subsection{Convergent graph sequences}

For two simple graphs $F$ and $G$, ${\rm hom}(F,G)$ denotes the number of
homomorphisms (adjacency-preserving maps) from $V(F)$ to $V(G)$. We
also consider the {\it homomorphism densities}
\begin{equation}\label{HOMDENSE}
t(F,G)=\frac{{\rm hom}(F,G)}{|V(G)|^{|V(F)|}}.
\end{equation}
(Thus $t(F,G)$ is the probability that a random map of $V(F)\to V(G)$
is a homomorphism.)

A sequence $(G_n)$ of graphs is {\it convergent}, if the sequence
$t(F,G_n)$ has a limit for every simple graph $F$.

Convergent graph sequences have a limit object, which can be
represented as measurable functions \cite{LSz1}. Let $\WW$ denote the
space of all bounded measurable functions $W:~[0,1]^2\to {\mathbb R}$ such
that $W(x,y)=W(y,x)$ for all $x,y\in[0,1]$. We also define
$\WW_0=\{W\in \WW:~0\le W\le 1\}$. For every simple graph $F$ and
$W\in\WW$, we define
\[
t(F,W)=\int_{[0,1]^{V(F)}} \prod_{ij\in E(F)} W(x_i,x_j)\,dx.
\]

Every finite simple graph $G$ can be represented by a function
$W_G\in\WW_0$: Let $V(G)=\{1,\dots,n\}$. Split the interval $[0,1]$
into $n$ equal intervals $J_1,\dots,J_n$, and for $x\in J_i, y\in
J_j$ define
\[
W_G(x,y)=
  \begin{cases}
    1, & \text{if $ij\in E(G)$}, \\
    0, & \text{otherwise}.
  \end{cases}
\]
Informally, we replace the $(i,j)$ entry in the adjacency matrix of
$G$ by a square of size $(1/n)\times(1/n)$, and define the value of
the function $W_G$ on this square as the corresponding entry of the
adjacency matrix.

Graphons represent limits of convergent graph sequences in the
following sense.

\begin{theorem}\label{THM:LIMIT}
{\rm(a)} For every convergent graph sequence $(G_n)$ there is a
$W\in\WW$ such that $t(F,G_n)\to t(F,W)$ for every simple graph $F$.

\smallskip

{\rm(b)} This function $W$ is uniquely determined up to measure
preserving transformations in the following sense: For every other
limit function $W'$ there are measure preserving maps
$\phi,\psi:~[0,1]\to[0,1]$ such that
$W(\phi(x),\phi(y))=W'(\psi(x),\psi(y))$.

\smallskip

{\rm(c)} Every function $W\in\WW_0$ arises as the limit of a
convergent graph sequence.
\end{theorem}

Parts (a) and (c) of the theorem were proved in \cite{LSz1}, and part
(b), in \cite{BCL}. The proof of (c) in \cite{LSz1} depends on
$W$-random graphs, to be discussed in the next section.

We could consider any probability space $(\Omega,{\cal A}}\def\BB{{\cal B}}\def\CC{{\cal C},\pi)$ instead of
$[0,1]$, with a symmetric measurable function
$W:~\Omega\times\Omega\to [0,1]$. These structures are called {\it
graphons}. The densities $t(F,W)$ in a graphon could be defined by a
similar integral. Considering graphons would not give greater
generality, since we could always replace $(\Omega,{\cal A}}\def\BB{{\cal B}}\def\CC{{\cal C},\pi)$ by the
uniform measure on $[0,1]$. Still, it is sometimes useful to
represent the limit object by other probability spaces, as we shall
see.

\subsection{Distance of graphs}

The {\it cut-norm} introduced in \cite{FK} is defined for $W\in\WW$
by
\[
\|W\|_\square=\sup_{S,T\subset [0,1]} \Bigl|\int_{S\times T}
W(x,y)dxdy\Bigr|,
\]
where the supremum goes over measurable subsets of $[0,1]$. We define
the {\it cut-distance} of two functions in $\WW$ by
\begin{equation}
\label{d-cut-graphon}
\delta_\square(U,W)
=\inf_{\phi:\,[0,1]\to[0,1]} \|U-W^\phi\|_\square
\end{equation}
where the infimum goes over all invertible maps $\phi:~[0,1]\to[0,1]$
such that both $\phi$ and its inverse are measure preserving, and
$W^\phi$ is defined by $W^\phi(x,y)=W(\phi(x),\phi(y))$. For two
graphs $G$ and $G'$, this yields a distance
\[
\delta_\square(G,G')=\delta_\square(W_G,W_{G'}).
\]

\begin{remark}\label{RM:DIST}
(a) We call this a ``distance'' rather than a ``metric'' since two
different graphs can have distance $0$. This is the case when one
graph can be obtained from the other by replacing each node by the
same number of twins, or more generally, when both can be obtained
from a third graph this way. To get a metric, we should identify such
pairs of graphs. Similarly, to get a metric on $\WW_0$, we have to
identify functions $U,W$ for which $\delta_\square(U,W)=0$. Several
characterizations of such pairs are given in \cite{BCL}.

\smallskip

(b) There are combinatorial, but somewhat lengthy ways to define this
distance between graphs; see \cite{BCLSV1}.
\end{remark}

We can define a similar distance function based on other norms. We
shall use the $L_1$-norm
\[
\|W\|_1=\int_{[0,1]^2} |W(x,y)|\,dx\,dy,
\]
from which we can define the {\it edit distance} of two functions in
$\WW$ by
\begin{equation}
\label{d-edit-graphon}
\delta_1(U,W)
=\inf_{\phi:\,[0,1]\to[0,1]} \|U-W^\phi\|_1
\end{equation}

The following characterization of convergent graph sequences was
proved in \cite{BCLSV1} (see \cite{BCLSV2} for other
characterizations not used in this paper).

\begin{theorem}\label{THM:CONV-DIST}
A sequence of graphs $(G_n)$ is convergent if and only if it is
Cauchy in the $\delta_\square$ distance. The sequence $(G_n)$
converges to $W$ if and only if $\delta_\square(W_{G_n},W)\to 0$.
Furthermore, there is a way to label the nodes of the graphs in the
sequence so that $\|W_{G_n}-W\|_\square\to 0$.
\end{theorem}

If the graphs $G_n$ are labeled so that $\|W_{G_n}-W\|_\square\to 0$,
then
\[
\sup_{S,T}\left|\int_{S\times T} (W_{G_n}-W)\right| \to 0\qquad
(n\to\infty)
\]
In particular, it follows that
\begin{equation}\label{EQ:STW}
\int_{S\times T} (W_{G_n}-W) \to 0
\end{equation}
for every product set $S\times T$, which implies that $W_{G_n}\to W$
in the weak* topology of $L_\infty([0,1]^2)$. Convergence in the norm
$\|.\|_\square$ is, however, not equivalent to convergence in this
weak* topology, as the sequence prefix attachment graphs shows
(Section \ref{SEC:PFX-ATT}).

\subsection{$W$-random graphs and extensions}\label{SEC:WRAND}

Let $(\Omega,{\cal A}}\def\BB{{\cal B}}\def\CC{{\cal C},\pi,W)$ be a graphon. For every finite subset
$S\subseteq \Omega$ we define two graphs ${G}(S,W)$ and ${H}(S,W)$ on
$V({G}(S,W))=V({H}(S,W))=S$. In ${G}(S,W)$, we connect $i,j\in S$,
$i\not= j$ with probability $W(i,j)$. In ${H}(S,W)$, we connect
$i,j\in S$, $i\not= j$ by an edge with weight $W(i,j)$. If $W$ is
$\{0,1\}$-valued, then ${G}(S,W)={H}(S,W)$ is deterministic, and can
be considered as an ``induced subgraph''.

Let ${\mathbf S}_n$ be a random $n$-element subset of $\Omega$ (each element
of ${\mathbf S}_n$ chosen independently from the distribution $\pi$). The
graph ${G}(n,W)={G}({\mathbf S}_n,W)$ is called a {\it $W$-random} graph. The
following fact was shown in \cite{LSz1} (for the case when the
underlying probability space is the uniform distribution on $[0,1]$,
but this is no essential restriction of generality).

\begin{lemma}\label{LEM:WRAND}
With probability $1$, the sequence ${G}(n,W)$ is convergent and its
limit is represented by the function $W$.
\end{lemma}

\killtext{
It will be convenient to use the following notation.
Consider a graph $F$ whose edges are partitioned into two sets $E'$
and $E''$, called ``blue'' and ``red'', to get a two-edge-colored
graph $F'=(V,E',E'')$. We define
\begin{equation} \label{tindFW-def}
t(F',W)=\int\limits_{\Omega^V} \prod_{ij\in E'}
W(x_i,x_j)\prod_{ij\in E''} (1-W(x_i,x_j))\,\prod_{i\in
V}d\pi(x_i)\,.
\end{equation}
If all edges are blue, then $t(F',W)=t(F,W)$. If all edges are red,
then $t(F',W)=t(F,1-W)$. In general, $t(F',W)$ can be expressed as
\begin{equation}\label{SIEVE}
t(F',W) = \sum_{Y\subseteq E''} (-1)^{|E''\setminus Y|} t(F\setminus
Y, W).
\end{equation}
For a simple graph $F$, let $K_F$ denote the complete graph on
$V(F)$, where the edges in $E(F)$ are colored red, the other edges
are colored blue. Then for any two simple graphs $F$ and $G$,
$t(K_F,W_G)$ is the probability that a random map $V(F)\to V(G)$
preserves both adjacency and non-adjacency. With this notation, we
can express the probability that ${G}(n,W)$ is a given graph $F$
(with a fixed labeling of the nodes):
\[
{\sf P}({G}(n,W)=F)=t(K_F,W).
\]
}

In this paper, we will also need sequences $S_n$ of subsets of
$\Omega$ that are not random, but still ${G}(S_n,W)$ converges to
$W$. We prove and use the following sufficient condition for a
deterministic sequence $S_n$. Let $(\Omega,d)$ be a metric space, and
$\pi$, a probability measure on the Borel subsets of $(\Omega,d)$.
For every $n\ge 1$, let $S_n$ be a finite subset of $\Omega$ such
that $|S_n|\to \infty$. We say that the sequence $(S_n)$ is {\it well
distributed in a set} $X\subseteq\Omega$, if $|S_n\cap X|/|S_n|\to
\pi(X)$ as $n\to\infty$. We say that $(S_n)$ is {\it well distributed
in $(\Omega,d,\pi)$}, if for every $\varepsilon>0$ there exists a partition
$\{P_1,\dots,P_m\}$ of $\Omega$ into sets with diameter at most
$\varepsilon$ such that $S_n$ is well distributed in each $P_j$.

\begin{lemma}\label{LEM:CONV}
Let $(\Omega,d,\pi)$ be a metric space with an atom-free probability
measure. Let $W:~\Omega\times\Omega \to[0,1]$ be a symmetric
measurable function that is almost everywhere continuous. Let $S_n$
be a sequence of sets that is well distributed in $(\Omega,d,\pi)$.

\smallskip

{\rm (a)} Then $\delta_1(W_{{H}(S_n,W)},W)\to 0$ and with probability
$1$, $\delta_\square(W_{{G}(S_n,W)},W)\to 0$.

\smallskip

{\rm (b)} If $W$ is $0$-$1$ valued, then
$\delta_1(W_{{G}(S_n,W)},W)\to 0$.
\end{lemma}

\noindent It is clear that such a conclusion cannot hold without some
assumption on $W$, since a general measurable function could be
changed on the sets $S_n\times S_n$ arbitrarily without changing its
subgraph densities.

\begin{proof}
(a) First we construct a special partition of $\Omega$.

\begin{claim}\label{CLAIM:EQUI}
There exists a sequence of partitions $\QQ_n$ of $\Omega$ into
$|S_n|$ sets such that every partition class contains exactly one
point of $S_n$, the maximum diameter of partition classes tends to
$0$, and the maximum of $\bigl|\pi(Q)|S_n|-1\bigr|$ $(Q\in\QQ_n)$,
tends to $0$.
\end{claim}

Let $\varepsilon>0$. Consider a partition $\{P_1,\dots,P_m\}$ into sets with
diameter at most $\varepsilon$ such that $S_n$ is well distributed in every
$P_j$. For $n$ large enough, we have $(1-\varepsilon)\pi(P_j) \le |S_n\cap
P_j|/|S_n|\le (1+\varepsilon)\pi(P_j)$ for every $j$. Let us partition each
set $P_j$ into $|S_n\cap P_j|$ sets of equal measure, each containing
exactly one point of $S_n\cap P_j$ to get the partition $\QQ_n$. It
is clear that this sequence of partitions has the properties as
required in the Claim.

For each $n$ and $s\in S_n$, let $Q_s$ be the partition class of
$\QQ$ containing $s$. Define the function $W_n$ as follows: for
$s,s'\in S_n$ and $(x,y)\in Q_s\times Q_{s'}$, let
$W_n(x,y)=W(s,s')$. Then $W_n(x,y)\to W(x,y)$ in every point $(x,y)$
where $W$ is continuous, in particular $W_n\to W$ almost everywhere.
This implies that
\begin{equation}\label{WWN}
\|W_n-W\|_1\to 0\qquad(n\to\infty).
\end{equation}

We can view $W_n$ as $W_{H_n}$, where $H_n$ is a weighted graph with
$V(H_n)=S_n$, the weight of node $s\in S_n$ is $\pi(Q_s)$, and the
weight of  $ss'$ ($s,s'\in S$) is $W(s,s')$. Note that $H_n$ is
almost the same weighted graph as ${H}_n={H}(S_n,W)$: they are
defined on the same set of nodes, the edges have the same weights,
and the nodeweight $\pi(Q_s)$ is asymptotically $1/|S_n|$ by the
Claim. Given $\varepsilon>0$, we have $|\pi(Q_s)-1/|S_n||<\varepsilon/|S_n|$ if $n$
is large enough. Hence there is a measure preserving bijection
$\phi:~[0,1]\to[0,1]$ and a set $R\subseteq[0,1]$ of measure $\varepsilon$
such that
\[
W_{H_n}(x,y)=W^\phi_{{H}_n}(x,y) \qquad (x,y\notin R).
\]
This implies that
\begin{equation}\label{HNH}
\delta_1(H_n,{H}_n)\to 0\qquad (n\to\infty).
\end{equation}
By Lemma 4.3 from \cite{BCLSV1} it follows that with probability $1$,
\begin{equation}\label{HNG}
\delta_\square({H}(S_n,W),{G}(S_n,W))\to 0\qquad (n\to\infty).
\end{equation}
Equations \eqref{WWN}, \eqref{HNH} and \eqref{HNG} imply that
${G}(S_n,W)\to W$ with probability $1$.

(b) follows trivially, since in this case ${H}(S_n,W)={G}(S_n,W)$.
\end{proof}

We note that (b) would also follow from the result of Pikhurko
\cite{Pik} that if a graph sequence tends to a 0-1 valued function
$W$ in the $\delta_\square$ distance, then it also tends to $W$ in
the $\delta_1$ distance.

\subsection{Pixel picture}

We have seen that every finite simple graph $G$ can be represented by
a function $W_G\in\WW_0$. In fact, this representation is very useful
for creating figures representing graphs.

Every function $W\in\WW_0$ can be represented by a grayscale picture
on the unit square: the point $(x,y)$ is black if $W(x,y)=1$, it is
white if $W(x,y)=0$, and it is appropriately dark grey if
$0<W(x,y)<1$. For a graph, this picture gives a black-and-white
picture consisting of a finite number of ``pixels''. The origin is in
the upper left corner (as for a matrix). Figure \ref{FIG:PIXEL}
illustrates this construction. Note that the function associated with
a graph depends on the ordering of the nodes.

\begin{figure}[htb]
  \centering
  \includegraphics*[width=.25\textwidth,angle=180,origin=c]{Figs/petersen.eps}
  $\begin{array}[b]({cccccccccc})0&1&0&0&1&1&0&0&0&0\\
1&0&1&0&0&0&1&0&0&0\\
0&1&0&1&0&0&0&1&0&0\\
0&0&1&0&1&0&0&0&1&0\\
1&0&0&1&0&0&0&0&0&1\\
1&0&0&0&0&0&0&1&1&0\\
0&1&0&0&0&0&0&0&1&1\\
0&0&1&0&0&1&0&0&0&1\\
0&0&0&1&0&1&1&0&0&0\\
0&0&0&0&1&0&1&1&0&0
\end{array}$
  \includegraphics*[width=.25\textwidth]{Figs/petersenpix1.eps}
  \caption{The Petersen graph, its adjacency matrix, and its pixel picture}
  \label{FIG:PIXEL}
\end{figure}

\begin{example}[Half graphs]\label{EXA:HALF}
Consider the {\it half-graphs} $H_{n,n}$: they are bipartite graphs
on $2n$ nodes $\{1,\dots,n,1',\dots,n'\}$, where $i$ is connected to
$j'$ if and only if $i\le j'$. It is easy to see that this sequence
is convergent, and to guess the limit function (Figure
\ref{FIG:HALF}).
\end{example}

\begin{figure}[htb]
  \centering
  \includegraphics*[width=.3\textwidth]{Figs/half.eps}\qquad
  \includegraphics*[width=.25\textwidth]{Figs/halfpix.eps}\qquad
  \includegraphics*[width=.25\textwidth]{Figs/halflimit.eps}
  \caption{A half-graph, its pixel picture, and the limit function}
  \label{FIG:HALF}
\end{figure}

\begin{example}[Erd\H{o}s-R\'enyi random graphs]\label{EXA:RAND}
The pixel picture of a random graph is essentially grey.
\end{example}

\begin{figure}[htb]
  \centering
  \includegraphics*[height=120pt,width=120pt]{Figs/random.eps}
  \caption{A random graph with 100 nodes and with edge density 1/2}
  \label{FIG:RANDOM}
\end{figure}

The following simple example illustrates the importance of the
ordering of the nodes:

\begin{example}[Chessboard]\label{EXA:CHESS}
The $100\times 100$ chessboard in Figure \ref{FIG:CHESS} is the pixel
picture of a complete bipartite graph. It is also uniformly grey, so
one might assume that it represents a graph that is close to random.
But rearranging the rows and columns so that odd indexed columns come
first, we see that it is isomorphic to the graph represented by the
$2\times 2$ chessboard.

This example also shows that different graphs may be represented by
the same pixel picture: all complete bipartite graphs with equal
color classes have the same pixel picture. If we restrict our
attention to graphs with no twin nodes, the pixel picture will
determine the graph.
\end{example}

The pixel picture of a random graph remains uniformly grey, no matter
how you reorder the nodes.

It is easy to verify that
\[
t(F,G)=t(F,W_G)
\]
for every finite simple graph $G$.

\begin{figure}[htb]
  \centering
  \includegraphics*[height=120pt,width=120pt]{Figs/chess.eps}
  \includegraphics*[height=115pt,width=115pt]{Figs/chess2.eps}
  \caption{A chessboard and the pixel picture obtained by rearranging the
  rows and columns}\label{FIG:CHESS}
\end{figure}

\section{Convergent graph sequences and their limits}

\subsection{Growing uniform attachment graphs}\label{SEC:UNIF-ATT}

We generate a randomly growing graph sequence $G^{\rm ua}_n$ as
follows. We start with a single node. At the $n$-th iteration, a new
node is born, and then every pair of nonadjacent nodes is connected
with probability $1/n$. We call this graph sequence a {\it randomly
grown uniform attachment graph sequence}.

\begin{figure}[htb]
  \centering
  \includegraphics*[height=120pt,width=120pt]{Figs/unif.eps}
  \caption{A randomly grown uniform attachment graph with 100 nodes}
  \label{FIG:UNIF}
\end{figure}

Let us do some simple calculations. After $n$ steps, let
$\{0,1,\dots,n-1\}$ be the nodes (born in this order). The
probability that nodes $i < j$ are not connected is
$\frac{j}{j+1}\cdot \frac{j+1}{j+2}\cdots\frac{n-1}{n}= \frac{j}{n}$.
These events are independent for all pairs $(i,j)$. The expected
degree of $j$ is
\[
\sum_{i=0}^{j-1}\frac{n-j}{n} + \sum_{i=j+1}^{n-1}\frac{n-i}{n} =
\frac{n-1}{2}-\frac{j(j-1)}{2n}.
\]
The expected number of edges is
\[
\frac{1}{2}\sum_{j=0}^{n-1}
\left(\frac{n-1}{2}-\frac{j(j-1)}{2n}\right) = \frac{n^2-1}{6}.
\]

To figure out the limit function, note that the probability that
nodes $i$ and $j$ are connected is $1-\max(i,j)/n$. If $i=xn$ and
$j=yn$, then this is $1-\max(x,y)$. This motivates the following:

\begin{theorem}\label{THM:MAX}
The sequence $G^{\rm ua}_n$ tends to the limit function $1-\max(x,y)$
with probability $1$.
\end{theorem}

\begin{proof}
For a fixed $n$, the events that nodes $i$ and $j$ are connected are
independent for different $i,j$, and so by the computation above,
$G^{\rm ua}_n$ has the same distribution as ${G}(S_n,1-\max(x,y))$,
where $S_n=\{0, 1/n,\dots,(n-1)/n\}$. It is easy to see that this
sequence is well distributed in the metric space $[0,1]$ with the
uniform measure, and so the Theorem follows by Lemma \ref{LEM:CONV}.

One can get a good explicit bound on the convergence rate by
estimating the cut-distance of $W_{G^{\rm ua}_n}$ and $1-\max(x,y)$,
using the Chernoff-Hoeffding bound.
\end{proof}

\subsection{Growing ranked attachment graphs}\label{SEC:R-ATT}

This randomly growing graph sequence $G^{\rm ra}_n$ is generated
somewhat similarly. We start with a single node. At the $n$-th
iteration, a new node is born, and it is connected to node $i$ with
probability $1-i/n$. Then every pair of nonadjacent nodes is
connected with probability $2/n$. We call this graph sequence a {\it
randomly grown ranked attachment graph sequence}.

\begin{theorem}\label{THM:1-XY}
The sequence $G^{\rm ra}_n$ tends to the limit function $1-xy$ with
probability $1$.
\end{theorem}

\begin{proof}
The probability that nodes $i$ and $j$ are {\it not} connected after
the $n$-th step is
\begin{align*}
p_{ij}&=\frac{i}{j}\cdot \left(1-\frac2j\right)\cdot
\left(1-\frac2{j+1}\right)\cdots
\left(1-\frac2n\right)=\frac{i(j-2)(j-1)}{j(n-1)n}\\
&= \frac{ij}{n^2} - \frac{(3n-j)ij-2ni}{jn(n-1)} = \frac{ij}{n^2} -
q_{ij},
\end{align*}
where $0<q_{ij}<\min\{\frac3n,ij/n^2\}$. Furthermore, these events
are independent for different pairs $i,j$. Therefore, we can generate
the graph $G^{\rm ra}_n$ as follows: We generate ${G}(S_n,1-xy)$,
where $S_n=\{0, 1/n,\dots,(n-1)/n\}$, and then connect each
nonadjacent $i$ and $j$ with probability $1-p_{ij}$. Since
${G}(S_n,1-xy)$ tends to the function $1-xy$ by Lemma \ref{LEM:CONV}
and the added edges change ${G}(S_n,1-xy)$ negligibly in
$\delta_\square$ distance, the Theorem follows.
\end{proof}

\subsection{Growing prefix attachment graph}\label{SEC:PFX-ATT}

In this construction, it will be more convenient to label the nodes
starting with $1$. At the $n$-th iteration, a new node $n$ is born, a
node $z$ is selected at random, and node $n$ is connected to nodes
$1,\dots,z-1$. We denote the $n$-th graph in the sequence by
$G_n^{\rm pfx}$, and call this graph sequence a {\it randomly grown
prefix attachment graph sequence} (Figure \ref{FIG:PREFIX}).

\begin{figure}[htb]
  \centering
  \includegraphics*[height=120pt]{Figs/prefix.eps}\qquad
  \includegraphics*[height=120pt]{Figs/prefixdeg.eps}
  \caption{A randomly grown prefix attachment graph with 100 nodes,
  and the same graph with nodes ordered by their degrees.}
  \label{FIG:PREFIX}
\end{figure}

Again we start with some simple calculations. The probability that
nodes $i<j$ are connected is $\frac{j-i}{j}$ (but these events are
not independent in this case!). The expected degree of $j$ is
therefore
\[
\sum_{i=1}^{j-1} \frac{j-i}{j} + \sum_{i=j+1}^{n} \frac{i-j}{i}
=n-\frac{j}{2}+j\ln\frac{n}{j}+o(n).
\]
The expected number of edges is $n(n-1)/4$.

Looking at the picture, it seems that it tends to some function,
which we can try to figure out similarly as in the case of uniform
attachment graphs. The probability that $i$ and $j$ are connected can
be written in a symmetric form as
\[
\frac{|j-i|}{\max(i,j)}.
\]
If $i=xn$ and $j=yn$, then this is
\[
\frac{|x-y|}{\max(x,y)}.
\]

Does this mean that the function $U(x,y)=|x-y|/\max(x,y)$ is the
limit? Somewhat surprisingly, the answer is negative, which we can
see by computing triangle densities. The probability that nodes
$i<j<k$ form a triangle is
$\bigl(1-\frac{j}{k}\bigr)\bigl(1-\frac{i}{j}\bigr)$ (since if $k$ is
connected to $j$, then it is also connected to $i$). Hence the
expected number of triangles is
\[
\sum_{i<j<k}\left(1-\frac{j}{k}\right)\left(1-\frac{i}{j}\right)
\killtext{&= \sum_{j<k}\left(1-\frac{j}{k}\right)\frac{j-1}{2} =
\sum_{j<k}\left(\frac{j-1}{2}-\frac{j(j-1)}{2k}\right) \\
&=\sum_k\left(\frac{(k-1)(k-2)}{4} - \frac{(k-1)(k-2)}{6}\right)
}
= \frac{1}{6}\binom{n}{3}.
\]
Hence
\[
t(K_3,G_n) = \frac{1}{n^3}\binom{n}{3}\to \frac16.
\]
On the other hand,
\[
t(K_3,U)=\int_{[0,1]^3} \frac{|x-y|}{\max(x,y)}\cdot
\frac{|x-z|}{\max(x,z)} \cdot\frac{|y-z|}{\max(y,z)}\,dx\,dy\,dz.
\]
Since the integrand is independent of the order of the variables, we
can compute this easily:
\[
t(K_3,U)= 6 \int_{0\le x<y<z\le 1}
\left(1-\frac{x}{y}\right)\left(1-\frac{x}{z}\right)
\left(1-\frac{y}{z}\right)\,dx\,dy\,dz=\frac{5}{36}.
\]
So $U$ is not the limit of the sequence $G_n^{\rm pfx}$. On the other
hand, it is not hard to verify that
\begin{equation}\label{WEAKSTAR}
\int_{S\times T} (W_{G_n^{\rm pfx}}-W) \to 0
\end{equation}
for every $S,T\subseteq[0,1]$. Indeed, it is enough to prove this for
sets $S,T$ from a generating set of the $\sigma$-algebra of Borel
sets, e.g. rational intervals. Since there is only a countable number
of these intervals, it suffices to prove that \eqref{WEAKSTAR} holds
with probability $1$ for each fixed $S$ and $T$. It is also easy to
see that it suffices to consider the case $S=T$. For a node $j$ with
$j/n\in S$, let $X_{n,j}$ denote the number of edges $ij$ ($i<j$) in
$G_n^{\rm pfx}$ with $i/n\in S$, and let $X_n=\sum_{j/n\in S}
X_{n,j}$. Then direct computation shows that
\[
\frac1{n^2}{\sf E}(X_n)\to \int_{S\times S} U.
\]
Furthermore, the variables $X_{n,j}$ are independent for fixed $n$,
hence the Chernoff--Hoeffding Inequality implies that
${\sf P}(|X_n-{\sf E}(X_n)|>\varepsilon n^2)$ drops exponentially with $n$. Hence it
follows that $X_n/n^2\to \int_{S\times S} U$ with probability $1$.

So $W_{G_n^{\rm pfx}}\to W$ in the weak-star topology of
$L_\infty[0,1]^2$, but not in our sense. This example also shows that
had we defined convergence of a graph sequence by this convergence in
weak-star topology (after appropriate relabeling), the limit would
not be unique.

Perhaps ordering the nodes by degrees helps? The second pixel picture
in Figure \ref{FIG:PREFIX} suggests that after this reordering, the
functions $W_{G_n^{\rm pfx}}$ converge to some other continuous
function. But again this convergence is only in the weak-star
topology, not in the $\delta_\square$ distance. We'll see that no
continuous function can represent the ``right'' limit: the limit
graphon is $0$-$1$ valued, and it is uniquely determined up to
measure preserving transformations by Theorem \ref{THM:LIMIT}, which
do not change this property.

Is this graph sequence convergent at all? Our computation of the
triangle densities above can be extended to computing the density of
any subgraph, and it follows that the sequence of densities
$t(F,G_n^{\rm pfx})$ is convergent for every $n$. How to figure out
the limit?

Let us label a node born in step $k$, connected to $\{1,\dots,m\}$,
by $(k/n, m/k)\in [0,1]\times[0,1]$. Then we can observe that {\it
nodes with label $(x_1, y_1)$ and $(x_2, y_2)$ are connected if and
only if either $x_1< x_2y_2$ or $x_2< x_1y_1$.}

Consider the function $W:~[0,1]^2\times [0,1]^2\to[0,1]$, given by
\[
W^{\rm pfx}((x_1, y_1),(x_2, y_2))=
  \begin{cases}
    1, & \text{if $x_1< x_2y_2$ or $x_2< x_1y_1$}, \\
    0, & \text{otherwise}.
  \end{cases}
\]

\begin{prop}\label{PROP:PREFIX}
The prefix attachment graphs $G_n^{\rm pfx}$ tend to $W^{\rm pfx}$
with probability $1$.
\end{prop}

\begin{proof}
Let $S_n$ be the (random) set of points in $[0,1]^2$ of the form
$(i/n,z_i/i)$ where $i=1,\dots,n$ and $z_i$ is a uniformly chosen
random integer in $\{1,\dots,i\}$. Then $G_n^{\rm pfx}={G}(S_n,W^{\rm
pfx})={H}(S_n,W^{\rm pfx})$.

Furthermore, with probability $1$, the sets $S_n$ are well
distributed in $[0,1]^2$. Indeed, for $m\ge 1$, let $J_{m,k}$ denote
the interval $(k/m, (k+1)/m]$, and let ${\cal P}}\def\QQ{{\cal Q}}\def\RR{{\cal R}_m$ denote the partition
of $[0,1]^2$ into the sets $J_{m,k}\times J_{m,l}$
($k,l=0,\dots,m-1$). We want to prove that for every fixed $m$ and
$0\le k,l\le m-1$, $|S_n\cap(J_{m,k}\times J_{m,l})|/n\to 1/m^2$ as
$n\to\infty$ with probability $1$. Let
\[
X_i=
   \begin{cases}
    1, & \text{if $(i,z_i)\in J_{m,k}\times J_{m,l}$}, \\
    0, & \text{otherwise},
  \end{cases}
\]
then
\[
|S_n\cap(J_{m,k}\times J_{m,l})| =\sum_{i=1}^n X_i.
\]
We have
\[
{\sf E}(X_i)=
  \begin{cases}
     \displaystyle \frac1i\left(\Bigl\lfloor\frac{(l+1)i}{m}\Bigr\rfloor
     -\Bigl\lfloor\frac{li}{m}\Bigr\rfloor\right), &
     \text{if $\displaystyle \frac{k}m\le \frac{i}n\le \frac{k+1}m$},\\
     0, & \text{otherwise},
  \end{cases}
\]
and hence
\begin{align*}
{\sf E}|S_n\cap(J_{m,k}\times J_{m,l})| &=\sum_{i\in nJ_{m,k}}
\frac1i\left(\left\lfloor\frac{(l+1)i}{m}\right\rfloor-
\left\lfloor\frac{li}{m}\right\rfloor\right)=\sum_{i\in nJ_{m,k}} \frac1m +O(\log n)\\
&=\frac1m\left(\left\lfloor\frac{(k+1)n}{m}\right\rfloor-
\left\lfloor\frac{kn}{m}\right\rfloor\right) +O(\log
n)=\frac{n}{m^2}+O(\log n).
\end{align*}
Thus
\[
{\sf E}\Bigl(\frac1n|S_n\cap(J_{m,k}\times J_{m,l})|\Bigr)
\to\frac1{m^2}\qquad (n\to\infty).
\]
The fact that $|S_n\cap(J_{m,k}\times J_{m,l})|/n \to1/m^2$ with
probability $1$ (not just in expectation) follows by the Law of Large
Numbers, since the $X_i$ are independent.

Thus Lemma \ref{LEM:CONV} applies and proves the Proposition.
\end{proof}

Lemma \ref{LEM:CONV} in fact implies (since $W^{\rm pfx}$ is 0-1
valued) that $W_{G_n^{\rm pfx}}$ tend to $W^{\rm pfx}$ with
probability $1$ in the edit distance, not just in the cut distance.
This means that while the graphs $G_n^{\rm pfx}$ are random, they are
very highly concentrated: two instances of $G_n^{\rm pfx}$ only
differ in $o(n^2)$ edges if overlayed properly (not in the original
ordering of the nodes!). Informally, they have a relatively small
amount of randomness in them, which disappears as $n\to\infty$.
Indeed, $G_n^{\rm pfx}$ is generated using only $O(n\log n)$ bits, as
opposed to, say, ${G}(n,1/2)$, which is generated using
$\binom{n}{2}$ bits. It would be interesting to explore this
phenomenon.

Proposition \ref{PROP:PREFIX} gives a nice and simple representation
of the limit object with the underlying probability space $[0,1]^2$
(with the uniform measure). If we want a representation on $[0,1]$,
we can map $[0,1]$ into $[0,1]^2$ by a measure preserving map $\phi$;
then $W_{\rm pfx}^\phi(x,y)=W^{\rm pfx}(\phi(x),\phi(y))$ gives a
representation of the same graphon as a 2-variable function. For
example, using the map $\phi$ that separates even and odd bits of
$x$, we get the fractal-like picture in Figure \ref{FIG:PREFIX-LIM}.

It is interesting to note that the graphs ${G}(n,W)$ form another
(different) sequence of random graphs tending to the same limit $W$
with probability 1.

\begin{figure}[htb]
  \centering
  \includegraphics*[height=120pt,width=120pt]{Figs/fractal2.eps}
  \caption{The limit of randomly grown prefix attachment graphs (as a function
on $[0,1]^2$)}\label{FIG:PREFIX-LIM}
\end{figure}

\subsection{Preferential attachment graph on n fixed nodes}\label{SEC:PFR-ATT}

A {\it preferential attachment graph with $n$ fixed nodes and $m$
edges} ${\rm PAG}(n,m)$ is the random graph obtained by the following
procedure. Let $v_1\dots v_n$ be a set of nodes. We extend this
sequence one by one by picking an element of the current sequence
randomly and uniformly, and append a copy of it at the end. We repeat
this until $2m$ further elements have been added. So we get a
sequence $v_1\dots v_nv_{n+1}\dots v_{n+2m}$.

Now we connect nodes $v_{n+2k-1}$ and $v_{n+2k}$ for $k=1,2,\dots,m$,
to get ${\rm PAG}(n,m)$. (Note that ${\rm PAG}(n,m)$ may have multiple edges
and loops, which we have to live with for the time being).

Another way of describing this construction is to view it as adding
edges one by one, where the probability of adding an edge connecting
$u$ and $v$ is proportional to the product of their degrees. To be
more precise, the probability that the $(k+1)$-st edge connects $u$
and $v$ is
\[
  \begin{cases}
    \displaystyle\frac{2(d_k(u)+1)(d_k(v)+1)}{(n+2k)(n+2k+1)}
     & \text{if $u\not= v$}, \\[12pt]
    \displaystyle\frac{(d_k(u)+1)(d_k(u)+2)}{(n+2k)(n+2k+1)}
     & \text{if $u=v$},
  \end{cases}
\]
where $d_k(u)$ is the current degree of the node (adding 1 to the
degree is needed to start the procedure at all; adding 2 to the
second factor in the case when $u=v$ is a minor trick that makes
everything come out nicer).

\begin{figure}[htb]
  \centering
  \includegraphics*[height=120pt,width=120pt]{Figs/prefer.eps}\qquad
  \includegraphics*[height=120pt,width=120pt]{Figs/preferdeg.eps}
  \caption{(a) A preferential attachment graph ${\rm PAG}(50,1000)$.
  Darkness of a pixel indicates multiplicity of
  the edge. (b) The same graph with the nodes ordered by decreasing
  degrees.}
  \label{FIG:PREF}
\end{figure}

Preferential attachment graphs are motivated by the (sparse)
Albert--Barab\'asi graphs \cite{AlBa}, and they have been studied in
detail by Pittel \cite{Pit}.

The somewhat awkward definition of preferential attachment graphs is
justified by the following nice properties. First, let us compute the
probability that this process yields a multigraph $G$ on $V(G)=[n]$,
with degrees $d_1,\dots,d_n$, with $m$ edges and $m'$ non-loop edges.
Fix any order of the edges, and for the non-loop edges fix an order
in which their endpoints were inserted (i.e., an orientation of $G$).
Then the probability that $G$ arises this way is
\begin{equation}\label{PROB-G-ORD}
\frac{d_1!\dots d_n!}{n(n+1)\dots (n+2m-1)}.
\end{equation}
Summing over all orientations and orderings of the edges, we get that
the probability that ${\rm PAG}(n,m)=G$ is
\begin{equation}\label{PROB-G}
m! 2^{m'} \frac{d_1!\dots d_n!}{n(n+1)\dots (n+2m-1)}.
\end{equation}

An important observation we can make from this computation is the
following:

\begin{lemma}\label{INVARIANT}
Conditioning on the graph $G(n,m)$, all the $2^{m'}m!$ possibilities
in which the edges could have been inserted have the same
probability.
\end{lemma}

We can use this lemma to determine the expected subgraph densities in
${\rm PAG}(n,m)$. For two multigraphs $F$ and $G$, let $inj(F,G)$ denote
the number of embeddings of $f$ into $G$, i.e., the number of pairs
$(\phi,\psi)$ of injective maps $\phi:~V(F)\to V(G)$ and
$\psi:~E(F)\to E(G)$ that preserve incidence. Let
\[
t_{\rm inj}(F,G)=\frac{{\rm inj}(F,G)}{(n)_k},
\]
where $k=|V(F)|$ and $n=|V(G)|$.

Let $F$ be a multigraph on $V(G)=[k]$, with degrees $r_1,\dots,r_k$,
with $l$ edges and $l'$ non-loop edges. Fix an order of the edges of
$F$ and also an orientation $\sigma$ of the non-loop edges of $F$ as
above. Let $\overrightarrow{e}_1, \dots,\overrightarrow{e}_m$ be the
order and orientation in which ${\rm PAG}(n,m)$ arises. Let
$p(\sigma,v_1,\dots,v_k, j_1,\dots,j_l)$ denote the probability that
edges $\overrightarrow{e}_{j_1}, \dots,\overrightarrow{e}_{j_l}$ form
a copy of $F$ on nodes $v_1,\dots,v_k$ (with the given labeling of
the nodes, the given order of the edges, and the given orientation).
By Lemma \ref{INVARIANT}, this number is the same for any $l$-tuple
$(j_1,\dots,j_l)$, and trivially, it is the same for every $k$-tuple
$(v_1,\dots,v_k)$. Hence
\begin{align*}
{\sf E}\bigl({\rm inj}(F,{\rm PAG}(n,m))\bigr)&= \sum_{v_1,\dots,v_k}
\sum_{j_1,\dots,j_l}\sum_{\sigma} p(\sigma,v_1,\dots,v_k,
j_1,\dots,j_l)\\
&= (n)_k(m)_l 2^{l'} p(\sigma_0,1,\dots,k,1,\dots,l),
\end{align*}
where $\sigma_0$ is any fixed orientation of $F$. By
(\ref{PROB-G-ORD}), we have
\[
p(\sigma_0,1,\dots,k,1,\dots,l)=\frac{r_1!\dots r_k!}{(n+2l-1)}_{2l},
\]
and so
\begin{equation}\label{PAG-T}
{\sf E}\bigl(t_{\rm inj}(F,{\rm PAG}(n,m))\bigr)=\frac{1}{(n)_k}(n)_k(m)_l
2^{l'}\frac{r_1!\dots r_k!}{(n+2l-1)}_{2l}=2^{l'}r_1!\dots r_k!
\frac{(m)_l}{(n)_{2l}}.
\end{equation}

Suppose that $n,m\to\infty$ so that $m\sim cn^2/2$. Then
\[
{\sf E}\bigl(t_{\rm inj}(F,{\rm PAG}(n,m))\bigr)\sim 2^{l'}r_1!\dots r_k!
\frac{m^l}{n^{2l}}\longrightarrow 2^{l'-l}c^lr_1!\dots r_k!\,.
\]
If we assume that $F$ has no loops, then
\[
{\sf E}\bigl(t_{\rm inj}(F,{\rm PAG}(n,m))\bigr)\longrightarrow c^lr_1!\dots r_k!\,.
\]
Using high concentration results, one can show that this convergence
holds not only in expectation, but with probability 1,
\[
t_{\rm inj}(F,{\rm PAG}(n,m))\longrightarrow c^lr_1!\dots r_k!\,.
\]

Note that the relation $t_{\rm inj}(F,{\rm PAG}(n,m))\sim t(F,{\rm PAG}(n,m))$ does
not hold in general if $F$ has multiple edges. In fact, it is easy to
see that
\[
t_{\rm inj}(F,{\rm PAG}(n,m))\sim \sum_{F'} t(F,{\rm PAG}(n,m))\prod_{i,j\in V(F)}
m'_ij! \Bigl\{{m_{ij}\atop m'_{ij}}\Bigr\},
\]
where $F'$ ranges through all multigraphs obtained from $F$ by
reducing the edge multiplicities (not strictly, but keeping at least
one copy of each edge), $m_{ij}$ and $m_{ij}'$ denote the
multiplicities of the edge $ij$ in $F$ and $F'$, respectively, and
$\{ {a\atop b}\}$ denotes the Stirling number of the second kind. For
example, if $K_2^{(2)}$ denotes the graph on two nodes having two
parallel edges, then
\[
t(K_2^{(2)},{\rm PAG}(n,m))\sim t_{\rm inj}(K_2^{(2)},{\rm PAG}(n,m))
+t_{\rm inj}(K_2,{\rm PAG}(n,m)).
\]

Let $L_c(x,y)=c(\ln x)(\ln y)$. Then for a multigraph $F$ without
loops we have
\[
t(F,L_c)=\int_{[0,1]^k} \prod_{ij\in E(F)} W(x_i,x_j)\,dx =
\int_{[0,1]^k} c^l\prod_{i=1}^k (\ln x_i)^{r_i}\,dx =c^lr_1!\dots
r_k!\,.
\]

This implies that the limit of preferential attachment graphs
${\rm PAG}(n, cn^2)$, with probability 1, is described by the function
$L_c$. To be precise, the graphs ${\rm PAG}(n, cn^2)$ have multiple edges,
and hence the theory of convergent graph sequences developed in
\cite{BCLSV1,BCLSV2} does not apply, but the computations above show
that the convergence does occur in at least one possible sense.

\begin{prop}\label{PROP:PREFER}
If $m(n)=(c+o(1))n^2$, then with probability $1$,
$t_{\rm inj}(F,{\rm PAG}(n,m))\to t(F,L_c)$ for every multigraph $F$ without
loops.
\end{prop}

Let ${\rm SPAG}(n,cn^2)$ denote the {\it simplified preferential
attachment graph} obtained from ${\rm PAG}(n,cn^2)$ by deleting loops and
keeping only one copy of parallel edges. L.~Szak\'acs \cite{Szak}
proved that this sequence of graphs is convergent with probability
$1$, and its limit is the function $1-\exp(-c\ln x\ln y)$.

\section{Convergence to a prescribed function}

Lemma \ref{LEM:WRAND} gives a way to construct a randomly growing
graph sequence converging to a given function $W$. Let
$s_1,s_2,\dots\in\Omega$ be independent random samples from $\pi$,
and let $S_n=\{s_1,\dots,s_n\}$. We can construct ${G}(S_n,W)$ by
taking $G(S_{n-1},W)$, adding $s_n$ as a new node, and connecting
$s_n$ to $s_i$ with probability $W(s_n,s_i)$. Then
${G}(S_1,W),{G}(S_2,W),\dots$ is a randomly growing sequence of
graphs, and by Lemma \ref{LEM:WRAND}, we have ${G}(S_n,W)\to W$ with
probability $1$.

\killtext{ ??? Another way of describing how $G_n={G}(S_n,W)$ is
obtained from the graph $G_{n-1}={G}(S_{n-1},W)$ is the following.
For $J\subseteq V(G_{n-1})$, let $\bar{G}_{n-1,J}$ be obtained from
$\bar{G}_{n-1}$ by adding a new node and connecting it to the points
in $J$ by red edges, and to the other nodes of $V(G_{n-1})$ by blue
nodes. Then
\[
p(J)=\frac{t(\bar{G}_{n-1,J},W)}{t(\bar{G}_{n-1},W)}
\]
defines a probability distribution on $2^{V(G_{n-1})}$, and $G_n$ can
be obtained from $G_{n-1}$ by adding a new node and connecting it to
a set of old nodes $J$ with probability}

However, one can have several objections to this method: First, the
new edges are not added independently of each other. Second, even if
$\Omega=[0,1]$, and the function $W$ is, say, continuous and
monotone, the order in which the nodes of ${G}(S_n,W)$ are born is
random, and has nothing to do with the order of the points
$s_i\in[0,1]$ representing them. In other words, to get a labeling
for which $W_{{G}(S_n,W)}\to W$ in the $\|.\|_\square$ norm, we have
to reorder the nodes.

It may be interesting to consider rules for generating randomly
growing graph sequences $(G_n)$ with a prescribed limit function $W$
for which these objections cannot be raised. Given a function
$W\in\WW_0$, monotone decreasing in each variable, construct a
randomly growing simple graph sequence $(G_1,G_2,\dots)$ as follows.
$G_1$ is a single node labeled $1$. For $n>1$, define
\[
p_{n,j}=W(\tfrac{j}{n},1),\qquad p_{n,ij}=
\frac{W(\frac{i}{n},\frac{j}{n})-W(\frac{i}{n-1},
\frac{j}{n-1})}{1-W(\frac{i}{n-1},\frac{j}{n-1})}.
\]
To get $G_n$ from $G_{n-1}$, we add a new node $n$, connect it to
each node $j<n$ with probability $p_{n,j}$, and connect any two
nonadjacent nodes $i,j<n$ with probability $p_{n,ij}$. All these
decisions are independent. The monotonicity of $W$ implies that $0\le
p_{n,ij}\le 1$ is a legal probability.

\begin{prop}\label{PROP:}
The sequence of graphs $G_n$ constructed above has the property that
$W_{G_n}\to W$ in the $\|.\|_\square$ norm.
\end{prop}

\begin{proof}
The probability that nodes $i<j$ are not connected in $G_n$ is
\begin{align*}
(1-p_{j,i})(1-p_{j+1,ij})\cdots(1-p_{n,ij})
&=\bigl(1-W(\tfrac{i}{j},1)\bigr)
\frac{1-W(\frac{i}{j+1},\frac{j}{j+1})}{1-W(\frac{i}{j},\frac{j}{j})}
\cdots
\frac{1-W(\frac{i}{n},\frac{j}{n})}{1-W(\frac{i}{n-1},\frac{j}{n-1})}\\
&=1-W(\tfrac{i}{n},\tfrac{j}{n}),
\end{align*}
and hence the probability that they are adjacent is
$W(\tfrac{i}{n},\tfrac{j}{n})$. Thus $G_n$ is the graph ${G}(S_n,W)$,
where $S_n=\{\frac1n,\tfrac2n,\dots\tfrac{n-1}n\}$. It is trivial
that this sequence of sets is well distributed in $[0,1]$, and since
$W$ is almost everywhere continuous, it follows by Lemma
\ref{LEM:CONV} that $G_n\to W$ with probability $1$.
\end{proof}

The convergent sequences discussed in Sections \ref{SEC:UNIF-ATT} and
\ref{SEC:R-ATT} are special cases of this construction. A more
general nice case is when $W=1-U$, where $U$ is homogeneous of some
degree: $U(\lambda x, \lambda y)= \lambda^c U(x,y)$ with some $c\ge
0$. When a new node $n$ is born we connect it to node $i<n$ with
probability $W(\frac in,1)$, and then at each further step, we
connect any two nonadjacent nodes with probability
$1-\bigl(\frac{n-1}{n}\bigr)^c$.

Combinatorics (math.CO); Probability (math.PR)


Optimal sine and sawtooth inequalities

Abstract: We determine the optimal inequality of the form $\sum_{k=1}^m a_k\sin kx\leq 1$, in the sense that $\sum_{k=1}^m a_k$ is maximal. We also solve exactly the analogous problem for the sawtooth (or signed fractional part) function. Equivalently, we solve exactly an optimization problem about equidistribution on the unit circle.

\subsection{Acknowledgments}

LE and BT were supported by NSF grant DMS-2054553.  TT was supported by a Simons Investigator grant, the James and Carol Collins Chair, the Mathematical Analysis \& Application Research Fund Endowment, and by NSF grant DMS-1764034.
Thanks to John Ottem, Sam Payne, and Miles Reid for their suggestions.

\section{Dilated fractional parts of a random real number}
\label{sectionsawtooth}

In this section, we prove an optimal inequality for the sawtooth
function (Theorem \ref{sawtooth}). By linear programming duality,
this is equivalent to an optimal bound in a problem
about equidistribution on the unit circle.

For a real number $x$, let $\lfloor x \rfloor$ denote the greatest integer less than or equal to $x$ and $\lceil x \rceil$ the smallest integer greater than or equal to $x$.  Note that
\begin{equation}\label{lf}
 \lfloor x+n \rfloor = \lfloor x\rfloor + n \;\text{ and }\;
\lceil x+n \rceil = \lceil x\rceil + n
\end{equation}
for any integer $n$, and that
\begin{equation}\label{cc}
\lceil x \rceil = - \lfloor -x\rfloor.
\end{equation}
We also define the lower fractional part
\begin{equation}\label{lfrac}
\{x\} \coloneqq x - \lfloor x \rfloor
\end{equation}
which takes values in $[0,1)$, and the upper fractional part
\begin{equation}\label{ufrac}
\{x\}^* \coloneqq x - \lceil x \rceil + 1
\end{equation}
which takes values in $(0,1]$.  Finally, define the signed fractional part
\begin{equation}\label{g-def}
g(x) \coloneqq x - \bigl\lceil x-\tfrac{1}{2} \bigr\rceil = x + \bigl\lfloor \tfrac{1}{2} - x \bigr\rfloor
\end{equation}
which takes values in $(-1/2,1/2]$. We call $g(x)$
the \emph{sawtooth function}.

For a (Borel) probability measure $\mu$ on the reals
and a positive integer $k$, define the expectation
$$ \E_\mu g(k x) \coloneqq \int_\R g(kx)\ d\mu(x).$$
Consider the quantity
\begin{equation}\label{gk}
 \min_{1 \leq k \leq m} \E_\mu g(k x),
\end{equation}
where $m$ is a natural number and $\mu$ is a probability measure on the reals.
Since each function $g(kx)$ is pointwise bounded by $1/2$, we trivially have the bound
\begin{equation}\label{minr}
 \min_{1 \leq k \leq m} \E_\mu g(k x) \leq \tfrac{1}{2},
\end{equation}
but one expects to do better as $m$ gets large.  For instance, from the Dirichlet approximation theorem one sees that
$$ \min_{1 \leq k \leq m} |g(kx)| \leq \frac{1}{m+1},$$
but this does not directly allow one to improve the bound \eqref{minr} since one cannot interchange the minimum and the expectation.  As it turns out, there is an improvement in $m$, and the optimal value of \eqref{gk} can be computed exactly, but it only decays like $\frac{1}{\log m}$ rather than $\frac{1}{m}$ as $m \to \infty$.

As a first attempt to control the quantity \eqref{gk}, one could try to estimate it by its unweighted mean
$$ \frac{1}{m} \sum_{k=1}^m \E_\mu g(k x).$$
However, this quantity can be quite large: in particular, if $\mu$ is the Dirac mass at $1/2$, then this mean is equal to $\frac{\lceil m/2 \rceil}{2m}$, which is asymptotic to $\frac{1}{4}$ as $m \to \infty$.  Closely related to this is the observation that the unweighted sum
$$ g(x) + g(2x) + \dots + g(mx)$$
of the $g(jx)$ can be much larger than $1$, and in particular equal to $\lceil m/2\rceil / 2$ when $x=1/2$.

However, one can obtain much better results by working with \emph{weighted} means of the $\E_\mu g(kx)$, or equivalently by \emph{weighted} linear combinations of the $g(jx)$; indeed by linear programming duality, we see that a bound of the form
$$  \min_{1 \leq k \leq m} \E_\mu g(k x) \leq \lambda$$
for all $\mu$ holds if and only if there exist non-negative coefficients $a_1,\dots,a_m$ with $\sum_{j=1}^m a_j \geq \frac{1}{\lambda}$ such that we have the dual inequality
$$ \sum_{k=1}^m a_k g(kx) \leq 1$$
for all $x$.  Thus to compute the minimal value of \eqref{gk}, we just need to find an optimal dual inequality.

We begin with the model case where $m$ is a power of two, in which the dual inequality is particularly easy to establish.

\begin{proposition}
  Let $r$ be a natural number, and set $m = 2^r$.
\begin{itemize}
\item[(i)] For every real number $x$, we have
\begin{equation}\label{3r-easy}
2g(x) + \sum_{j=1}^r g(2^j x) \leq 1.
\end{equation}
\item[(ii)] We have
\begin{equation}\label{4r-easy}
\min_{1 \leq k \leq m} \E_\mu g(k x)  \leq \frac{1}{r+2}
\end{equation}
for every (Borel) probability measure $\mu$ on the real line. Moreover,
this is the optimal bound: equality is attained for the measure $\mu_m$
with mass $\frac{1}{r+2}$ at each of the numbers
$\frac{1}{2}, \frac{1}{4}, \frac{1}{8}, \ldots, \frac{1}{2^{r}}$,
and mass $\frac{2}{r+2}$ at $\frac{1}{2^{r+1}}$.
\end{itemize}
\end{proposition}

\begin{proof}
We begin with (i).  We observe the identity
\begin{equation}\label{tele}
 g(x) = \{2x\}^* - \{x\}^*
\end{equation}
for all real numbers $x$, since both sides of this equation are $1$-periodic, equal to $x$ on $(0,1/2]$, and equal to $x-1$ on $(1/2,1]$. Similarly,
$$ 2g(x) - \{2x\}^* = - 1_{\{x\}^* > 1/2},$$
where the indicator function $1_{\{x\}^* > 1/2}$ is defined to equal $1$ when $\{x\}^* > 1/2$ and vanish otherwise.
Thus we have the telescoping formula
\begin{equation}\label{telescoping}
 2g(x) + \sum_{j=1}^r g(2^j x) = \{2^{r+1} x\}^* - 1_{\{x\}^* > 1/2}
\end{equation}
(see Figure \ref{fig:combination2}.)  This establishes (i).

Now we prove (ii).  Integrating (i) against an arbitrary probability measure $\mu$ on $\R$, we conclude that
$$
2 \E_\mu g(x) + \sum_{j=1}^r \E_\mu g(2^j x) \leq 1.
$$
Thus we have
$$ \biggl(2 + \sum_{j=1}^r 1\biggr)
\min_{1 \leq k \leq m} \E_\mu g(k x)  \leq 1,$$
which gives the upper bound in \eqref{4r-easy}.

To establish the matching lower bound using the measure $\mu_m$, it suffices to show that
$$ \sum_{j=1}^{r} g\biggl( \frac{k}{2^j}\biggr) + 2 g\biggl( \frac{k}{2^{r+1}} \biggr) = 1$$
for all $k=1,\dots,m$.  But from \eqref{telescoping} with $x = k/2^{r+1}$, the left-hand side is equal to
$$ \{k\}^* - 1_{\{k/2^{r+1}\}^* > 1/2} = 1 - 0,$$
giving the claim.
\end{proof}

\begin{figure} [t]
\centering
\includegraphics[width=4in]{./gsum8.png}
\caption{The left-hand side of \eqref{3r-easy} when $m=8$.  We are showing that it is at most $1$.  Note the large number of locations where the bound of $1$ is attained, including the support $\{1/2,1/4,1/8,1/16\}$ of the optimal measure $\mu_8$.}
\label{fig:combination2}
\end{figure}

Now we handle the general case.

\begin{theorem}
\label{sawtooth}
  Let $r,m$ be natural numbers such that $2^r < m \leq 2^{r+1}$.
\begin{itemize}
\item[(i)] For every real number $x$, we have
\begin{equation}\label{3r}
2g(x) + \sum_{j=1}^r g(2^j x) +  \sum_{\ell = 2^r+1}^m \frac{m}{\ell(\ell-1)}
\biggl( g(\ell x) + g((2^{r+1}+1-\ell)x)-g(x)\biggr) \leq 1.
\end{equation}
\item[(ii)] We have
\begin{equation}\label{4r}
\min_{1 \leq k \leq m} \E_\mu g(k x)  \leq \frac{2^r}{(r+1)2^r + m}
\end{equation}
for every (Borel) probability measure $\mu$ on the real line. Moreover,
this is the optimal bound: equality is attained for the measure $\mu_m$
with mass $\frac{2^r}{(r+1)2^r+m}$ at each of the numbers
$\frac{1}{2}, \frac{1}{4}, \frac{1}{8}, \ldots, \frac{1}{2^{r+1}}$
and mass $\frac{m}{(r+1)2^r+m}$ at $\frac{1}{2m}$.
\end{itemize}
\end{theorem}

In particular, the right side of (ii) is less than $\frac{\log 2}{\log m}$.
So (ii) says in particular: for every probability measure $\mu$
on the real line and every positive integer $m$, there is
a positive integer $k$ at most $m$ such that the expected value
$\E_{\mu} g(kx)$ is at most $\frac{\log 2}{\log m}$. This
is an equidistribution statement, sharpening
the rough idea that the image measure of $\mu$ on $\R/\Z$
under multiplication by
some not-too-large positive integer is not concentrated too much
in the first half of $[0,1]$.

It follows from our argument (in particular the properties
of the measure $\mu_m$ in (ii))
that statement (i) is an optimal inequality of the form
$\sum_{k=1}^m a_k g(kx)\leq 1$, in the sense that it has
the maximal value of $\sum a_k$ (namely, $r+1+\frac{m}{2^r}$)
among all inequalities of this form. See Remark \ref{non-unique}
on the non-uniqueness of this inequality.

\begin{figure} [t]
\centering
\includegraphics[width=4in]{./gsum.png}
\caption{The left-hand side of \eqref{3r} when $m=7$. Note the large number of locations where the bound of $1$ is attained, including the support $\{1/2,1/4,1/8,1/14\}$ of the optimal measure $\mu_7$.}
\label{fig:combination}
\end{figure}

\begin{proof}
By \eqref{telescoping}, we can rearrange \eqref{3r} as
$$ \sum_{\ell = 2^r+1}^m \frac{m}{\ell(\ell-1)}
\biggl( g(\ell x) + g((2^{r+1}+1-\ell)x) - g(x)\biggr) \leq 1 - \{2^{r+1} x\}^* + 1_{\{x\}^* > 1/2}.$$
Both sides are $1$-periodic, so we may assume that $x \in (0,1]$, and thus we may write
\begin{equation}\label{jdef}
 x = \frac{j-\theta}{2^{r+1}}
\end{equation}
for some integer $1 \leq j \leq 2^{r+1}$ and some real number $0 \leq \theta < 1$.  In particular,
we have $\{2^{r+1} x\}^* = 1-\theta$.  From \eqref{g-def} we have
$$ g(\ell x) + g((2^{r+1}+1-\ell)x) - g(x)  = 2^{r+1} x + \bigl\lfloor \tfrac{1}{2} - \ell x \bigr\rfloor + \bigl\lfloor \tfrac{1}{2} + \ell x - 2^{r+1} x - x \bigr\rfloor - \bigl\lfloor \tfrac{1}{2} - x\bigr\rfloor.$$
But $-\lfloor \frac{1}{2} - x \rfloor = 1_{\{x\}^* > 1/2}$
since $x\in (0,1]$, so we have
$$ \sum_{\ell = 2^r+1}^m \frac{m}{\ell(\ell-1)} \bigl( -\bigl\lfloor \tfrac{1}{2} - x \bigr\rfloor \bigr) \leq 1_{\{x\}^* > 1/2},$$
since
\begin{equation}\label{aum}
\sum_{\ell = 2^r+1}^m \frac{m}{\ell(\ell-1)} = m \biggl(\frac{1}{2^r}-\frac{1}{m}\biggr)
\leq 1.
\end{equation}
So it will suffice to establish the inequality
$$ \sum_{\ell = 2^r+1}^m \frac{m}{\ell(\ell-1)} \biggl( 2^{r+1} x + \bigl\lfloor \tfrac{1}{2} - \ell x \bigr\rfloor + \bigl\lfloor \tfrac{1}{2} + \ell x - 2^{r+1} x - x \bigr\rfloor \biggr) \leq \theta.$$
Writing $2^{r+1} x = j-\theta$, we can rearrange this using \eqref{lf} as
$$ \sum_{\ell = 2^r+1}^m \frac{m}{\ell(\ell-1)} \biggl( -\theta + \bigl\lfloor \tfrac{1}{2} - \ell x \bigr\rfloor + \bigl\lfloor \tfrac{1}{2} + \ell x + \theta - x \bigr\rfloor \biggr) \leq \theta.$$
By \eqref{aum}, it is equivalent
to show that
$$ \sum_{\ell = 2^r+1}^m \frac{m}{\ell(\ell-1)} \biggl( \bigl\lfloor \tfrac{1}{2} - \ell x \bigr\rfloor + \bigl\lfloor \tfrac{1}{2} + \ell x + \theta - x \bigr\rfloor\biggr) \leq \frac{m \theta}{2^r}.$$
We may cancel the factor of $m$ on both sides. The quantity $\lfloor \frac{1}{2} - \ell x \rfloor + \lfloor \frac{1}{2} + \ell x + \theta - x \rfloor$ is clearly an integer that is bounded above by
$$
\bigl(\tfrac{1}{2} - \ell x\bigr) + \bigl(\tfrac{1}{2} + \ell x + \theta - x\bigr) = 1 + \theta - x < 2,$$
and by \eqref{lfrac} it is equal to $1$ if and only if
$$ \bigl\{ \tfrac{1}{2} - \ell x \bigr\} + \bigl\{ \tfrac{1}{2} + \ell x + \theta - x \bigr\} = \theta - x,$$
so in particular
$$ 0 \leq \bigl\{ \tfrac{1}{2} - \ell x \bigr\} \leq \theta - x.$$
Thus it will suffice to show that
\begin{equation}\label{test}
 \sum_{2^r < \ell \leq m: \; 0 \leq \{ \frac{1}{2} - \ell x \} \leq \theta - x} \frac{1}{\ell(\ell-1)} \leq \frac{\theta}{2^r}.
\end{equation}
We can write the left-hand side as
$$
 \sum_{k = 0}^\infty \; \sum_{2^r < \ell \leq m: \;
-k \leq \frac{1}{2} - \ell x \leq -k + \theta - x} \frac{1}{\ell(\ell-1)}
$$
or equivalently
\begin{equation}\label{k-1}
 \sum_{k = 0}^\infty \; \sum_{\max(2^r+1, \frac{k-\theta+1/2}{x}+1) \leq \ell \leq \min(\frac{k+1/2}{x}, m)} \frac{1}{\ell(\ell-1)}.
\end{equation}
Using the fundamental theorem of calculus to write $\frac{1}{\ell(\ell-1)} = \int_{\ell-1}^\ell \frac{dt}{t^2}$, we may upper bound this expression by
$$
 \sum_{k = 0}^\infty  \int_{[2^r,m] \cap [\frac{k-\theta+1/2}{x}, \frac{k+1/2}{x}]} \frac{dt}{t^2}
$$
and so (using $m \leq 2^{r+1}$) it will suffice to establish the bound
\begin{equation}\label{k-2}
 \sum_{k = 0}^\infty  \int_{[2^r,2^{r+1}] \cap [\frac{k-\theta+1/2}{x}, \frac{k+1/2}{x}]} \frac{dt}{t^2} \leq \frac{\theta}{2^r}.
\end{equation}
The interval
$[2^r,2^{r+1}] \cap [\frac{k-\theta+1/2}{x}, \frac{k+1/2}{x}]$ is only non-empty when
$$ \frac{k-\theta+1/2}{x} \leq 2^{r+1}\;\text{ and }\; \frac{k+1/2}{x} \geq 2^r.$$
Hence we may restrict the $k$ summation in \eqref{k-2} to the region
$$
2^r x - \tfrac{1}{2} \leq k \leq 2^{r+1} x - \tfrac{1}{2} + \theta.
$$
By \eqref{jdef} and the fact that $0 \leq \theta < 1$, we conclude that
\begin{equation}\label{k-bound}
\frac{j}{2}-1 < k < j.
\end{equation}

We now split into cases.

{\bf Case 1:} $j=1$.  By \eqref{k-bound}, the only value of $k$ that contributes to \eqref{k-2} is $k=0$, and we can upper bound the left-hand side of \eqref{k-2} by
$$
\int_{[2^r,\frac{1/2}{x}]} \frac{dt}{t^2} = \frac{1}{2^r} - 2x$$
which is precisely $\frac{\theta}{2^r}$ as desired thanks to \eqref{jdef}.

{\bf Case 2:} $j=2$.  Now \eqref{k-bound} restricts us to $k=1$, and we can upper bound the left-hand side of \eqref{k-2} by
$$ \int_{[\frac{3/2 - \theta}{x},\frac{3/2}{x}]} \frac{dt}{t^2} = \frac{x}{3/2-\theta} - \frac{x}{3/2}$$
which by \eqref{jdef} simplifies to
$$ \frac{2}{3} \cdot \frac{2-\theta}{3-2\theta} \cdot \frac{\theta}{2^r}.$$
Since $\frac{2}{3}$ and $\frac{2-\theta}{3-2\theta}$ are at most 1,
we obtain the desired upper bound of $\frac{\theta}{2^r}$ (with a little room to spare).

{\bf Case 3:} $j=3$.  Now \eqref{k-bound} restricts us to $k=1,2$.  The left-hand side of \eqref{k-2} is now upper bounded by
$$ \int_{[2^r,\frac{3/2}{x}]} \frac{dt}{t^2}
+ \int_{[\frac{5/2 - \theta}{x},\frac{5/2}{x}]} \frac{dt}{t^2}
= \frac{1}{2^r} - \frac{x}{3/2} + \frac{x}{5/2-\theta} - \frac{x}{5/2}$$
which by \eqref{jdef} simplifies to
$$ \biggl( \frac{1}{3} + \frac{2}{5} \cdot \frac{3-\theta}{5-2\theta}\biggr)
\frac{\theta}{2^r}.$$
Since $0 \leq \theta < 1$, we have $\frac{1}{3} + \frac{2}{5} \cdot \frac{3-\theta}{5-2\theta}
< \frac{1}{3} + \frac{2}{5} \cdot \frac{2}{3} < 1$,
and we obtain the desired upper bound of $\frac{\theta}{2^r}$ (with a little more room to spare).

{\bf Case 4:} $j=4$.  Now \eqref{k-bound} restricts us to $k=2,3$.  The left-hand side of \eqref{k-2} is now upper bounded by
$$ \int_{[\frac{5/2 - \theta}{x},\frac{5/2}{x}]} \frac{dt}{t^2}
+ \int_{[\frac{7/2 - \theta}{x},\frac{7/2}{x}]} \frac{dt}{t^2}
 = \frac{x}{5/2-\theta} - \frac{x}{5/2} + \frac{x}{7/2-\theta} - \frac{x}{7/2}$$
which by \eqref{jdef} simplifies to
$$ \biggl( \frac{2}{5} \cdot \frac{4-\theta}{5-2\theta} + \frac{2}{7} \cdot \frac{4-\theta}{7-2\theta}\biggr) \frac{\theta}{2^r}.$$
Since $0 \leq \theta < 1$, we have
$$ \frac{2}{5} \cdot \frac{4-\theta}{5-2\theta} + \frac{2}{7} \cdot \frac{4-\theta}{7-2\theta}
< \frac{2}{5} \cdot \frac{3}{3} + \frac{2}{7} \cdot \frac{3}{5} < 1$$
and we again obtain the desired upper bound of $\frac{\theta}{2^r}$ (with a fair amount\footnote{Note that the increasing ease of proof of \eqref{3r} as $j$ increases is consistent with the behavior exhibited in Figure \ref{fig:combination}.} of room to spare).

{\bf Case 5:} $j>4$.  There is a finite interval $[k_1,k_2]$ of integers $k$ for which $[2^r,m] \cap [\frac{k-\theta+1/2}{x}, \frac{k+1/2}{x}]$ is non-empty.  From the decreasing nature of $\frac{1}{t^2}$, we have
$$ \int_{[2^r,2^{r+1}] \cap [\frac{k-\theta+1/2}{x}, \frac{k+1/2}{x}]} \frac{dt}{t^2} \leq
\theta \int_{[2^r,2^{r+1}] \cap [\frac{k-1+1/2}{x}, \frac{k+1/2}{x}]} \frac{dt}{t^2}$$
when $k_1 < k \leq k_2$.  Thus we may bound the left-hand side of \eqref{k-2} by
$$ \int_{[2^r,2^{r+1}] \cap [\frac{k_1-\theta+1/2}{x}, \frac{k_1+1/2}{x}]} \frac{dt}{t^2} + \theta \int_{[2^r,2^{r+1}]} \frac{dt}{t^2}.$$
For the first integral, we observe that the domain is an interval of length at most $\theta/x$ and the integrand is at most $1/2^{2r}$; meanwhile, the second integral can be evaluated as $\frac{1}{2^r} - \frac{1}{2^{r+1}}$.  Putting all this together, we have upper bounded the left-hand side of \eqref{k-2} by
$$ \frac{\theta}{2^{2r} x} + \frac{\theta}{2^r} - \frac{\theta}{2^{r+1}}.$$
But since $j>4$, we have from \eqref{jdef} that
$$ \frac{\theta}{2^{2r} x} \leq \frac{\theta}{2^{2r} \cdot 4/2^{r+1}} = \frac{\theta}{2^{r+1}}$$
and the claim \eqref{k-2} follows.  This concludes the proof of (i).

Now we prove (ii).  Integrating (i) against an arbitrary probability measure $\mu$ on $\R$, we conclude that
\begin{multline*}
2 \E_\mu g(x)  + \sum_{j=1}^r \E_\mu g(2^j x)\\
+  \sum_{\ell = 2^r+1}^m \frac{m}{l(l-1)} \biggl(\E_\mu g(\ell x) + \E_\mu g((2^{r+1}+1-\ell)x)- \E_\mu g(x)\biggr) \leq 1.
\end{multline*}
Since
\begin{equation}\label{asum}
\sum_{\ell=2^r+1}^m \frac{m}{l(l-1)} = \frac{m}{2^r} - 1 < 2,
\end{equation}
the net coefficient of $\E_\mu g$ here is positive.  Thus we have
$$ \biggl(2 + \sum_{j=1}^r 1
+ \sum_{\ell = 2^r+1}^m \frac{m}{l(l-1)}(1+1-1)\biggr)
\min_{1 \leq k \leq m} \E_\mu g(kx) \leq 1$$
which gives the upper bound in \eqref{4r} after a brief computation using \eqref{asum}.

To establish the matching lower bound using the measure $\mu_m$, it suffices to show that
$$ \sum_{j=1}^{r+1} g\biggl( \frac{k}{2^j}\biggr) + \frac{m}{2^r} g\biggl( \frac{k}{2m}\biggr) = 1$$
for all $k=1,\dots,m$.  But from \eqref{tele} and telescoping series we have
$$ \sum_{j=1}^{r+1} g\biggl( \frac{k}{2^j}\biggr) = \{k\}^* - \biggl\{\frac{k}{2^{r+1}}\biggr\}^* = 1 - \frac{k}{2^{r+1}}$$
while since $\frac{k}{2m} \leq \frac{1}{2}$ we have
$$ g\biggl(\frac{k}{2m}\biggr)  = \frac{k}{2m}$$
and the claim follows.
\end{proof}

\begin{remark}
\label{non-unique}
The particular linear combination of the $g(kx)$ used in \eqref{3r} was discovered after some numerical experimentation, guided by the fact that this combination should attain the bound of $1$ at every point in the support of the optimal measure $\mu_m$.  However, this constraint does not fully determine the coefficients of the combination,
and it would be possible to establish the bound \eqref{4r} using other linear combinations of $g(kx)$
instead.  For instance, when $m$ is a power of two, the inequalities \eqref{3r} and \eqref{3r-easy} differ, even though they both imply \eqref{4r}: see Figures \ref{fig:combination2}, \ref{fig:combination3}.
\end{remark}

\begin{figure} [t]
\centering
\includegraphics[width=4in]{./gsum8-alt.png}
\caption{The left-hand side of \eqref{3r} when $m=8$; compare with Figure \ref{fig:combination2}.}
\label{fig:combination3}
\end{figure}

\section{Optimal equidistribution for the sine function}
\label{sectionsine}

The function $\sin(2\pi x)$ is somewhat analogous
to the sawtooth function $g(x)$ studied in Theorem \ref{sawtooth}.
We now solve exactly the corresponding optimization problem
for the sine function in Theorem \ref{sine}.
The problem solved here
is equivalent to finding
the optimal inequality of the form $\sum_{k=1}^m a_k\sin kx\leq 1$
for each positive integer $m$.

\begin{theorem}
\label{sine}
Let $m$ be a positive integer.
\begin{itemize}
\item[(i)]  We have
\begin{equation}\label{sine-ineq}
\sum_{1\leq k\leq m; \; k\text{ odd}}\frac{2}{(m+1)^2}
\cot\biggl( \frac{\pi k}{2m+2}\biggr)\bigl[(m+1-k) \sin kx+ k \sin (m+1-k)x\bigr]\leq 1
\end{equation}
for all real numbers $x$. Write this inequality
as $\sum_{k=1}^m a_k\sin kx\leq 1$; then all the coefficients
$a_k$ are nonnegative.
\item[(ii)] We have
\begin{equation}\label{sine-r}
\min_{1 \leq k \leq m} \E_\mu \sin k x  \leq \frac{1}{c_m}
\end{equation}
for every (Borel) probability measure $\mu$ on the real line, where
\begin{equation}\label{cm-def}
c_m \coloneqq \frac{2}{m+1} \sum_{1 \leq j \leq m; \; j \text{ odd}}
\cot \biggl(\frac{\pi j}{2m+2}\biggr).
\end{equation}
This is the optimal bound: equality is attained for the measure $\mu_m$
with mass $\frac{2}{(m+1)c_m} \cot \bigl(\frac{\pi j}{2m+2}\bigr)$ at $\frac{\pi j}{m+1}$ for every odd $1 \leq j \leq m$.
\end{itemize}

\end{theorem}

It follows from our argument (in particular the properties
of the measure $\mu_m$ in (ii))
that statement (i) is the optimal inequality of the form
$\sum_{k=1}^m a_k \sin kx\leq 1$, in the sense that it has
the maximal value of $\sum a_k$ (namely, $c_m$)
among all inequalities of this form. The closest relative
of this inequality in the literature seems to be Vaaler's inequality,
of the form
$\sum_{k=1}^m a_k\sin 2\pi kx\geq x-\tfrac{1}{2}$
for $x\in [0,\tfrac{1}{2}]$
\cite[Theorem 18]{Vaaler}.

By comparing
the cotangent sum $c_m$ to an integral, with the first few
terms of the sum separated off for greater accuracy,
one checks that $c_m$ is close to $(2/\pi)\log(m+1)$.
Precisely, by an argument due to Pinelis \cite{Pinelis},
$$c_m=\frac{2}{\pi}\log(m+1)
+\frac{2}{\pi}\biggl(\log\biggl(\frac{4}{\pi}\biggr)+\gamma\biggr)+o(1),$$
where $\gamma$ is Euler's constant.
In particular, the bounds for the sine problem are of the same order of magnitude as the bounds for the sawtooth problem.  If one replaces sine by cosine then the problem becomes trivial, as in this case the Dirac mass at the origin is clearly the extremizing measure and there is no decay in $m$.

Another formula for the constant $a_k$
in inequality \eqref{sine-ineq} is
$$a_k=\frac{4(m+1-k)}{(m+1)^2} \;
\frac{\sin^2 \frac{\lceil m/2 \rceil k \pi}{m+1}}{\sin \frac{\pi k}{m+1}}$$
for $1\leq k\leq m$. We will not use this, however.

\begin{figure} [t]
\centering
\includegraphics[width=4in]{./ssum-8.png}
\caption{The left-hand side $f(x)$ of \eqref{sine-ineq} when $m=8$.  We are showing that it is at most $1$.  The bound of $1$ is attained exactly at the support $\{\pi/9,3\pi/9,5\pi/9,7 \pi/9\}$ of the optimal measure $\mu_8$.}
\label{fig:combination8-sine}
\end{figure}

\begin{figure} [t]
\centering
\includegraphics[width=4in]{./ssum-9.png}
\caption{The left-hand side $f(x)$ of \eqref{sine-ineq} when $m=9$.  We are showing that it is at most $1$.  The bound of $1$ is attained exactly at the support $\{\pi/10,3\pi/10,5\pi/10,7 \pi/10, 9\pi/10\}$ of the optimal measure $\mu_9$.}
\label{fig:combination9-sine}
\end{figure}

\begin{proof}  We first show that part (ii) follows from (i).
All the coefficients in the inequality
$\sum_{k=1}^m a_k\sin kx\leq 1$ from \eqref{sine-ineq} are nonnegative,
since $\cot x$ decreases from $\infty$ to 0 on the interval
$(0,\pi/2]$.
Therefore, on integrating this inequality
against any Borel probability measure $\mu$ on the real line, we have
$$\sum_{k=1}^m a_k\; \E_\mu \sin kx \leq 1.$$
From the definition of $a_k$ in terms of cotangents, it is immediate
that $\sum_{k=1}^m a_k = c_m$. This proves \eqref{sine-r},
namely that $\min_{1 \leq k \leq m} \E_\mu \sin k x  \leq 1/c_m$.

Next, we show that for every $1 \leq k \leq m$,
the measure $\mu_m$ defined in (ii) satisfies
$$\E_{\mu_m} \sin k x = \frac{1}{c_m}.$$
The proof seems easiest in terms
of the Fourier transform on the cyclic group $G=\Z/(2m+2)$.
Namely, for a complex-valued function $f$ on $G$, define the Fourier
transform on the dual group $\widehat{G}=\Z/(2m+2)$ by
$\widehat{f}(\xi)=(1/(2m+2))\sum_{x\in G}f(x)e^{-2\pi i \xi x/(2m+2)}$;
then the inverse Fourier transform gives that $f(x)=
\sum_{\xi\in \widehat{G}} \widehat{f}(\xi)e^{2\pi i\xi x/(2m+2)}$.

Let $\sigma_m$ be the function on $G=\Z/(2m+2)$
defined by $\sigma_m(k)=1$ if $1\leq k\leq m$, $\sigma_m(k)=-1$ if $-m\leq k\leq -1$,
and zero otherwise (a discrete version of a square wave).
Let $\zeta=e^{2\pi i/(2m+2)}$. Then
the Fourier transform of $\sigma_m$ is, for $j\in \Z/(2m+2)$,
\begin{align*}
\widehat{\sigma_m}(j)&=\frac{1}{2m+2}\sum_{k=0}^{2m+1}\sigma_m(k) \zeta^{-jk}\\
&=\frac{-1}{2m+2}\sum_{k=1}^m (\zeta^{jk}-\zeta^{-jk}).
\end{align*}
Clearly $\widehat{\sigma_m}(0)=0$. For $j\neq 0$ in $\Z/(2m+2)$, we have
$\sum_{k=1}^m \zeta^{jk}=(\zeta^j-(\zeta^j)^{m+1})/(1-\zeta^j)$.
Since $\zeta^{m+1}=-1$, that sum is $(1+\zeta^j)/(1-\zeta^j)$ if $j$
is odd and $-1$ if $j$ is even. Likewise,
$\sum_{k=1}^m \zeta^{-jk}$ is $-(1+\zeta^j)/(1-\zeta^j)$ if $j$ is
odd and $-1$ if $j$ is even. So the Fourier transform above is given
by $\widehat{\sigma_m}(j)=(-1/(m+1))(1+\zeta^j)/(1-\zeta^j)$ if $j$ is odd
and 0 if $j$ is even. Equivalently,
$\widehat{\sigma_m}(j)=(-i/(m+1))\cot(\pi j/(2m+2))$
for $j$ odd.

Therefore, applying the inverse Fourier transform tells us,
in particular for $1\leq k\leq m$, that
\begin{align*}
1&=\sigma_m(k)\\
&=\sum_{j=0}^{2m+1}\widehat{\sigma_m}(j) e^{2\pi i jk/(2m+2)}\\
&=\sum_{1\leq j\leq m; \; j\text{ odd}}\frac{2}{m+1} \;
\cot\biggl( \frac{\pi j}{2m+2}\biggr) \;
\sin\biggl(\frac{\pi jk}{m+1}\biggr).
\end{align*}
(This can also be deduced from an identity due to Eisenstein
and Stern, discussed in the introduction to \cite{BY}.)
After dividing by $c_m$, this says that the measure $\mu_m$
defined in (ii) has $\E_{\mu_m}\sin kx=1/c_m$
for all $1\leq k\leq m$, as we want.

It remains to prove part (i).
We can relate the linear combination of sines $f(x)$
on the left side of \eqref{sine-ineq} to the function
$\sigma_m$ above.
First, let $\nu_m$ be the function on $\Z/(2m+2)$
defined by $\nu_m(j)=2\sigma_m(j)$ if $j$ is odd and 0 otherwise;
so $\nu_m(j)$ is 2 for $1\leq j\leq m$ and $j$ odd,
$-2$ for $m+2\leq j\leq 2m-1$ and $j$ odd, and 0 otherwise.
One checks that multiplying a function $f(j)$ on $\Z/(2m+2)$
by $(-1)^j$ corresponds to shifting its Fourier transform
by $m+1$. Therefore, the Fourier transform of $\nu_m$ is
$$\widehat{\nu_m}(j)=\widehat{\sigma_m}(j)-\widehat{\sigma_m}(m+1+j).$$
Since $\sigma_m$ is an odd function, so is $\widehat{\sigma_m}$,
and hence we
can rewrite this formula as
$$\widehat{\nu_m}(j)=\widehat{\sigma_m}(j)+\widehat{\sigma_m}(m+1-j).$$
If $m$ is odd, then this is
$$\widehat{\nu_m}(j)=\frac{-i}{m+1}\biggl(\cot\frac{\pi j}{2m+2}
+\cot\frac{\pi (m+1-j)}{2m+2}\biggr) $$
if $j$ is odd and 0 if $j$ is even.
If $m$ is even, then
$$\widehat{\nu_m}(j)=\begin{cases}
\frac{-i}{m+1}\cot\bigl(\frac{\pi j}{2m+2}\bigr)
&\text{if }j\text{ is odd,}\\
\frac{-i}{m+1}\cot\bigl(\frac{\pi (m+1-j)}{2m+2}\bigr)
&\text{if }j\text{ is even.}
\end{cases}$$

This is clearly related to the function $f(x)$. To make
the connection precise, consider another interpretation
of the Fourier transform on $\Z/(2m+2)$: namely, as Fourier
series on the circle $\R/2\pi\Z$ applied to linear combinations
of Dirac delta functions
with support in $(1/(2m+2))2\pi\Z$.
Let $S$ denote the square wave function
$$ S(x) \coloneqq 1_{0 < \{x/2\pi\} < 1/2} - 1_{1/2 < \{x/2\pi\} < 1}.$$
We sample this function at odd multiples of $\pi/(m+1)$
to create a discrete approximation $\nu_m$ to $S(x)$,
basically a Dirac comb modulated by a square wave:
\begin{equation}\label{num}
 \nu_m \coloneqq \frac{2\pi}{m+1} \sum_{j \in \Z; j \text{ odd}} S\biggl(\frac{\pi j}{m+1}\biggr) \delta_{\pi j/(m+1)}.
\end{equation}
This measure is $2\pi$-periodic. Here we multiplied the function
$\nu_m$ defined earlier on $\Z/(2m+2)$ by $2\pi/(2m+2)$ in order to make
the Fourier coefficients
$$ \widehat{\nu_m}(k) \coloneqq \frac{1}{2\pi}
\int_0^{2\pi} e^{-i kx}\ d\nu(x)$$
the same as those we computed
on $\Z/(2m+2)$. (In particular,
these Fourier coefficients are periodic with period $2m+2$.)

By inspection, then, the function $f(x)$ from part (i) of the theorem is
$$ f(x) =  \frac{2i}{m+1} \sum_{1 \leq k \leq m} (m+1-k)
\widehat{\nu_m}(k) \sin kx,$$
or equivalently (due to the odd nature of $\nu_m$ and hence $\widehat{\nu_m}$)
$$ f(x) = \sum_{-m \leq k \leq m} \biggl(1 - \frac{|k|}{m+1}\biggr)
\widehat{\nu_m}(k) e^{ikx}.$$

This is clearly related to the {\it Fej\'er kernel},
$F_{m+1}(x) \coloneqq \frac{1}{m+1} \left( \frac{\sin (m+1)(x/2)}{\sin x/2}
\right)^2
=\sum_{|k|\leq m}(1-\frac{|k|}{m+1})e^{ikx}$.
(The original motivation for the Fej\'er kernel was to show
that every continuous function on the circle
is the uniform limit of the averaged partial sums of its Fourier series
\cite[Theorem 1.3.3]{DM}.)
Namely, since the Fourier series takes convolution
to multiplication,
$f$ is the convolution of $\nu_m$ with the Fej\'er kernel:
$$ f(x) = \frac{1}{2\pi} \int_0^{2\pi} F_{m+1}(x-y) \; d\nu_m(y).$$
Here $F_{m+1}(x)$ equals $m+1$ at multiples of $2\pi$,
and it vanishes at other even multiples of $\pi / (m+1)$.
So from \eqref{num} we have
$$ f\biggl(\frac{\pi j}{m+1}\biggr) = S\biggl(\frac{\pi j}{m+1}\biggr)$$
whenever $j$ is odd.  This proves:
\begin{equation}\label{fa}
 f\biggl(\frac{\pi j}{m+1}\biggr) = 1
\end{equation}
whenever $1 \leq j \leq m$ is odd.  More broadly, we now have
an interpretation of $f$ as an interpolation of $S$
given by the Fej\'er kernel.

\begin{figure} [t]
\centering
\includegraphics[width=4in]{./fejer-8.png}
\caption{The Fej\'er kernel $F_{m+1}(x)$ with $m=8$.}
\label{fig:fejer-8}
\end{figure}

Next, let us show that
\begin{equation}\label{fb}
 f'\biggl(\frac{\pi j}{m+1}\biggr) = 0
\end{equation}
for any odd integer $j$.
Namely, since $f$ is the convolution of $\nu$ with the Fej\'er kernel
$F_{m+1}$, $f'$ is the convolution of $\nu$ with the derivative
$F_{m+1}'$.
But $F_{m+1}'(x)$ vanishes at all even multiples of $\pi/(m+1)$,
since $F_{m+1}$ reaches its minimum 0 or maximum $m+1$ at those points.
Since $\nu$ is supported on odd multiples of $\pi/(m+1)$, this proves
\eqref{fb}.

Clearly $f$ is odd and $2\pi$-periodic; in particular
\begin{equation}\label{fosc}
f(0) = f(\pi) = 0.
\end{equation}
Next, since $f'(x)$ is a linear combination of the functions
$\cos kx$ for $1\leq k \leq m$,
de Moivre's formula gives that $f'(x) = P(\cos x)$ for some polynomial $P$ of degree $m$.  In particular, $f'$ has at most $m$ zeros in the interval $[0,\pi]$ (counting multiplicity for the zeros in $(0,\pi)$).  On the other hand, from \eqref{fb} we see that $f'$ has $\lfloor m/2 \rfloor + 1$ zeros in this region, at the points $\frac{\pi j}{m+1}$ with $1 \leq j \leq m+1$ odd.  On the other hand, from \eqref{fa} and Rolle's theorem (and the fact that $f$ is not locally constant) we also see that we have $\lceil m/2 \rceil - 1$ additional zeros distinct from the preceding ones, with one additional zero strictly between $\frac{\pi j}{m+1}$ and $\frac{\pi (j+2)}{m+1}$ whenever $1 \leq j \leq j+2 \leq m$ is odd.  Thus all the $m$ zeros of $f'$ are accounted for, and there are no further zeros; in particular all the zeros of $f'$ in $(0,\pi)$ are simple, and $f'$ changes sign as it crosses each zero in $(0,\pi)$.  We then conclude from \eqref{fosc}, \eqref{fa}, and the mean value theorem that
\begin{itemize}
\item $f(x)$ is strictly increasing from $0$ to $1$ as $x$ goes from $0$ to $\frac{\pi}{m+1}$;
\item Whenever $1 \leq j \leq j+2 \leq m$ is odd, $f$ starts at a local maximum of $1$ at $x = \frac{\pi j}{m+1}$, strictly decreases to a local minimum somewhere between $\frac{\pi j}{m+1}$ and $\frac{\pi (j+2)}{m+1}$, then strictly increases back to a local maximum of $1$ at $x = \frac{\pi (j+2)}{m+1}$.
\item If $j = 2 \lfloor \frac{m}{2} \rfloor + 1$ is the largest odd number less than $m+1$, $f$ is strictly decreasing from $1$ to $0$ as $x$ goes from $\frac{\pi j}{m+1}$ to $\pi$.
\end{itemize}
(See Figures \ref{fig:combination8-sine}, \ref{fig:combination9-sine}.)
This already establishes that $f(x) \leq 1$ when $0 \leq x \leq \pi$.
If we can also show that $f(x) \geq -1$ for $0 \leq x \leq \pi$, then as $f$ is odd and $2\pi$-periodic we will have $f(x) \leq 1$ for all $x$,
proving the theorem. In reality, this bound will be true with substantial room to spare, as $f(x)$ is only moderately smaller than $1$ on most of the interval
$[0,\pi]$ (cf.\ the Gibbs phenomenon).

From the observations above and the oddness of $f$,
we know that $f(x)\geq -1$ if $x\in [-\pi/(m+1),\pi/(m+1)]$
and also if $x\in [m\pi/(m+1),(m+2)\pi/(m+1)]$. So it suffices
to show that $f(x+\frac{\pi}{m+1})-f(x-\frac{\pi}{m+1})]$ is nonnegative for
$x\in [0, (m-1)\pi/(2m+2)]$, and nonpositive for $x\in [(m+3)\pi/(2m+2),
\pi]$.

Assume that $m$ is odd.
Since $f$ is the convolution of $\nu_m$ with the Fej\'er kernel
$F_{m+1}$, we have
\begin{align*}
f\biggl(x+\frac{\pi}{m+1}\biggr) -f\biggl(x-\frac{\pi}{m+1}\biggr)
&= \biggl[\nu_m\biggl( x+\frac{\pi}{m+1}\biggr)
-\nu_m\biggl(x-\frac{\pi}{m+1}\biggr)\biggr]*F_{m+1}\\
&= \frac{4\pi}{m+1}\bigl[ \delta_0-\delta_{\pi}\bigr] *F_{m+1}\\
&= \frac{4\pi}{m+1}\bigl[ F_{m+1}(x)-F_{m+1}(x-\pi)\bigr].
\end{align*}
(This description of the change of $\nu_m$ when the input changes
by $2\pi/(m+1)$ uses that $m$ is odd.)
So it suffices
to show that $F_{m+1}(x)-F_{m+1}(x-\pi)$ is nonnegative for
$x\in [0, (m-1)\pi/(2m+2)]$, and that it is nonpositive
for $x\in [(m+3)\pi/(2m+2),
\pi]$. We prove this (in fact for slightly bigger intervals)
in Lemma \ref{fejer} below.
That completes the proof for $m$ odd.

For $m$ even,
we have the somewhat messier situation that
\begin{align*}
{} &\; f\biggl(x+\frac{\pi}{m+1}\biggr) -f\biggl(x-\frac{\pi}{m+1}\biggr)\\
{}=&\; \biggl[\nu_m\biggl( x+\frac{\pi}{m+1}\biggr)
-\nu_m\biggl(x-\frac{\pi}{m+1}\biggr)\biggr]*F_{m+1}\\
{}=&\; \frac{2\pi}{m+1}\bigl[ 2\delta_0-\delta_{m\pi/(m+1)}
-\delta_{(m+2)\pi/(m+1)}\bigr] *F_{m+1}\\
{}=&\; \frac{2\pi}{m+1}\biggl[2F_{m+1}(x)
-F_{m+1}\biggl(x-\frac{m\pi}{m+1}\biggr)
-F_{m+1}\biggl(x-\frac{(m+2)\pi}{m+1}\biggr)\biggr].
\end{align*}
This is nonnegative for $x\in [0, \frac{(m-1)\pi}{2m+2}]$
and nonpositive for $x\in [\frac{(m+3)\pi}{2m+2},\pi]$, by Lemma
\ref{fejer} below (which in fact works for slightly bigger
intervals). This completes the proof of Theorem
\ref{sine}.
\end{proof}

\begin{lemma}
\label{fejer}
Let $m$ be a positive integer, and let $F(x)=F_{m+1}(x)
=\frac{1}{m+1} \left( \frac{\sin (m+1)(x/2)}{\sin x/2} \right)^2$
be the Fej\'er kernel.
\begin{itemize}
\item[(i)] If $m$ is odd, then $F(x)-F(x-\pi)$
is nonnegative if $x\in [-\pi/2,\pi/2]$ and nonpositive
if $x\in [\pi/2,3\pi/2]$.
\item[(ii)] If $m$ is even,  then $2F(x)-F(x-\frac{m\pi}{m+1})
-F(x-\frac{(m+2)\pi}{m+1})$ is nonnegative if $x\in [-\frac{\pi}{2}
+\frac{\pi}{m+1},\frac{\pi}{2}-\frac{\pi}{m+1}]$
and nonpositive if $x\in [\frac{\pi}{2}+\frac{\pi}{m+1},
\frac{3\pi}{2}-\frac{\pi}{m+1}]$.
\end{itemize}
\end{lemma}

\begin{proof}
(i) Let $m$ be an odd positive integer. By definition of
the Fej\'er kernel $F(x)$, we have
$$F(x)-F(x-\pi)=\frac{1}{m+1}
\biggl[ \frac{\sin^2 ((m+1)x/2)}{\sin^2 x/2}
-\frac{\sin^2 (\frac{(m+1)x}{2}-\frac{(m+1)\pi}{2})}
{\sin^2 (x-\pi)/2}\biggr].$$
Here $\sin((x-\pi)/2)=-\cos (x/2)$. Since $m$ is odd,
$(m+1)\pi/2$ is an integer multiple of $\pi$, and so the numerators
of the two terms are equal. We deduce that
$$F(x)-F(x-\pi)=\frac{\sin^2((m+1)x/2)}{m+1}
\biggl[ \frac{1}{\sin^2(x/2)}-\frac{1}{\cos^2(x/2)}\biggr].$$
For $x\in [-\pi/2,\pi/2]$, we have $\sin^2 (x/2)\leq 1/2$, while
$\cos^2(x/2)\geq 1/2$.
It follows that $F(x)-F(x-\pi)$
is nonnegative if $x\in [-\pi/2,\pi/2]$.
By applying that result to $x-\pi$ in place of $x$, we also find
that $F(x)-F(x-\pi)$ is nonpositive if $x\in [\pi/2,
3\pi/2]$, as we want.

(ii) Let $m$ be an even positive integer. By definition
of the Fej\'er kernel $F(x)$,
\begin{align*}
{}&\; 2F(x)-F(x-m\pi/(m+1))
-F(x-(m+2)\pi/(m+1))\\
{}=&\; \frac{1}{m+1}\biggl[\frac{2\sin^2 ((m+1)x/2)}{\sin^2 (x/2)}
-\frac{\sin^2 (\frac{(m+1)x}{2}-\frac{m\pi}{2})}{\sin^2 (\frac{x}{2}
-\frac{m\pi}{2m+2})}
-\frac{\sin^2 (\frac{(m+1)x}{2}-\frac{(m+2)\pi}{2})}{\sin^2 (\frac{x}{2}
-\frac{(m+2)\pi}{2m+2})}
\biggr].
\end{align*}
Since $m$ is even, $m\pi/2$ and $(m+2)\pi/2$ are both integer
multiples of $\pi$, and so the three $\sin^2$ terms
in the numerators
are equal. So we can rewrite the expression above as
$$\frac{\sin^2((m+1)x/2)}{m+1}\biggl[\frac{2}{\sin^2 (x/2)}
-\frac{1}{\cos^2(\frac{x}{2}+\frac{\pi}{2m+2})}
-\frac{1}{\cos^2(\frac{x}{2}-\frac{\pi}{2m+2})}\biggr].$$

For $x\in [-\frac{\pi}{2}+\frac{\pi}{m+1},\frac{\pi}{2}-\frac{\pi}{m+1}]$,
we have $\sin^2(x/2)\leq 1/2$,
while $\cos^2(\frac{x}{2}-\frac{\pi}{2m+2})$ and $\cos^2(\frac{x}{2}
+\frac{\pi}{2m+2})$
are both $\geq 1/2$. It follows that the previous paragraph's
expression is nonnegative for this range of $x$.
Likewise, if $x\in [\frac{\pi}{2}+\frac{\pi}{m+1},\frac{3\pi}{2}
-\frac{\pi}{m+1}]$,
then $\sin^2(x/2)\geq 1/2$
while $\cos^2(\frac{x}{2}+\frac{\pi}{2m+2})$ and $\cos^2(\frac{x}{2}
-\frac{\pi}{2m+2})$
are both $\leq 1/2$. It follows that the previous paragraph's
expression is nonpositive for this range of $x$.
Lemma \ref{fejer} is proved.
\end{proof}

Algebraic Geometry (math.AG); Classical Analysis and ODEs (math.CA)

Optimal sine and sawtooth inequalities