Fundamental Limitations on Subquadratic Alternatives to Transformers

1 Basic notation and transformer model

Definition 1 Finite real vectors and matrices
#

For a positive integer \(d\), a real vector of length \(d\) is represented as a function \(\{ 1,\ldots ,d\} \to \mathbb {R}\), and an \(n\times d\) real matrix is represented as a function \(\{ 1,\ldots ,n\} \times \{ 1,\ldots ,d\} \to \mathbb {R}\). The notation \(v[i]\), \(A_{i,:}\), and \(A_{:,j}\) denotes coordinate projection, row projection, and column projection.

Definition 2 Inner product and Euclidean norm
#

For \(v,w\in \mathbb {R}^d\), \(\left\langle v,w\right\rangle =\sum _i v[i]w[i]\) and \(\| v\| =(\left\langle v,v\right\rangle )^{1/2}\).

Lemma 3 Cauchy–Schwarz inequality
#

For real finite-dimensional vectors \(v,w\), \(|\left\langle v,w\right\rangle |\leq \| v\| \, \| w\| \).

Definition 4 Binary vector operations

A binary vector is an element of \(\{ 0,1\} ^d\). The all-one vector is \(\mathbf{1}_d\). If \(v\in \{ 0,1\} ^d\), then \(\bar v\in \{ 0,1\} ^d\) is defined by \(\bar v[i]=1-v[i]\) for every coordinate \(i\).

Lemma 5 Complement flips binary inner products

If \(v,w\in \{ 0,1\} ^d\) and \(\| v\| _1=\sum _i v[i]\), then \(\left\langle v,\bar w\right\rangle =\| v\| _1-\left\langle v,w\right\rangle \).

Proof

By definition of the complement, \(\left\langle v,\bar w\right\rangle =\sum _i v[i](1-w[i])\). Distributing the product and separating the finite sum gives \(\sum _i v[i]-\sum _i v[i]w[i]=\| v\| _1-\left\langle v,w\right\rangle \).

Definition 6 Kronecker product
#

For \(v\in \mathbb {R}^a\) and \(w\in \mathbb {R}^b\), the Kronecker product \(v\otimes w\in \mathbb {R}^{ab}\) has coordinates indexed by pairs and satisfies \((v\otimes w)[i,j]=v[i]w[j]\).

Definition 7 Kronecker power coordinate product

For a vector \(v\in \mathbb {R}^d\) and a positive integer \(q\), the \(q\)-fold Kronecker power \(v^{\otimes q}\in \mathbb {R}^{d^q}\) is the vector whose coordinates are indexed by functions \(\alpha :\{ 1,\ldots ,q\} \to \{ 1,\ldots ,d\} \) and whose coordinate value is the concrete product

\[ v^{\otimes q}[\alpha ]=\prod _{r=1}^{q} v[\alpha (r)]. \]

Equivalently, \(v^{\otimes 1}=v\) under the one-coordinate identification and \(v^{\otimes (q+1)}=v\otimes v^{\otimes q}\) with the coordinate equation of Definition 6. This node defines only the power construction and its coordinate product relation.

Definition 8 Vector concatenation
#

For \(v\in \mathbb {R}^a\) and \(w\in \mathbb {R}^b\), the concatenation \(v\circ w\in \mathbb {R}^{a+b}\) is the vector with coordinates

\[ (v\circ w)[r]=v[r]\quad (1\leq r\leq a), \qquad (v\circ w)[a+s]=w[s]\quad (1\leq s\leq b). \]

This node defines only concatenation; Kronecker products and Kronecker powers are Definition 6 and Definition 7.

Lemma 9 Kronecker inner product

For finite real vectors \(v,w\) and every positive integer \(q\),

\[ \left\langle v^{\otimes q},w^{\otimes q}\right\rangle =\left\langle v,w\right\rangle ^{q}. \]
Proof

For \(q=1\) this is the definition. The step from \(q\) to \(q+1\) expands the inner product over pairs of coordinates: \(\sum _{i,\alpha } v[i]v^{\otimes q}[\alpha ]w[i]w^{\otimes q}[\alpha ]\). Separating the product of finite sums gives \(\left\langle v,w\right\rangle \left\langle v^{\otimes q},w^{\otimes q}\right\rangle \), which is \(\left\langle v,w\right\rangle ^{q+1}\) by the induction hypothesis.

Lemma 10 Kronecker norm

For every finite real vector \(v\) and positive integer \(q\), \(\| v^{\otimes q}\| =\| v\| ^q\).

Proof

Squaring both sides reduces the claim to \(\left\langle v^{\otimes q},v^{\otimes q}\right\rangle =\left\langle v,v\right\rangle ^{q}\), which is Lemma 9 with \(w=v\). Both norms are nonnegative, so equality of squares implies equality of norms.

Definition 11 Softmax on vectors

For \(x\in \mathbb {R}^n\),

\[ \operatorname {softmax}(x)=\frac{(\exp (x[1]),\ldots ,\exp (x[n]))}{\sum _{i=1}^n\exp (x[i])}. \]
Definition 12 Row-wise softmax on matrices

For \(A\in \mathbb {R}^{n\times n}\), \(\operatorname {softmax}(A)\) is defined row-wise by \(\operatorname {softmax}(A)_{i,:}=\operatorname {softmax}(A_{i,:})\).

Definition 13 Document-keyword occurrence relation
#

A document-similarity instance fixes a type \({\cal D}\) of documents, a type \({\cal K}\) of keywords, and a concrete occurrence predicate

\[ \operatorname {Occurs}(D,k) \]

for \(D\in {\cal D}\) and \(k\in {\cal K}\), meaning that keyword \(k\) occurs in document \(D\). The predicate is part of the input model as decidable data: for every pair \((D,k)\) there is a yes/no occurrence decision whose true branch is exactly \(\operatorname {Occurs}(D,k)\) and whose false branch is exactly \(\neg \operatorname {Occurs}(D,k)\).

This occurrence datum contains no length parameter and no built-in keyword list. The Lean-facing structure \(\operatorname {def\_ document\_ keyword\_ occurrence}\) has exactly the following four fields and field names:

\[ \mathrm{Document}:\mathrm{Type},\qquad \mathrm{Keyword}:\mathrm{Type},\qquad \mathrm{Occurs}:\mathrm{Document}\to \mathrm{Keyword}\to \mathrm{Prop}, \]

and

\[ \mathrm{occurs\_ decidable}: \forall D:\mathrm{Document},\ \forall k:\mathrm{Keyword}, \operatorname {Decidable}(\mathrm{Occurs}(D,k)). \]

Thus the tuple is \(({\cal D},{\cal K},\operatorname {Occurs},\operatorname {occurs\_ decidable})\) with the displayed names. The keyword vector used for a particular bag-of-words embedding is supplied separately in Definition 14; it is not a field of this occurrence structure.

Definition 14 Coordinate-indexed keyword vector
#

For an occurrence datum \(\mathsf{doc}:\operatorname {def\_ document\_ keyword\_ occurrence}\) and a chosen bag-of-words length \(\ell \), a keyword list is the concrete coordinate-indexed function

\[ K:\{ 1,\ldots ,\ell \} \to \mathsf{doc}.\mathrm{Keyword}. \]

Formally,

\[ \operatorname {def\_ keyword\_ coordinate\_ vector}(\mathsf{doc},\ell ) =(\{ 1,\ldots ,\ell \} \to \mathsf{doc}.\mathrm{Keyword}). \]

This definition has exactly the displayed inputs \((\mathsf{doc},\ell )\) and returns a type of keyword-vector parameters. It does not construct a default keyword vector, erase the occurrence datum, use an ambient keyword family, or store the vector in \(\mathsf{doc}\). The \(r\)th coordinate of a document embedding refers to the concrete keyword \(K(r)\). Two instances with the same documents and occurrence predicate but different functions \(K\) are different bag-of-words inputs and may produce different embedding matrices.

Definition 15 Real-valued keyword occurrence indicator
#

For an occurrence datum \(\mathsf{doc}:\operatorname {def\_ document\_ keyword\_ occurrence}\), a document \(D:\mathsf{doc}.\mathrm{Document}\), and a keyword \(k:\mathsf{doc}.\mathrm{Keyword}\), define the real-valued occurrence indicator

\[ \operatorname {OccVal}_{\mathsf{doc}}(D,k)= \begin{cases} 1\in \mathbb {R}, & \mathsf{doc}.\mathrm{Occurs}(D,k),\\ 0\in \mathbb {R}, & \neg \mathsf{doc}.\mathrm{Occurs}(D,k). \end{cases} \]

Lean-facing, this is the function

\[ \operatorname {def\_ keyword\_ occurrence\_ indicator} (\mathsf{doc})(D)(k):\mathbb {R}= \begin{cases} 1, & \mathsf{doc}.\mathrm{Occurs}(D,k),\\ 0, & \neg \mathsf{doc}.\mathrm{Occurs}(D,k), \end{cases} \]

where the branch is selected by the concrete \(\mathsf{doc}.\mathrm{occurs\_ decidable}(D,k)\) field. No other document encoding or keyword semantics are implicit in this value.

Lemma 16 Present keyword occurrence indicator

For every occurrence datum \(\mathsf{doc}\), document \(D:\mathsf{doc}.\mathrm{Document}\), and keyword \(k:\mathsf{doc}.\mathrm{Keyword}\),

\[ \mathsf{doc}.\mathrm{Occurs}(D,k)\Rightarrow \operatorname {OccVal}_{\mathsf{doc}}(D,k)=1. \]
Proof

Under the hypothesis \(\mathsf{doc}.\mathrm{Occurs}(D,k)\), the defining occurrence decision for \(\operatorname {OccVal}_{\mathsf{doc}}(D,k)\) takes its true branch, whose value is \(1\).

Lemma 17 Absent keyword occurrence indicator

For every occurrence datum \(\mathsf{doc}\), document \(D:\mathsf{doc}.\mathrm{Document}\), and keyword \(k:\mathsf{doc}.\mathrm{Keyword}\),

\[ \neg \mathsf{doc}.\mathrm{Occurs}(D,k)\Rightarrow \operatorname {OccVal}_{\mathsf{doc}}(D,k)=0. \]
Proof

Under the hypothesis \(\neg \mathsf{doc}.\mathrm{Occurs}(D,k)\), the defining occurrence decision for \(\operatorname {OccVal}_{\mathsf{doc}}(D,k)\) takes its false branch, whose value is \(0\).

Definition 18 Bag-of-words embedding
#

For an occurrence datum \(\mathsf{doc}:\operatorname {def\_ document\_ keyword\_ occurrence}\) and a length \(\ell \), the Lean-facing bag-of-words embedding is the function

\[ \operatorname {def\_ bag\_ of\_ words}(\mathsf{doc},\ell ): \mathsf{doc}.\mathrm{Document}\to \operatorname {def\_ keyword\_ coordinate\_ vector}(\mathsf{doc},\ell )\to (\{ 1,\ldots ,\ell \} \to \mathbb {R}) \]

defined by the coordinate equation

\[ \operatorname {def\_ bag\_ of\_ words}(\mathsf{doc},\ell )(D)(K)(r) = \operatorname {def\_ keyword\_ occurrence\_ indicator} (\mathsf{doc})(D)(K(r)). \]

We write this output as \(\mathrm{BOW}_{\mathsf{doc}}(D,K):\{ 1,\ldots ,\ell \} \to \mathbb {R}\). The keyword vector \(K\) is an explicit argument of this definition, not a field of the occurrence datum, and the codomain is the real vector space \(\mathbb {R}^\ell \) used by the paper rather than a Boolean-valued coordinate type.

Lemma 19 Bag-of-words coordinate is occurrence indicator

For every occurrence datum \(\mathsf{doc}\), document \(D:\mathsf{doc}.\mathrm{Document}\), coordinate-indexed keyword vector \(K:\{ 1,\ldots ,\ell \} \to \mathsf{doc}.\mathrm{Keyword}\), and coordinate \(r\),

\[ \operatorname {def\_ bag\_ of\_ words}(\mathsf{doc},\ell )(D)(K)(r) =\operatorname {OccVal}_{\mathsf{doc}}(D,K(r)). \]
Proof

This is the coordinate equality in the definition of the bag-of-words row \(\operatorname {def\_ bag\_ of\_ words}(\mathsf{doc},\ell )(D)(K)\) at coordinate \(r\). There is no separate fixed-keyword wrapper declaration: the keyword vector \(K\) is the explicit second argument of \(\operatorname {def\_ bag\_ of\_ words}(\mathsf{doc},\ell )(D)\).

Lemma 20 Bag-of-words present keyword coordinate

For every occurrence datum \(\mathsf{doc}\), document \(D:\mathsf{doc}.\mathrm{Document}\), coordinate-indexed keyword vector \(K:\{ 1,\ldots ,\ell \} \to \mathsf{doc}.\mathrm{Keyword}\), and coordinate \(r\),

\[ \mathsf{doc}.\mathrm{Occurs}(D,K(r)) \Rightarrow \operatorname {def\_ bag\_ of\_ words}(\mathsf{doc},\ell )(D)(K)(r)=1. \]
Proof

Expanding Definition 18 rewrites the displayed bag-of-words coordinate as the occurrence indicator \(\operatorname {OccVal}_{\mathsf{doc}}(D,K(r))\). Applying Lemma 16 to the concrete keyword \(K(r)\) and the hypothesis \(\mathsf{doc}.\mathrm{Occurs}(D,K(r))\) gives that this indicator value is \(1\).

Lemma 21 Bag-of-words absent keyword coordinate

For every occurrence datum \(\mathsf{doc}\), document \(D:\mathsf{doc}.\mathrm{Document}\), coordinate-indexed keyword vector \(K:\{ 1,\ldots ,\ell \} \to \mathsf{doc}.\mathrm{Keyword}\), and coordinate \(r\),

\[ \neg \mathsf{doc}.\mathrm{Occurs}(D,K(r)) \Rightarrow \operatorname {def\_ bag\_ of\_ words}(\mathsf{doc},\ell )(D)(K)(r)=0. \]
Proof

Expanding Definition 18 rewrites the displayed bag-of-words coordinate as the occurrence indicator \(\operatorname {OccVal}_{\mathsf{doc}}(D,K(r))\). Applying Lemma 17 to the concrete keyword \(K(r)\) and the hypothesis \(\neg \mathsf{doc}.\mathrm{Occurs}(D,K(r))\) gives that this indicator value is \(0\).

Lemma 22 Bag-of-words coordinates are binary

For every occurrence datum \(\mathsf{doc}\), document \(D:\mathsf{doc}.\mathrm{Document}\), coordinate-indexed keyword vector \(K:\{ 1,\ldots ,\ell \} \to \mathsf{doc}.\mathrm{Keyword}\), and coordinate \(r\),

\[ \operatorname {def\_ bag\_ of\_ words}(\mathsf{doc},\ell )(D)(K)(r)=0 \quad \text{or}\quad \operatorname {def\_ bag\_ of\_ words}(\mathsf{doc},\ell )(D)(K)(r)=1. \]
Proof

Expand Definition 18 at the coordinate \(r\), reducing the displayed value to the occurrence indicator \(\operatorname {OccVal}_{\mathsf{doc}}(D,K(r))\). The occurrence predicate is decidable for the pair \((D,K(r))\). If \(\mathsf{doc}.\mathrm{Occurs}(D,K(r))\), then Lemma 16 gives the value \(1\). If \(\neg \mathsf{doc}.\mathrm{Occurs}(D,K(r))\), then Lemma 17 gives the value \(0\).

Definition 23 Document row equals its bag-of-words embedding

For an occurrence datum \(\mathsf{doc}\), a document \(D:\mathsf{doc}.\mathrm{Document}\), a coordinate-indexed keyword vector \(K:\{ 1,\ldots ,\ell \} \to \mathsf{doc}.\mathrm{Keyword}\), and a row vector \(e\in \mathbb {R}^\ell \), the predicate

\[ \operatorname {RowBOW}_{\mathsf{doc}}(D,K,e) \]

holds exactly when \(e\) is the concrete bag-of-words embedding of \(D\) with respect to \(K\):

\[ \forall \, 1\leq r\leq \ell ,\qquad e[r]=\operatorname {def\_ bag\_ of\_ words}(\mathsf{doc},\ell )(D)(K)(r). \]

This predicate has exactly the displayed inputs \((\mathsf{doc},D,K,e)\). It has no matrix index, no occurrence-value expansion, no nonzero-row promise, and no access to an ambient keyword vector stored in the occurrence datum.

Definition 24 Matrix row as a vector

For a matrix \(E\in \mathbb {R}^{n\times \ell }\) and an index \(i\in \{ 1,\ldots ,n\} \), the row vector

\[ \operatorname {RowVec}(E,i):\{ 1,\ldots ,\ell \} \to \mathbb {R} \]

is defined coordinatewise by

\[ \operatorname {RowVec}(E,i)(r)=E[i,r] \qquad \text{for every }r\in \{ 1,\ldots ,\ell \} . \]

This is only the concrete row-projection function from a finite matrix to a finite vector.

Definition 25 Valid document-similarity input matrix

For an occurrence datum \(\mathsf{doc}\), a document family \(D:\{ 1,\ldots ,n\} \to \mathsf{doc}.\mathrm{Document}\), a coordinate-indexed keyword vector \(K:\{ 1,\ldots ,\ell \} \to \mathsf{doc}.\mathrm{Keyword}\), and a matrix \(E\in \mathbb {R}^{n\times \ell }\), define

\[ \operatorname {ValidBOW}_{\mathsf{doc}}(D,K,E) \]

to be the concrete matrix-entry relation

\[ \forall \, i\in \{ 1,\ldots ,n\} ,\ \forall \, r\in \{ 1,\ldots ,\ell \} ,\qquad E[i,r]= \operatorname {def\_ bag\_ of\_ words}(\mathsf{doc},\ell )(D(i))(K)(r). \]

Lean-facing, the document input is the single finite-indexed function \(D\), not a variadic tuple of fields. The predicate has exactly the displayed inputs \((\mathsf{doc},D,K,E)\), with \(K\) explicit. It contains no nonzero-row hypothesis and no occurrence-value expansion; those are separate consequences proved below. Thus a valid document-similarity input is a real matrix whose entries are precisely the bag-of-words coordinates for the displayed document family and keyword vector. Consequently, any later proof needing an entry equality specializes this definition directly at the relevant row and coordinate; Lemma 26 records that specialization as a separate one-line formal interface. There is no alternate rowwise validity predicate.

Lemma 26 Valid document matrix entry is its bag-of-words coordinate

If \(\operatorname {ValidBOW}_{\mathsf{doc}}(D,K,E)\) holds, then for every \(i\in \{ 1,\ldots ,n\} \) and \(r\in \{ 1,\ldots ,\ell \} \),

\[ E[i,r]= \operatorname {def\_ bag\_ of\_ words}(\mathsf{doc},\ell )(D(i))(K)(r). \]
Proof

This is exactly Definition 25 specialized to the displayed row \(i\) and coordinate \(r\).

Lemma 27 Document row bag-of-words coordinate is occurrence value

For all positive integers \(n\) and \(\ell \), every occurrence datum \(\mathsf{doc}\), document family \(D:\{ 1,\ldots ,n\} \to \mathsf{doc}.\mathrm{Document}\), coordinate-indexed keyword vector \(K:\{ 1,\ldots ,\ell \} \to \mathsf{doc}.\mathrm{Keyword}\), row \(i\in \{ 1,\ldots ,n\} \), and coordinate \(r\in \{ 1,\ldots ,\ell \} \),

\[ \operatorname {def\_ bag\_ of\_ words}(\mathsf{doc},\ell )(D(i))(K)(r) = \operatorname {def\_ keyword\_ occurrence\_ indicator} (\mathsf{doc})(D(i))(K(r)). \]
Proof

Expand Definition 18 at the concrete document \(D(i)\), keyword vector \(K\), and coordinate \(r\). The right-hand side is exactly the Lean-facing occurrence-value function introduced in Definition 15.

Lemma 28 Valid document matrix entries are occurrence values

If \(\operatorname {ValidBOW}_{\mathsf{doc}}(D,K,E)\) holds, then for every \(i\in \{ 1,\ldots ,n\} \) and \(r\in \{ 1,\ldots ,\ell \} \),

\[ E[i,r]=\operatorname {OccVal}_{\mathsf{doc}}(D(i),K(r)). \]
Proof

Lemma 26 gives

\[ E[i,r]= \operatorname {def\_ bag\_ of\_ words}(\mathsf{doc},\ell )(D(i))(K)(r). \]

Lemma 27 gives

\[ \operatorname {def\_ bag\_ of\_ words}(\mathsf{doc},\ell )(D(i))(K)(r) =\operatorname {OccVal}_{\mathsf{doc}}(D(i),K(r)). \]

Transitivity of equality yields the displayed occurrence-value equation for \(E[i,r]\).

Lemma 29 Valid document matrix entry for present keyword

If \(\operatorname {ValidBOW}_{\mathsf{doc}}(D,K,E)\) holds, then for every \(i\in \{ 1,\ldots ,n\} \) and \(r\in \{ 1,\ldots ,\ell \} \),

\[ \mathsf{doc}.\mathrm{Occurs}(D(i),K(r))\Rightarrow E[i,r]=1 \]
Proof

Lemma 26 rewrites \(E[i,r]\) as the bag-of-words coordinate of \(D(i)\) at \(r\). Under the hypothesis \(\mathsf{doc}.\mathrm{Occurs}(D(i),K(r))\), Lemma 20 gives that same coordinate value as \(1\).

Lemma 30 Valid document matrix entry for absent keyword

If \(\operatorname {ValidBOW}_{\mathsf{doc}}(D,K,E)\) holds, then for every \(i\in \{ 1,\ldots ,n\} \) and \(r\in \{ 1,\ldots ,\ell \} \),

\[ \neg \mathsf{doc}.\mathrm{Occurs}(D(i),K(r))\Rightarrow E[i,r]=0. \]
Proof

Lemma 26 rewrites \(E[i,r]\) as the bag-of-words coordinate of \(D(i)\) at \(r\). Under the hypothesis \(\neg \mathsf{doc}.\mathrm{Occurs}(D(i),K(r))\), Lemma 21 gives that same coordinate value as \(0\).

Lemma 31 Valid document matrix entry occurrence cases

If \(\operatorname {ValidBOW}_{\mathsf{doc}}(D,K,E)\) holds, then for every \(i\in \{ 1,\ldots ,n\} \) and \(r\in \{ 1,\ldots ,\ell \} \), exactly the concrete occurrence decision for \((D(i),K(r))\) determines the entry value:

\[ \bigl(\mathsf{doc}.\mathrm{Occurs}(D(i),K(r))\wedge E[i,r]=1\bigr) \quad \text{or}\quad \bigl(\neg \mathsf{doc}.\mathrm{Occurs}(D(i),K(r))\wedge E[i,r]=0\bigr). \]
Proof

Use the decidability field of Definition 13 for the proposition \(\mathsf{doc}.\mathrm{Occurs}(D(i),K(r))\). In the true case, Lemma 29 supplies \(E[i,r]=1\). In the false case, Lemma 30 supplies \(E[i,r]=0\).

Definition 32 Nonzero document-row promise

For an occurrence datum \(\mathsf{doc}\), a document family \(D:\{ 1,\ldots ,n\} \to \mathsf{doc}.\mathrm{Document}\), keyword vector \(K:\{ 1,\ldots ,\ell \} \to \mathsf{doc}.\mathrm{Keyword}\), and matrix \(E\in \mathbb {R}^{n\times \ell }\), the separate predicate

\[ \operatorname {NonzeroRows}_{\mathsf{doc}}(D,K,E) \]

means that every document embedding row used in a cosine-similarity instance is nonzero:

\[ \forall \, i\in \{ 1,\ldots ,n\} ,\qquad \| \operatorname {def\_ bag\_ of\_ words}(\mathsf{doc},\ell )(D(i))(K)\| {\gt}0 \]

and no other condition. The matrix argument \(E\) is present only so that \(\operatorname {NonzeroRows}_{\mathsf{doc}}(D,K,E)\) has the same displayed instance parameters as \(\operatorname {ValidBOW}_{\mathsf{doc}}(D,K,E)\); the predicate itself does not inspect entries of \(E\) and does not require a proof of \(\operatorname {ValidBOW}\). This is the standing promise for MSD and LSD instances, but it is not an argument of \(\operatorname {ValidBOW}_{\mathsf{doc}}\).

Definition 33 Cosine similarity

For nonzero document embeddings \(v,w\in \mathbb {R}^d\), their cosine similarity is

\[ \frac{\left\langle v,w\right\rangle }{\| v\| \cdot \| w\| }. \]
Lemma 34 Cosine similarity range for binary vectors

If \(v,w\in \{ 0,1\} ^d\) are nonzero binary vectors, then their cosine similarity lies in \([0,1]\).

Proof

The inner product is a sum of nonnegative products, so it is nonnegative. The denominator is positive because both vectors are nonzero. The upper bound is exactly Cauchy–Schwarz divided by this positive denominator.

Definition 35 Attention, Definition 2.1

For \(d_{\rm in},d_{\rm out},m\in \mathbb {N}\), matrices \(Q,K\in \mathbb {R}^{d_{\rm in}\times m}\) and \(V\in \mathbb {R}^{d_{\rm in}\times d_{\rm out}}\) define an attention map \(A_{Q,K,V}:\mathbb {R}^{n\times d_{\rm in}}\to \mathbb {R}^{n\times d_{\rm out}}\) by

\[ A_{Q,K,V}(X)=\operatorname {softmax}(XQK^\top X^\top )XV. \]
Definition 36 Family of attention maps

The family \(\mathcal A_{d_{\rm in},m,d_{\rm out}}\) consists of all maps \(A_{Q,K,V}\) with \(Q,K\in \mathbb {R}^{d_{\rm in}\times m}\) and \(V\in \mathbb {R}^{d_{\rm in}\times d_{\rm out}}\).

Definition 37 Multi-layer perceptron, Definition 2.2
#

For positive integers \(a\) and \(b\), an \((a,b)\) multi-layer perceptron is a continuous function

\[ \varphi :(\{ 1,\ldots ,a\} \to \mathbb {R})\to (\{ 1,\ldots ,b\} \to \mathbb {R}), \]

equivalently a continuous map \(\mathbb {R}^a\to \mathbb {R}^b\) on the corresponding finite-dimensional real vector spaces. For every number of rows \(n\), its row-wise matrix lift is the map

\[ \varphi ^{[n]}:\mathbb {R}^{n\times a}\to \mathbb {R}^{n\times b} \]

defined by the coordinate equality

\[ \bigl(\varphi ^{[n]}(X)\bigr)_{i,:}=\varphi (X_{i,:}) \qquad \text{for every }1\leq i\leq n. \]

Thus the lifted output has entries \((\varphi ^{[n]}(X))[i,j]=\varphi (X_{i,:})[j]\).

Definition 38 Single-attention-unit transformer, Definition 2.3

Fix positive integers \(n,d,d_{\rm in},d_{\rm out},m\). A transformer in the paper’s simplified single-attention-unit model is the following concrete data: an input MLP \(\varphi _1:\mathbb {R}^d\to \mathbb {R}^{d_{\rm in}}\), matrices \(Q,K\in \mathbb {R}^{d_{\rm in}\times m}\) and \(V\in \mathbb {R}^{d_{\rm in}\times d_{\rm out}}\), and an output MLP

\[ \varphi _2:\mathbb {R}^{n d_{\rm out}}\to \mathbb {R}, \]

where an \(n\times d_{\rm out}\) matrix is identified with its flattened vector in \(\mathbb {R}^{n d_{\rm out}}\). Its value on a matrix input \(E\in \mathbb {R}^{n\times d}\) is

\[ {\rm TF}(E)= \varphi _2\! \left(\operatorname {flat} \left(A_{Q,K,V}(\varphi _1^{[n]}(E))\right)\right). \]

Equivalently, the computation first applies \(\varphi _1\) row-wise, producing a matrix in \(\mathbb {R}^{n\times d_{\rm in}}\); then applies the attention map \(A_{Q,K,V}\) from Definition 35, producing a matrix in \(\mathbb {R}^{n\times d_{\rm out}}\); then applies the continuous output MLP to the flattened finite-dimensional matrix.

Definition 39 Document transformer input contract

For document-similarity tasks the transformer input dimension is exactly the bag-of-words length. Concretely, the parameters satisfy \(d=\ell \), the document data consist of an occurrence datum \(\mathsf{doc}\), a document family \(D:\{ 1,\ldots ,n\} \to \mathsf{doc}.\mathrm{Document}\), and a coordinate-indexed keyword vector \(K:\{ 1,\ldots ,\ell \} \to \mathsf{doc}.\mathrm{Keyword}\). The Lean-facing contract is the single predicate

\[ \operatorname {def\_ document\_ transformer\_ input\_ contract} (\mathsf{doc},D,K,E) : \operatorname {Prop} \]

defined by exactly the bag-of-words validity condition

\[ \operatorname {def\_ document\_ transformer\_ input\_ contract} (\mathsf{doc},D,K,E) \quad \Longleftrightarrow \quad \operatorname {ValidBOW}_{\mathsf{doc}}(D,K,E). \]

It has precisely the displayed data arguments \((\mathsf{doc},D,K,E)\), with \(n\) and \(\ell \) supplied by the finite index types. Its only input hypothesis is \(\operatorname {ValidBOW}_{\mathsf{doc}}(D,K,E)\); it has no conjunct, premise, field, or hidden promise asserting that rows are nonzero. In particular, the general transformer input contract must still hold for valid bag-of-words matrices with zero rows, because those are legitimate transformer inputs even though cosine similarity may be undefined for them.

From this contract and Lemma 26, every entry \(E[i,r]\) is the corresponding bag-of-words coordinate, and by Lemma 28 it is the real-valued occurrence indicator \(\operatorname {OccVal}_{\mathsf{doc}}(D(i),K(r))\). By Lemma 29, present keywords give entry value \(1\); by Lemma 30, absent keywords give entry value \(0\). Lemma 31 records the complete decidable case split for each entry. The scalar answer to the document-similarity instance is the pure transformer value \({\rm TF}(E)\) from Definition 38 evaluated on this concretely determined bag-of-words matrix. Thus the model never evaluates a document-similarity task on an unconstrained abstract row encoding, and the matrix column type of the transformer is the same finite coordinate type as the keyword list.

Definition 40 Sentinel-augmented input matrix
#

For a base matrix \(E\in \mathbb {R}^{n\times d}\) and a concrete sentinel row \(s\in \mathbb {R}^d\), the sentinel augmentation data is the concrete finite object

\[ \operatorname {def\_ sentinel\_ augmented\_ input}(E,s) = \bigl(\operatorname {Aug}_s(E),\operatorname {ProblemRow}, \operatorname {AdmissiblePair},\operatorname {LiftDecision}\bigr) \]

with the following four components.

First, \(\operatorname {Aug}_s(E)\) is the matrix

\[ \operatorname {Aug}_s(E)\in \mathbb {R}^{(n+1)\times d} \]

defined by the row equalities

\[ \operatorname {Aug}_s(E)_{i,:}=E_{i,:}\quad (1\leq i\leq n), \qquad \operatorname {Aug}_s(E)_{n+1,:}=s. \]

Second, the problem-row predicate on augmented row indices is

\[ \operatorname {ProblemRow}(r)\quad \Longleftrightarrow \quad 1\leq r\leq n . \]

Thus row \(n+1\) is definitionally not a problem row.

Third, the admissible witness-pair predicate on augmented row indices is

\[ \operatorname {AdmissiblePair}(p,q) \quad \Longleftrightarrow \quad 1\leq p\leq n,\quad 1\leq q\leq n,\quad p\neq q . \]

Consequently no pair containing the sentinel index \(n+1\) is admissible. Explicitly, for every augmented index \(r\),

\[ \neg \operatorname {AdmissiblePair}(n+1,r), \qquad \neg \operatorname {AdmissiblePair}(r,n+1). \]

Every underlying document, OV, Max-IP, Min-IP, MSD, or LSD witness predicate is evaluated only on pairs satisfying this displayed predicate, so it ranges over exactly the original first \(n\) rows. In predicate form, for every base pair relation \(W_E\) on indices of \(E\),

\[ \exists p,q,\, \operatorname {AdmissiblePair}(p,q)\wedge W_E(p,q) \quad \Longleftrightarrow \quad \exists i,j\in \{ 1,\ldots ,n\} ,\, i\neq j\wedge W_E(i,j), \]

and

\[ \forall p,q,\, \operatorname {AdmissiblePair}(p,q)\Rightarrow W_E(p,q) \quad \Longleftrightarrow \quad \forall i,j\in \{ 1,\ldots ,n\} ,\, i\neq j\Rightarrow W_E(i,j). \]

Fourth, for any base matrix decision predicates \(\Valid ,\Yes ,\No :\mathbb {R}^{n\times d}\to \operatorname {Prop}\), the lifted predicates attached to this augmentation are not new predicates on arbitrary \((n+1)\times d\) matrices. They are the three concrete precompositions

\[ \Valid ^{\operatorname {Aug}}(E,s)\Longleftrightarrow \Valid (E),\qquad \Yes ^{\operatorname {Aug}}(E,s)\Longleftrightarrow \Yes (E),\qquad \No ^{\operatorname {Aug}}(E,s)\Longleftrightarrow \No (E). \]

Hence appending the sentinel preserves the original size-\(n\) yes/no condition by definition: the augmented encoding is valid, yes, or no exactly when the base matrix \(E\) is valid, yes, or no. The sentinel row is only a fixed computational token supplied to the transformer construction; it is never part of the mathematical problem instance.

Definition 41 Sentinel-augmented transformer solver

A sentinel-augmented transformer for a matrix decision problem with base input shape \(n\times d\) consists of a fixed sentinel row \(s\in \mathbb {R}^d\) and a single-attention-unit transformer whose sequence length parameter is \(n+1\). It solves predicates \(\Valid (E)\), \(\Yes (E)\), and \(\No (E)\) on base matrices \(E\in \mathbb {R}^{n\times d}\) when both concrete correctness implications hold after augmentation:

\[ \Valid (E)\wedge \Yes (E)\Rightarrow {\rm TF}(\operatorname {Aug}_s(E))=1, \qquad \Valid (E)\wedge \No (E)\Rightarrow {\rm TF}(\operatorname {Aug}_s(E))=0. \]

Thus appending the sentinel is part of the fixed input encoding of the constructed transformer, while the mathematical decision problem remains the original problem on the first \(n\) rows.

Definition 42 Transformer solves a decision problem

A matrix decision problem with input shape \(n\times d\) consists of predicates \(\Valid (E)\), \(\Yes (E)\), and \(\No (E)\) on matrices \(E\in \mathbb {R}^{n\times d}\) such that every valid instance is classified exactly once:

\[ \Valid (E)\Rightarrow \bigl((\Yes (E)\wedge \neg \No (E))\vee (\No (E)\wedge \neg \Yes (E))\bigr). \]

A transformer \({\rm TF}:\mathbb {R}^{n\times d}\to \mathbb {R}\) solves this decision problem if both correctness implications hold for every matrix input:

\[ \Valid (E)\wedge \Yes (E)\Rightarrow {\rm TF}(E)=1, \qquad \Valid (E)\wedge \No (E)\Rightarrow {\rm TF}(E)=0. \]

The no-instance implication is an independent requirement; it is not conditional on the existence of a yes-instance witness.