---
title: 'SpanTL: Tree Counting Complexity'
url: https://www.emergentmind.com/topics/spantl
type: topic
---

# SpanTL: Tree Counting Complexity

\(\mathsf{SpanTL}\) is a counting complexity class introduced to capture functions that count **distinct valid output trees** of a restricted alternating machine model, and to provide a modular approximation-theoretic framework for combined-complexity operational consistent query answering under primary keys. Its defining feature is that the counted objects are not accepting computations and not output strings, but rooted labeled trees extracted from accepting computations of an alternating Turing machine with output. In the formulation used for operational CQA, \(\mathsf{SpanTL}\) is broad enough to contain the numerator-counting problems associated with operational repairs and complete repairing sequences, yet sufficiently constrained to admit a fully polynomial randomized approximation scheme (FPRAS) for every function in the class [2508.15814].

## 1. Origin and intended role

\(\mathsf{SpanTL}\) was introduced in the study of **uniform operational consistent query answering** in combined complexity, where the query is part of the input. The motivating quantity is the **repair relative frequency**
\[
\mathsf{RF}(D,\Sigma,Q,\bar c) \;=\; \frac{|\{D' \in ORep{D}{} \mid \bar c \in Q(D')\}|}{|ORep{D}{}|},
\]
for a database \(D\), a set \(\Sigma\) of primary keys, a conjunctive query \(Q(\bar x)\), and a tuple \(\bar c\). In this setting, the denominator \(|ORep{D}{}|\) is already known to be polynomial-time computable, so the technical bottleneck is the numerator
\[
|\{D' \in ORep{D}{} \mid \bar c \in Q(D')\}|.
\]
The auxiliary counting problem isolating this numerator is denoted \(\sharp\mathsf{Repairs}[k]\), with input \(D,\Sigma,Q(\bar x)\) from \(SJF\), a generalized hypertree decomposition of width \(k\), and \(\bar c\) [2508.15814].

The immediate candidate approximable class would have been \(\mathsf{SpanL}\), since the paper recalls the theorem that every function in \(\mathsf{SpanL}\) admits an FPRAS. However, the target counting problem is unlikely to lie in \(\mathsf{SpanL}\). The paper proves that, unless \(NL = LOGCFL\), for each \(k>0\),
\[
\sharp\mathsf{Repairs}[k] \not\in SpanL.
\]
The underlying reason is that for \(f\in \mathsf{SpanL}\), the decision version \(f_{>0}\) lies in \(NL\), whereas the decision version of \(\sharp\mathsf{Repairs}[k]\) is \(LOGCFL\)-hard. \(\mathsf{SpanTL}\) is therefore introduced to fill an expressive gap between \(\mathsf{SpanL}\) and the structured database counting problems arising from bounded generalized hypertree decompositions.

At a high level, the class is the tree analogue of \(\mathsf{SpanL}\). In \(\mathsf{SpanL}\), one counts distinct output strings of a nondeterministic logspace machine with output. In \(\mathsf{SpanTL}\), the outputs are rooted labeled trees produced by an alternating machine with output. This tree-valued notion of output is what allows the class to encode witness structures aligned with decomposition trees and operational repair processes.

## 2. Formal definition via alternating Turing machines with output

The machine model underlying \(\mathsf{SpanTL}\) is the **alternating Turing machine with output** (ATO), defined as
\[
M=(S,\Lambda,s_\text{\rm init},s_\text{\rm accept},s_\text{\rm reject},S_\exists,S_\forall,S_{L},\delta),
\]
where \(S\) is the state set, \(\Lambda\) is the alphabet including \(\bot\) and \(\triangleright\), \(s_\text{\rm init}\) is the initial state, \(s_\text{\rm accept},s_\text{\rm reject}\) are accepting and rejecting states, \(S_\exists,S_\forall\) partition the non-halting states into existential and universal states, \(S_L\subseteq S\) are the labeling states including the initial state, and
\[
\delta : (S \setminus \{s_\text{\rm accept},s_\text{\rm reject}\}) \times \Lambda \times \Lambda \rightarrow P(S \times \{-1,0,+1\} \times \{-1,0,+1\} \times \Lambda \times \Lambda^*)
\]
is the transition function [2508.15814].

The ATO has a read-only input tape, a read-write work tape, and a write-only one-way labeling tape. The unusual component is the labeling tape together with the set \(S_L\) of labeling states. Whenever the machine enters a labeling configuration, the current content of the labeling tape is used to create a fresh node in an output tree, after which the labeling tape is reset for future labels. Because the initial state is labeling, every output tree has a root.

A computation of an ATO on input \(w\) is a finite rooted tree of configurations. Existential configurations choose one successor; universal configurations branch to all successors. A computation is accepting iff all leaves are accepting configurations. If \(T=(V,E,\lambda)\) is such a computation, its output is the node-labeled rooted tree \(O=(V',E',\lambda')\) defined by taking \(V'\) to be the nodes of \(T\) labeled by labeling configurations, connecting \(u\) to \(v\) when \(u\) reaches \(v\) through a labeled-free path, and letting \(\lambda'(v)\) be the string on the labeling tape at that labeling configuration. A tree \(O\) is a **valid output** precisely when it comes from an accepting computation.

Given an ATO \(M\), the associated counting function is
\[
\mathsf{span}_M : (\Lambda \setminus \{\bot,\triangleright\})^* \rightarrow \mathbb{N},
\]
with
\[
\mathsf{span}_M(w) = |\{T \mid T \text{ is a valid output of } M \text{ on } w\}|.
\]
The class itself is then defined by
\[
\mathsf{SpanTL}\ =\ \left\{\mathsf{span}_M \mid M \text{ is a well-behaved ATO}\right\}.
\]
The term “span” has the same sense as in \(\mathsf{SpanL}\): the count is over distinct accepted outputs, not over accepting computations.

## 3. Resource restrictions and structural properties

The restriction to **well-behaved** ATOs is the formal mechanism that keeps the class within an approximable regime. An ATO \(M\) is well-behaved if there is a polynomial \(\text{\rm pol}\) and an integer \(k\ge 0\) such that, for every input \(w=w_1\cdots w_n\) and every computation \(T=(V,E,\lambda)\) of \(M\) on \(w\), the following hold:
\[
|V| \in O(\text{\rm pol}(n)),
\]
the working-tape and labeling-tape contents satisfy \(|y|,|z| \in O(\log n)\) for every configuration \((\cdot,\cdot,y,z,\cdot,\cdot)\) occurring in \(T\), and for every labeled-free path \(v_1,\ldots,v_m\) of \(T\),
\[
|\{v_i \mid \lambda(v_i) \text{ is universal}\}| \le k.
\]
These conditions combine polynomial-size computations, logarithmic work and labeling space, and a constant bound on the number of universal configurations along any labeled-free path [2508.15814].

The comparison with \(\mathsf{SpanL}\) is explicit. The paper proves
\[
SpanL \subseteq SpanTL.
\]
The inclusion is immediate from the observation that a nondeterministic logspace machine with output can be viewed as an ATO using only existential states, and that a string output can be regarded as a path-shaped tree output. The paper also establishes that, unless \(NL = LOGCFL\),
\[
SpanL \subset SpanTL.
\]
The strictness claim is witnessed by natural problems later shown to lie in \(\mathsf{SpanTL}\) whose decision versions are \(LOGCFL\)-hard, and therefore cannot lie in \(\mathsf{SpanL}\) unless \(NL=LOGCFL\).

A further structural fact is robustness under preprocessing:
\[
\text{\(\mathsf{SpanTL}\) is closed under logspace reductions.}
\]
Formally, if \(g\in \mathsf{SpanTL}\) and there is a logspace-computable mapping \(h\) such that \(f(w)=g(h(w))\) for all \(w\), then \(f\in \mathsf{SpanTL}\). This closure is used in the operational CQA application, where instances are first put into a convenient normal form by a logspace transformation.

The class is not presented as a standard counting class such as \(\#\mathsf{P}\), and the development does not focus on completeness theory. Its role is instead that of a tailored approximable counting class with nontrivial structural content: containment of \(\mathsf{SpanL}\), strictness unless \(NL=LOGCFL\), closure under logspace reductions, and class-wide FPRAS-approximability.

## 4. Approximation via reduction to finite tree automata

The central algorithmic theorem states that
\[
\text{Every function in } \mathsf{SpanTL} \text{ admits an FPRAS.}
\]
The paper uses the standard multiplicative notion: for \(f : \Lambda^* \to \mathbb{N}\), an FPRAS is a randomized algorithm \(\mathsf{A}\) taking \(w,\epsilon,\delta\), running in time polynomial in \(|w|\), \(1/\epsilon\), and \(\log(1/\delta)\), and satisfying
\[
\Pr\left(\left|\mathsf{A}(w,\epsilon,\delta)-f(w)\right|\le \epsilon \cdot f(w)\right)\ge 1-\delta.
\]
The proof is entirely automata-theoretic [2508.15814].

The relevant automata problem is \(\sharp\mathsf{NFTA}\): given a nondeterministic finite tree automaton \(A\) and \(0^n\), output
\[
\left|\bigcup_{i=0}^n L_i(A)\right|,
\]
where \(L_i(A)\) is the set of accepted trees of size \(i\). The paper recalls that \(\sharp\mathsf{NFTA}\) admits an FPRAS. The key reduction proposition then states that for every \(f\in \mathsf{SpanTL}\) and every input \(w\), one can construct in polynomial time in \(|w|\) an NFTA \(A\) and a string \(0^n\) such that
\[
f(w) = \left|\bigcup_{i = 0}^n L_i(A)\right|.
\]

The construction proceeds through the **computation DAG** of a well-behaved ATO on a fixed input \(w\). Because the machine uses logarithmic working and labeling space and has polynomial-size computations, the number of reachable configurations is polynomial in \(|w|\), and thus the computation DAG is polynomial-sized. The procedure \(\mathsf{BuildNFTA}(w)\) traverses this DAG and creates NFTA states corresponding to labeling configurations. Its recursive subprocedure \(\mathsf{Process}\) computes, for each configuration \(C\), either a singleton tuple \((s_C)\) if \(C\) is labeling, or a set of tuples of NFTA states representing the possible sets of next labeling configurations reachable via labeled-free paths.

Existential and universal branching are treated differently. At an existential configuration, the construction takes a union of possibilities. At a universal configuration, it uses a product-like combination \(\bigotimes\) that merges tuples from all children, because all universal branches must be realized simultaneously in an accepting computation. The bounded-number-of-universal-configurations condition on labeled-free paths is exactly what prevents exponential blow-up and ensures polynomial-time construction.

Two lemmas complete the reduction. First, \(\mathsf{BuildNFTA}(w)\) runs in polynomial time and returns an NFTA \(A\) such that
\[
\mathsf{span}_M(w)=|L(A)|.
\]
Second, since computations of a well-behaved ATO have polynomial size, there is a polynomial \(\mathsf{pol}\) with
\[
L(A)=\bigcup_{i=0}^{\mathsf{pol}(|w|)} L_i(A).
\]
The class-wide FPRAS theorem follows by combining these facts with the FPRAS for \(\sharp\mathsf{NFTA}\).

## 5. Membership results for operational consistent query answering

The main application concerns operational CQA under the following syntactic restrictions: primary keys, conjunctive queries, self-join-free queries, bounded generalized hypertreewidth \(k\), and combined complexity. In this setting, the paper proves
\[
\text{For every } k > 0,\ \sharp\mathsf{Repairs}[k] \text{ is in } SpanTL.
\]
The proof begins with a logspace normalization step putting \((D,Q,H)\) into a form where all relations in \(D\) occur in \(Q\), and the given generalized hypertree decomposition \(H\) is strongly complete and 2-uniform. Closure of \(\mathsf{SpanTL}\) under logspace reductions allows the argument to proceed under this normal form assumption [2508.15814].

The alternating procedure \(\mathsf{Rep}[k]\), implementable by a well-behaved ATO \(M_R^k\), is then defined so that its valid outputs are trees encoding operational repairs \(D'\) such that \(\bar c \in Q(D')\). The encoding uses the tree structure of the generalized hypertree decomposition, one path segment per relevant database block, and labels indicating which fact in each primary-key block is kept, or \(\bot\) if none is kept. The paper states that \(\mathsf{Rep}[k]\) can be implemented as a well-behaved ATO \(M_R^k\), and that for normalized input,
\[
\mathsf{span}_{M_R^k}(D,\Sigma,Q,H,\bar c) = |\{D' \in ORep{D}{} \mid \bar c \in Q(D')\}|.
\]
This establishes \(\sharp\mathsf{Repairs}[k]\in \mathsf{SpanTL}\).

Since every \(\mathsf{SpanTL}\) function has an FPRAS and \(|ORep{D}{}|\) is polynomial-time computable, the quotient
\[
\mathsf{RF}(D,\Sigma,Q,\bar c) = \frac{|\{D' \in ORep{D}{} \mid \bar c \in Q(D')\}|}{|ORep{D}{}|}
\]
also admits an FPRAS. The resulting positive theorem is
\[
\text{For every } k > 0,\ OCQA^{ur}[SJF \cap GHW_k] \text{ admits an FPRAS.}
\]

The same framework extends to the “uniform sequences” variant. The corresponding quantity is
\[
\mathsf{RF}^{us}(D,\Sigma,Q,\bar c) = \frac{|\{s \in CRS{D}{} \mid \bar c \in Q(s(D))\}|}{|CRS{D}{}|},
\]
and the paper states that the sequence-counting analogue \(\sharp\mathsf{Sequences}[k]\) can also be placed in \(\mathsf{SpanTL}\), yielding an FPRAS for the uniform-sequences version as well.

## 6. Boundaries, related problems, and significance

The positive approximation results do not extend to arbitrary conjunctive queries or arbitrary widths. The paper first proves exact hardness:
\[
\text{For every } k>0,\ OCQA^{ur}[SJF \cap GHW_k] \text{ is } \#\mathrm{P}\text{-hard}.
\]
Thus exact counting remains intractable even inside the positive approximation regime. It then establishes the negative approximation boundary:
\[
\text{Unless } RP = NP,
\]
there is no FPRAS for \(OCQA^{ur}[SJF]\), and for every \(k>0\), there is no FPRAS for \(OCQA^{ur}[GHW_k]\). These two inapproximability statements show that dropping either self-join-freeness or bounded generalized hypertreewidth destroys the positive picture [2508.15814].

These negative results are not claims about \(\mathsf{SpanTL}\) itself. Rather, they show that the operational CQA problem leaves the approximable regime once one removes either of the syntactic restrictions that permit placement in \(\mathsf{SpanTL}\). This sharp boundary clarifies the role of the class: it captures the structurally restricted region where the witness objects can be represented as trees generated by bounded alternation under logspace-like control and counted via distinct accepted tree outputs.

The paper also identifies other natural database counting problems in \(\mathsf{SpanTL}\): \(\sharp\mathsf{GHWCQ}[k]\), counting answers to a conjunctive query given a width-\(k\) generalized hypertree decomposition; \(\sharp\mathsf{UR}[k]\), counting subsets \(D'\subseteq D\) with \(\bar c\in Q(D')\); and \(\sharp\mathsf{SRepairs}[k]\), counting classical subset repairs entailing the query. For the first two, the paper notes that membership in \(\mathsf{SpanTL}\) reproves known FPRAS results in a cleaner and more modular way.

A plausible implication is that \(\mathsf{SpanTL}\) isolates a broader methodological pattern: counting problems whose combinatorial witnesses are naturally **trees** rather than strings, whose generation requires **alternation** rather than mere nondeterminism, and whose structure still permits compilation to finite tree automata. In the operational CQA setting, that abstraction yields a two-step proof strategy: show that the numerator-counting problem belongs to \(\mathsf{SpanTL}\), then invoke the theorem that every \(\mathsf{SpanTL}\) function admits an FPRAS.

Source: https://www.emergentmind.com/topics/spantl