# Counting lemma

The counting lemmas this article discusses are statements in combinatorics and graph theory. The first one extracts information from $\epsilon$-regular pairs of subsets of vertices in a graph $G$, in order to guarantee patterns in the entire graph; more explicitly, these patterns correspond to the count of copies of a certain graph $H$ in $G$. The second counting lemma provides a similar yet more general notion on the space of graphons, in which a scalar of the cut distance between two graphs is correlated to the homomorphism density between them and $H$.

## Graph embedding version of counting lemma

Whenever we have an $\epsilon$-regular pair of subsets of vertices $U,V$ in a graph $G$, we can interpret this in the following way: the bipartite graph, $(U,V)$, which has density $d(U,V)$, is close to being a random bipartite graph in which every edge appears with probability $d(U,V)$, with some $\epsilon$ error.
In a setting where we have several clusters of vertices, some of the pairs between these clusters being $\gamma$-regular, we would expect the count of small, or local patterns, to be roughly equal to the count of such patterns in a random graph. These small patterns can be, for instance, the number of graph embeddings of some $H$ in $G$, or more specifically, the number of copies of $H$ in $G$ formed by taking one vertex in each vertex cluster.
The above intuition works, yet there are several important conditions that must be satisfied in order to have a complete statement of the theorem; for instance, the pairwise densities are at least $\varepsilon$, the cluster sizes are at least $\gamma ^{-1}$ , and $\gamma \leq \varepsilon ^{h}/4h$. Being more careful of these details, the statement of the graph counting lemma is as follows:

   ### Statement of the theorem

   If $H$ is a graph with vertices $1,\cdots ,h$ and $m$ edges, and $G$ is a graph with (not necessarily disjoint) vertex subsets $W_{1},\cdots ,W_{h}$, such that $|W_{i}|\geq \gamma ^{-1}$ for all $i=1,\ldots ,h$ and for every edge $(i,j)$ of $H$ the pair $(W_{i},W_{j})$ is $\gamma$-regular with density $d(W_{i},W_{j})>\varepsilon$ and $\gamma \leq \varepsilon ^{h}/4h$, then $G$ contains at least $2^{-h}\varepsilon ^{m}|W_{1}|\cdot \ldots \cdot |W_{h}|$ many copies of $H$ with the copy of vertex $i$ in $W_{i}$.
This theorem is a generalization of the triangle counting lemma, which states the above but with $H=K_{3}$:

   ### Triangle counting Lemma

   Let $G$ be a graph on $n$ vertices, and let $X,Y,Z$ be subsets of $V(G)$ which are pairwise $\epsilon$-regular, and suppose the edge densities $d_{XY},d_{XZ},d_{YZ}$ are all at least $2\epsilon$. Then the number of triples $(x,y,z)\in X\times Y\times Z$ such that $x,y,z$ form a triangle in $G$ is at least$(1-2\epsilon )(d_{XY}-\epsilon )(d_{XZ}-\epsilon )(d_{YZ}-\epsilon )|X||Y||Z|.$

#### Proof of triangle counting lemma:

Since $(X,Y)$ is a regular pair, less than $\varepsilon |X|$ of the vertices in $X$ have fewer than $(d_{XY}-\varepsilon )|Y|$ neighbors in $Y$; otherwise, this set of vertices from $X$ along with its neighbors in $Y$ would witness irregularity of $(X,Y)$, a contradiction. Intuitively, we are saying that not too many vertices in $X$ can have a small degree in $Y$.
By an analogous argument in the pair $(X,Z)$, less than $\varepsilon |X|$ of the vertices in $X$ have fewer than $(d_{XZ}-\varepsilon )|Z|$ neighbors in $Z$. Combining these two subsets of $X$ and taking their complement, we obtain a subset $X'\subseteq X$ of size at least $(1-2\varepsilon )|X|$ such that every vertex $x\in X'$ has at least $(d_{XY}-\varepsilon )|Y|$ neighbors in $Y$ and at least $(d_{XZ}-\varepsilon )|Z|$ neighbors in $Z$.
We also know that $d_{XY},d_{XZ}\geq 2\varepsilon$, and that $(Y,Z)$ is an $\varepsilon$-regular pair; therefore, the density between the neighborhood of $x$ in $Y$ and the neighborhood of $x$ in $Z$ is at least $(d_{YZ}-\varepsilon )$, because by regularity it is $\varepsilon$-close to the actual density between $Y$ and $Z$.
Summing up, for each of these at least $(1-2\varepsilon )|X|$ vertices $x\in X'$, there are at least $(d_{XY}-\epsilon )(d_{XZ}-\epsilon )(d_{YZ}-\epsilon )|Y||Z|$ choices of edges between the neighborhood of $x$ in $Y$ and the neighborhood of $x$ in $Z$. From there we can conclude this proof.
Idea of proof of graph counting lemma:The general proof of the graph counting lemma extends this argument through a greedy embedding strategy; namely, vertices of $H$ are embedded in the graph one by one, by using the regularity condition so as to be able to keep a sufficiently large set of vertices in which we could embed the next vertex.

## Graphon version of counting lemma

The space ${\tilde {\mathcal {W}}}_{0}$ of graphons is given the structure of a metric space where the metric is the cut distance $\delta _{\Box }$. The following lemma is an important step in order to prove that $({\tilde {\mathcal {W}}}_{0},\delta _{\Box })$ is a compact metric space. Intuitively, it says that for a graph $F$, the homomorphism densities of two graphons with respect to this graph have to be close (this bound depending on the number of edges $F$) if the graphons are close in terms of cut distance.

### Definition (cut norm).

The cut norm of $W:[0,1]^{2}\to \mathbb {R}$ is defined as $\|W\|_{\square }=\sup _{S,T\subseteq [0,1]}\left|\int _{S\times T}W\right|$, where $S$ and $T$ are measurable sets.

### Definition (cut distance).

The cut distance is defined as $\delta _{\square }(U,W)=\inf _{\phi }||U-W^{\phi }||_{\square }$, where $W^{\phi }(x,y)$ represents $W(\phi (x),\phi (y))$ for a measure-preserving bijection $\phi$.

   ### Graphon Counting Lemma

   For graphons $W,U$ and graph $F$, we have $|t(F,W)-t(F,U)|\leq |E(F)|\delta _{\square }(W,U)$, where $|E(F)|$ denotes the number of edges of graph $F$.

#### Proof of the graphon counting lemma:

It suffices to prove $|t(F,W)-t(F,U)|\leq |E(F)|\|W-U\|_{\square }.$Indeed, by considering the above, with the right hand side expression having a factor $\|W-U^{\phi }\|_{\Box }$ instead of $\|W-U\|_{\Box }$, and taking the infimum of the over all measure-preserving bijections $\phi$, we obtain the desired result.
Step 1: Reformulation. We prove a reformulation of the cut norm, which is by definition the left hand side of the following equality. The supremum in the right hand side is taken among measurable functions $u$ and $v$:$\sup _{S,T\subseteq [0,1]}\left|\int _{S\times T}W\right|=\sup _{u,v:[0,1]\rightarrow [0,1]}\left|\int _{[0,1]^{2}}W(x,y)u(x)v(y)dxdy\right|.$
Here's the reason for the above to hold: By taking $u=\mathbb {1} _{S}$ and $u=\mathbb {1} _{T}$, we note that the left hand side is less than or equal than the right hand side. The right hand side is less than or equal than the left hand side by bilinearity of the integrand in $u,v$, and by the fact that the extrema are attained for $u,v$ taking values at $0$ or $1$.
Step 2: Proof for $F=K_{3}$. In the case that $F=K_{3}$, we observe that
${\begin{aligned}t(K_{3},W)-t(K_{3},U)&=\int _{[0,1]^{3}}((W(x,y)W(x,z)W(y,z)-U(x,y)U(x,z)U(y,z))dxdydz\\&=\int _{[0,1]^{3}}(W-U)(x,y)W(x,z)W(y,z)dxdydz\\&\qquad +\int _{[0,1]^{3}}U(x,y)(W-U)(x,z)W(y,z)dxdydz\\&\qquad +\int _{[0,1]^{3}}U(x,y)U(x,z)(W-U)(y,z)dxdydz.\end{aligned}}$
By Step 1, we have that for a fixed $z$ that
   $\left|\int _{[0,1]^{2}}(W-U)(x,y)W(x,z)W(y,z)dxdy\right|\leq \|W-U\|_{\square }$
Therefore, when integrating over all $z\in [0,1]$ we get that
   $\left|\int _{[0,1]^{3}}(W-U)(x,y)W(x,z)W(y,z)dxdydz\right|\leq \|W-U\|_{\square }$
Using this bound on each of the three summands, we get that the whole sum is bounded by $3\|W-U\|_{\square }$.
Step 3: General case. For a general graph $F$, we need the following lemma to make everything more convenient:

   ##### Lemma.

   The following expression holds:$a_{1}a_{2}\cdots a_{n}-b_{1}b_{2}\cdots b_{n}=(a_{1}-b_{1})a_{2}\cdots a_{n}+b_{1}(a_{2}-b_{2})\cdots a_{n}+\cdots b_{1}b_{2}\cdots (a_{n}-b_{n}).$
The above lemma follows from a straightforward expansion of the right hand side. Then, by the triangle inequality of norm, we have the following${\begin{aligned}\left|t(F,W)-t(F,U)\right|&=\left|\int \left(\prod _{u_{i}v_{i}\in E(F)}W(u_{i},v_{i})-\prod _{u_{i}v_{i}\in E(F)}U(u_{i},v_{i})\right)\prod _{v\in V}dv\right|\\&\leq \sum _{i=1}^{|E(F)|}\left|\int \left(\ \prod _{j=1}^{i-1}U(u_{j},v_{j})(W(u_{i},v_{i})-U(u_{i},v_{i}))\prod _{k=i+1}^{|E(F)|}W(u_{k},v_{k})\right)\prod _{v\in V}dv\right|.\end{aligned}}$
Here, each absolute value term in the sum is bounded by the cut norm $\|W-U\|_{\square }$ if we fix all the variables except for $u_{i}$ and $v_{i}$ for each $i$-th term, altogether implying that $|t(F,W)-t(F,U)|\leq |E(F)|\ \delta _{\square }(W,U)$. This finishes the proof.