[step:Define slice rank and compute the rank of a diagonal tensor]
Let $X$ be a finite set and let
\begin{align*}
T:X \times X \times X &\to \mathbb{F}_3
\end{align*}
be a function. We say that $T$ has slice rank at most $r$ if it can be written as a sum of $r$ functions, each of one of the three forms
\begin{align*}
(x,y,z) &\mapsto f(x)g(y,z),\\
(x,y,z) &\mapsto f(y)g(x,z),\\
(x,y,z) &\mapsto f(z)g(x,y),
\end{align*}
where the displayed functions have values in $\mathbb{F}_3$. The slice rank of $T$, denoted $\operatorname{srank}(T)$, is the least such $r$.
Let $B$ be a finite set, and let
\begin{align*}
D:B \times B \times B &\to \mathbb{F}_3
\end{align*}
be the diagonal tensor defined by $D(a,b,c)=1$ if $a=b=c$ and $D(a,b,c)=0$ otherwise. We claim that
\begin{align*}
\operatorname{srank}(D)=|B|.
\end{align*}
The inequality $\operatorname{srank}(D)\le |B|$ follows from
\begin{align*}
D(a,b,c)=\sum_{u\in B}\mathbb{1}_{\{u\}}(a)\mathbb{1}_{\{(u,u)\}}(b,c).
\end{align*}
For the reverse inequality, suppose $D$ has slice rank $r$. By grouping the terms according to the singled-out variable, write
\begin{align*}
D(a,b,c)=\sum_{i=1}^{r_1} f_i(a)g_i(b,c)+\sum_{j=1}^{r_2} h_j(b)k_j(a,c)+\sum_{\ell=1}^{r_3} p_\ell(c)q_\ell(a,b),
\end{align*}
where $r_1+r_2+r_3=r$, where $f_i,h_j,p_\ell:B\to\mathbb{F}_3$ are functions, and where $g_i,k_j,q_\ell:B\times B\to\mathbb{F}_3$ are functions.
Define the [vector space](/page/Vector%20Space)
\begin{align*}
V:=\left\{\lambda:B\to\mathbb{F}_3 : \sum_{a\in B}\lambda(a)f_i(a)=0\text{ for every }1\le i\le r_1\right\}.
\end{align*}
Since $V$ is the kernel of a [linear map](/page/Linear%20Map) from $\mathbb{F}_3^B$ to $\mathbb{F}_3^{r_1}$, the [rank-nullity theorem](/theorems/916) gives
\begin{align*}
\dim_{\mathbb{F}_3}V\ge |B|-r_1.
\end{align*}
We use the elementary support bound that every $d$-dimensional subspace of $\mathbb{F}_3^B$ contains a vector whose support has cardinality at least $d$. Indeed, choose a basis of the subspace and row-reduce the corresponding $d\times |B|$ matrix; the sum of the row-reduced basis vectors has nonzero entries in all pivot columns. Hence there exists $\lambda\in V$ such that, with
\begin{align*}
S:=\{b\in B:\lambda(b)\ne 0\},
\end{align*}
one has $|S|\ge |B|-r_1$.
Contract the decomposition of $D$ against $\lambda$ in the first variable, obtaining a function
\begin{align*}
M:B\times B&\to\mathbb{F}_3\\
(b,c)&\mapsto \sum_{a\in B}\lambda(a)D(a,b,c).
\end{align*}
Because $D$ is diagonal, $M(b,c)=\lambda(b)$ when $b=c$ and $M(b,c)=0$ when $b\ne c$. Thus, as the matrix indexed by $B\times B$, $M$ is diagonal with precisely $|S|$ nonzero diagonal entries, so $\operatorname{rank}(M)=|S|$.
The same contraction applied to the right-hand side annihilates the first group by the definition of $V$. The remaining terms have the form
\begin{align*}
M(b,c)=\sum_{j=1}^{r_2}h_j(b)K_j(c)+\sum_{\ell=1}^{r_3}p_\ell(c)Q_\ell(b),
\end{align*}
where the functions $K_j:B\to\mathbb{F}_3$ and $Q_\ell:B\to\mathbb{F}_3$ are defined by
\begin{align*}
K_j(c)&:=\sum_{a\in B}\lambda(a)k_j(a,c),\\
Q_\ell(b)&:=\sum_{a\in B}\lambda(a)q_\ell(a,b).
\end{align*}
Each summand $h_j(b)K_j(c)$ or $Q_\ell(b)p_\ell(c)$ is a rank-one matrix, so subadditivity of matrix rank gives
\begin{align*}
|S|=\operatorname{rank}(M)\le r_2+r_3.
\end{align*}
Combining $|S|\ge |B|-r_1$ with this inequality yields $|B|\le r_1+r_2+r_3=r$. Therefore every slice decomposition of $D$ has at least $|B|$ slices, and hence $\operatorname{srank}(D)=|B|$.
[/step]