Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Homomorphism density, Sidorenko's inequality, bipartite graphs with bounded sides

Definition
TenChallenges_Sidorenko

by utkuokur · Nov 4, 2026 · Mathlib 0df444a (Lean v4.33.1)

extremal-graph-theorygraph-theoryhomomorphism-densitysidorenko

The definitions behind Challenge 4 of the Ten Challenges benchmark, for simple graphs HHH on a finite vertex type WWW and GGG on a finite vertex type VVV.

  1. Homomorphism density. t(H,G)t(H,G)t(H,G) is the number of maps f ⁣:W→Vf\colon W\to Vf:W→V such that f(a)f(b)f(a)f(b)f(a)f(b) is an edge of GGG whenever ababab is an edge of HHH, divided by ∣V∣∣W∣|V|^{|W|}∣V∣∣W∣, as a real number.
  2. Sidorenko's inequality for HHH in GGG:
t(H,G) ≥ t(K2,G) e(H),t(H,G)\ \ge\ t(K_2,G)^{\,e(H)},t(H,G) ≥ t(K2​,G)e(H),

where K2K_2K2​ is the complete graph on two vertices, so that t(K2,G)t(K_2,G)t(K2​,G) is the edge density 2e(G)/∣V∣22e(G)/|V|^22e(G)/∣V∣2, and e(H)e(H)e(H) is the number of edges of HHH. 3. Bipartite with sides bounded by kkk. HHH admits sets X,YX,YX,Y of vertices with X∪Y=WX\cup Y=WX∪Y=W, XXX and YYY disjoint, every edge of HHH joining XXX to YYY, ∣X∣≤k|X|\le k∣X∣≤k and ∣Y∣≤k|Y|\le k∣Y∣≤k.

These definitions express Sidorenko's conjecture and its restriction to bipartite graphs of bounded size; the density t(H,G)t(H,G)t(H,G) is reusable for any subgraph-counting statement.

Formalization Note. The count of homomorphisms is Nat.card of a subtype of functions; the bipartition uses Mathlib's IsBipartiteWith and the sizes are Set.ncard. When ∣V∣=0|V|=0∣V∣=0 the density is 000 by the convention for division by zero.

Definition code
import Mathlib.Combinatorics.SimpleGraph.Bipartite
import Mathlib.Data.Real.Basic

open SimpleGraph

variable {W V : Type*} [Fintype W] [Fintype V]

/-- The homomorphism density `t(H, G)`: the number of
graph homomorphisms `H → G`, divided by `|V(G)| ^ |V(H)|`. -/
noncomputable def homDensity (H : SimpleGraph W) (G : SimpleGraph V) : ℝ :=
  (Nat.card {f : W → V // ∀ ⦃a b : W⦄, H.Adj a b → G.Adj (f a) (f b)} : ℝ) /
    (Fintype.card V : ℝ) ^ Fintype.card W

/-- Sidorenko's inequality for a graph `H` over `G`,
in normalized homomorphism-density form: `t(H, G) ≥ t(K₂, G) ^ e(H)`. -/
def SidorenkoFor (H : SimpleGraph W) (G : SimpleGraph V) : Prop :=
  homDensity H G ≥ homDensity (completeGraph (Fin 2)) G ^ Nat.card H.edgeSet

/-- `H` is *bipartite with sides bounded by `k`*: it admits
a bipartition `V(H) = X ∪ Y`, with `|X| ≤ k` and `|Y| ≤ k`. -/
def BipartiteBoundedBy (H : SimpleGraph W) (k : ℕ) : Prop :=
  ∃ X Y : Set W,
    H.IsBipartiteWith X Y ∧ X ∪ Y = Set.univ ∧ X.ncard ≤ k ∧ Y.ncard ≤ k
Source
Ten Challenges repository, file Defs_and_Lems/Sidorenko.lean (commit ff14a56), https://github.com/TenChallenges/ten-challenges/blob/main/Defs_and_Lems/Sidorenko.lean; conjecture as in A. F. Sidorenko, A correlation inequality for bipartite graphs, Graphs Combin. 9 (1993).
Read-back

What the Lean code literally says, in plain math · claude-fable-5-1

Conventions used throughout this file. A simple graph on a type of vertices is a symmetric and irreflexive adjacency relation ∼\sim∼ (undirected, no loops, no multiple edges). ∣S∣|S|∣S∣ denotes the cardinality of a set as a natural number. The file contains three definitions; their vertex types live in arbitrary universes, and their finiteness assumptions differ, so each is listed separately below.

Definition 1: homDensity, written t(H,G)t(H,G)t(H,G). Parameters: a vertex type WWW and a vertex type VVV, each equipped with a finiteness structure (so both are finite sets of vertices); a simple graph HHH on WWW; a simple graph GGG on VVV. The value is the real number

t(H,G)  =  #{ f:W→V  ∣  ∀ a,b∈W, a∼Hb  ⇒  f(a)∼Gf(b) }∣V∣ ∣W∣.t(H,G) \;=\; \frac{\#\{\, f : W \to V \;\mid\; \forall\, a, b \in W,\ a \sim_H b \;\Rightarrow\; f(a) \sim_G f(b) \,\}}{|V|^{\,|W|}} .t(H,G)=∣V∣∣W∣#{f:W→V∣∀a,b∈W, a∼H​b⇒f(a)∼G​f(b)}​.

The numerator counts all functions fff from WWW to VVV (not required to be injective or surjective) such that every pair of HHH-adjacent vertices is sent to a pair of GGG-adjacent vertices (graph homomorphisms H→GH \to GH→G); because GGG has no loops, a function that sends two HHH-adjacent vertices to the same vertex is not counted. The count is formed as a natural number (with the convention that an infinite set counts as 000; this does not arise, since WWW and VVV are finite) and then cast to a real. The denominator is the real number ∣V∣|V|∣V∣ raised to the natural-number power ∣W∣|W|∣W∣. Edge cases the definition silently includes, using the conventions that real division by 000 yields 000 and that x0=1x^0 = 1x0=1: (i) if W=∅W = \varnothingW=∅, there is exactly one function (the empty map), the condition holds vacuously, the denominator is ∣V∣0=1|V|^0 = 1∣V∣0=1, and t(H,G)=1t(H,G) = 1t(H,G)=1 — this holds even when V=∅V = \varnothingV=∅ (as 00=10^0 = 100=1); (ii) if V=∅V = \varnothingV=∅ and W≠∅W \neq \varnothingW=∅, there are no functions, the denominator is 0∣W∣=00^{|W|} = 00∣W∣=0, and t(H,G)=0/0=0t(H,G) = 0/0 = 0t(H,G)=0/0=0; (iii) if HHH has no edges and V≠∅V \neq \varnothingV=∅, every function is counted and t(H,G)=∣V∣∣W∣/∣V∣∣W∣=1t(H,G) = |V|^{|W|}/|V|^{|W|} = 1t(H,G)=∣V∣∣W∣/∣V∣∣W∣=1.

Definition 2: SidorenkoFor HHH GGG. Parameters: as in Definition 1 (WWW and VVV finite, HHH a simple graph on WWW, GGG a simple graph on VVV). It is the proposition, about these two specific graphs (nothing is quantified),

t(H,G)  ≥  t(K2,G) e(H),t(H,G) \;\ge\; t(K_2, G)^{\,e(H)} ,t(H,G)≥t(K2​,G)e(H),

where: K2K_2K2​ is the complete graph on the two-element vertex set {0,1}\{0,1\}{0,1} (its two distinct vertices are adjacent, and nothing else); t(K2,G)t(K_2,G)t(K2​,G) is the density of Definition 1 with W={0,1}W = \{0,1\}W={0,1}, i.e. the number of maps f:{0,1}→Vf : \{0,1\} \to Vf:{0,1}→V with f(0)∼Gf(1)f(0) \sim_G f(1)f(0)∼G​f(1) divided by ∣V∣2|V|^2∣V∣2 — equivalently, the number of ordered pairs (u,v)∈V×V(u,v) \in V \times V(u,v)∈V×V with u∼Gvu \sim_G vu∼G​v (which is twice the number of edges of GGG) divided by ∣V∣2|V|^2∣V∣2, and equal to 000 when V=∅V = \varnothingV=∅; and e(H)e(H)e(H) is the number of edges of HHH, i.e. the number of unordered pairs {a,b}\{a,b\}{a,b} with a∼Hba \sim_H ba∼H​b, as a natural number (an infinite edge set would count as 000, which does not arise because WWW is finite). The exponent is a natural-number power of a real, so when e(H)=0e(H) = 0e(H)=0 the right-hand side equals 111 regardless of t(K2,G)t(K_2,G)t(K2​,G) (even when t(K2,G)=0t(K_2,G) = 0t(K2​,G)=0). The inequality is non-strict (≥\ge≥).

Definition 3: BipartiteBoundedBy HHH kkk. Parameters: a vertex type WWW with no finiteness assumption (this is the one definition in the file whose signature carries none); a simple graph HHH on WWW; a natural number kkk. It is the proposition: there exist subsets X,Y⊆WX, Y \subseteq WX,Y⊆W such that

  • XXX and YYY are disjoint, X∩Y=∅X \cap Y = \varnothingX∩Y=∅;
  • for all v,w∈Wv, w \in Wv,w∈W: if v∼Hwv \sim_H wv∼H​w then (v∈Xv \in Xv∈X and w∈Yw \in Yw∈Y) or (v∈Yv \in Yv∈Y and w∈Xw \in Xw∈X);
  • X∪Y=WX \cup Y = WX∪Y=W (every vertex lies in XXX or in YYY);
  • ∣X∣≤k|X| \le k∣X∣≤k and ∣Y∣≤k|Y| \le k∣Y∣≤k.

The first two bullets are exactly Mathlib's "HHH is bipartite with parts XXX and YYY"; the third adds that the two parts cover all of WWW. Here ∣X∣|X|∣X∣ and ∣Y∣|Y|∣Y∣ are set cardinalities as natural numbers with the convention that an infinite set has cardinality 000. Consequently, when WWW is infinite an infinite part satisfies its bound ∣X∣≤k|X| \le k∣X∣≤k automatically, for every kkk including k=0k = 0k=0; when WWW is finite the cardinalities are the true ones. Nothing requires XXX or YYY to be nonempty, nothing requires HHH to have any edges (an edgeless graph satisfies the adjacency condition for any disjoint cover X,YX, YX,Y), and a vertex with no neighbours may be placed on either side. For finite WWW and k=0k = 0k=0 the conditions force W=∅W = \varnothingW=∅.

Human review
  • Endorsed by Shuze Chen · Nov 4, 2026

    Confirmed by the moderator at approval.

  • Endorsed by utkuokur · Nov 4, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me