---
title: Rational Stochastic Languages
url: https://www.emergentmind.com/topics/rational-stochastic-languages
type: topic
---

# Rational Stochastic Languages

Rational stochastic languages are probability distributions on words that are realized by finite-state quantitative devices with nonnegative weights. In the formulation developed in "Stochastic Languages at Sub-stochastic Cost" [2510.19276], they are exactly the stochastic quantitative languages \(f:\Sigma^*\to \mathbb R_{\ge 0}\) computed by weighted finite automata, equivalently by linear cost-register automata (CRAs), and they admit both a spectral normalization theory and an algebraic Kleene–Schützenberger characterization. The topic sits at the intersection of weighted automata, probabilistic automata, formal power series, and distributional analysis on infinite discrete domains, with later work connecting the class to limit laws for random word generation and to identity testing over string distributions [2102.09478], [2508.03826].

## 1. Formal definition and equivalent presentations

A quantitative language over an alphabet \(\Sigma\) is any function \(f:\Sigma^*\to\mathbb R\). Its total mass is
\[
\mathrm{mass}(f)\;=\;\sum_{w\in \Sigma^*} f(w),
\]
when the sum converges. Such an \(f\) is stochastic if \(f(w)\ge 0\) for all \(w\) and \(\mathrm{mass}(f)=1\) [2510.19276].

A real-weighted finite automaton is a tuple
\[
\mathcal{W}=(\Sigma,Q,\lambda,\{M_\sigma\}_{\sigma\in\Sigma},\mu)
\]
with initial vector \(\lambda\in\mathbb R^Q_{\ge 0}\), nonnegative transition matrices \(M_\sigma\in\mathbb R^{Q\times Q}_{\ge 0}\), and final vector \(\mu\in\mathbb R^Q_{\ge 0}\). Its semantics is the series
\[
\llbracket \mathcal W\rrbracket(w)
= \lambda^{\top} M_{w_1}M_{w_2}\cdots M_{w_n}\mu,
\quad w=w_1\cdots w_n.
\]
The class of rational stochastic languages is
\[
S^{\mathrm{rat}}(\Sigma)
=
\bigl\{
f:\Sigma^*\to\mathbb R_{\ge 0}
\mid
f=\llbracket \mathcal W\rrbracket,\;
\sum_{w\in\Sigma^*}f(w)=1
\bigr\}.
\]

The same class is captured by linear CRAs over \(\mathbb R_{\ge 0}\). In that presentation, a transition \(q\stackrel{\sigma}{\to}q'\) updates the register vector \(x\in\mathbb R^X\) by a nonnegative linear map \(x\mapsto A_{q,\sigma}x\). The fully linear fragment is equivalent to weighted automata: every linear CRA can be flattened into an equivalent weighted automaton with state space \(Q\times X\), and conversely every weighted automaton arises as a linear CRA [2510.19276].

A related convention appears in "Identity Testing for Stochastic Languages" [2508.03826], which writes \(S(\Sigma)\) for stochastic languages over \(\Sigma^+\), i.e. nonempty strings. This is a notational difference in presentation rather than a distinct automata-theoretic mechanism.

## 2. Spectral normalization and the stochasticity problem

The central technical question is when a deterministic quantitative model actually defines a probability distribution. For weighted automata and CRAs this is the stochasticity problem. The general CRA setting is undecidable, but the fully linear fragment admits a complete and tractable theory [2510.19276].

For a weighted automaton with transition matrices \(M_\sigma\), define
\[
M=\sum_{\sigma\in\Sigma} M_\sigma.
\]
Then
\[
\sum_{w:|w|=k}\llbracket\mathcal W\rrbracket(w)
=
\lambda^\top M^k \mu,
\]
and the total mass is the Neumann series
\[
\mathrm{mass}(\llbracket\mathcal W\rrbracket)
=
\sum_{k=0}^\infty \lambda^\top M^k\mu
=
\lambda^\top (I-M)^{-1}\mu
\quad\text{iff }\rho(M)<1,
\]
where \(\rho(M)\) is the spectral radius. By Perron–Frobenius one computes \(\rho(M)\) in \(O(n^3)\), checks \(\rho(M)<1\), and if so inverts \(I-M\) in \(O(n^3)\). Consequently, for linear CRAs, equivalently weighted automata over \(\mathbb R_{\ge 0}\) with affine output, one can decide in polynomial time whether the total mass converges and compute it as \(\lambda^\top (I-M)^{-1}\mu\) [2510.19276].

This result separates two levels of difficulty. Global stochasticity is undecidable for CRAs in general, but becomes polynomial-time decidable in the linear setting. A plausible implication is that linearity is not merely a technical convenience; it is the boundary at which the semantic normalization problem becomes algebraically analyzable by matrix methods.

A later formulation in [2508.03826] expresses the same verification problem as a linear system. If \(s_q\) denotes the total continuation mass from state \(q\), then
\[
s_q
=
\mu(q)
+
\sum_{\sigma\in\Sigma}\sum_{q'\in Q}\rho(q,\sigma,q')\,s_{q'}
\quad(\forall q\in Q),
\]
and Gaussian elimination yields an \(O(|Q|^3)\) validity test for nonnegative weighted automata.

## 3. Algebraic characterization of the class

The algebraic core of the theory is a Kleene–Schützenberger theorem specialized to normalized nonnegative series. The class of rational stochastic languages is the smallest class of quantitative languages \(f:\Sigma^*\to\mathbb R_{\ge 0}\) that contains all Dirac distributions \(\delta_\sigma\) for \(\sigma\in\Sigma\) and is closed under convex combinations, Cauchy product, and discounted Kleene star [2510.19276].

The operators are given explicitly. For \(f,g\in S\) and \(\lambda\in(0,1)\),
\[
(\lambda f+(1-\lambda)g)(w)=\lambda f(w)+(1-\lambda)g(w).
\]
For the Cauchy product,
\[
(f*g)(w)=\sum_{uv=w} f(u)g(v).
\]
For \(\alpha\in(0,1)\), the discounted Kleene star is
\[
f^*_\alpha(w)
=
\sum_{k=1}^\infty
\sum_{\substack{w_1,\dots,w_k\in\Sigma^+\\ w_1\cdots w_k=w}}
\alpha(1-\alpha)^{k-1}\prod_{i=1}^k f(w_i).
\]

These operations preserve nonnegativity and total mass \(1\). Convex combination preserves normalization by direct summation. The Cauchy product preserves normalization because
\[
\sum_w (f*g)(w)
=
\Bigl(\sum_u f(u)\Bigr)\Bigl(\sum_v g(v)\Bigr)=1.
\]
For the discounted star, the geometric law on the number of factors yields total mass \(1\) [2510.19276].

The proof of the characterization has two directions. In the automata-to-algebra direction, one first normalizes any stochastic weighted automaton to be locally sub-stochastic and then applies a state-elimination construction. Eliminating a state \(q\) with total outgoing weight \(w_q<1\) produces a star operator with discount \(1-w_q\), while finite path concatenations become Cauchy products. In the algebra-to-automata direction, every stochastic regular expression built from Dirac distributions, convex combination, product, and discounted star yields a locally stochastic weighted automaton whose semantics is the desired distribution [2510.19276].

This characterization sharpens a classical fact from weighted automata theory. "On the Theory of Stochastic Automata" states that a series \(f:\Sigma^*\to\mathbb R_{\ge 0}\) is rational over \(\mathbb R_{\ge 0}\) if and only if there exists a finite stochastic automaton \(A\) such that \(f=f_A\), with rational series closed under finite sums, Cauchy product, and star [2103.14423]. The normalized stochastic-language version replaces arbitrary finite sums by convex combinations and ordinary star by discounted Kleene star so that total mass remains \(1\).

## 4. Local sub-stochasticity and stochastic regular expressions

A weighted automaton is locally sub-stochastic if for every state \(q\),
\[
\sum_{\sigma\in\Sigma}\sum_{q'} M_\sigma(q,q')\le 1.
\]
This is a local, per-state condition, in contrast to the global condition \(\rho(M)<1\). One of the principal results of [2510.19276] is that whenever the global matrix \(M=\sum_\sigma M_\sigma\) satisfies \(\rho(M)<1\), there exists a positive diagonal matrix \(D\) such that \(DMD^{-1}\) has each row sum \(\le 1\). Conjugating each \(M_\sigma\), as well as the initial and final vectors, yields an equivalent automaton whose transitions are locally sub-stochastic.

In the CRA view, this becomes a syntactic criterion:
\[
\sum_\sigma A_{q,\sigma}\preceq I.
\]
The significance is twofold. First, it provides a local characterization of a global semantic property. Second, it is the normalization step that supports the state-elimination proof of the Kleene–Schützenberger theorem [2510.19276].

The same paper introduces stochastic regular expressions (SREs) as a complete grammar for rational stochastic languages:
\[
r
:=
\delta_\sigma
\;\mid\;
\lambda r_1+(1-\lambda)r_2
\;\mid\;
r_1\cdot r_2
\;\mid\;
(r)^*_\alpha,
\]
where \(\sigma\in\Sigma\) and \(\lambda,\alpha\in(0,1)\). Their semantics is defined by the closure equations above, and every SRE denotes a stochastic language. Conversely, every rational stochastic language arises from an SRE [2510.19276].

A worked example in [2510.19276] starts from a two-state linear CRA over \(\Sigma=\{a,b,c\}\). Its equivalent weighted automaton satisfies
\[
\rho(M)=\tfrac34<1,
\qquad
\mathrm{mass}=\lambda^T(I-M)^{-1}\mu=1.
\]
After Perron–Frobenius normalization to a sub-stochastic automaton, state elimination yields the SRE
\[
\Bigl(\tfrac14a+\tfrac14b+\tfrac12c\,(\,\tfrac23a+\tfrac13b\,)^*_{\tfrac12}\Bigr)^*_{\tfrac23}
\;\cdot\;a^*_{\tfrac34}\;
\cdot\;c\;
\bigl(\tfrac23a+\tfrac13b\bigr)^*_{\tfrac12},
\]
whose semantics coincides with the original CRA.

## 5. Relation to stochastic automata and structural theory

Rational stochastic languages are closely related to the older theory of stochastic automata. In that setting, a discrete-time stochastic automaton is a 5-tuple
\[
A=(Q,\Sigma,\tau,\alpha,\rho)
\]
with transition probabilities \(\tau(q,a,p)\), initial distribution \(\alpha\), and accepting probabilities \(\rho\). For each \(a\in\Sigma\), one defines a matrix \(T(a)\) by \(T(a)_{ij}=\tau(q_i,a,q_j)\), and for a word \(w=w_1\cdots w_k\),
\[
T(w)=T(w_1)\cdots T(w_k).
\]
The recognized stochastic series is
\[
P_A(w)=\alpha^T T(w)\rho,
\]
yielding a function \(f_A:\Sigma^*\to[0,1]\) [2103.14423].

The classical equivalence theorem states that a series \(f:\Sigma^*\to\mathbb R_{\ge 0}\) is rational over \(\mathbb R_{\ge 0}\) if and only if there exists a finite stochastic automaton \(A\) such that \(f=f_A\) [2103.14423]. This theorem is attributed there to Schützenberger, Rabin, and Fliess. It situates rational stochastic languages within the broader landscape of rational series and stochastic finite-state devices.

The same source develops structural notions that parallel classical automata theory. Equivalence of underlying series is decidable in polynomial time. For cut-point languages
\[
L_{A,\lambda}=\{\,w\in\Sigma^*\mid f_A(w)>\lambda\},
\]
emptiness with general rational \(\lambda\) is PSPACE-complete in the size of \(A\) and the bit-length of \(\lambda\), while Rabin’s theorem implies that if \(\lambda\) is isolated then \(L_{A,\lambda}\) is regular [2103.14423].

Canonical forms are likewise available. Reduction merges states with identical result vectors; minimization removes states that are convex combinations of others; strong reduction yields a unique minimal linear representation of dimension equal to the Hankel rank; and observability or determinism may be enforced, though determinization can incur exponential blow-up [2103.14423]. These results concern the broader stochastic-automata framework rather than normalized distributions specifically, but they provide the ambient representation theory in which rational stochastic languages are naturally embedded.

## 6. Statistical behavior, approximation, and testing

Once a rational stochastic language is used as a model for random word generation, one can study statistics conditioned on word length. For a rational series \(r\) with linear representation \((\alpha,A,B,\eta)\), [2102.09478] defines a probability measure on \(\Sigma^n\) by
\[
P_n(w)=\frac{(r,w)}{\sum_{|x|=n}(r,x)}
\]
and studies the random variable \(Y_n(w)=|w|_a\). Writing
\[
h_n(z)=\alpha(Ae^z+B)^n\eta,
\qquad
\phi_n(t)=\frac{h_n(it)}{h_n(0)},
\]
one obtains exact mean and variance from derivatives at \(0\). If \(M=A+B\) is primitive and an aperiodicity condition holds, then
\[
\mu_n=\mu n+O(1),
\qquad
\sigma_n^2=\sigma^2 n+O(1),
\]
and there is a Gaussian local limit with uniform \(O(n^{-1/2})\) error [2102.09478].

In bicomponent models, the limiting law depends on spectral and perturbative parameters of the two primitive blocks. The regimes reported in [2102.09478] are as follows.

| Model regime | Local limit law |
|---|---|
| Single primitive, aperiodic | Gaussian \(N(\mu n,\sigma^2 n)\) with \(O(n^{-1/2})\) error |
| Communicating bicomponent, \(\lambda_1>\lambda_2\) | Gaussian driven by component \(1\) |
| Communicating bicomponent, \(\lambda_1=\lambda_2\), \(\mu_1\ne\mu_2\) | Uniform law on \([\mu_1,\mu_2]\) |
| Communicating bicomponent, \(\mu_1=\mu_2\), \(\sigma_1^2\ne\sigma_2^2\) | Mixture over a variance interval |
| Sum bicomponent, \(\lambda_1=\lambda_2\) | Convex combination of two Gaussians |

A detailed example in the communicating equipotent case uses \(\Sigma=\{a,b,c\}\) and yields \(\mu_1=\tfrac13\), \(\mu_2=\tfrac23\), \(\sigma_1^2=\sigma_2^2=\tfrac23\), so \(Y_n/n\) converges locally to the uniform density on \([1/3,2/3]\) with rate \(O(n^{-1/2})\) [2102.09478].

Algorithmic developments extend beyond representation and asymptotics. "Identity Testing for Stochastic Languages" proves that a nonnegative weighted automaton can be checked in polynomial time for being a stochastic language, shows that convex mixtures of geometric distributions are dense in \(S(\Sigma)\) under \(\ell_1\), and develops a truncation-based identity tester for a known rational reference distribution against an unknown distribution [2508.03826]. The geometric subclass is defined by
\[
P_w^\alpha(w^k)=\alpha(1-\alpha)^{k-1},
\quad
P_w^\alpha(u)=0\text{ for }u\ne w^k,
\]
and for every stochastic language \(r\in S(\Sigma)\) and \(\varepsilon>0\), there exist geometric distributions \(p_1,\dots,p_k\) and convex weights \(\lambda_i\) such that
\[
\Bigl\|\,r-\sum_{i=1}^k\lambda_i p_i\Bigr\|_1<\varepsilon
\]
[2508.03826].

For identity testing, the key observation is that rational languages have exponential decay:
\[
\sum_{|w|\ge t} Q(w)\le C\beta^t
\]
for computable \(C,\beta<1\). Truncating at length \(\theta\) reduces the problem to a finite domain \(\Sigma^{\le \theta}\). Using the tolerant identity tester of Canonne et al. with thresholds \(\tau_1=\varepsilon/3\) and \(\tau_2=\varepsilon\), one obtains sample complexity
\[
\widetilde\Theta\!\Bigl(\frac{\sqrt{k}}{\varepsilon^2}+\frac{k}{\ln k}\Bigr),
\qquad
k=|\Sigma^{\le \theta}|,
\]
or, in the abstract’s notation,
\[
\widetilde\Theta\!\left(\frac{\sqrt{n}}{\varepsilon^2}+\frac{n}{\log n}\right)
\]
where \(n\) is the size of the truncated support [2508.03826]. The paper states completeness if \(\|P-Q\|_1<\varepsilon\), soundness if \(\|P-Q\|_1>5\varepsilon/3\), both with probability at least \(0.8\).

Taken together, these results position rational stochastic languages as a finite-state class of distributions over strings with three distinctive features: exact automata-theoretic realization, a normalization theory based on spectral or linear-system methods, and enough regularity to support asymptotic analysis, approximation, and testing on infinite discrete domains.

Source: https://www.emergentmind.com/topics/rational-stochastic-languages