\documentclass[11pt]{article} \usepackage[margin=1in]{geometry} \usepackage{amsmath,amssymb,amsthm,mathtools} \usepackage{graphicx} \usepackage{xcolor} \usepackage{tikz} \usepackage{enumitem} \usepackage{booktabs} \usepackage{array} \usepackage[colorlinks=true,linkcolor=blue!50!black,citecolor=blue!50!black,urlcolor=blue!50!black]{hyperref} \usepackage{bookmark} \newtheorem{theorem}{Theorem}[section] \newtheorem{proposition}[theorem]{Proposition} \newtheorem{lemma}[theorem]{Lemma} \newtheorem{corollary}[theorem]{Corollary} \newtheorem{conjecture}[theorem]{Conjecture} \newtheorem{claim}[theorem]{Computational Claim} \theoremstyle{remark} \newtheorem{remark}[theorem]{Remark} \numberwithin{equation}{section} \newcommand{\Km}{K_4^{-}} \newcommand{\Hs}{H_6} \newcommand{\ex}{\mathrm{ex}} \newcommand{\RR}{\mathbb{R}} \newcommand{\EE}{\mathbb{E}} \newcommand{\PP}{\mathbb{P}} \newcommand{\cF}{\mathcal{F}} \newcommand{\cC}{\mathcal{C}} \newcommand{\cO}{\mathcal{O}} \newcommand{\ip}[2]{\langle #1,#2\rangle} \newcommand{\Pcap}{\pi_0} \newcommand{\sA}{s_A} \newcommand{\cA}{c_A} \newcommand{\cB}{c_B} \newcommand{\Emono}{E_{\mathrm{mono}}} \newcommand{\Tmono}{T_{\mathrm{mono}}} \newcommand{\Ecross}{E_{\mathrm{cross}}} \newcommand{\Tcross}{T_{\mathrm{cross}}} \newcommand{\emono}{e_{\mathrm{mono}}} \newcommand{\tmono}{t_{\mathrm{mono}}} \newcommand{\ecross}{e_{\mathrm{cross}}} \newcommand{\tcross}{t_{\mathrm{cross}}} \title{The Tur\'an density of $\Km$ is $2/7$} \author{ J\'ozsef Balogh\thanks{Department of Mathematics, UIUC, Urbana, IL, USA. E-mail: \texttt{jobal@illinois.edu}. Partially supported by NSF grants RTG DMS-1937241, FRG DMS-2152488, and DMS-2554179, UIUC Campus Research Board Award RB26026, the Simons Collaboration grant [SFI-MPS-TSM-00013107, JB].} \and Bernard Lidick\'{y}\thanks{Department of Mathematics, Iowa State University, Ames, IA. E-mail: {\tt lidicky@iastate.edu}. Research of this author is supported in part by NSF FRG DMS-2152490 and DMS-2554129, the Simons Foundation TSM-00013439 and Scott Hanna Professorship. } \and Florian Pfender\thanks{Department of Mathematical and Statistical Sciences, University of Colorado Denver, Denver, CO. E-mail: {\tt Florian.Pfender@ucdenver.edu}. Research is partially supported by NSF DMS-2152498 and DMS-2554130.} \and Jan Volec\thanks{Department of Theoretical Computer Science, Faculty of Information Technology, Czech Technical University in Prague, Th\'akurova 9, Prague, 160 00, Czech Republic. E-mail: {\tt jan@ucw.cz}. Research of this author was supported by the grant 23-06815M of the Grant Agency of the Czech Republic. } } \date{\today} \begin{document} \maketitle \begin{abstract} Denote by $K_4^-$ the $3$-uniform hypergraph with four vertices and three edges. We prove that the Tur\'an density of $K_4^-$ is $2/7$. This confirms a conjecture of Frankl and F\"uredi, who constructed $K_4^-$-free $3$-uniform hypergraphs of density $2/7$ in 1984. More precisely, we prove that every $K_4^-$-free $3$-uniform hypergraph on $n$ vertices has at most $(n^3-n)/21$ edges. Furthermore, this bound is attained if and only if $n$ is a power of $6$, in which case the extremal $3$-graph is unique, and isomorphic to the hypergraph constructed by Frankl and F\"uredi. We also prove stability, that every $K_4^-$-free $3$-graph of density close to $2/7$ is close to the Frankl--F\"uredi construction. The proof is computer-assisted: it uses flag-algebra computations, and all main results, including the verification of the exact certificates, are formalized in the proof assistant Lean~4. The authors also used Claude Fable 5.2, see the precise AI declaration in the paper. \end{abstract} The authors are working on a write-up with an improved presentation to replace this first preprint. \section{Introduction}\label{sec:intro} Let $r\ge 2$ be an integer. For an $r$-uniform hypergraph ($r$-graph) $F$, an $r$-graph $G$ is \emph{$F$-free} if $G$ contains no subgraph isomorphic to $F$. The Tur\'an problem asks for the maximum number of edges, $\ex(n,F)$, of an $F$-free $r$-graph on $n$ vertices. The \emph{Tur\'an density} of $F$ is \[ \pi(F)=\lim_{n\to\infty}\frac{\ex(n,F)}{\binom nr} . \] The limit exists because the sequence is nonincreasing, which follows from a simple averaging argument first observed by Katona, Nemetz and Simonovits~\cite{KNS64}. Tur\'an~\cite{Turan41} initiated the study of $\ex(n,F)$ by determining it when $r=2$ and $F$ is a complete graph. The problem was soon extended to hypergraphs, although the general problem was published only much later~\cite{Turan61}. Determining $\ex(n,F)$, or even $\pi(F)$, for $r\ge 3$ turned out to be an extremely hard problem. Erd\H{o}s~\cite{Er64} proved that $\pi(F)=0$ if and only if $F$ is $r$-partite, and for $r\ge3$ the Tur\'an density is known only for few $r$-graphs that are not $r$-partite. One of the first exact results concerns cancellative $3$-graphs. A $3$-graph is \emph{cancellative} if $A\cup B=A\cup C$ implies $B=C$ for all its edges $A,B,C$; equivalently, it contains neither $F_5=\{123,124,345\}$ nor $\Km=\{123,124,134\}$, the $3$-uniform hypergraph ($3$-graph) with four vertices and three edges. Bollob\'as~\cite{Bo74} proved that the largest cancellative $3$-graphs on $n$ vertices are the balanced complete $3$-partite $3$-graphs; in particular $\pi(\{F_5,\Km\})=2/9$. Frankl and F\"uredi~\cite{FF83} showed that for large $n$ the same $3$-graphs are extremal when only $F_5$ is forbidden, and Keevash and Mubayi~\cite{KM04} proved the corresponding stability results. Forbidding only $\Km$ leads to a different and much harder problem, the subject of this paper: how many triples can a set of $n$ points contain if every four points span at most two of them? Mubayi~\cite{Mu} calls $\Km$ ``the smallest (in the sense of both vertices and edges) $3$-graph with positive Tur\'an density''. All $3$-graphs with at most two edges are tripartite and thus have Tur\'an density $0$. For the two remaining $3$-graphs on four vertices, $\Km$ and the tetrahedron $K_4$, the Tur\'an density was not known. In 1974 Erd\H{o}s wrote that the determination of the limit of $f(n;G_3(4;3))/n^3$ ``seems to be very difficult, perhaps as difficult as Tur\'an's problem on $f(n;K_3(4))$''~\cite[pp.~80--81]{Er74}; here $f(n;G_3(4;3))=\ex(n,\Km)+1$ is the least number of edges on $n$ vertices that forces three edges on four vertices. Keevash's survey says: ``It is remarkable that the Tur\'an problem is still open for such a seemingly simple $3$-graph --- we do not even know its Tur\'an density!''~\cite[Section~6]{Ke}. Our main result determines the Tur\'an density $\pi(\Km)$. \begin{theorem}\label{thm:main} $\pi(\Km)=2/7$. \end{theorem} With Theorem~\ref{thm:main}, among the $3$-graphs on four vertices only Tur\'an's tetrahedron problem (conjectured value $5/9$) remains open. \subsection{The construction and the conjecture}\label{const11} According to Frankl and F\"uredi~\cite{FF}, Tur\'an had conjectured that $\pi(\Km)=1/4$, and in 1982 Erd\H{o}s and S\'os still wrote that this is ``very probably'' the case~\cite{ES82}. Frankl and F\"uredi disproved this. Figure~\ref{fig:H6} shows the $3$-graph $\Hs$ on $\{1,\dots,6\}$ with the ten edges \[ 123,\ 125,\ 136,\ 145,\ 146,\ 234,\ 246,\ 256,\ 345,\ 356 . \] The vertices $1,\dots,5$ induce the tight $5$-cycle with edges $\{i,i+1,i+2\}$ (indices modulo $5$), and the edges containing $6$ are $\{i,i+2,6\}$.\footnote{The Lean formalization and its data files use a different labeling of the vertices of $\Hs$, with edges $123,124,135,146,156,236,245,256,345,346$; it is obtained from the labeling used here by renaming the vertices $3,4,5$ to $4,5,3$, respectively.} Every four vertices of $\Hs$ span exactly two edges, every five vertices induce a tight $5$-cycle $C_5$, and the link of every vertex is a cycle of length five. For a partition $V=V_1\cup\dots\cup V_6$ of a set $V$ (where some $V_i$ are allowed to be empty), the \emph{blow-up of $\Hs$} on $V$ consists of all triples $\{x,y,z\}$ with $x\in V_i$, $y\in V_j$, $z\in V_k$ for an edge $ijk$ of $\Hs$. A set of four vertices $\{w,x,y,z\}$ in a blow-up of $\Hs$ spans exactly two edges if and only if the four vertices are in four different parts or if they meet exactly three parts and these three parts correspond to an edge of $\Hs$. Otherwise, the set spans no edges. In particular, any blow-up of $\Hs$ is $\Km$-free. An \emph{iterated balanced blow-up of $\Hs$} on a set $V$ with $|V|=n$ is the blow-up of $\Hs$ for a partition of $V$ into six parts of sizes in $\{\lfloor\frac{n}{6}\rfloor,\lceil\frac{n}{6}\rceil\}$, together with an iterated balanced blow-up on every part (for $n\le2$ it is the empty $3$-graph). An iterated balanced blow-up of $\Hs$ may contain sets of vertices $\{w,x,y,z\}$ spanning exactly one edge (in fact, every iterated balanced blow-up of $\Hs$ with $n\ge 19$ contains such sets), but it is still $\Km$-free as every edge meets three different parts of a single blow-up of $\Hs$. As observed by Frankl and F\"uredi (and independently by Giraud, as reported in~\cite{FF}), the edge density of all iterated balanced blow-ups of $\Hs$ is $2/7+o(1)$ as $n$ grows, which implies that $\pi(\Km)\ge 2/7$. If we further insist that at every level of the recursion, whenever a set of $n'\equiv3\pmod 6$ vertices is partitioned, the three parts of size $\lceil\frac{n'}{6}\rceil$ correspond to an edge in $\Hs$, the iterated balanced blow-up is unique up to isomorphism and we denote it by $B_n$. Among all iterated balanced blow-ups of $\Hs$ on $n$ vertices, it is easy to verify that $B_n$ uniquely maximizes the number of edges. \begin{figure}[ht] \begin{center} \scalebox{1.08}{ \begin{tikzpicture}[ vtx/.style={circle, fill, draw, inner sep=0pt, minimum size=5.4pt}, hyperedgeP/.style={fill=pink, opacity=0.5, draw=black}, hyperedgeB/.style={fill=blue, opacity=0.3, draw=black}, hyperedgeG/.style={fill=green, opacity=0.5, draw=black}, hyperedgeY/.style={fill=yellow, opacity=0.5, draw=black}] \draw[hyperedgeY] (0:1.5) to (120:1.5) to (240:1.5) to (0:1.5); \draw[hyperedgeP] (0:1.5) to[out=180,in=290,looseness=1.2] (120:1.5) to[out=280,in=30,looseness=1.2] (240:2.5) to[out=10,in=190,looseness=1.2] (0:1.5); \draw[hyperedgeP] (0:2.5) to[out=170,in=0,looseness=1.2] (120:1.5) to[out=60,in=330,looseness=1.2] (120:2.5) to[out=0,in=150,looseness=1.2] (0:2.5); \draw[hyperedgeP] (240:2.5) to[out=90,in=250,looseness=1.2] (120:1.5) to[out=140,in=290,looseness=1.2] (120:2.5) to[out=270,in=110,looseness=1.2] (240:2.5); \draw[hyperedgeB] (120:1.5) to[out=300,in=410,looseness=1.2] (240:1.5) to[out=400,in=150,looseness=1.2] (360:2.5) to[out=130,in=310,looseness=1.2] (120:1.5); \draw[hyperedgeB] (120:2.5) to[out=290,in=120,looseness=1.2] (240:1.5) to[out=180,in=450,looseness=1.2] (240:2.5) to[out=120,in=270,looseness=1.2] (120:2.5); \draw[hyperedgeB] (360:2.5) to[out=210,in=370,looseness=1.2] (240:1.5) to[out=260,in=410,looseness=1.2] (240:2.5) to[out=390,in=230,looseness=1.2] (360:2.5); \draw[hyperedgeG] (240:1.5) to[out=420,in=530,looseness=1.2] (360:1.5) to[out=520,in=270,looseness=1.2] (480:2.5) to[out=250,in=430,looseness=1.2] (240:1.5); \draw[hyperedgeG] (240:2.5) to[out=410,in=240,looseness=1.2] (360:1.5) to[out=300,in=570,looseness=1.2] (360:2.5) to[out=240,in=390,looseness=1.2] (240:2.5); \draw[hyperedgeG] (480:2.5) to[out=330,in=490,looseness=1.2] (360:1.5) to[out=380,in=530,looseness=1.2] (360:2.5) to[out=510,in=350,looseness=1.2] (480:2.5); \draw[hyperedgeY] (0:1.5) to (120:1.5) to (240:1.5) to (0:1.5); \draw[hyperedgeP] (0:1.5) to[out=180,in=290,looseness=1.2] (120:1.5) to[out=280,in=30,looseness=1.2] (240:2.5) to[out=10,in=190,looseness=1.2] (0:1.5); \draw[hyperedgeG] (240:1.5) to[out=420,in=530,looseness=1.2] (0:1.5) to[out=520,in=270,looseness=1.2] (120:2.5) to[out=250,in=430,looseness=1.2] (240:1.5); \draw[hyperedgeG] (240:2.5) to[out=410,in=240,looseness=1.2] (0:1.5) to[out=300,in=570,looseness=1.2] (0:2.5) to[out=240,in=390,looseness=1.2] (240:2.5); \draw[hyperedgeG] (120:2.5) to[out=330,in=490,looseness=1.2] (0:1.5) to[out=380,in=530,looseness=1.2] (0:2.5) to[out=510,in=350,looseness=1.2] (120:2.5); \draw[thick] (120:1.5) to (240:1.5); \draw[thick] (120:1.5) to[out=280,in=30,looseness=1.2] (240:2.5); \draw[thick] (120:2.5) to[out=250,in=430,looseness=1.2] (240:1.5); \draw[thick] (0:2.5) to[out=240,in=390,looseness=1.2] (240:2.5); \draw[thick] (0:2.5) to[out=510,in=350,looseness=1.2] (120:2.5); \draw (0:1.5) node[vtx]{} (120:1.5) node[vtx]{} (240:1.5) node[vtx]{} (0:2.5) node[vtx]{} (120:2.5) node[vtx]{} (240:2.5) node[vtx]{}; \end{tikzpicture} } \end{center} \caption{The $3$-graph $\Hs$ on six vertices; its ten edges are drawn as shaded triangles, and the link of one vertex is emphasized.}\label{fig:H6} \end{figure} Frankl and F\"uredi conjectured that their construction is optimal, that is, that $\pi(\Km)=2/7$ (Z.~F\"uredi, personal communication). The conjecture is not stated in~\cite{FF}; it appears in print in F\"uredi's survey~\cite[(15.7)]{Fu91}, which credits the construction showing the lower bound to~\cite{FF}, to Giraud (1983, unpublished) and to the 1982 thesis of Sidorenko. It is not known to us whether Giraud or Sidorenko also conjectured the construction to be optimal. The conjecture was later stated by Mubayi~\cite[Conjecture~2]{Mu}, and some of the later papers attribute it to him~\cite{Ke,FPVV,LMP,MPS}; it is Conjecture~4 of the problem list of Mubayi, Pikhurko and Sudakov~\cite[Section~2.2]{MPS}. Two finite forms are in the literature: \begin{conjecture}[Mubayi~\cite{Mu}]\label{con:Mubayi} For infinitely many $n$, $B_n$ has the most edges among $\Km$-free $3$-graphs on $n$ vertices. \end{conjecture} \begin{conjecture}[Markstr\"om and Talbot~\cite{MT}]\label{con:MT} For $n\ge11$ the unique $\Km$-free $3$-graph with $\ex(n,\Km)$ edges is ``the $3$-graph constructed by the blow-up construction of''~\cite{FF}. \end{conjecture} Conjecture~\ref{con:MT} has to be read as a statement about the top level: every $\Km$-free $3$-graph on $n\ge11$ vertices with $\ex(n,\Km)$ edges is a balanced blow-up of $\Hs$ on six parts with extremal $3$-graphs inside the parts. Together with the fully known set of extremal $3$-graphs up to $n\le 19$ from the same paper, this would imply that $B_n$ is extremal for every $n$, but not uniquely extremal for a significant set of values $n$. Since there are several different extremal $3$-graphs on $n$ vertices when $8\le n\le 10$ (see Section~\ref{sec:finiteconj}), the extremal $3$-graph on $n$ vertices would not be unique whenever repeated balanced partitions result in a part of order in that range (e.g. for $43\le n\le 65$ and $253\le n\le 395$ etc.). \subsection{Exact results and stability}\label{sec:intro-results} The asymptotic theorem implies an inequality for every $n$, and we determine when it is tight. \begin{theorem}\label{thm:exact} For every $n\ge1$, \[ \frac27\binom n3\ \le\ |B_n|\ \le\ \ex(n,\Km)\ \le\ \frac27\binom{n+1}3. \] Moreover, a $\Km$-free $3$-graph on $n$ vertices has $\frac27\binom{n+1}3$ edges if and only if $n=6^t$ for some $t\ge0$ and it is isomorphic to $B_{n}$. \end{theorem} The next theorem shows that the iterated blow-ups $B_n$ converge to a hypergraphon which is the unique $\Km$-free hypergraphon of density $2/7$. \begin{theorem}\label{thm:stab} For every $\delta>0$ there are $\varepsilon>0$ and $n_0$ such that for every $\Km$-free $3$-graph $H$ on $n\ge n_0$ vertices with at least $(\frac27-\varepsilon)\binom n3$ edges, we have $|H\triangle B_n|\le\delta n^3$ for some relabeling of the vertices of $B_n$. \end{theorem} Theorem~\ref{thm:exact} proves Conjecture~\ref{con:Mubayi}: the construction of Frankl and F\"uredi is optimal for $n=6^t$, and it is then the only extremal $3$-graph. This is also the case $n=6^t$, $t\ge2$, of Conjecture~\ref{con:MT}. Together with a count of the edges of $B_n$, the upper bound in Theorem~\ref{thm:exact} determines $\ex(n,\Km)$ up to an error $O(n\log n)$ for every $n$ (Proposition~\ref{prop:error}). Theorems~\ref{thm:exact} and~\ref{thm:stab} are proved in Section~\ref{sec:stability}, together with a weighted form of the upper bound (Theorem~\ref{thm:lagr}) and a description of the top level of the structure (Theorem~\ref{thm:level}). \subsection{Previous upper bounds and related problems}\label{sec:bounds} Here is a list of upper bounds for $\pi(\Km)$ in the literature. Years are those of the journal volume (of the thesis for Matthias, of the preprint for the last two rows). \begin{center}\small \begin{tabular}{@{}lllp{0.27\textwidth}@{}} \toprule bound on $\pi(\Km)$ & year & & method\\ \midrule $1/3$ & 1983 & de Caen~\cite{dC} & counting\\ $1/3-10^{-10}$ & 1994 & Matthias~\cite{Mat} (thesis; see~\cite{Mu,Ra}) & \\ $1/3-4.5305\cdot10^{-6}$ & 2003 & Mubayi~\cite{Mu} & counting, supersaturation\\ $1/3-1.8982\cdot10^{-5}$ & 2006 & Li et al.~\cite[Theorem~5.1]{LRSW} & small cases, supersaturation\\ $0.32975$ & 2007 & Talbot~\cite{Ta} & chromatic Tur\'an problems\\ $0.32908$ & 2010 & Markstr\"om, Talbot~\cite{MT} & \raggedright $2$-colorable $3$-graphs on $16$ vertices, supersaturation\tabularnewline $0.2978$ & 2010 & Razborov~\cite{Ra} & flag algebras\\ $0.2871$ & 2011 & Baber, Talbot~\cite{BT} & flag algebras\\ $0.286889$ & 2013 & Falgas-Ravry, Vaughan~\cite{FV} & flag algebras\\ $0.286504$ & 2026 & Lidick\'y, Volec~\cite{LV} & flag algebras on $8$ vertices\\ $2/7=0.285714\ldots$ & 2026 & this paper & partition method, flag algebras\\ \bottomrule \end{tabular} \end{center} The previously best bound $0.286504$ is verified again in exact arithmetic in Section~\ref{sec:proofP}. The values of $\ex(n):=\ex(n,\Km)$ are known for $n\le19$~\cite{De,LRSW,MT}; they are listed in Section~\ref{sec:finiteconj} and compared there with the bound of Theorem~\ref{thm:exact}. Several related parameters of $\Km$ were determined earlier, and some are still open. \emph{Codegree.} The codegree density of $\Km$ is $1/4$: the largest minimum codegree of a $\Km$-free $3$-graph on $n$ vertices is at most $(n+1)/4$ for large $n$, with equality for infinitely many $n$ (Falgas-Ravry, Pikhurko, Vaughan and Volec~\cite{FPVV}). \emph{Positive codegree.} If only the pairs that lie in an edge are considered, the answer is different: the largest minimum codegree of such pairs in a $\Km$-free $3$-graph on $n$ vertices is $\lfloor n/3\rfloor$ (Halfpap, Lemons and Palmer~\cite{HLP}). \emph{Uniform density.} The uniform Tur\'an density of $\Km$ is $1/4$ (Glebov, Kr\'al' and Volec~\cite{GKV}; Reiher, R\"odl and Schacht~\cite{RRS}): if every linear-size vertex set of a large $3$-graph has density at least $\frac14+\varepsilon$, then it contains $\Km$. \emph{$2$-colorable $3$-graphs.} For the largest density $p_2$ of $2$-colorable $\Km$-free $3$-graphs, $0.2572\le p_2<0.291$~\cite{MT}, and Razborov~\cite[Section~6.3]{Ra} improved the upper bound to $p_2<0.2621$; the problem was introduced by Talbot~\cite{Ta}. \emph{Codegree squared.} For the $\ell_2$-norm version of the problem (maximize the sum of the squares of the codegrees), Balogh, Clemen and Lidick\'y conjecture that the same iterated blow-up is optimal, with value $4/43$~\cite[Section~3.9, Conjecture~3.2]{BCL}; all $\Km$-free $3$-graphs of density close to $2/7$ have this value in the limit (Section~\ref{sec:limit}). \emph{Families of forbidden $3$-graphs.} $\pi(\{\Km,F_{3,2}\})=5/18$, attained by the (one-level) blow-up of $\Hs$, and $\pi(\{\Km,C_5,F_{3,2}\})=12/49$~\cite[Theorems~4 and~5]{FV}, where $F_{3,2}=\{123,124,125,345\}$ and $C_5$ is the tight cycle on five vertices. \emph{Forbidden induced subgraphs.} Frankl and F\"uredi~\cite{FF} originally determined the $3$-graphs in which every four vertices span exactly $0$ or $2$ edges (i.e. $3$-graphs on four vertices with 1, 3 or 4 edges are forbidden): other than the (not iterated) blow-ups of $\Hs$, they are the $3$-graphs $G_P$ defined by points $P$ on a circle, no two of them antipodal (a triple is an edge if its triangle contains the center in its interior). \subsection{Recursive constructions and the method}\label{sec:method} Few Tur\'an densities of $3$-graphs are known; the survey~\cite{Ke} lists some of them (for example $2/9$ for $F_5=\{123,124,345\}$ (Frankl and F\"uredi), $4/9$ for $F_{3,2}$ (F\"uredi, Pikhurko and Simonovits), $3/4$ for the Fano plane (de Caen and F\"uredi), all with extremal constructions given by a fixed partition of the vertex set into a bounded number of parts; see~\cite[Section~14]{Ke}, and~\cite[Theorem~3]{FV} for $F_{3,2}$). Pikhurko~\cite[Theorem~3]{Pi} showed that for every minimal $r$-graph pattern (a finite construction, blown up, with recursion inside a specified set of parts) the maximum constructions are exactly the extremal $r$-graphs for some finite forbidden family of $r$-graphs, and for $r\ge3$ Liu and Pikhurko~\cite[Theorem~1.2]{LP} extended this, with stability, to recursions that mix finitely many minimal patterns; these results do not determine the density of a given small $3$-graph such as $\Km$. Further, Tur\'an densities with recursive extremal constructions were determined for tight cycles $C_\ell$ (vertices $1,\dots,\ell$ in cyclic order, edges the triples of consecutive vertices) of length $\ell\ge5$ not divisible by $3$ (density $2\sqrt3-3$: Kam\v{c}ev, Letzter and Pokrovskiy~\cite[Theorem~1.3]{KLP} for large $\ell$; Bodn\'ar, Le\'on, Liu and Pikhurko~\cite{bodnar2025turandensityshorttight} for $\ell\ge7$; Graham~\cite{GrahamC5} for $\ell=5$) and for tight cycles minus an edge $C_\ell^-$, $\ell\ge5$ not divisible by $3$ (density $1/4$: Balogh and Luo~\cite[Theorem~1.1]{BL} for large $\ell$; Lidick\'y, Mattes and Pfender~\cite{LMP}; Bodn\'ar, Le\'on, Liu and Pikhurko~\cite{BLLP}). In these cases the patterns have only two or three parts, respectively. For $\Km$, the conjectured pattern has six parts, all of them recursive. All the most recent bounds on $\pi(\Km)$ in the table above use flag algebras, a method due to Razborov~\cite{Ra07}. Falgas-Ravry and Vaughan, whose bound was announced in 2011 and stood until 2026, wrote that they did not believe their bounds for $\Km$ and two other $3$-graphs could ``be made tight by a purely flag algebra calculus approach'', one reason being that they ``would not expect the structure of iterated blow-up configurations to be properly captured by the flag algebra calculus''~\cite[Section~4.1]{FV}. Our proof gets around this by putting the top level of the structure into the computation: the vertices are colored by a partition, and the flag-algebra inequalities are proved for colored $3$-graphs. This \emph{partition method} was first used by Balogh, Hu, Lidick\'y, Pfender, Volec and Young for the maximum number of rainbow triangles in $3$-edge-colored complete graphs~\cite{BHLPVY}, and then for the inducibility of the $5$-cycle by Balogh, Hu, Lidick\'y and Pfender~\cite{BHLP}. The papers~\cite{LMP} and~\cite{BLLP} combine a partition of the vertex set with flag-algebra computations for tight cycles minus an edge; there the construction is the iterated blow-up of a single edge, and for all large $n$ every extremal $3$-graph is shown to have the top-level partition exactly. The same approach gave the Tur\'an densities of the short tight cycles~\cite{bodnar2025turandensityshorttight,GrahamC5} and their codegree-squared densities~\cite{DLPV}. We follow the same plan with $\Hs$ as the pattern. In outline, the proof of the upper bound in Theorem~\ref{thm:main} is as follows. Let $H$ be a $\Km$-free $3$-graph on $n$ vertices with $\ex(n)$ edges. Color its vertices with six colors, and call an edge \emph{good} if its three colors are distinct and form an edge of $\Hs$; in the blow-up of $\Hs$ on six equal parts, the good edges have density $5/18+o(1)$. First, Proposition~\ref{prop:A} shows that $H$ has a coloring in which the good edges have density at least $0.2476$. A coloring is obtained from five vertices that induce $C_5$: every other vertex receives the color suggested by its adjacencies to these five vertices according to $\Hs$. A flag-algebra computation in the theory of $\Km$-free $3$-graphs on $8$ vertices shows that the expected density of good edges is large enough. It involves the $9{,}895{,}719$ $\Km$-free $3$-graphs on $8$ vertices and became feasible with the solver of Lidick\'y and Volec~\cite{LV}. Second, Proposition~\ref{prop:B} shows that in any coloring of $H$ that maximizes the number of good edges, among the non-monochromatic triples at most a fraction of $\frac27+o(1)$ are edges. This is a flag-algebra computation in the theory of $\Km$-free $3$-graphs with vertices colored by six colors, on $6$ vertices. The monochromatic edges lie inside the color classes, where the density is at most $\pi+o(1)$. Together with Proposition~\ref{prop:B} this gives $\pi\le2/7$ (Section~\ref{sec:reduction}). \subsection{Consequences} Section~\ref{sec:cons} contains consequences of the theorems in other formulations. Among them: \emph{Jumps.} Every $\alpha\in[\frac27,\frac8{27})$ is a jump for $3$-graphs (Section~\ref{sec:jumps}). \emph{Coverings and threshold set systems.} The least number of triples such that every four points contain at least two of them is $(\frac57+o(1))\binom n3$, and the same constant holds for the threshold set systems of F\"uredi, Sloan, Takata and Tur\'an, which come from the study of frequent sets in data mining (Section~\ref{sec:cover}). \emph{Ramsey--Tur\'an and colorings.} Every $\Km$-free $3$-graph of density close to $2/7$ has independence number $o(n)$. The Ramsey--Tur\'an density of $\Km$, which equals its Tur\'an density by a theorem of Erd\H{o}s and S\'os~\cite{ES82}, is therefore $2/7$, and $\Km$-free $3$-graphs with bounded chromatic number have density bounded away from $2/7$ (Section~\ref{sec:other}). \emph{An endpoint of a codegree problem.} Problem~6.5 of~\cite{FPVV} asks for the largest density $f(c)$ of $\Km$-free $3$-graphs with minimum codegree at least $c(n-2)$; now $f(0)=2/7$ and $f(1/4)=1/4$ are known (Section~\ref{sec:degcodeg}). \subsection{Computer assistance}\label{sec:intro-verif} The proofs of Theorems~\ref{thm:main}, \ref{thm:exact} and~\ref{thm:stab} are computer-assisted. They rest on four finite statements, Computational Claims~\ref{claim:P}, \ref{claim:A}, \ref{claim:B} and~\ref{claim:S}. Each of them asserts that an explicit certificate, given by rational numbers, satisfies finitely many inequalities, one for every $\Km$-free $3$-graph on $8$ vertices or for every colored $\Km$-free $3$-graph on $6$ vertices. The claims were verified by independent programs, and the whole proof, including the claims, is also formalized in a proof assistant; see Section~\ref{sec:trust}. \subsection{AI use} The authors thought about this problem repeatedly in the past and developed several proof strategies using different variations of the partition method. Flag algebra bounds looked promising. They finally gave their progress to Claude Fable 5.2, tasking it to put the pieces together and to fix any remaining gaps. Claude put together the proof, the initial write-up and the certificate in Lean. It recycled programs for flag algebra and semidefinite programming written by the second author. OpenAI 6.1-Sol was used to point out mistakes and suggestions. The authors used the cluster for large calculations and guided Claude along the way whenever needed. Finally, they checked the write-up for correctness and edited it substantially for better reading. \subsection{Organization} Section~\ref{sec:prelim} contains notation and some facts about $\Km$-free $3$-graphs. Section~\ref{sec:reduction} states the key Propositions~\ref{prop:A} and~\ref{prop:B} and derives Theorem~\ref{thm:main} from them. Section~\ref{sec:cert} explains, in a finite form, how certificates are used. Sections~\ref{sec:proofP}, \ref{sec:proofA} and~\ref{sec:proofB} contain an auxiliary bound and the proofs of the two propositions. Section~\ref{sec:stability} proves Theorems~\ref{thm:exact} and~\ref{thm:stab}, Section~\ref{sec:cons} derives the consequences, and Section~\ref{sec:trust} describes the verification. \section{Preliminaries}\label{sec:prelim} \subsection{Notation} For a $3$-graph $H$ we write $H$ also for its edge set, $V(H)$ for its vertex set, $d_H(v)$ for the number of edges containing $v$, and $d_H(u,v)$ for the number of edges containing both $u$ and $v$. For $S\subseteq V(H)$, $H[S]$ is the induced subhypergraph of $H$ on $S$. For a $3$-graph $F$ on $m$ vertices and a $3$-graph $H$ on at least $m$ vertices, denote by $p(F;H)$ the probability that a uniformly chosen random $m$-subset of $V(H)$ induces a subgraph isomorphic to $F$. All asymptotic notation refers to $n=|V(H)|\to\infty$; constants hidden in $O(\cdot)$ and $o(\cdot)$ never depend on $H$. We write $\pi=\pi(\Km)$. Recall the definition of the $6$-vertex hypergraph $\Hs$, which was defined in Section~\ref{const11}. It is easy to check that the automorphism group $\Gamma=\mathrm{Aut}(\Hs)$ has order $60$, as $\Hs$ is vertex-transitive, and the link graph of each vertex is a $C_5$. We use two properties of $\Hs$: every pair of vertices lies in exactly two edges, and every four vertices span exactly two edges. \subsection{Three facts about \texorpdfstring{$\Km$}{K4\unichar{"207B}}-free \texorpdfstring{$3$-graphs}{3-graphs}} \begin{lemma}\label{lem:clone} Let $H$ be a $\Km$-free $3$-graph, and $u\ne v$ vertices of $H$. Let $H'$ be obtained from $H$ by deleting all edges containing $u$ and adding the hyperedge $uab$ whenever $vab\in H$ with $u\notin\{a,b\}$. In other words, $u$ becomes a clone of $v$. Then $H'$ is $\Km$-free. \end{lemma} \begin{proof} Every two vertices of $\Km$ lie in a common edge, and no edge of $H'$ contains both $u$ and $v$. So four vertices spanning three edges of $H'$ contain at most one of $u,v$; replacing $u$ by $v$ (if $u$ is among them) gives four vertices spanning three edges of $H$. \end{proof} \begin{lemma}\label{lem:reg} Let $H$ be a $\Km$-free $3$-graph on $n\ge2$ vertices with $\ex(n)$ edges. Then $|d_H(u)-d_H(v)|\le n-2$ for all vertices $u,v$. Consequently every vertex has degree $\frac{3\ex(n)}{n}+O(n)$. \end{lemma} \begin{proof} The $3$-graph $H'$ of Lemma~\ref{lem:clone} has $|H|-d_H(u)+d_H(v)-d_H(u,v)$ edges and is $\Km$-free, so $d_H(v)-d_H(u)\le d_H(u,v)\le n-2$. \end{proof} \begin{lemma}\label{lem:sub} The sequence $\ex(m)/\binom m3$, $m\ge3$, is nonincreasing, so $\ex(m)\ge\pi\binom m3$ for all $m$ and $\ex(m)=(\pi+o(1))\binom m3$. In particular, if $H$ is $\Km$-free on $n$ vertices and $S\subseteq V(H)$, then $|H[S]|\le\pi\binom{|S|}3+o(n^3)$, uniformly in $S$. \end{lemma} \begin{proof} Averaging over the deletion of a vertex gives monotonicity. For the last statement fix $\varepsilon>0$ and $m_0$ with $\ex(m)\le(\pi+\varepsilon)\binom m3$ for $m\ge m_0$; sets with $|S|0$, and $W(H)\le\max_FW(F)\le5/168$. Therefore \[ \frac{N(H)}{W(H)}\ \ge\ \frac6{25}+\frac{\sA-o(1)}{W(H)}\ \ge\ \frac6{25}+\frac{168}{5}\sA-o(1)=\cA-o(1). \] For $r$ inducing $\tau$ let $X_r$ be the number of ordered triples $(a,b,d)$ of distinct vertices outside $r$ with $\{a,b,d\}\in H$ good, under the random coloring. By definition $N(H)/W(H)$ is the average over $r$ inducing $\tau$ of $\EE[X_r]/((n-5)(n-6)(n-7))$. Hence some $r$ and some outcome of the coloring $\chi$ have at least $\frac{N(H)}{W(H)}\binom{n-5}3$ good edges, and thus $g(H,\chi)\ge\cA-o(1)$. \qed \section{Cross edges in a locally optimal coloring}\label{sec:proofB} In this section we prove Proposition~\ref{prop:B}. The $3$-graphs are colored, $m=6$, and $\cC_6$ is the set of colored $\Km$-free $3$-graphs on $6$ vertices up to color-preserving isomorphism; $|\cC_6|=2{,}333{,}533$. The group $\Gamma$ acts on $\cC_6$ by recoloring, with $41{,}322$ orbits. For a colored $3$-graph $(H,\chi)$, a vertex $v$ and a color $j$ let \[\nu_j(v)=\#\{\{a,b\}:\ \{v,a,b\}\in H,\ j,\chi(a),\chi(b)\text{ distinct and }\{j,\chi(a),\chi(b)\}\in\Hs\}.\] Recoloring $v$ with $j$ changes the number of good edges by $\nu_j(v)-\nu_{\chi(v)}(v)$, so \ref{B:loc} says that $\nu_{\chi(v)}(v)\ge \nu_j(v)$ for every vertex $v$ and color $j$. The properties \ref{B:loc}--\ref{B:inside} are invariant under $\Gamma$, which preserves good triples and monochromatic triples and permutes the colors: if $(H_n,\chi_n)$ has the properties, so have $(H_n,\gamma\circ\chi_n)$ for every $\gamma\in\Gamma$. \subsection{The rows} For $F\in\cC_6$ define \[ \mathrm{obj}(F)=\frac1{20}\sum_{A\in\binom{V(F)}3}[A\text{ cross}]\Bigl([A\in F]-\frac27\Bigr), \] so that \[\sum_{F\in\cC_6}p(F;(H,\chi))\,\mathrm{obj}(F)=\ecross-\frac27\tcross\] for every colored $3$-graph. The rows are the following, constructed from \ref{B:loc}--\ref{B:inside}. Several of the inequalities expressing the properties require fewer than six vertices to express. In these cases, we produce a set of new valid inequalities on six vertices by multiplying the inequalities by all $3$-graphs or flags of the missing size. In the list, ``$3$-graphs on three vertices'' means that the inequality is multiplied by each colored $3$-graph on three vertices (the row~\eqref{eq:row} with $k=0$, $s=3$), and similarly for rooted flags. This new set of inequalities is stronger than merely translating the inequalities into $3$-graphs or flags on six vertices, and this technique is well known in the flag algebra community. The inequalities are written without their error terms: for colored $3$-graphs with the properties \ref{B:loc}--\ref{B:inside} they hold up to $o(1)$ after normalization, on average for \ref{B:reg}, which is what Lemma~\ref{lem:rows} needs. \begin{center}\small \begin{tabular}{lll} \toprule property & inequality & multiplied by\\ \midrule \ref{B:loc}, $\chi(v)=1$, $j=2$ & $\nu_1(v)-\nu_2(v)\ge0$ & $4$-vertex flags, root of color $1$\\ \ref{B:G} & $g-\cB\ge0$ & $3$-graphs on three vertices\\ \ref{B:dens} & $e-\frac27\ge0$ & $3$-graphs on three vertices\\ \ref{B:reg}, root colors $(1,1)$, $(1,2)$ & $d(u)-d(v)=0$ (both signs) & $4$-vertex flags, two roots\\ \ref{B:inside} & $e\,\tmono-\emono\ge0$ & (already on $6$ vertices)\\ \bottomrule \end{tabular} \end{center} The row for \ref{B:inside} is, for $F\in\cC_6$, \[ L^{\mathrm{in}}_F=\sum_{A\in\binom{V(F)}3}[A\in F]\bigl([V(F)\setminus A\text{ monochromatic}]-[A\text{ monochromatic}]\bigr), \] and \[\sum_Fp(F;(H,\chi))L^{\mathrm{in}}_F=20\,(e\tmono-\emono)+O(1/n).\] The squares use $33$ colored types $\sigma$ ($1$ of size $0$, $2$ of size $2$, $30$ of size $4$) with all their flags on $3$, $4$, $5$ vertices respectively. \begin{lemma}\label{lem:Brows} If $(H,\chi)=(H_n,\chi_n)$ have the properties \ref{B:loc}--\ref{B:inside}, then every row $L$ of the table satisfies \[ \sum_{F\in\cC_6}p(F;(H,\chi))\,L_F\ \ge\ -o(1). \] \end{lemma} \begin{proof} For $L^{\mathrm{in}}$ this is \ref{B:inside}. The other rows are of the form~\eqref{eq:row}, and the hypothesis of Lemma~\ref{lem:rows} holds with $\delta=o(1)$: for \ref{B:loc} exactly, as $X(H,v)=\nu_1(v)-\nu_2(v)\ge0$ for a vertex $v$ of color~$1$; for \ref{B:G} and \ref{B:dens} these are inequalities between densities, up to $o(1)$; for \ref{B:reg}, where $s=4$ and $X(H,(u,v))=(d(u)-d(u,v))-(d(v)-d(u,v))=d(u)-d(v)$, because $\sum_{u,v}|X(H,(u,v))|=o(n^4)$. \end{proof} \subsection{The certificate} For $F\in\cC_6$, positive semidefinite $Q^\sigma$ and nonnegative $z_r$, $w$ put \[ c_F=\mathrm{obj}(F)+\sum_\sigma\ip{Q^\sigma}{M^\sigma_F}+\sum_rz_rL^{(r)}_F+w\,L^{\mathrm{in}}_F , \] where $r$ runs over the multiplied rows of the table. \begin{claim}\label{claim:B} For $\cB=99/400$ there are positive semidefinite rational matrices $Q^\sigma$ for the $33$ types and rational $z_r\ge0$, $w\ge0$ such that \begin{equation}\label{eq:certB} \sum_{F\in\cO}c_F\ \le\ 0\qquad\text{for every orbit }\cO\text{ of }\Gamma\text{ on }\cC_6 . \end{equation} \end{claim} \begin{remark}\label{rem:tight} The certificate is necessarily tight, since the construction attains $0$. Moreover \[ \ecross-\tfrac27\tcross=\bigl(e-\tfrac27\bigr)(1-\tmono)+\bigl(e\,\tmono-\emono\bigr), \] and both terms on the right are nonnegative combinations of rows: with \[K_F=\sum_{A}([A\in F]-\frac27)[V(F)\setminus A\text{ cross}],\] the sum of the rows of \ref{B:dens} multiplied by the cross $3$-graphs on three vertices, one has $K_F+L^{\mathrm{in}}_F=20\,\mathrm{obj}(F)$ for every $F\in\cC_6$. So the objective is nonnegative wherever the rows are, and the set of certificates is unbounded. \end{remark} \subsection{Proof of Proposition~\ref{prop:B} from Claim~\ref{claim:B}}\label{sec:proofBproof} For $F\in\cC_6$ let $\cO(F)$ be its orbit under $\Gamma$ and $\bar c_F=\frac1{|\cO(F)|}\sum_{F'\in\cO(F)}c_{F'}$, where the numbers $c_F$ are defined by matrices $Q^\sigma$ and numbers $z_r$, $w$ as in Claim~\ref{claim:B}. \begin{lemma}\label{lem:Bcert} If $(H,\chi)=(H_n,\chi_n)$ have the properties \ref{B:loc}--\ref{B:inside}, then \[ \ecross-\tfrac27\tcross\ \le\ \sum_{F\in\cC_6}p(F;(H,\chi))\,\bar c_F+o(1). \] \end{lemma} \begin{proof} For $\gamma\in\Gamma$ the colored $3$-graphs $(H,\gamma\circ\chi)$ have the properties \ref{B:loc}--\ref{B:inside}, so by Lemmas~\ref{lem:Brows} and~\ref{lem:squares} \[ \ecross-\tfrac27\tcross=\sum_Fp(F;(H,\gamma\circ\chi))\,\mathrm{obj}(F)\ \le\ \sum_Fp(F;(H,\gamma\circ\chi))\,c_F+o(1); \] the left side does not depend on $\gamma$. Since $p(F;(H,\gamma\circ\chi))=p(\gamma^{-1}F;(H,\chi))$, averaging over $\gamma\in\Gamma$ gives \[ \ecross-\tfrac27\tcross\le\sum_{F\in\cC_6}p(F;(H,\chi))\cdot\frac1{60}\sum_{\gamma\in\Gamma}c_{\gamma F}+o(1) =\sum_{F\in\cC_6}p(F;(H,\chi))\,\bar c_F+o(1).\qedhere \] \end{proof} By~\eqref{eq:certB}, $\bar c_F\le0$ for every $F$, so Lemma~\ref{lem:Bcert} gives Proposition~\ref{prop:B}. \qed \begin{remark}\label{rem:cB} Proposition~\ref{prop:B} is needed only for one value $\cB\le\cA$, and the value $\cB=99/400$ is just below $\cA$. A good lower bound in Proposition~\ref{prop:A} is necessary for this approach: numerically, the semidefinite program for $\cB=23/100$ has a positive optimum, which indicates that the analogue of Claim~\ref{claim:B} fails there. \end{remark} \begin{remark} Only representatives of the properties under $\Gamma$ appear in the program (for example \ref{B:loc} only for color $1\to2$). This is what the averaging over $\Gamma$ in the proof pays for: the certificate is required only on orbit sums, and the properties are used for all $(H,\gamma\circ\chi)$. \end{remark} \section{The bound for every \texorpdfstring{$n$}{n}, stability, and the extremal \texorpdfstring{$3$-graphs}{3-graphs}}\label{sec:stability} In this section we prove Theorems~\ref{thm:exact} and~\ref{thm:stab}. Besides Theorem~\ref{thm:main} the proofs use Proposition~\ref{prop:A}, Lemma~\ref{lem:Bcert}, and a certificate for Claim~\ref{claim:B} with one more property (Computational Claim~\ref{claim:S} below). Let $(H,\chi)$ be a colored $3$-graph. Recall that a triple of vertices is monochromatic if its three colors are equal, cross otherwise, and good if its colors are distinct and form an edge of $\Hs$. A triple is \emph{wrong} if it is cross and either an edge that is not good, or a good triple that is not an edge. So $(H,\chi)$ has no wrong triple if and only if $H$ is the blow-up of $\Hs$ on the color classes together with arbitrary $\Km$-free $3$-graphs inside the classes. The property is invariant under $\Gamma$. \subsection{The weighted bound}\label{sec:lagr} The following theorem is a weighted form of the upper bound, in which every vertex carries a weight; with equal weights it gives the upper bound of Theorem~\ref{thm:exact}. \begin{theorem}\label{thm:lagr} Let $H$ be a $\Km$-free $3$-graph and let $x_a\ge0$, $a\in V(H)$, be reals with $\sum_ax_a=1$. Then \[ 6\sum_{\{a,b,d\}\in H}x_ax_bx_d+\frac27\sum_{a\in V(H)}x_a^3\ \le\ \frac27 . \] \end{theorem} \begin{proof}[Proof of Theorem~\ref{thm:lagr}] For $m\ge1$ put $m_a=\lfloor x_am\rfloor$ and let $U_a$, $a\in V(H)$, be disjoint sets with $|U_a|=m_a$. Let $H_m$ be the $3$-graph on $\bigcup_aU_a$ whose edges are all triples with one vertex in each of $U_a,U_b,U_d$ for $\{a,b,d\}\in H$, together with a $\Km$-free $3$-graph with $\ex(m_a)$ edges on each $U_a$. No edge has exactly two vertices in one $U_a$. Hence four vertices in sets $U_a,U_a,U_b,U_d$ ($a,b,d$ distinct) span at most two edges, in $U_a,U_a,U_b,U_b$ none, in $U_a,U_a,U_a,U_b$ at most one, in one set at most two, and in four different sets at most two because $H$ is $\Km$-free. So $H_m$ is $\Km$-free, on $M=\sum_am_a\le m$ vertices, and \[ \sum_{\{a,b,d\}\in H}m_am_bm_d+\sum_a\ex(m_a)=|H_m|\le\ex(M)\le\ex(m). \] Divide by $m^3/6$ and let $m\to\infty$: $m_a/m\to x_a$, and $\ex(k)=(\frac27+o(1))k^3/6$ as $k\to\infty$ by Theorem~\ref{thm:main} (if $x_a=0$ then $m_a=0$; we put $\ex(0)=0$). \end{proof} \begin{proof}[Proof of the bounds in Theorem~\ref{thm:exact}] The $3$-graph $B_n$ is $\Km$-free, so $|B_n|\le\ex(n)$. The inequality $\frac27\binom n3\le|B_n|$ is proved in Section~\ref{sec:error} (Proposition~\ref{prop:error}) by a count of the edges of $B_n$; the weaker inequality $\frac27\binom n3\le\ex(n)$ is also Lemma~\ref{lem:sub} with $\pi=\frac27$. For the upper bound put \[ U(n)=\frac{n^3-n}{21}=\frac27\binom{n+1}3, \] and take $x_a=1/n$ in Theorem~\ref{thm:lagr}: $6|H|/n^3+\frac27n^{-2}\le\frac27$. For $n=6^t$ the number $a_t=6|B_n|/n^3$ satisfies $a_0=0$ and $a_t=\frac{60}{216}+\frac1{36}a_{t-1}$ ($60$ of the $216$ ordered triples of parts carry the edges of the blow-up, and each of the six parts contributes $a_{t-1}(n/6)^3/6$ edges), and $a_t=\frac27(1-6^{-2t})$ solves this recurrence. So $|B_n|=U(n)$ for $n=6^t$. The remaining statements of the theorem are proved in Section~\ref{sec:equality}. \end{proof} The upper bound, rounded down, is also attained for $n\le 6$: the values $0,0,1,2,5,10$ are attained by induced subgraphs of $\Hs$. \subsection{Part sizes}\label{sec:sizes} On the simplex $\Delta=\{x\in\RR^6:\ x_i\ge0,\ \sum_ix_i=1\}$ put \[ h(x)=6\sum_{ijk\in\Hs}x_ix_jx_k,\qquad f(x)=h(x)+\frac27\sum_{i=1}^6x_i^3 . \] If $(H,\chi)$ has $n$ vertices and $x_i=|V_i|/n$, then $h(x)+O(1/n)$ is the density of good triples and $\sum_ix_i^3+O(1/n)$ is $\tmono$. \begin{lemma}\label{lem:sizes} \begin{enumerate}[label=\textup{(\alph*)},itemsep=1pt,topsep=2pt] \item\label{sz:le} $f(x)\le\frac27$ for all $x\in\Delta$. \item\label{sz:eq} $f(x)=\frac27$ only for $x=(\frac16,\dots,\frac16)$ and for the six unit vectors. \item\label{sz:stab} For all $c>0$ and $\delta>0$ there is $\varepsilon>0$ such that $x\in\Delta$, $h(x)\ge c$ and $f(x)\ge\frac27-\varepsilon$ imply $|x_i-\frac16|\le\delta$ for all $i$. \end{enumerate} \end{lemma} \begin{proof} \ref{sz:le} is Theorem~\ref{thm:lagr} for $H=\Hs$. \ref{sz:stab} follows from \ref{sz:eq} by compactness, as $h$ vanishes at the unit vectors. It remains to prove~\ref{sz:eq}. Let $f(x)=\frac27$, let $S=\{i:x_i>0\}$, $q=\sum_ix_i^2$, and $p_i(x)=\sum_{jk:\,ijk\in\Hs}x_jx_k$, so that $\partial f/\partial x_i=6p_i+\frac67x_i^2$. By~\ref{sz:le}, $x$ maximizes $f$ on $\Delta$, so $\partial f/\partial x_i$ has the same value $\lambda$ for all $i\in S$; as $f$ is homogeneous of degree $3$, $\lambda=\sum_ix_i\,\partial f/\partial x_i=3f(x)=\frac67$. Hence $7p_i(x)=1-x_i^2$ for $i\in S$. Summing over $i\in S$, \begin{equation}\label{eq:kkt} 7\sum_{\{j,k\}\subseteq S}\mu_{jk}\,x_jx_k=|S|-q,\qquad\text{where }\mu_{jk}=\#\{i\in S:\ ijk\in\Hs\}. \end{equation} We use $1=(\sum_ix_i)^2=q+2\sum_{\{j,k\}\subseteq S}x_jx_k$, and that every pair lies in exactly two edges of $\Hs$ and every four vertices span exactly two edges. We split the remaining analysis into cases depending on $|S|$. \smallskip\noindent $|S|=6$: all $\mu_{jk}=2$, so \eqref{eq:kkt} reads $7(1-q)=6-q$, that is $q=\frac16$, and $x$ is the uniform vector. \smallskip\noindent $|S|=5$: let $v$ be the vertex outside $S$. Then $\mu_{jk}=1$ for the five pairs $jk$ with $vjk\in\Hs$ (the set $L$) and $\mu_{jk}=2$ for the other five pairs of $S$ (the set $M$); every vertex of $S$ lies in two pairs of $M$. Writing $|S|-q=5(q+2\sum_Lx_jx_k+2\sum_Mx_jx_k)-q$, \eqref{eq:kkt} becomes \[0=4q-4\sum_Mx_jx_k+3\sum_Lx_jx_k=2\sum_{jk\in M}(x_j-x_k)^2+3\sum_{jk\in L}x_jx_k,\] which is impossible as the last sum is positive. \smallskip\noindent $|S|=4$: let the two edges in $S=\{a,b,c,d\}$ be $abc$ and $abd$. Then \eqref{eq:kkt} is \[14x_ax_b+7(x_a+x_b)(x_c+x_d)=4-q=3q+8x_ax_b+8(x_a+x_b)(x_c+x_d)+8x_cx_d,\] that is \[0=3(x_a-x_b)^2+3x_c^2+3x_d^2+(x_a+x_b)(x_c+x_d)+8x_cx_d,\] again impossible. \smallskip\noindent $|S|=3$: if $S$ is an edge, \eqref{eq:kkt} is $7\sigma=3-q=2q+6\sigma$ with $\sigma=\sum_{\{j,k\}\subseteq S}x_jx_k$, so $\sigma=2q$, impossible as $\sigma\le q$. If $S$ is not an edge, or if $|S|=2$, the left side of~\eqref{eq:kkt} is $0$ and the right side is at least $|S|-1>0$. If $|S|=1$, $x$ is a unit vector. \end{proof} \subsection{One level}\label{sec:level} The following theorem describes the top level of the structure of a $\Km$-free $3$-graph of density close to $2/7$. Here $V_i=\chi^{-1}(i)$. \begin{theorem}\label{thm:level} For every $\delta>0$ there are $\varepsilon>0$ and $n_0$ such that every $\Km$-free $3$-graph $H$ on $n\ge n_0$ vertices with at least $(\frac27-\varepsilon)\binom n3$ edges has a coloring $\chi$ with \begin{enumerate}[label=\textup{(\roman*)},itemsep=1pt,topsep=2pt] \item\label{lv:size} $\bigl||V_i|-n/6\bigr|\le\delta n$ for $i=1,\dots,6$; \item\label{lv:wrong} at most $\delta n^3$ wrong triples; \item\label{lv:in} $|H[V_i]|\ge(\frac27-\delta)\binom{|V_i|}3$ for $i=1,\dots,6$. \end{enumerate} \end{theorem} The proof uses a certificate for Claim~\ref{claim:B} with an additional property. Recall from Section~\ref{sec:proofB}: $\cC_6$ is the set of colored $\Km$-free $3$-graphs on $6$ vertices; positive semidefinite matrices $Q^\sigma$ and numbers $z_r\ge0$, $w\ge0$ define numbers $c_F$, $F\in\cC_6$; and Computational Claim~\ref{claim:B} says that they can be chosen with $\sum_{F\in\cO}c_F\le0$ for every orbit $\cO$ of $\Gamma$ on $\cC_6$. A colored $3$-graph has a wrong triple if and only if all $3$-graphs in its orbit have one. \begin{claim}\label{claim:S} The matrices $Q^\sigma$ and the numbers $z_r$, $w$ in Computational Claim~\ref{claim:B} can be chosen such that, in addition to~\eqref{eq:certB}, \[ \sum_{F\in\cO}c_F\ <\ 0\qquad\text{for every orbit }\cO\text{ of }\Gamma\text{ on }\cC_6\text{ that consists of $3$-graphs with a wrong triple.} \] \end{claim} \medskip In the rest of this section, $Q^\sigma$, $z_r$ and $w$ are as in Computational Claim~\ref{claim:S}, and $c_F$ and $\bar c_F=\frac1{|\cO(F)|}\sum_{F'\in\cO(F)}c_{F'}$ (the notation of Section~\ref{sec:proofBproof}) refer to them. As there are finitely many orbits, there is a constant $\kappa>0$ (the least value of $-\frac1{|\cO|}\sum_{F\in\cO}c_F$ over the orbits that contain a wrong triple) such that \begin{equation}\label{eq:kappa} \bar c_F\ \le\ -\kappa\qquad\text{for every }F\in\cC_6\text{ with a wrong triple.} \end{equation} We also need that in a $\Km$-free $3$-graph of density close to $2/7$ almost all degrees are close to $\frac27\binom n2$. \begin{lemma}\label{lem:conc} Let $H_n$ be $\Km$-free $3$-graphs on $n\to\infty$ vertices with $|H_n|\ge(\frac27-o(1))\binom n3$. Then \[ \sum_{v\in V(H_n)}\Bigl|d_{H_n}(v)-\tfrac27\tbinom n2\Bigr|=o(n^3). \] \end{lemma} \begin{proof} Write $H=H_n$, $d=d_H$ and $D=\frac27\binom n2$. For a set $L$ of $\lambda n$ vertices, the $3$-graph $H-L$ has at least $|H|-\sum_{v\in L}d(v)$ edges and, by Lemma~\ref{lem:sub} and Theorem~\ref{thm:main}, at most $\frac27\binom{n-|L|}3+o(n^3)$. As $\binom n3-\binom{n-|L|}3\ge(1-\lambda)|L|\binom n2-O(n^2)$, this gives \begin{equation}\label{eq:setdeg} \sum_{v\in L}d(v)\ \ge\ (1-\lambda)\,|L|\,D-o(n^3), \end{equation} uniformly in $L$. Fix $\beta\in(0,1)$, let $L$ consist of $\lceil\beta n\rceil$ vertices of smallest degree, and let $L^-$ be the set of its vertices of degree less than $D$. By~\eqref{eq:setdeg} for $L^-$, \[\sum_{v\in L^-}(D-d(v))\le\beta|L^-|D+o(n^3)\le\beta n^3+o(n^3).\] If $L^-\ne L$, no vertex outside $L$ has degree less than $D$. Otherwise, by~\eqref{eq:setdeg} for $L$, the largest degree in $L$ is at least $(1-\beta)D-o(n^2)$, so every vertex outside $L$ has degree at least $D-\beta n^2-o(n^2)$. In both cases $\sum_v\max\{0,D-d(v)\}\le2\beta n^3+o(n^3)$. As $\beta$ was arbitrary, this sum is $o(n^3)$. Finally $\sum_v(d(v)-D)=3|H|-nD\le3\ex(n)-nD=o(n^3)$, so $\sum_v\max\{0,d(v)-D\}=o(n^3)$ as well. \end{proof} \subsection{Proof of Theorem~\ref{thm:level}}\label{sec:levelproof} It is enough to prove the following: \emph{if $H_n$ are $\Km$-free $3$-graphs on $n\to\infty$ vertices with $|H_n|\ge(\frac27-o(1))\binom n3$, then there are colorings $\chi_n$ of $H_n$ with $|V_i|=(\frac16+o(1))n$, with $o(n^3)$ wrong triples, and with $|H_n[V_i]|\ge(\frac27-o(1))\binom{|V_i|}3$.} (If the theorem failed for some $\delta$, there would be counterexamples $H$ for $\varepsilon=1/k$ and $n_0=k$, $k=1,2,\dots$; this sequence would contradict the statement.) Write $H=H_n$. By Lemma~\ref{lem:conc} the hypothesis of Proposition~\ref{prop:A} holds, so there is a coloring of $H$ with $g\ge\cA-o(1)$; let $\chi$ be a coloring of $H$ that maximizes $|G|$. We write $e$, $g$, $\emono$, \dots{} for the densities of $(H,\chi)$. \emph{Step 1: the properties.} The colored $3$-graphs $(H,\chi)$ have the properties \ref{B:loc}--\ref{B:inside} of Proposition~\ref{prop:B}: \ref{B:loc} because $\chi$ maximizes $|G|$; \ref{B:G} because $g\ge\cA-o(1)\ge\cB-o(1)$; \ref{B:dens} by assumption, and moreover $e\le\frac27+o(1)$ by Theorem~\ref{thm:main}; \ref{B:reg} by Lemma~\ref{lem:conc}, as $\sum_{u,v}|d_H(u)-d_H(v)|\le2n\sum_v\bigl|d_H(v)-\frac27\binom n2\bigr|=o(n^4)$; and \ref{B:inside} because $\emono\le\frac27\tmono+o(1)\le e\,\tmono+o(1)$, by Step~2 of the proof of Theorem~\ref{thm:main} in Section~\ref{sec:reduction} with $\pi=\frac27$, and by \ref{B:dens}. \emph{Step 2: few wrong triples.} By Lemma~\ref{lem:Bcert}, Claim~\ref{claim:B} ($\bar c_F\le0$) and~\eqref{eq:kappa}, \[ \ecross-\tfrac27\tcross\ \le\ \sum_{F\in\cC_6}p(F;(H,\chi))\,\bar c_F+o(1) \ \le\ -\kappa\,p_{\mathrm w}+o(1), \] where $p_{\mathrm w}$ is the probability that six random vertices of $(H,\chi)$ contain a wrong triple. On the other hand \[ \ecross-\tfrac27\tcross=\bigl(e-\tfrac27\bigr)(1-\tmono)+\bigl(e\,\tmono-\emono\bigr)\ \ge\ -o(1) \] by \ref{B:dens} and \ref{B:inside}. Hence $p_{\mathrm w}=o(1)$ and $\ecross-\frac27\tcross=o(1)$. A random triple of a random $6$-set is a random triple, so the number of wrong triples of $(H,\chi)$ is at most $p_{\mathrm w}\binom n3=o(n^3)$. Moreover $(e-\frac27)(1-\tmono)=o(1)$ by Step~1, so \begin{equation}\label{eq:inside} \emono=\tfrac27\tmono+o(1). \end{equation} \emph{Step 3: part sizes.} Let $x_i=|V_i|/n$. The good triples have density $h(x)+O(1/n)$, and all but $o(n^3)$ of them are edges, and all but $o(n^3)$ cross edges are good, by Step~2. So $\ecross=h(x)+o(1)$ and $g=h(x)+o(1)$, while $\tcross=1-\sum_ix_i^3+O(1/n)$. With $\ecross-\frac27\tcross=o(1)$ this gives $f(x)=\frac27+o(1)$, and $h(x)\ge\cB-o(1)$ by \ref{B:G}. By Lemma~\ref{lem:sizes}\ref{sz:stab}, $x_i=\frac16+o(1)$ for all $i$. \emph{Step 4: inside the parts.} By Theorem~\ref{thm:main} and Lemma~\ref{lem:sub}, $|H[V_i]|\le(\frac27+o(1))\binom{|V_i|}3$ for each $i$, and by~\eqref{eq:inside} the sum of the six left sides is at least the sum of $\frac27\binom{|V_i|}3$ minus $o(n^3)$. As $|V_i|=(\frac16+o(1))n$, each $|H[V_i]|\ge(\frac27-o(1))\binom{|V_i|}3$. \qed \subsection{Stability} \begin{proof}[Proof of Theorem~\ref{thm:stab}] By a \emph{copy of $B_n$} on a set $V$ of $n$ vertices we mean a $3$-graph on $V$ that is isomorphic to $B_n$, that is, an iterated balanced blow-up on $V$ in which, at every level, the three larger parts correspond to an edge of $\Hs$ whenever a set of $n'\equiv3\pmod 6$ vertices is partitioned. For a copy $B$ of $B_n$ on $V$ with a fixed choice of the partitions in its definition, and $t\ge0$, say that a triple is \emph{resolved at depth $t$} if it is cross for the partition of one of the first $t$ levels of $B$ (for the partition of $V$ if $t=1$; for that partition or for the partition of one of its six parts if $t=2$; and so on). The triples that are not resolved at depth $t$ lie inside one of $6^t$ sets of size at most $\lceil n/6^t\rceil$, so there are at most $6^t\lceil n/6^t\rceil^3\le 2n^3/36^{t}$ of them if $n\ge 6^{t+1}$. \emph{Claim $Q_t$: for every $\delta>0$ there are $\varepsilon>0$ and $n_0$ such that for every $\Km$-free $H$ on $n\ge n_0$ vertices with at least $(\frac27-\varepsilon)\binom n3$ edges there is a copy $B$ of $B_n$ on $V(H)$ such that at most $\delta n^3$ triples of $H\triangle B$ are resolved at depth $t$.} The theorem follows from $Q_t$ for $\delta/2$ and $t$ with $2\cdot36^{-t}\le\delta/2$. $Q_0$ is trivial. Assume $Q_t$ and let $\delta>0$. Let $\varepsilon'$, $n_0'$ be given by $Q_t$ for $\delta/2$, and put $\delta''=\min\{\delta,\varepsilon'\}/10^5$. Apply Theorem~\ref{thm:level} with $\delta''$ to $H$ and let $\chi$ be the coloring. Move at most $6\delta''n$ vertices to other classes so that the new classes $V_i'$ have sizes differing by at most one and, if $n\equiv3\pmod 6$, the three larger classes correspond to an edge of $\Hs$ (any assignment of the sizes $\lfloor n/6\rfloor$ and $\lceil n/6\rceil$ to the classes can be reached in this way for large $n$, as $\bigl||V_i|-n/6\bigr|\le\delta''n$). At most $\delta''n^3+6\delta''n\cdot n^2$ triples are wrong for the new partition, and \[ |H[V_i']|\ \ge\ |H[V_i]|-6\delta''n^3\ \ge\ \bigl(\tfrac27-\delta''\bigr)\binom{|V_i|}3-6\delta''n^3\ \ge\ \bigl(\tfrac27-\varepsilon'\bigr)\binom{|V_i'|}3 \] for large $n$, since $\binom{|V_i'|}3\ge n^3/1300$ and $\binom{|V_i|}3\ge\binom{|V_i'|}3-6\delta''n^3$. By $Q_t$ there is, for each $i$, a copy $B_i$ of $B_{|V_i'|}$ on $V_i'$ such that at most $\frac\delta2|V_i'|^3$ triples of $H[V_i']\triangle B_i$ are resolved at depth $t$. Let $B$ be the blow-up of $\Hs$ on $V_1',\dots,V_6'$ together with $B_1,\dots,B_6$; it is a copy of $B_n$. The triples of $H\triangle B$ resolved at depth $t+1$ are the wrong triples of the partition $V_1',\dots,V_6'$ and the triples of the $H[V_i']\triangle B_i$ resolved at depth $t$; there are at most $7\delta''n^3+\frac\delta2\sum_i|V_i'|^3\le\delta n^3$ of them. This is $Q_{t+1}$. \end{proof} \subsection{The extremal \texorpdfstring{$3$-graphs}{3-graphs} for \texorpdfstring{$n=6^t$}{n = 6\textasciicircum t}}\label{sec:equality} \begin{proof}[Proof of Theorem~\ref{thm:exact}, the case of equality] We show that a $\Km$-free $3$-graph on $n\ge1$ vertices with $U(n)=(n^3-n)/21$ edges exists only for $n=6^t$ and is then isomorphic to $B_{6^t}$; that $B_{6^t}$ has $U(6^t)$ edges was shown in Section~\ref{sec:lagr}. We use induction on $n$. For $n=1$ there is nothing to prove, and for $2\le n\le5$ the number $(n^3-n)/21$ is not an integer. So let $n\ge6$, and let $H$ be $\Km$-free on the vertex set $V$, $|V|=n$, with $(n^3-n)/21$ edges. For $m\ge1$ let $H^{(m)}$ be the $3$-graph $H_m$ from the proof of Theorem~\ref{thm:lagr} for $x_a=1/n$ and $nm$ in place of $m$: every vertex $a$ is replaced by a set $U_a$ of size $m$, every edge by $m^3$ edges, and each $U_a$ carries a $\Km$-free $3$-graph with $\ex(m)$ edges. It is $\Km$-free, has $N=nm$ vertices, and \[ |H^{(m)}|=\frac{n^3-n}{21}\,m^3+n\,\ex(m)=\Bigl(\frac{n^3-n}{21}+\frac n{21}+o(1)\Bigr)m^3=\Bigl(\frac27+o(1)\Bigr)\frac{N^3}6 \qquad(m\to\infty). \] By Theorem~\ref{thm:level} (in the form for sequences proved in Section~\ref{sec:levelproof}, applied to the sequence $H^{(m)}$, $m\to\infty$, with $n$ fixed) there are colorings $\chi_m$ of $H^{(m)}$ with classes $V_i^m$ of size $(\frac16+o(1))N$ and with $o(N^3)$ wrong triples. \emph{Claim 1. For every $a\in V$ and every large $m$ there is a color $c_m(a)$ such that all but $o(m)$ vertices of $U_a$ have color $c_m(a)$.} Otherwise there are $\beta>0$, a vertex $a$, colors $i\ne j$ and infinitely many $m$ such that $U_a$ contains at least $\beta m$ vertices of color $i$ and at least $\beta m$ of color $j$. The pair $ij$ lies in two edges $ijk$, $ijk'$ of $\Hs$. A triple $\{u,u',w\}$ with $u,u'\in U_a$ of colors $i,j$ and $w\notin U_a$ of color $k$ or $k'$ is good, and it is not an edge, because no edge of $H^{(m)}$ has exactly two vertices in $U_a$. So all these triples are wrong; there are at least $(\beta m)^2\bigl(|V_k^m|+|V_{k'}^m|-m\bigr)\ge\beta^2m^2\bigl(\frac N3-o(N)-\frac N6\bigr)$ of them, using $n\ge6$. This is not $o(N^3)$, a contradiction. \emph{Claim 2. For large $m$ the colored $3$-graph $(H,c_m)$ has no wrong triple.} Let $\{a,b,d\}$ be a triple of $V$. A triple with one vertex in each of $U_a,U_b,U_d$ is an edge of $H^{(m)}$ if and only if $\{a,b,d\}\in H$, and $(1-o(1))m^3$ of these triples have the colors $c_m(a),c_m(b),c_m(d)$. If $\{a,b,d\}$ were wrong for $(H,c_m)$, these $(1-o(1))N^3/n^3$ triples would be wrong for $(H^{(m)},\chi_m)$. Fix a large $m$ and $c=c_m$, and let $W_i=c^{-1}(i)$. By Claim~1, $|V_i^m|=m|W_i|+o(N)$, so $|W_i|/n=\frac16+o(1)$; as $n$ is fixed, $|W_i|=n/6$ if $m$ is large. By Claim~2, $H$ is the blow-up of $\Hs$ on $W_1,\dots,W_6$ together with the $3$-graphs $H[W_i]$, and by the upper bound of Theorem~\ref{thm:exact} \[ \frac{n^3-n}{21}=|H|=10\Bigl(\frac n6\Bigr)^3+\sum_{i=1}^6|H[W_i]|\ \le\ 10\Bigl(\frac n6\Bigr)^3+6\cdot\frac{(n/6)^3-n/6}{21}=\frac{n^3-n}{21}. \] So each $H[W_i]$ has $((n/6)^3-n/6)/21$ edges. By induction $n/6=6^{t-1}$ and $H[W_i]\cong B_{6^{t-1}}$, hence $n=6^t$ and $H\cong B_{6^t}$. \end{proof} \section{Consequences}\label{sec:cons} This section collects consequences of Theorems~\ref{thm:main}, \ref{thm:exact}, \ref{thm:lagr} and~\ref{thm:stab}. The arguments are short. \subsection{Small cases}\label{sec:finiteconj} The values of $\ex(n)$ for $n\le8$ are due to Deng et al.~\cite{De} (as reported in~\cite[Section~1]{LRSW}), for $9\le n\le12$ to Li, van Rees, Stinson and Wei~\cite{LRSW}, and for $n\le19$, together with all extremal $3$-graphs, to Markstr\"om and Talbot~\cite{MT}; moreover $\ex(20)<377$~\cite{MT}. For $n\ge1$ not a power of $6$, Theorem~\ref{thm:exact} gives $\ex(n)\le\lceil U(n)\rceil-1$. The following table compares this bound with the known values. \begin{center}\small\setlength{\tabcolsep}{4.5pt} \begin{tabular}{l|rrrrrrrrrrrrrrrrr} $n$ & 3&4&5&6&7&8&9&10&11&12&13&14&15&16&17&18&19\\ \midrule $\ex(n)$ &1&2&5& 10&15&22&32&44&60&80&101&126&156&190&230&276&322\\ extremal $3$-graphs & 1&1&1&1&1&5&6&43&1&1&1&1&1&1&1&1&1\\ bound & 1&2&5&10&15&23&34&47&62&81&103&129&159&194&233&276&325 \end{tabular} \end{center} The bound is attained for $n\le7$ and for $n=18$, and it exceeds $\ex(n)$ by at most $4$ for $n\le19$. For $n\le 7$ and $11\le n\le19$ the unique extremal $3$-graph is the iterated balanced blow-up $B_n$~\cite{MT}. In all cases $n\le19$, $B_n$ is one of the extremal $3$-graphs. \subsection{The error term for all \texorpdfstring{$n$}{n}}\label{sec:error} \begin{proposition}\label{prop:error} For all $n\ge1$, \[ U(n)-\tfrac3{14}\,n\log_6n-n\ \le\ |B_n|\ \le\ \ex(n)\ \le\ U(n)\qquad\text{and}\qquad\tfrac27\tbinom n3\ \le\ |B_n| . \] In particular $\ex(n)=\frac{n^3}{21}+O(n\log n)$ and $\ex(n)/\binom n3=\frac27+\frac6{7n}+O\bigl(\frac{\log n}{n^2}\bigr)$. \end{proposition} \begin{proof} The upper bound is Theorem~\ref{thm:exact}, and $|B_n|\le\ex(n)$ because $B_n$ is $\Km$-free. Put $d(n)=U(n)-|B_n|$ for $n\ge0$, so that $d(0)=d(1)=0$ and $d(2)=\frac27$. We show by induction that \begin{equation}\label{eq:deficit} d(n)\ \le\ \tfrac3{14}\,n\log_6n+\tfrac27(n-1)\qquad\text{for all }n\ge1 , \end{equation} and that $d(n)\le\frac27\binom n2$ for all $n\ge0$. This proves the proposition, as $U(n)-\frac27\binom n2=\frac27\binom n3$. Let $n\ge2$ and $n=6q+r$ with $0\le r\le5$, and let $n_i=q+1$ for $i\le r$ and $n_i=q$ for $i>r$. Every vertex of $\Hs$ lies in five edges and every pair of vertices in two, so a blow-up of $\Hs$ with $r$ parts of size $q+1$ and $6-r$ parts of size $q$ has $10q^3+5rq^2+r(r-1)q+A$ edges, where $A$ is the number of edges of $\Hs$ among the larger parts. If $r\ne3$, then $A$ does not depend on the choice of the larger parts (every four vertices of $\Hs$ span two edges and every five vertices five), and if $r=3$, then $A=1$ in $B_n$ by definition. As $123$ is an edge of $\Hs$, the top level of $B_n$ has as many edges as the blow-up of $\Hs$ on parts of sizes $n_1,\dots,n_6$, and the parts of $B_n$ carry copies of $B_{n_1},\dots,B_{n_6}$. Hence $|B_n|=\sum_{ijk\in\Hs}n_in_jn_k+\sum_i|B_{n_i}|$, that is, \[ d(n)\ =\ \sum_{i=1}^6d(n_i)+D,\qquad\text{where}\quad D=U(n)-\sum_{i=1}^6U(n_i)-\sum_{ijk\in\Hs}n_in_jn_k . \] Write $n_i=n/6+\eta_i$. Expanding, and using again that every vertex of $\Hs$ lies in five edges and every pair in two, \[ D=\frac n7\sum_i\eta_i^2-\frac1{21}\sum_i\eta_i^3-\sum_{ijk\in\Hs}\eta_i\eta_j\eta_k =\frac3{14}\,n-\frac{(r-3)^2}{42}\,n+C_r , \] where $\sum_i\eta_i^2=r(6-r)/6$ and $C_r=0,-\frac5{42},-\frac2{21},-\frac12,\frac2{21},\frac5{42}$ for $r=0,\dots,5$; for $r=3$ this uses that the three larger parts $1,2,3$ form an edge of $\Hs$. As $n\ge r$, in all cases \begin{equation}\label{eq:onelevel} D\ \le\ \tfrac3{14}\,n . \end{equation} Now~\eqref{eq:deficit} holds for $n=1$. For $2\le n\le5$ all parts have size at most $1$ and $d(0)=d(1)=0$, so $d(n)\le\frac3{14}n$ by~\eqref{eq:onelevel}, and~\eqref{eq:deficit} follows from $\log_6n\ge\frac13$. For $n\ge6$ all parts have sizes $1\le n_i\le(n+5)/6$, hence $\log_6n_i\le\log_6n-1+\frac6n$ and $\sum_in_i\log_6n_i\le n\log_6n-n+6$. By induction and~\eqref{eq:onelevel}, \[ d(n)\ \le\ \tfrac3{14}\bigl(n\log_6n-n+6\bigr)+\tfrac27(n-6)+\tfrac3{14}\,n=\tfrac3{14}\,n\log_6n+\tfrac27\,n-\tfrac37 . \] This proves~\eqref{eq:deficit}. For the second bound, $d(n)=\frac27\binom n2$ for $n\le2$. Let $n\ge3$. Then $n_i\le n/2$ for all $i$, so $\sum_in_i^2\le n^2/2$, and by induction and~\eqref{eq:onelevel} \[ d(n)\ \le\ \tfrac27\sum_{i=1}^6\tbinom{n_i}2+\tfrac3{14}\,n =\tfrac27\tbinom n2-\tfrac17\Bigl(n^2-\sum_{i=1}^6n_i^2\Bigr)+\tfrac3{14}\,n \ \le\ \tfrac27\tbinom n2-\tfrac1{14}\,n^2+\tfrac3{14}\,n\ \le\ \tfrac27\tbinom n2 . \] The last statement of the proposition uses $U(n)/\binom n3=\frac27\cdot\frac{n+1}{n-2}$. \end{proof} So the bounds $\frac27\binom n3\le\ex(n)\le\frac27\binom{n+1}3$ of Theorem~\ref{thm:exact}, which differ by $\frac27\binom n2$, are improved to an interval of length $O(n\log n)$. The argument does not give an error $O(n)$. With a little more work one can bound $U(n)-|B_n|$ more precisely and improve the lower bound to $U(n)-\frac{10}{49}\,n\log_6n-O(n)$, which is tight for $B_n$ up to the $O(n)$ term. \subsection{Jumps}\label{sec:jumps} A number $\alpha\in[0,1)$ is a \emph{jump} for $3$-graphs if there is $c>0$ such that for every $\varepsilon>0$ and $t\ge 3$, every sufficiently large $3$-graph with density at least $\alpha+\varepsilon$ has a subgraph on $t$ vertices with density at least $\alpha+c$. By a criterion of Frankl and R\"odl~\cite{FR} (see~\cite[Theorem~1.2]{BT}), $\alpha$ is a jump if there is a finite family $\mathcal F$ with $\pi(\mathcal F)\le\alpha$ such that every $F\in\mathcal F$ has Lagrangian density $\Lambda(F)=6\max\{\sum_{ijk\in F}x_ix_jx_k:\ x\ge0,\ \sum_ix_i=1\}$ greater than $\alpha$. For $\Km$, with weight $a$ on the vertex of degree three, $\Lambda(\Km)=\max_a2a(1-a)^2=\frac8{27}$. Baber and Talbot~\cite[Corollary~2.3]{BT} deduced that every $\alpha\in[0.2871,\frac8{27})$ is a jump. With $\pi(\Km)=\frac27$ we obtain the following. \begin{corollary}\label{cor:jumps} Every $\alpha\in[\frac27,\frac8{27})$ is a jump for $3$-graphs. \end{corollary} The lower end of this interval cannot be improved with the family $\{\Km\}$. \subsection{Coverings and threshold set systems}\label{sec:cover} A $3$-graph on $n$ vertices in which every four vertices span at least two edges has at least \[ T_3(n,4,2)=\binom n3-\ex(n)\ \ge\ \binom n3-U(n)=\frac{n(n-1)(5n-16)}{42} \] edges, with equality exactly for the complements of the $B_{6^t}$; so $T_3(n,4,2)=(\frac57+o(1))\binom n3$, and by Proposition~\ref{prop:error}, $T_3(n,4,2)=\binom n3-U(n)+O(n\log n)$. Equivalently, an $(n,n-3,n-4)$ double covering design without repeated blocks has at least that many blocks. F\"uredi, Sloan, Takata and Tur\'an~\cite{FSTT} study \emph{threshold set systems}, whose minimum size had been studied by Sloan, Takata and Tur\'an in the context of frequent sets of Boolean matrices, used in data mining~\cite[Section~1]{FSTT}: let $m(n,4,2)$ be the least size of a family of subsets of $[n]$ such that every $4$-set contains at least two members of the family and every $3$-set at most one. They prove that $m(n,k,2)=(1+o(1))\,T_{k-1}(n,k,2)$~\cite[Theorem~4]{FSTT}, where $T_{k-1}(n,k,2)$ is the least number of $(k-1)$-sets such that every $k$-set contains at least two of them; that is, sets of other sizes do not help asymptotically. Hence \[ m(n,4,2)=\Bigl(\frac57+o(1)\Bigr)\binom n3 . \] For a related parameter there is an exact formula. Let $m(n,4,12)$ be the least size of a family of nonempty subsets of $[n]$ such that every $4$-set contains at least $12$ members of the family and every $3$-set at most $11$. Mubayi and Zhao~\cite[Theorem~3]{MZ03} proved that $m(n,4,12)=n+\binom n2+\binom n3-\ex(n)$ for $n\ge4$. Hence $m(n,4,12)\ge n+\binom n2+\binom n3-U(n)$ for $n\ge4$, with equality exactly for $n=6^t$, and the difference is $O(n\log n)$ by Proposition~\ref{prop:error}. \subsection{Degrees and codegrees}\label{sec:degcodeg} Every $\Km$-free $3$-graph on $n\ge1$ vertices has minimum degree at most $3U(n)/n=(n^2-1)/7$, with equality only for $B_{6^t}$. In particular the minimum vertex degree that forces a copy of $\Km$ is $(\frac27+o(1))\binom n2$. Extremal $3$-graphs satisfy $d(v)=n^2/7+O(n)$ for every vertex (Lemma~\ref{lem:reg}), and $\ex(n)-\ex(n-1)=n^2/7+O(n)$ (delete a vertex of minimum degree; add a clone of a vertex of maximum degree). Falgas-Ravry, Pikhurko, Vaughan and Volec~\cite[Problem~6.5]{FPVV} ask for the largest density $f(c)$ of $\Km$-free $3$-graphs with minimum codegree at least $c(n-2)$, $0\le c\le\frac14$. They prove $f(\frac14)=\frac14$ and note that $f(0)=\frac27$ is the conjecture that $\pi(\Km)=\frac27$ (attributed there to Mubayi); this endpoint is now settled. \subsection{The limit}\label{sec:limit} By Theorem~\ref{thm:stab}, all sequences of $\Km$-free $3$-graphs with density tending to $2/7$ have the same subgraph densities in the limit: for every fixed $F$, $p(F;H_n)$ converges to the density of $F$ in the iterated balanced blow-ups. (Changing $o(n^3)$ triples changes $p(F;\cdot)$ by $o(1)$, and two iterated balanced blow-ups on $n$ vertices agree up to relabeling on all triples that are cross at one of the first $t$ levels, up to $O_t(n^2)$ triples.) In flag-algebra terms, the homomorphism with edge density $2/7$ is unique; by the hypergraph removal lemma the limit is also determined by finitely many density constraints (edge density $2/7$ and no copy of $\Km$). For example, let $q_j$ be the limiting proportion of $4$-sets spanning exactly $j$ edges. Four random vertices lie in four different parts with probability $\frac{5}{18}$ (two edges); in parts $i,i,j,k$ with probability $\frac59$ (two edges if $ijk\in\Hs$, which has probability $\frac12$, none otherwise); in parts $i,i,j,j$ with probability $\frac5{72}$ (no edge); in parts $i,i,i,j$ with probability $\frac5{54}$ (one edge with probability $\frac27$); and in one part with probability $\frac1{216}$ (recursion). Solving, \[ q_0=\frac{125}{301},\qquad q_1=\frac{8}{301},\qquad q_2=\frac{24}{43}. \] The value of $q_2$ determines the sum of the squares of the codegrees. In a $\Km$-free $3$-graph $H$ two edges that share a pair of vertices span four vertices with exactly two edges, and four vertices with exactly two edges contain exactly one such pair of edges. So \[ \sum_{\{u,v\}}d_H(u,v)^2=3|H|+2N_2(H), \] where $N_2(H)$ is the number of $4$-sets that span exactly two edges. Hence, for every sequence of $\Km$-free $3$-graphs $H_n$ on $n$ vertices with density tending to $2/7$, \[ \sum_{\{u,v\}}d_{H_n}(u,v)^2\Big/\Bigl(\binom n2(n-2)^2\Bigr)\ \longrightarrow\ \frac{q_2}{6}=\frac4{43} . \] This is the value conjectured in~\cite[Conjecture~3.2]{BCL} for the codegree-squared density of $\Km$. The conjecture itself concerns all $\Km$-free $3$-graphs and remains open, since a $3$-graph with fewer edges could have a larger sum. \subsection{Independent sets, colorings, and other forbidden \texorpdfstring{$3$-graphs}{3-graphs}}\label{sec:other} \emph{Supersaturation.} For every $\varepsilon>0$, large $3$-graphs with at least $(\frac27+\varepsilon)\binom n3$ edges contain $\Omega_\varepsilon(n^4)$ copies of $\Km$. If $\Km\subseteq F\subseteq\Km(s)$ for some blow-up $\Km(s)$ of $\Km$, then $\pi(F)=2/7$. \emph{Independent sets.} $\Km$-free $3$-graphs of density $\frac27-o(1)$ have independence number $o(n)$. Indeed, $\Hs$ has independence number $3$, so an independent set of an iterated blow-up meets at most $3^t$ of the $6^t$ parts of depth $t$. Let $B$ be an iterated balanced blow-up and $A$ a set of $\eta n$ vertices; choose $t$ with $2^{-t}<\eta/2$. The parts of depth $t$ containing at least $\eta n/(2\cdot6^t)$ vertices of $A$ cannot all avoid the edges of the pattern of depth $t$ (otherwise there are at most $3^t$ of them and $|A|<\eta n$ for large $n$), so three of them span $\Omega_\eta(n^3)$ edges inside $A$. Such a set cannot become independent by changing $o(n^3)$ triples, and Theorem~\ref{thm:stab} applies. \emph{Ramsey--Tur\'an.} Consequently the largest density of $\Km$-free $3$-graphs with independence number $o(n)$ is also $2/7$: the extremal $3$-graphs already have small independence number. That this Ramsey--Tur\'an density equals $\pi(\Km)$ was proved by Erd\H{o}s and S\'os~\cite[Theorem~1]{ES82}; here we obtain its value, and that every $\Km$-free $3$-graph of density close to $2/7$ has small independence number. \emph{Colorings.} For every fixed $q$, the largest density $p_q$ of $q$-colorable $\Km$-free $3$-graphs is strictly less than $2/7$, since a $q$-colorable $3$-graph has an independent set of size $n/q$. For $q=2$ this is weaker than Razborov's bound $p_2<0.2621$~\cite[Section~6.3]{Ra}. \subsection{Forcing density of order-size pairs}\label{sec:forcing} Extending a notion of Erd\H{o}s, F\"uredi, Rothschild and S\'os~\cite{EFRS} from graphs to $3$-graphs, write $(n,e)\to_3(m,f)$ if every $3$-graph with $n$ vertices and $e$ edges has $m$ vertices that span exactly $f$ edges, and define the \emph{forcing density} $\sigma_3(m,f)=\limsup_{n\to\infty}|\{e:\ 0\le e\le\binom n3,\ (n,e)\to_3(m,f)\}|/\binom n3$. Axenovich, Balogh, Clemen and Weber~\cite{ABCW} prove that $\sigma_3(6,10)>0$, which is the first pair with positive forcing density for $3$-graphs other than the trivial pairs $(m,0)$ and $(m,\binom m3)$, and they conjecture that it is the only one. The $3$-graph $\Km$ enters through the identity $\sigma_3(6,10)=1-2\,\pi(\{\Km,\Hs\})$~\cite[Theorem~1.1]{ABCW}; here $\pi(\{\Km,\Hs\})$ is the largest density of $\Km$-free $3$-graphs in which no six vertices span exactly ten edges, that is, which contain no copy of $\Hs$ (a $\Km$-free $3$-graph with ten edges on six vertices is isomorphic to $\Hs$ by Theorem~\ref{thm:exact}). Since $\pi(\{\Km,\Hs\})\le\pi(\Km)$, Theorem~\ref{thm:main} improves the bound $\sigma_3(6,10)\ge0.42622$ of~\cite[Theorem~1.1]{ABCW} to $\frac37$. This is not the best known bound: the authors remark that a flag algebra computation gives $\pi(\{\Km,\Hs\})\le0.275$ and hence $\sigma_3(6,10)\ge0.45$~\cite[Section~4]{ABCW}. \subsection{The same bound for other problems}\label{sec:same} The proof of Theorem~\ref{thm:lagr} uses only that $\Km$-free $3$-graphs are closed under substitution: replacing every vertex of a $\Km$-free $3$-graph by a $\Km$-free $3$-graph, with all edges between the new sets as prescribed by the old $3$-graph and no others, gives a $\Km$-free $3$-graph. For any family of $3$-graphs that is closed under this operation and under taking induced subgraphs, with Tur\'an density $\pi$ and extremal function $\ex(n)$, the same argument gives \[ \pi\binom n3\ \le\ \ex(n)\ \le\ \pi\binom{n+1}3\qquad\text{for all }n. \] This applies for example to $K_4$-free $3$-graphs. What is special for $\Km$ is that the upper bound is attained for infinitely many $n$. (That every pair of vertices of the forbidden $3$-graph lies in an edge is not enough for closure under substitution: contracting a line of the Fano plane gives a Fano-free $3$-graph on five vertices, and substituting an edge for the new vertex gives back a $3$-graph containing the Fano plane.) \section{Computer verification}\label{sec:trust} The proofs in Sections~\ref{sec:prelim}--\ref{sec:stability} rest on Computational Claims~\ref{claim:P}, \ref{claim:A}, \ref{claim:B} and~\ref{claim:S}. Each of them asserts that explicit rational data, a certificate, satisfies finitely many inequalities. The certificates were found by semidefinite programming followed by rounding; this search is not part of the proof. \emph{The certificates.} For Claims~\ref{claim:P} and~\ref{claim:A} every matrix $Q^\sigma$ is given as a combination $\sum\mu vv^{\mathsf T}$ of squares of integer vectors $v$ with rational multipliers $\mu\ge0$, so it is positive semidefinite by construction. There are $2{,}987$ squares for Claim~\ref{claim:P}, converted from the certificate of~\cite{LV}, and $8{,}587$ squares and $411$ rows with positive multipliers for Claim~\ref{claim:A}. For Claim~\ref{claim:B} the matrices have the form $BGB^{\mathsf T}$ with integer matrices $B$ and rational positive definite matrices $G$ (not to be confused with the set of good edges), and $487$ rows have positive multipliers (not counting the row $L^{\mathrm{in}}$). To reduce their size, the matrices are given in bases adapted to the automorphisms of the types $\sigma$, that is, in terms of matrices $P^{\mathsf T}M_F^\sigma P$ for fixed matrices $P$. Such a certificate is a certificate in the sense of~\eqref{eq:cert} whatever $P$ is, because a positive semidefinite $Q_1$ gives $\ip{Q_1}{P^{\mathsf T}M_F^\sigma P}=\ip{PQ_1P^{\mathsf T}}{M_F^\sigma}$ with $PQ_1P^{\mathsf T}$ positive semidefinite. \emph{Verification.} The four claims were verified in two ways that do not depend on each other. \emph{Programs.} Programs evaluate~\eqref{eq:certP} and~\eqref{eq:certA} for all $9{,}895{,}719$ $3$-graphs of $\cF_8$: all terms are computed as exact rational numbers, and the final combination for each $3$-graph is evaluated in floating-point arithmetic with a rigorous error bound that is far smaller than the margin. For Claims~\ref{claim:B} and~\ref{claim:S} the inequalities for all $41{,}322$ orbits are evaluated in exact rational arithmetic; for Claim~\ref{claim:B} this was done by three programs written independently of each other, which also verify exactly that the matrices $G$ are positive definite. \emph{Formal proof.} The proofs of Theorems~\ref{thm:main}, \ref{thm:exact}, \ref{thm:stab}, \ref{thm:lagr} and~\ref{thm:level} are formalized in the proof assistant Lean~4~\cite{Lean4} with the library Mathlib~\cite{Mathlib}. This includes the four computational claims: for each claim, the evaluation of the certificate on a $3$-graph is defined in Lean and proved to compute the quantity in the claim, the list of evaluated $3$-graphs is proved to contain every $3$-graph up to isomorphism (and, for Claims~\ref{claim:B} and~\ref{claim:S}, up to the action of $\Gamma$), and the evaluations are executed by compiled code (Lean's \texttt{native\_decide}). So the formal proof uses, besides the standard axioms of Lean, the correctness of the Lean compiler for these computations. It does not use the programs of the previous paragraph. The formal statements concern $3$-graphs on labeled vertex sets instead of isomorphism classes, which makes no difference. The consequences in Section~\ref{sec:cons} are formalized as well, except for the statements listed in Table~\ref{tab:cons}, most of which rest on results from the literature. Complete formal proofs of flag-algebra results, certificate checks included, were recently given for a bound on the Tur\'an density of the tetrahedron~\cite[Section~3.2]{JPILY} and for the Tur\'an density of the tight $5$-cycle~\cite{GrahamC5}. The latter also executes its finite computations as compiled code, and our formalization reuses some of its general lemmas on Gram matrices. The arguments of~\cite{DLPV} are formalized in Lean as well, with the computational claims as hypotheses. \begin{table}[ht] \centering\small \renewcommand{\arraystretch}{1.15} \begin{tabular}{@{}>{\raggedright\arraybackslash}p{0.56\textwidth}>{\raggedright\arraybackslash}p{0.40\textwidth}@{}} \toprule statement of Section~\ref{sec:cons} & reason\\ \midrule \S\ref{sec:finiteconj}: the values of $\ex(n)$ and the numbers of extremal $3$-graphs for $n\le19$ & taken from~\cite{De,LRSW,MT}\\ \S\ref{sec:jumps}: Corollary~\ref{cor:jumps} & uses the criterion of~\cite{FR}\\ \S\ref{sec:cover}: threshold set systems & uses~\cite[Theorem~4]{FSTT} and~\cite[Theorem~3]{MZ03}\\ \S\ref{sec:degcodeg}: the codegree problem of~\cite{FPVV} & quoted from~\cite{FPVV}\\ \S\ref{sec:limit}: convergence of $p(F;H_n)$ for every $F$; uniqueness of the limit & only the proportions $q_0,q_1,q_2$ and the codegree-squared limit are formalized\\ \S\ref{sec:other}: supersaturation; $\pi(F)=\frac27$ for $\Km\subseteq F\subseteq\Km(s)$ & uses hypergraph supersaturation\\ \S\ref{sec:forcing}: forcing density & uses~\cite[Theorem~1.1]{ABCW}\\ \S\ref{sec:same}: the remarks on $K_4$ and on the Fano plane & examples only\\ \bottomrule \end{tabular} \caption{The statements of Section~\ref{sec:cons} that are not formalized.}\label{tab:cons} \end{table} The Lean certificate is available at \url{https://doi.org/10.5281/zenodo.24763317}. \section*{Acknowledgment} The authors thank Konstantin Slutsky for guidance on efficient use of AI technology. The authors thank Benjamin Bridenbaugh and Michal Dvo\v{r}\'ak for earlier discussions. Some of the calculations while working on this material were performed on the Alderaan cluster. The Alderaan cluster was funded by the National Science Foundation Campus Computing program grant OAC-2019089 and a contribution from the Simons Foundation. It is operated by the Center for Computational Mathematics, Department of Mathematical and Statistical Sciences, College of Liberal Arts and Sciences at University of Colorado, Denver. The work of the second and fourth authors was also partially supported by the MEYS of the Czech Republic under the INTER-EXCELLENCE II program (project No. LUAUS26294). \bibliographystyle{alphaurl} \bibliography{literature} \end{document}