  We prove a stability result for general $3$-wise correlations over
distributions satisfying mild connectivity properties. More concretely, we show
that if $\Sigma,\Gamma$ and $\Phi$ are alphabets of constant size, and $\mu$ is
a pairwise connected distribution over $\Sigma\times\Gamma\times\Phi$ with no
$(\mathbb{Z},+)$ embeddings in which the probability of each atom is
$\Omega(1)$, then the following holds. Any triplets of $1$-bounded functions
$f\colon \Sigma^n\to\mathbb{C}$, $g\colon \Gamma^n\to\mathbb{C}$, $h\colon
\Phi^n\to\mathbb{C}$ satisfying
  \[
  \left|\mathbb{E}_{(x,y,z)\sim \mu^{\otimes
n}}\big[f(x)g(y)h(z)\big]\right|\geq \varepsilon
  \]
  must arise from an Abelian group associated with the distribution $\mu$. More
specifically, we show that there is an Abelian group $(H,+)$ of constant size
such that for any such $f,g$ and $h$, the function $f$ (and similarly $g$ and
$h$) is correlated with a function of the form $\tilde{f}(x) =
\chi(\sigma(x_1),\ldots,\sigma(x_n)) L (x)$, where $\sigma\colon \Sigma \to H$
is some map, $\chi\in \hat{H}^{\otimes n}$ is a character, and $L\colon
\Sigma^n\to\mathbb{C}$ is a low-degree function with bounded $2$-norm.
  En route we prove a few additional results that may be of independent
interest, such as an improved direct product theorem, as well as a result we
refer to as a ``restriction inverse theorem'' about the structure of functions
that, under random restrictions, with noticeable probability have significant
correlation with a product function. In companion papers, we show applications
of our results to the fields of Probabilistically Checkable Proofs, as well as
various areas in discrete mathematics such as extremal combinatorics and
additive combinatorics.
