Calibrating Generative Models: The Probabilistic Chomsky-Schützenberger Hierarchy∗ Thomas F. Icard Stanford University icard@stanford.edu December 14, 2019 1 Introduction and Motivation Probabilistic computation enjoys a central place in psychological modeling and theory, ranging in application from perception (Knill and Pouget, 2004; Orbán et al., 2016), attention (Vul et al., 2009), and decision making (Busemeyer and Diederich, 2002; Wilson et al., 2014) to the analysis of memory (Ratcliff, 1978; Abbott et al., 2015), categorization (Nosofsky and Palmeri, 1997; Sanborn et al., 2010), causal inference (Denison et al., 2013), and various aspects of language processing (Chater and Manning, 2006). Indeed, much of cognition and behavior is usefully modeled as stochastic, whether this is ultimately due to indeterminacy at the neural level or at some higher level (see, e.g., Glimcher 2005). Random behavior may even enhance an agent's cognitive efficiency (see, e.g., Icard 2019). A probabilistic process can be described in two ways. On one hand we can specify a stochastic procedure, which may only implicitly define a distribution on possible outputs of the process. Familiar examples include well known classes of generative models such as finite Markov processes and probabilistic automata (Miller, 1952; Paz, 1971), Boltzmann machines (Hinton and Sejnowski, 1983), Bayesian networks (Pearl, 1988), topic models (Griffiths et al., 2007), and probabilistic programming languages (Tenenbaum et al., 2011; Goodman and Tenenbaum, 2016). On the other hand we can specify an analytical expression explicitly describing the distribution over outputs. Both styles of description are commonly employed, and it is natural to ask about the relationship between them. The question is one of definability or expressiveness: for a given class of generative models, what kinds of distributions (analytically characterized) can those models implicitly define? A prominent way of classifying models of computation, and generative procedures in particular, is in terms of memory usage. In the classical non-probabilistic setting this leads to the well known Chomsky hierarchy-also called the Chomsky-Schützenberger hierarchy-of machines and grammars. At the bottom are finite-state automata (or equivalently, regular grammars), which are limited to a fixed, finite memory; at the top are Turing machines (equivalently, unrestricted grammars or "production systems"), which have unrestricted access to an unbounded memory; and in between are various models of limitedaccess memory such as stack automata and context-free grammars (see Figure 1). Much ∗Preprint. Forthcoming in Journal of Mathematical Psychology. 1 is known about the languages-that is, sets of strings over a finite alphabet-definable at different levels of the hierarchy (see, e.g., Eilenberg 1974; Hopcroft and Ullman 1979). The driving motivation for early theoretical work on formal grammars came from the psychology of language, where the focus was on finding adequate frameworks for describing and explaining human grammatical competence (Chomsky, 1959, 1965; Chomsky and Schützenberger, 1963). With increased emphasis on detailed processing, parsing, and acquisition accounts, in addition to large-scale grammar induction from corpora in computational linguistics, a considerable amount of applied work has explored probabilistic grammars (see, e.g., Klein and Manning 2003; Levy 2008; Kim et al. 2019 for representative examples), the straightforward result of adding probabilistic transitions to classical grammar formalisms. Here again, much of the interest has been to find formalisms that are powerful enough-but not too powerful-to capture relevant linguistic structure. Aside from their prevalence in models of language processing, probabilistic grammars have featured in numerous other psychological domains. For instance, they have recently appeared in characterizations of abstract conceptual knowledge (Tenenbaum et al., 2006, 2011), in computational models of vision (Zhu and Mumford, 2007), and in accounts of how people perceive randomness (Griffiths et al., 2018), among others. However, the psychological interest of probabilistic grammars is not limited to these direct applications. As in the classical setting, there is a systematic correspondence between probabilistic grammar classes and machine models. For example, probabilistic regular grammars can be shown expressively equivalent to hidden Markov models and probabilistic automata (see, e.g., Smith and Johnson 2007) and to classes of artificial neural networks (MacKay, 1996); probabilistic context-free grammars have been shown equivalent to branching processes (Harris, 1963), probabilistic pushdown automata (Abney et al., 1999) and so called recursive Markov chains (Etessami and Yannakakis, 2009), while also being powerful enough to define tools like topic models (Johnson, 2010); and unrestricted probabilistic grammars are equivalent to probabilistic Turing machines and indeed to any other Turing-complete probabilistic programming language (Theorem 2 below). Meanwhile, probabilistic grammars have even been invoked to calibrate and assess the capabilities of recurrent neural networks (Lin and Tegmark, 2017), and they have also been assimilated to causal models (Chater and Oaksford, 2013; Icard, 2017b). Studying the expressive capacity of probabilistic grammars thus promises to illuminate that of many other important model classes. More generally, the resulting probabilistic Chomsky-Schützenberger hierarchy offers a meaningful classification of discrete probabilistic models, and serves as a useful target for understanding the expressiveness of probabilistic models broadly. As running examples, consider the following four common discrete distributions: Example 1 (Poisson). The Poisson distribution, μ(k) = e−λ λ k k! , is ubiquitous in psychological modeling, reaching even to the level of neural firing rates (Faisal et al., 2008). Given an average rate λ of independent occurrences in an interval, μ(k) is the probability of observing exactly k occurrences in the interval. Example 2 (Negative Binomial). Consider a measure μq,t(k) = (t+kk )q t+1(1− q)k, for t ∈N and q ∈ Q ∩ [0, 1], giving the probability that we will make k observations other than our target observation by the time we see the t + 1st target. The negative binomial distribution is often used in place of the Poisson distribution for probabilistic modeling. In fact, μq,t converges to the Poisson distribution as t goes to infinity (Johnson et al., 2005). 2 Example 3 (Random Walk Hitting Time). Various kinds of random walks have appeared in psychological modeling (see, e.g., Townsend and Ashby 1983; Abbott et al. 2015 for very different examples). Consider the simplest symmetric 1/2-random walk on the nonnegative integers, starting at 1. The hitting time for first reaching 0 is given by a distribution μ(2k + 1) = ck2−2k+1, where ck = ( 2k k ) 1 k+1 is the kth Catalan number. Example 4 (Beta-Binomial). Hierarchical probabilistic models have generated a great deal of interest in cognitive science (e.g., Griffiths et al. 2007; Liang et al. 2010; Gershman and Blei 2012; Li et al. 2019). One of the most basic building blocks in these models is the BetaBinomial distribution (and its multidimensional generalization, the Dirichlet-Multinomial), which defines a generative procedure for flipping coins with unknown weight. Consider a measure defined by first drawing p from a Beta(α, β) distribution and then generating a number k with probability (nk)p k(1− p)n−k. The distribution on k is then: μ(k) = ( n k ) B(α + k, β + n− k) B(α, β) In fact, μ approximates a negative binomial as n and β increase (Johnson et al., 2005). Our basic question is this: how high in the hierarchy do we need to ascend before we can (implicitly) define probability distributions like these? The aim of the present contribution is to present a picture, as comprehensive as possible, of the expressive capacity of probabilistic grammar formalisms across the ChomskySchützenberger hierarchy, from probabilistic regular grammars to unrestricted grammars (Figure 1). Our study draws from a wealth of previous work in different research traditions. Most prominently, we employ analytic techniques that date back to the beginning of formal language and automata theory, to the pioneering algebraic approach of Schützenberger (Schützenberger, 1961, 1965; Chomsky and Schützenberger, 1963), which has in turn spawned a rich literature in theoretical computer science and analytic combinatorics (see Eilenberg 1974; Salomaa and Soittola 1978; Kuich and Salomaa 1986; Flajolet 1987; Flajolet and Sedgewick 2001; Droste et al. 2009, among many others). Much of this work is quite abstract, e.g., dealing with generalized notions of rational and algebraic power series. Probabilistic interpretations are often discussed as special cases (for instance, as a possible semi-ring related to a weighted grammar or automaton, see Droste et al. 2009), and some of the literature deals with languages defined by probabilistic automata with "cut-points" (Rabin, 1963; Salomaa and Soittola, 1978). However, extracting lessons for probabilistic grammars specifically often requires further work. Meanwhile, there have been a number of important results dealing with expressivity of probabilistic grammars and machines per se, from mathematical psychology (e.g., Vitányi and Chater 2017), mathematical linguistics (e.g., Chi 1999; Smith and Johnson 2007; Kornai 2008), statistics (e.g., O'Cinneide 1990), and other areas of computer science (e.g., de Leeuw et al. 1956; Yao 1985). We draw on this body of work as well. Our presentation and analysis of the probabilistic Chomsky-Schützenberger hierarchy combines a number of old and new results, and is intended to be as streamlined and selfcontained as possible. Many of the observations are original, but we also aim to bring together techniques and ideas from disparate areas in order to paint an expansive picture of the hierarchy as a whole. We include proofs of all new results, as well as results whose proofs might be difficult to find or reconstruct. 3 After formal preliminaries (§2), we characterize the class of all probabilistic grammars showing that they define exactly the enumerable semi-measures (Theorem 3). An important question pertinent to (especially Bayesian) cognitive modeling is whether a class of distributions is closed under conditioning (a kind of counterpart to the notion of conjugacy in statistics). We show that distributions defined by probabilistic grammars (or machines) are not in general closed, even under conditioning with a finite set (Theorem 6). However, the probabilistic grammars that almost-surely terminate are closed under conditioning on any computable set whatsoever (Theorem 7). Turning to the most restrictive class, the probabilistic regular grammars, we show that they are capable of defining any finite-support rational-valued distribution (Corollary 9), before giving a self-contained proof of the result that the probability generating function for a probabilistic regular grammar is always rational (Theorem 15). We also show that the distributions defined by probabilistic regular grammars are closed under conditioning with arbitrary regular sets (Theorem 17). Probabilistic context-free grammars are shown by several examples (13-17) to define irrational generating functions; however, they are all still algebraic (Theorem 22). The result contrasts with the classical Chomsky-Schützenberger characterization (Chomsky and Schützenberger, 1963), which requires restriction to unambiguous context-free grammars (see §5.1). Perhaps surprisingly, when considering finite-support distributions-often central to applications-probabilistic context-free grammars define no more distributions than the regular grammars (Proposition 18). A consequence of this is that probabilistic contextfree grammars are not closed under conditioning, even with finite sets (Proposition 19). We consider two grammar classes that are not part of the original hierarchy, situated in between context-free and context-sensitive, namely indexed (Aho, 1968) and linear indexed (Duske and Parchmann, 1984) grammars. Both have played a notable role in computational linguistics (e.g., Gazdar 1988; Joshi et al. 1991; Kim et al. 2019). Probabilistic indexed grammars are capable of defining distributions with transcendental generating functions (Proposition 23). Even probabilistic linear indexed grammars-which possess algebraic generating functions and whose (right-linear) restrictions are weakly equivalent to context-free grammars (Aho, 1968)-can define finite-support irrational distributions, thus surpassing the power of context-free in the probabilistic setting (Proposition 24). Finally, it is shown that probabilistic context-sensitive grammars can also define distributions with transcendental generating functions, including some that elude probabilistic indexed grammars (Propositions 27 and 28). We demonstrate that, in some sense, probabilistic context-sensitive grammars come quite close to arbitrary probabilistic grammars (Proposition 29). In other ways, however, these grammars are unnatural from a probabilistic perspective. For finite-support measures they again coincide with the regular grammars, defining only rational-valued distributions; and unlike in the classical hierarchy, they do not even extend context-free (Proposition 30). The resulting hierarchy is summarized in Figure 1. Notably, the picture remains unchanged when restricting attention to a one-letter alphabet, a restriction that is very natural for many applications, viz. unary representations of positive integers (recall Examples 14). It has been observed that Parikh's Theorem (Parikh, 1966)-showing that the contextfree languages are "semi-linear" and thus coextensive with the regular languages for a one-letter alphabet-does not extend to the probabilistic setting (Petre, 1999; Bhattiprolu et al., 2017). We observe that this trend is widespread, applying also to the linear indexed grammars (which are also semi-linear, see Duske et al. 1992). Another emerging theme is that, while finite languages trivialize in the classical setting, finite-support distributions 4 Classical Hierarchy C on text-Free Li ne ar Indexed IndexedC ont ext-Sensitive Unr estricted Regular Probabilistic Hierarchy C on text-Free Li ne ar Indexed Indexed Context-Sensit ive Un restricted Regular Figure 1: The classical and probabilistic hierarchies. The shaded region signifies that these classes collapse into the regular languages when considering a one-element alphabet. No such collapse occurs in the probabilistic hierarchy. Meanwhile, the probabilistic contextsensitive grammars are incomparable with the probabilistic context-free grammars. can reveal subtle and significant distinctions in the probabilistic setting. In the concluding section (§8) we return to consider what repercussions this pattern of results may have for psychology and cognitive science. 2 Formal Preliminaries 2.1 Strings and Distributions Our interest is in distributions over strings from a finite alphabet Σ. We construe strings as lists, depicted by concatenation, and denote the empty string by ε. The length of a string |σ| is defined so that |ε| = 0 and |aσ| = |σ|+ 1. Exponentiation is defined by σ0 = ε and σn+1 = σnσ, so that |σn| = n|σ|. We will make use of a canonical ordering on the set of substrings of a string. Given σ and non-empty substrings σ1, σ2 of σ, we say σ1 has priority over σ2 if either (1) the left-most symbol of σ1 is to the left in σ of the left-most symbol of σ2, or (2) their leftmost symbols are identical, at the same index of σ, but σ2 is a proper substring of σ1. A discrete semi-measure (or simply a distribution) on Σ is a function P : Σ∗ → [0, 1] such that ∑σ∈Σ∗ P(σ) ≤ 1. When this sum is equal to 1 we call P a probability measure. We also consider associated measure functions defined on positive integers μ : Z+ → [0, 1], such that ∑n∈Z+ μ(n) ≤ 1, using the same nomenclature. When dealing with a one-element alphabet we will often think of ak as a unary notation for k, so that each P will correspond to an obvious function μ on integers, namely μ(k) = P(ak). The support of a distribution is the set of strings that receive non-zero measure. We say a distribution has finite support if its support is finite and omits the empty string. Finally, given a set S ⊆ Σ∗, we define the conditional distribution P(σ | S) as follows: P(σ | S) = P(σ) ∑σ′∈S P(σ′) (1) 5 when σ ∈ S, and P(σ | S) = 0 otherwise. As a special case, if S+ = {σ ∈ Σ∗ : P(σ) > 0} is the support of P, then P(σ | S+) is a probability measure, the normalization of P. Given the definition in (1), conditioning on the trivial proposition Σ∗ also produces the normalization: P(σ | Σ∗) = P(σ | S+). More generally, for any S we have P(σ | S) = P(σ | S ∩ S+). Any conditional distribution P( * | S) will be a probability measure, even if P is not. 2.2 Probability Generating Functions From a semi-measure μ we derive a probability generating function (pgf) Gμ defined so that Gμ(z) = ∑∞k=0 μ(k)z k. Gμ essentially summarizes the distribution as a formal power series. We say Gμ is algebraic if y = Gμ(z) is a solution to a polynomial equation 0 = Q(y, z). We call Gμ rational when Q is of degree 1 in y, i.e., when there are polynomials Q0(z) and Q1(z) such that Gμ(z) = Q0(z) Q1(z) . For example, the pgf for a simple geometric function μ(k) = 2−k is rational, equal to 12−z . Finally, a pgf is transcendental if it is not algebraic. For instance, the pgf for a Poisson distribution (Example 1) is eλz−λ, easily shown to be transcendental. For another notable example, consider a semi-measure μ such that μ(2k) = 2−k for k > 0, and μ(n) = 0 for all other n. Let us write the pgf for μ as Gμ(z) = ∑∞k=0 ckz k where ck = k−1 if k is a power of 2, and ck = 0 otherwise. The Hadamard product of two power series ∑∞k=0 ckz k and ∑∞k=0 dkz k is the power series ∑∞k=0(ckdk)z k. One can show that the Hadamard product of a rational and an algebraic power series must be algebraic (Jungen, 1931; Flajolet and Sedgewick, 2001). We thus obtain: Lemma 1. The pgf Gμ(z) is transcendental. Proof. It is known that the "lacunary" power series h(z) = ∑∞k=1 z 2k is transcendental (e.g., Theorem 1.1.2 of Nishioka 1996). The power series g(z) = ∑∞k=0 kz k = z/(z2 − 2z + 1) is patently rational. However, the Hadamard product of Gμ(z) and g(z) gives exactly h(z). Hence Gμ(z) cannot be algebraic. When Σ = {a} we will slightly abuse terminology by speaking of the pgf for a distribution on Σ∗ as being rational, algebraic, or transcendental, under the unary encoding. 2.3 Grammars and Probabilistic Grammars A grammar is a quadruple G = (N , Σ, Π, X0), given by a finite set of non-terminal symbols N , including a start symbol X0, an alphabet Σ, and a finite set Π of productions (α → β) where α, β ∈ (N ∪ Σ)∗. We will refer to elements of Σ∗ as words. The standard hierarchy is defined as in Chomsky (1959) (indexed grammars will be introduced separately in §6): • Regular (Type 3) Grammars: All productions are of the form (X → σY) or (X → σ), with σ ∈ Σ∗, X, Y ∈ N . • Context-Free (Type 2) Grammars: All production rules are of the form (X → α) with X ∈ N and α ∈ (N ∪ Σ)∗. • Context-Sensitive (Type 1) Grammars: Productions are of the form (αXβ → αγβ), where X ∈ N , α, β, γ ∈ (N ∪ Σ)∗, and γ 6= ε; we also allow (X0 → ε) provided X0 does not occur on the right-hand-side of any production. 6 X0 a aX0 aa aaX0 aaa aaaX0 aaaa aaaaX0 aaaaa ... aaaaaX0 ... X0 a aX0X0 aaX0 aaa aaaX0X0 aaaaX0 aaaaa ... aaaaaX0X0 ... aaaaX0X0X0 ... aaX0X0X0 aaaX0X0 aaaaX0 aaaaa ... aaaaaX0X0 ... aaaaX0X0X0 ... aaaX0X0X0X0 ... Figure 2: Partial parse trees for Examples 5 (left) and 6 (right). • Unrestricted (Type 0) Grammars: No restrictions. A probabilistic grammar is one with the following property: for each α ∈ (N ∪ Σ)∗ there may be only 0, 1, or 2 distinct β with (α → β) ∈ Π. If there is 1 we write α 1→ β, with the interpretation that α rewrites to β with probability 1; if there are 2 we will write α 1/2→ β for each, with the interpretation that α rewrites to β with probability 1/2. Intuitively, when rewriting α we imagine randomly choosing from among those productions with α on the left-hand-side. In effect this means we are only considering probabilistic grammars with production probabilities of 1/2. As far as definability is concerned, however, this implies no loss relative to allowing arbitrary rational probabilities (Theorem 8 below). It will often be convenient to refer to production probabilities, which we write as PG(α→ β)-or simply P(α→ β) when G is clear from context-always taking on value 0, 1, or 1/2. A parse of a word σ from a string γ in a grammar G is a finite sequence ρ = 〈ρ0, . . . , ρn〉, where ρ0 = γ, ρn = σ, and for all i < n: ρi+1 is obtained from ρi by replacing the substring α of ρi with β, where (α → β) ∈ Π, and α is the highest priority substring of ρi with an applicable production. The probability of the parse, PG(ρ), is given by the product of probabilities of productions used in ρ. The probability of γ rewriting as a word σ is given by the sum of probabilities of its parses: PγG(σ) = ∑ρ:ρ0=γ,ρn=σ PG(ρ). We will write PG(σ) for the distribution PX0G (σ) from the start symbol X0. Example 5. Consider the following simple probabilistic regular grammar G1: X0 1/2→ aX0 X0 1/2→ a The tree in Figure 2 depicts all parses of the first five strings, showing that PG1(a k) = 2−k. 7 Example 6. The following is a probabilistic context-free grammar G2, only minimally more complex than the regular G1 by allowing two non-terminals on the right: X0 1/2→ aX0X0 X0 1/2→ a As revealed in Figure 2, we have PG2(a) = 2 −1 and PG2(a 3) = 2−3, like in Example 5. However, a5 has two parses, each with probability 2−5. Hence, PG2(a 5) = 2−5 * 2 = 2−4. G1 and G2 are also both context-sensitive grammars. Example 7. Finally, we offer an example of a probabilistic unrestricted grammar G3, which is not regular, context-free, or context-sensitive: X0 1→WYaZ YZ 1/2→ U aV 1→ Va aU 1→ Ua Ya 1→ aaY YZ 1/2→ VZ WV 1→WY WU 1→ ε With probability 1, X0 rewrites to WaaYZ. Then, since YZ randomly rewrites to either U or VZ, we have that WaaYZ rewrites to either WaaU or WaaVZ, each with probability 1/2. Following the sequence of productions, WaaU rewrites with probability 1 to aa, while WaaVZ rewrites with probability 1 to WaaaaYZ. The latter string then again rewrites with probability 1/2 to aaaa and with probability 1/2 to WaaaaaaaaYZ. In other words, this grammar defines the distribution PG3(a 2k ) = 2−k, shown above (Lemma 1) to be transcendental. Example 7 also provides a simple instance of a conditional distribution, since we have PG3(σ) = PG1(σ | {a 2k : k > 0}). 3 Probabilistic Unrestricted Grammars Similar to the classical case, probabilistic grammars in general correspond to probabilistic Turing machines (de Leeuw et al., 1956), conceived as stochastic word generators. Such models have arguably delineated the class of possible psychological models for as long as the mind has been likened to a computing device (Turing, 1950; Putnam, 1967). A probabilistic Turing machine (PTM) comes with an infinite one-way read-only random bit tape with Bernoulli(1/2)-distributed binary variables, as well as a one-way infinite read/write tape initially consisting of a special end symbol B followed by an infinite list of blank symbols t. Given an alphabet Σ, a PTM consists of finitely many states S = {s0, s1 . . . , sn, s#}, with a distinguished start state s0 and a distinguished end state s#, and finitely many rules of the form: 〈si, a1, b, a2, d, sj〉 where si, sj ∈ S, a1, a2 ∈ Σ∪ {B,t}, b ∈ {0, 1}, d ∈ {L, R}. Such a rule is read: if in state si, reading a1 on the read/write tape and b on the random bit tape, rewrite a1 as a2 and go left (if d = L) or right (if d = R), entering state sj. We assume for each triple si, a1, b, there is at most one triple a2, d, sj such that 〈si, a1, b, a2, d, sj〉 is a rule of T . That is, T is deterministic given its random input. We also assume that a1 = B if and only if a2 = B; moreover, in this case d = R. The machine begins reading B and halts upon reaching state s#. By a familiar argument, we can assume that every PTM is in a normal form guaranteeing that, 8 upon halting, following the B symbol is some σ ∈ Σ∗, followed again by an infinite list of blank symbols. The word σ is the official output. We use PT to refer to the distribution effected by T . That is, PT (σ) is the probability that T halts with σ as output on the tape. Clearly PT is a semi-measure. The proof of the next proposition is similar to the non-probabilistic case (e.g., Chomsky 1959; Minsky 1967); we include the details as later results (Propositions 27 and 29) will depend on them. Proposition 2. Probabilistic unrestricted grammars and probabilistic Turing machines define the same distributions. Proof. We need to show that PT for any PTM T can be defined by some grammar G. If T has states s0, s1, . . . , sn, sn+1(=s#), then G will have non-terminals X0, X1, . . . , Xn, Xn+1, in addition to B and t, and one more "loop" non-terminal Λ having 0 productions. Our aim is to mimic the behavior of T , step-by-step, using the non-terminals Xi to keep track of the position of the read/write head. We begin with a rule (X0 → X0B) rewriting X as X0B. Then, for each rule of the form 〈si, a1, b, a2, L, sj〉 of T we add to G production rules for all a ∈ Σ ∪ {B,t}: aXia1 → Xjaa2 If there is no rule for si, a1, 1− b then we also add: aXia1 → Λ For each rule 〈si, a1, b, a2, R, sj〉, we include a production: Xia1 → a2Xj When a1 = t we additionally include: Xi → a2Xj Given our priority order on substrings (§2.1), this production will only be used when Xi occurs at the very end of the string. Again, for both of the previous we include productions leading to Λ if there is no rule appropriate for si, a1, 1− b. Finally, we include "clean-up" productions for the stage when we reach Xn+1, corresponding to s#. For all a ∈ Σ: aXn+1 → Xn+1a BXn+1 → Xn+1 Xn+1a → aXn+1 Xn+1t → Xn+1 Xn+1 → ε That is, (again, due to our priority order on substrings) Xn+1 moves along the string to the left (which, given our PTM normal form, contains no blank symbols) until it hits B. After erasing it, we move along the string to the right until reaching blank symbols, eliminate them, and then Xn+1 rewrites to the empty string, giving us a word from Σ∗. To show that a PTM can simulate any probabilistic grammar is routine (again similar to the classical case, e.g., Minsky 1967). 9 These distributions can be given a precise formulation. Call a semi-measure P (computably) enumerable if it is approximable from below (Zvonkin and Levin, 1970); that is, if for each σ ∈ Σ∗ there is a computably enumerable weakly increasing sequence q0, q1, q2, . . . of rational numbers, such that lim i→∞ qi = P(σ). Enumerable semi-measures have been argued to constitute a useful idealized inductive target for psychological learning models (Vitányi and Chater, 2017). PT and (by Theorem 2) PG are always guaranteed to be enumerable: consider the set Bi of binary strings β with |β| ≤ i, such that T accesses (exactly) the bits of β before terminating with output σ. Letting qi = ∑β∈Bi 2 −|β|, it is then evident that lim i→∞ qi = PT (σ). In fact, we have the converse as well. Theorem 3 (Icard 2017a). Probabilistic grammars (equivalently, probabilistic Turing machines) define exactly the enumerable distributions. Proof. Let P be an enumerable semi-measure on Σ∗. That is, for each word σ ∈ Σ∗, there is a computably enumerable weakly increasing sequence q0, q1, q2, . . . of rational numbers such that lim i→∞ qi = P(σ). Assume without loss that q0 = 0. Note then that P(σ) = ∑∞i=0(qi+1 − qi). Our aim is to show that P = PT for some PTM T . Let 〈 , 〉 : N×N → N be a fixed (computable) bijective pairing function with first projection π1(n) = k when n = 〈k, i〉. Let σ0, σ1, σ2, . . . be a fixed enumeration of Σ∗, each with a fixed enumeration of approximating rationals qk0, q k 1, . . . converging from below to P(σk). We define a sequence of rational (thus computable) numbers as follows: r0 = q00 rn+1 = rn + ( qki+1 − qki ) where we assume 0 = 〈0, 0〉 and n + 1 = 〈k, i〉. Our PTM T works in stages, observing a random sequence of bits b0, . . . , bj−1-which we can think of as ever closer approximations to some random real number-while producing an enumeration r0, . . . , rj−1. At each stage j, we observe a bit bj and add a rational rj, then check whether, for any n with 0 ≤ n < j, the following condition (2) is satisfied: rn < j ∑ i=0 bi2−i − 2−j and rn+1 > j ∑ i=0 bi2−i + 2−j (2) That is, where p = ∑ j i=0 bi2 −i is the rational generated so far, we know our randomly generated real number will lie somewhere in the interval ( p− ε, p + ε), and (2) tells us that this interval sits inside the interval (rn, rn+1). If this holds, output σπ1(n+1). Otherwise, move on to stage j + 1. Each word σ has its mass P(σ) distributed across different intervals in [0, 1]: P(σk) = ∑ n:π1(n+1)=k rn+1 − rn = ∞ ∑ i=0 (qki+1 − qki ). The procedure generates approximations p = ∑ j i=0 bi2 −i to a random real number, and as soon as we are guaranteed that this random number is in one of our intervals between 10 rn and rn+1 = rn + (qki+1 − qki ), i.e., that no further bits will take us out of that interval (condition (2) above), we halt and output the string σk corresponding to the interval, with k = π1(n + 1). The probability of outputting σ is exactly P(σ), and the probability of not halting at all is 1−∑σ P(σ). More restrictive than the class of enumerable semi-measures is the class of computable semi-measures (de Leeuw et al., 1956), namely those for which P(σ) can also be computably approximated from above. To be computable we additionally require a weakly decreasing sequence of rationals converging to P. Lemma 4. Every semi-computable probability measure is also computable. Proof. Since ∑σ∈Σ∗ P(σ) = 1, we can approximate from below the sum ∑σ′ 6=σ P(σ′) by dovetailing through approximating sequences for all strings other than σ. This gives us a sequence q1 ≤ q2 ≤ q3, . . . converging from below to ∑σ′ 6=σ P(σ′). Thus, the sequence 1− q1 ≥ 1− q2 ≥ 1− q3, . . . converges from above to P(σ). Theorem 3, together with Lemma 4, gives us the following known corollary (see, e.g., Dal Lago and Zorzi 2012; Freer et al. 2014): Corollary 5. Almost-surely terminating grammars define the computable probability measures. As in the classical case, determining almost-sure termination is algorithmically undecidable. In fact, in the present setting it is even more difficult than the classical halting problem (Kaminski and Katoen, 2015). So there can obviously be no computably defined subclass of grammars or machines corresponding exactly to the computable distributions. To give a sense of how subtle the boundary between almost-sure termination and possible non-termination can be, consider the following example: Example 8 (Icard 2017a). Imagine a race between a tortoise and a hare. Where flip(1/4) is a procedure that returns 1 with probability 1/4 and Unif(1,7) returns an integer between 1 and 7 uniformly, consider the following simulation pseudocode: t := 1; h := 0 while (h < t) t := t + 1 if flip(1/4) then h := h + Unif(1,7) return t-1 Whereas this program would almost-surely halt, a small change to the program (e.g., incrementing the tortoise's pace by ε) would lead to positive probability of not halting. Theorem 3 tells us, perhaps unsurprisingly, that probabilistic grammars are capable of defining essentially all of the discrete measures that have been considered in the literature (e.g., all of those surveyed in Johnson et al. 2005), and even encompasses procedures producing values with uncomputable (but enumerable) probabilities, such as Chaitin's famous "halting probability" (Chaitin, 1975). Of course, converting an analytical description into an appropriate procedure can be far from trivial, as illustrated by the following example: 11 Example 9 (Flajolet et al. 2011). The following pseudocode, compilable into probabilistic Turing machine code, outputs 1 with probability exactly 1/π: x1, x2 := Geom(1/4) t := x1 + x2 if flip(5/9) then t := t + 1 for j = 1, 2, 3 draw 2t fair coin flips if #Heads 6= #Tails then return 0 return 1 The verification depends on an identity for 1/π due to Ramanujan. Theorem 3 and Corollary 5 delineate our subject matter, giving an upper bound on the types of discrete distributions probabilistic grammars and machines can possibly represent. 3.1 Conditioning probabilistic grammars One of the most important operations on probability distributions is conditioning, typically used to encode the effect of updating the distribution with some observation. Our first result about conditioning is negative (cf. Wood et al. 2011 for a related result in the context of so called Solomonoff induction): Theorem 6. The class of distributions defined by probabilistic grammars (equivalently, probabilistic Turing machines) is not closed under conditioning, even with finite sets. Proof. Take any computably enumerable (but not computable) real number p and rational number r such that p + r < 1. By Theorem 3 there is a grammar G that terminates with probability p + r, such that PG(a) = p and PG(aa) = r. Consider the support S+ = {a, aa} of PG . We claim that the normalization PG(σ | S+) is not computably enumerable. If it were, it would also be computable (Lemma 4). In particular, there would be a computable sequence q1 ≥ q2 ≥ q3 . . . converging from above to PG(a | S+) = p p+r . But from this we can obtain another sequence t1t1+r ≥ t2 t2+r ≥ t3t3+r . . . converging to p p+r , such that the sequence t1, t2, t3 . . . converges from above to p, which by hypothesis is impossible. At the same time, we obtain a positive closure result by restricting attention to those grammars or machines that almost-surely terminate, or slightly more generally to those that define computable distributions. In fact, as Freer et al. (2014) describe, there is a single probabilistic Turing machine that takes as input (the code of) a machine T and (the code of) a computable predicate S, and then produces strings σ with probabilities PT (σ | S). In the present setting, all this machine must do is implement a kind of "rejection sampling" procedure, repeatedly running T until it outputs some σ ∈ S, at that point returning σ. Theorem 7. The computable semi-measures are closed under conditioning with computable sets. 4 Probabilistic Regular Grammars We turn now to the most restrictive class of grammars, the probabilistic regular grammars (PRGs). These grammars have received relatively little direct attention. However, due 12 to their equivalence with probabilistic finite state automata (see, e.g., Smith and Johnson 2007), which are in turn equivalent in expressive power to discrete hidden Markov models (Dupont et al., 2005) as well as so called discrete phase-type distributions (O'Cinneide, 1990), much is already known about them. Such models furthermore have a long history in psychology and cognitive science (Miller, 1952). As above, we deal with the special case of only 1/2 production probabilities, which would correspond to 1/2 transition probabilities in probabilistic automata. 4.1 Expressing Rational Probabilities A first observation is that, had we begun with any real-valued probabilities q and 1− q, we would nonetheless be able to simulate 1/2 productions. In this sense the assumption that we do have 1/2 productions is with no loss. The trick goes back to von Neumann (1951) and can in fact be carried out with PRGs. For example, if we wanted X 1/2→ Y1 and X 1/2→ Y2, we could simply add two new non-terminals, Z1, Z2, and define: X q→ Z1 Z1 q→ X Z2 1−q→ X X 1−q→ Z2 Z1 1−q→ Y1 Z2 q→ Y2 Perhaps more impressively, PRGs are able to produce strings with arbitrary rational probabilities using only 1/2. (This basic idea can be traced back at least to Knuth and Yao 1976.) Example 10. To simulate X 1/3→ Y1, X 1/3→ Y2 and X 1/3→ Y3 we again add just two new nonterminals and define: X 1/2→ Z1 Z1 1/2→ X Z2 1/2→ Y2 X 1/2→ Z2 Z1 1/2→ Y1 Z2 1/2→ Y3 The probability of X rewriting to each is ∑n>0 1/22n = 1/3. Indeed, consider any rational number q, guaranteed to have a periodic binary expansion 0.b1 . . . bkbk+1 . . . bk+m. To simulate productions (X q→ Y1), (X 1−q→ Y0), we use nonterminals X1(= X), X2, . . . , Xk+m and introduce productions: Xi 1/2→ Ybi for each i ≤ k + m Xi 1/2→ Xi+1 for each i < k + m Xk+m 1/2→ Xk+1 X rewrites to Y1 with probability q and to Y0 with probability 1− q. The intuition is similar to the proof of Theorem 3: we are effectively generating ever closer approximations to a random real number, and once we definitively undershoot q (by generating an nth bit 0 when the nth bit of q is 1) or overshoot q (generating 1 when the corresponding bit of q is 0) we know which of Y1 and Y0 to choose. Repeating this procedure finitely many times gives us: Theorem 8. Let P1, . . . , Pn be PRG-definable distributions. For any rational numbers q1, . . . , qn, with ∑i≤n qi ≤ 1, the semi-measure P given by P(σ) = ∑i≤n qiPi(σ) is also PRG-definable. 13 From now on we will freely label rules with rational probabilities, with the understanding that they can be rewritten using only 1/2, perhaps by adding further non-terminals. Corollary 9. Probabilistic regular grammars define all finite-support rational-valued distributions. This already captures an extraordinarily wide variety of distributions, including many that are of central importance in psychological modeling such as (rational parameter valued) Bayesian networks (Pearl, 1988). We also have: Example 11 (Beta-Binomial). Recall Example 4. As long as α, β ∈ Z+, the (finitely many non-zero) probability values will always be rational, which by Corollary 9 means we can define it with a PRG. The more general Dirichlet-Multinomial can likewise be expressed, again provided we restrict to positive-integer-valued parameters. In addition, PRGs can define many important infinite-support distributions, following again from Theorem 8. Recall Example 2: Example 12 (Negative Binomial). Let us introduce t + 1 non-terminals N = {X0, . . . , Xt} with productions for each n < t: Xn 1−q→ aXn Xn q→ Xn+1 Xt 1−q→ aXt Xt q→ ε This easily defines the negative binomial distribution μq,t from Example 2. Any discrete probability can of course be arbitrarily well approximated by rationalvalued distributions, and the same is even true for continuous measures: the finite-support rational-valued distributions are everywhere dense in the space of Borel probability measures (under the weak topology, see Billingsley 1999). Moreover, this extends to the setting of computable probability spaces, where we additionally require approximating sequences to be uniformly computable (Gács, 2005; Ackerman et al., 2019). Thus, concerning pure expressivity, if we accept mere approximation (which we must in the continuous setting anyway), probabilistic regular grammars with 1/2-productions suffice in principle. 4.2 Normal Form and Matrix Representation We would nonetheless like to understand the expressive limitations of PRGs, and in this direction it will be convenient to assume a normal form for them. In the following lemma let us say that a non-terminal Y is transient if either there are are no productions for Y at all, or there is α ∈ Σ∗ such that (Y → α) ∈ Π. In other words, Y fails to be transient just when it rewrites with probability 1 to another non-terminal. Say that Y is reachable from X if either X = Y or there is some sequence (X → Z1), . . . , (Zn → Y). Lemma 10 (PRG normal form). Every PRG-definable distribution can be expressed by a PRG with the following properties: 1. In all productions (X → σY) and (X → σ) we have |σ| ≤ 1, i.e., either σ ∈ Σ or σ = ε. 2. X0 does not appear on the right-hand-side of any production, and there are only productions of the form (X0 → Y) with Y a non-terminal. 3. From every X some transient Y is reachable. 14 Proof. To show 1, it is enough to observe that whenever we have a production (X → abY) where a, b ∈ Σ, we can simply introduce a new non-terminal Z and replace it with two new productions (X → aZ) and (Z → bY). By induction we can always replace any such (X → σY) with |σ| new productions. To guarantee 2, introduce a new non-terminal Z, replace X0 with Z everywhere in the grammar, and add (X0 → Z). For 3, consider the set X of non-terminals reachable from X. If X contains no transient elements, then for every Z ∈ X there are Z1, Z2 ∈ X with (Z → σ1Z1), (Z → σ2Z2) ∈ Π (possibly Z1 = Z2). Since the elements of X thus always rewrite to one another, the distribution on words would not change if we simply removed all productions with elements of X on the left-hand-side. This immediately guarantees all elements of X are transient. If X = ∅ then X itself is transient. From here on let us assume that G is in normal form, satisfying 1-3 of Lemma 10. We can represent G using (substochastic) matrices. WhereN = {X0, . . . , Xm} let L be an m×m matrix (indexed 1, . . . , m), with entries determined by G: L[i, j] = P(Xi → Xj) Similarly for each a ∈ Σ we define an m×m matrix A: A[i, j] = P(Xi → aXj) To summarize the remaining productions we define a (row) vector v and (column) vectors w and a (one for each a ∈ Σ), all of length m, defined so that: v[i] = P(X0 → Xi) w[i] = P(Xi → ε) a[i] = P(Xi → a) The probability of a word σ = a1 . . . an can thus be represented: PG(σ) = ∑ k1,...,kn+1≥0 vLk1 A1 . . . Lkn AnLkn+1 w + ∑ k1,...,kn≥0 vLk1 A1 . . . Lkn an = v ( ∑ k≥0 Lk ) A1 . . . ( ∑ k≥0 Lk ) An ( ∑ k≥0 Lk ) w + v ( ∑ k≥0 Lk ) A1 . . . ( ∑ k≥0 Lk ) an The fact that G is in normal form guarantees that these infinite sums can be eliminated from the equation. Specifically: Lemma 11. lim k→∞ Lk = 0. Proof. The statement is equivalent to the spectral radius of L (largest absolute value of its eigenvalues) being strictly less than 1 (see, e.g., Kress 1998). Because L is a contraction (e.g., with respect to l1 norm) we know the spectral radius is less than or equal to 1, so it remains only to show that it cannot be 1. If 1 were an eigenvalue of L then we would have Lx = x for some non-zero x. Thus, for each index i of x one of the following must hold: (1) x[i] = 0, (2) x[i] = 12 x[j] for some j, (3) x[i] = 12 x[j] + 1 2 x[k] for some j, k, or (4) x[i] = x[j] for some j. Note that those i corresponding to transient non-terminals Xi will never satisfy (3) or (4). Consider the set 15 I = {i : the absolute value of x[i] is maximal}. Since x is non-zero, no i ∈ I can satisfy (1) or (2). Moreover, for no such i do we have x[i] = x[j] with j /∈ I. By condition 3 of Lemma 10 (normal form), for some i we must therefore have x[i] = 12 x[j] + 1 2 x[k] for some j, k, at least one of which must not be in I. But this too is impossible. Lemma 12. ∑k≥0 Lk = (I− L)−1 Proof. The proof is standard, but we give it for completeness. We want to show that the matrix product (I− L)(∑k≥0 Lk) is equal again to the identity matrix I. (I− L)(∑ k≥0 Lk) = lim n→∞ ( (I− L)( ∑ n≥k≥0 Lk) ) = lim n→∞ ( ∑ n≥k≥0 Lk − ∑ n≥k≥0 Lk+1 ) = lim n→∞ ( L0 − Ln+1 ) = lim n→∞ ( I− Ln+1 ) But because lim n→∞ Ln+1 = 0, this limit is in fact equal to I. By Lemma 12, and abbreviating (I− L)−1 as M, we have: PG(σ) = vMA1 . . . MAnMw + vMA1 . . . Man = vMA1 . . . M(AnMw + an) (3) Because multiplying and taking inverses of matrices never leads to irrational numbers, Eq. (3) establishes a sort of converse of Corollary 9: Proposition 13. For any PRG G and any word σ, the probability PG(σ) is a rational number. 4.3 Rational Generating Functions Theorem 8 and Proposition 13 tell us about the kinds of probability values specific words can take. But we would also like to understand the overall structure of the distribution produced by a PRG. In the present section we restrict attention to Σ = {a}, which we interpret as providing unary notations for positive integers. In this case Eq. 3 can be written even more simply. Abbreviating MA by N we have: PG(ak+1) = vNk ( NMw + Ma ) In other words, there are fixed vectors v and u such that: PG(ak+1) = vNku (4) Eq. 4 leads to the following result (cf. Paz 1971): Lemma 14. There are fixed constants c1, . . . , cm, such that for every k ∈N: PG(ak+m+1) = m ∑ i=1 ci PG(ak+i). 16 Proof. By the Cayley-Hamilton Theorem, N satisfies its own characteristic equation, i.e.: Nm = c1I + c2N + * * *+ cmNm−1 for constants c1, . . . , cm. Multiplying each term on the left by vNk and on the right by u: vNk+mu = c1vNku + c2vNk+1u + * * *+ cmvNk+m−1u. In other words, PG(ak+m+1) = c1 PG(ak+1) + c2 PG(ak+2) + * * *+ cm PG(ak+m). A quick, high-level derivation of this next result from Lemma 14 can be found, e.g., in Theorem 4.1.1 of Stanley (2011). We give an explicit proof here. Theorem 15. The probability generating function for any PRG on Σ = {a} is a rational function. Proof. The aim is to show there are polynomials Q0(z) and Q1(z) such that GG(z) = Q0(z) Q1(z) . In other words we want Q0(z)−Q1(z)GG(z) = 0. We leave off the subscript G from GG and from PG . Define Q1(z) to be the m-degree polynomial −c1zm +−c2zm−1 + * * *+−cmz + 1: Q0(z)−Q1(z)G(z) = Q0(z) + c1zmG(z) + * * *+ cmzG(z)−G(z) Setting this equal to 0 we can solve for Q0(z). We would like Q0(z) such that: G(z) = Q0(z) + c1zmG(z) + * * *+ cmzG(z) ∞ ∑ k=0 P(ak)zk = Q0(z) + ∞ ∑ k=0 c1P(ak)zk+m + * * *+ ∞ ∑ k=0 cmP(ak)zk+1 By Lemma 14 we have ∑∞k=m P(a k)zk equal to: ∞ ∑ k=0 c1P(ak)zk+m + * * *+ ∞ ∑ k=m−1 cmP(ak)zk+1. Thus, setting Q0(z) equal to the m− 1-degree polynomial P(ε) + ( P(a)− cmP(ε) ) z + * * *+ ( P(am−1)− ( c2P(ε) + c3P(a) + * * *+ cmP(am−2) )) zm−1 gives us the desired equality. A version of Theorem 15 can be traced back to observations of Schützenberger (1961) (see also Eilenberg 1974; Salomaa and Soittola 1978; Kuich and Salomaa 1986; Flajolet and Sedgewick 2001; Kornai 2008; Bhattiprolu et al. 2017). It is known that probabilistic automata and the closely related discrete phase-type distributions (and therefore also PRGs) do not define all probability distributions with rational pgfs, even if we were to allow arbitrary positive real number weights (Eilenberg, 1974; Soittola, 1976; O'Cinneide, 1990). The reason is that any generating function for one of these devices must be a merge of rational functions possessing unique poles of minimal modulus (i.e., there can only be one zero of the denominator with minimal absolute value). See §VIII Example 6.1 of Eilenberg (1974). Note that it is important for Theorem 15 that positive integers be represented in unary. If we instead used a binary representation, for example, then as 10k is the binary representation of 2k, we could define a distribution whose pgf is transcendental (Lemma 1). 17 4.4 Conditioning with a Regular Set Given the previous results we can show that PRG-definable distributions are closed under conditioning with regular sets of words. In that direction we first show the following useful closure result (cf. Nederhof and Satta 2003): Lemma 16 (Normalization). Given a PRG G, consider the set S+G = {σ ∈ Σ ∗ : PG(σ) > 0} of words with positive probability. There is a PRG G+ such that PG+(σ) = PG(σ | S+G ) for all σ. Proof. Given G, for each non-terminal Xi define: ν(Xi) = ∑ σ∈Σ∗ P Xi G (σ) to be the probability that Xi rewrites to a word. We claim that ν(Xi) is always a rational number. Consider the grammar G now with Xi as the start symbol, and assume without loss that this grammar is in normal form (so in particular Xi satisfies condition (2) of Lemma 10). Define row vector v, matrix T, and column vector f so that: v[j] = PG(Xi → Xj) T[j, k] = ∑ σ∈Σ∪{ε} PG(Xj → σXk) f[j] = ∑ σ∈Σ∪{ε} PG(Xj → σ) Evidently, ν(Xi) = v ( ∑k≥0 Tk ) f, so it remains only to show that ∑k≥0 Tk is rational. As G is in normal form, the same argument as in Lemma 11 establishes that lim k→∞ Tk = 0, and hence that ∑k≥0 Tk = (I− T)−1 (Lemma 12), implying that ν(Xi) is indeed rational. To obtain the "normalized" grammar G+ we simply multiply each rule probability by a certain rational number, with Theorem 8 guaranteeing that we can always construct such a grammar. Specifically, each rule (X → σ) is now in G+ given probability PG(X → σ) ν(X) and each rule (X → σY) is now given probability PG(X → σY) * ν(Y) ν(X) . To show that PG+(σ) = PG(σ | S+G ) we establish a slightly stronger claim, namely that for every non-terminal X and every parse ρ = 〈X, . . . , σ〉, with σ ∈ Σ∗, we have PG+(ρ) = PG(ρ) ν(X) . (5) We show (5) by induction on the length of ρ, with the base case being ρ = 〈X, σ〉 and σ ∈ Σ ∪ {ε}. Then PG+(〈X, σ〉) = PG+(X → σ) = PG(X → σ)/ν(X) = PG(〈X, σ〉)/ν(X). 18 For the inductive case, consider ρ = 〈X, σ0Y, . . . , σ〉, where σ0 ∈ Σ ∪ {ε} and σ = σ0σ1: PG+(〈X, σ0Y, . . . , σ〉) = PG+(X → σ0Y) * PG+(〈Y, . . . , σ1〉) = PG(X → σ0Y) * ν(Y) ν(X) * PG(〈Y, . . . , σ1〉) ν(Y) = PG(X → σ0Y) * PG(〈Y, . . . , σ1〉) ν(X) = PG(ρ) ν(X) . Taking X = X0 and summing over all parses of σ, this establishes the main claim. Recall a non-deterministic finite-state automaton (NFA) is a tuple D = (Q, Σ, ∆, q0, q f ) consisting of a set Q of states, an alphabet Σ, a transition relation ∆ ⊆ Q × Σ × Q, and distinguished start q0 and final q f states (see, e.g., Hopcroft and Ullman 1979). D accepts a word σ ∈ Σ∗ if there is some sequence of transitions starting in state q0, successively reading the symbols of σ, and ending in q f . NFAs accept exactly the regular sets of words. We now show how to construct, from PRG G and some NFA D accepting a regular set R, a grammar G ⊗ D with the property that PG⊗D(σ | S+G⊗D) = P(σ | R). Lemma 16 in turn guarantees that this distribution can itself be defined by a PRG, which will prove: Theorem 17. The class of distributions definable by probabilistic regular grammars is closed under conditioning with regular sets. Proof. The non-terminals of G ⊗ D are all pairs 〈Xi, Q〉, with Xi a non-terminal of G and Q ⊆ Q a non-empty set of states of D. We also include a "loop" non-terminal Λ. The productions of G ⊗D are obtained from G and D. As before assume G is in normal form. 1. For each (Xi → Xj) and Q, add a production (〈Xi, Q〉 → 〈Xj, Q〉). 2. For each (Xi → ε) and Q containing q f , add a production (〈Xi, Q〉 → ε). 3. For each (Xi → a) and Q containing a q with (q, a, q f ) ∈ ∆, add (〈Xi, Q〉 → a). 4. For each (Xi → aXj) and Q, if Q′ = {q′ : (q, a, q′) for some q ∈ Q} is non-empty, then add the production (〈Xi, Q〉 → 〈Xj, Q′〉). Finally, if in G there were two productions with Xi on the left hand side, and for some Q we have added fewer than two productions for 〈Xi, Q〉, add a production (〈Xi, Q〉 → Λ). This guarantees, in the resulting grammar G ⊗D, that every parse of every word has the same probability as it did in G. In other words, PG(σ) = PG⊗D(σ) for every σ. However, the words that receive positive measure in G ⊗D are exactly those in R that received positive measure in G. That is to say, R ∩ S+G = S + G⊗D . In addition, PG(σ | R) = PG(σ | R ∩ S + G ). Hence, PG⊗D(σ | S+G⊗D) = P(σ | R), as desired. 5 Probabilistic Context-Free Grammars Probabilistic context-free grammars (PCFGs) are undoubtedly the most thoroughly studied of probabilistic grammars. Due to their ability to capture hierarchical structure in language, 19 and the existence of good learning models, PCFGs have been ubiquitous in computational approaches to language and grammar (see, e.g., Klein and Manning 2003; Levy 2008; Kim et al. 2019). But they have also seen many applications in other areas of psychology, for example, as encoding a probabilistic hypothesis space for concepts (Tenenbaum et al., 2011). As mentioned above, by results of Abney et al. (1999) and Etessami and Yannakakis (2009), PCFGs express the same class of distributions as pushdown automata and recursive Markov chains. (However, see the discussion below in §5.1 for qualification.) Example 13 (Symmetric Random Walk). Recall the symmetric 1/2-random walk on the nonnegative integers (Example 3). The hitting time for first reaching 0 is a random variable with the same distribution as that defined by the simple grammar G2 in Example 6: X0 1/2→ aX0X0 X0 1/2→ a In the analytic expression from Example 3, the kth Catalan number ck counts the number of parses of a2k+1, while each parse has probability 2−2k+1. The next four examples reveal irrational word probabilities: Example 14. Consider the grammar: X0 1/4→ X0X0 X0 1/4→ a X0 1/2→ ε Then, for instance, P(ε) is a solution to the equation x = 14 x 2 + 12 , equal to 2− √ 2. Example 15 (Olmedo et al. 2016). The following grammar is quite simple: X0 1/2→ X0X0X0 X0 1/2→ ε Yet, P(ε) is a solution to x = 12 x 3 + 12 , equal to 1/φ, where φ is the golden ratio. Example 16 (Etessami and Yannakakis 2009). This grammar is also quite simple. X0 1/6→ X0X0X0X0X0 X0 1/2→ a X0 1/3→ ε However, P(ε) is a solution to x = 16 x 5 + 13 , which is is not even solvable by radicals. The last three examples involve distributions assigning positive probability to the empty string. This is not essential for producing irrational probability values: Example 17. Consider the grammar: X0 1/2→ aY X0 1/2→ a Y 1/4→ YY Y 1/4→ a Y 1/2→ ε Then P(ε) = 0, but, for instance, P(a) = 3− √ 2 2 . However, it might also be noticed that these distributions all maintain infinite support, or assign positive probability to the empty string. It turns out that this is essential: Proposition 18. For distributions with finite support, PCFGs generate all and only the rationalvalued semi-measures. 20 Proof. Suppose a PCFG G has finite support S+G = {a k1 , . . . , akn} with all ki > 0, and let m = max(k1, . . . , kn). If X0 rewrites to some intermediate string α ∈ (N ∪Σ)∗ with positive probability and |α| > m, then |α| −m of the non-terminals in α cannot rewrite to a positivelength word with any positive probability. Otherwise the grammar would assign positive measure to a word longer than m. Revise G by removing each non-terminal Y such that PYG(ε) = 1, and replacing Y with the empty string anywhere it appears on the right-hand side of a rule. Thus, in the revised grammar X0 rewrites with positive probability to only finitely many intermediate strings α that may eventually rewrite to a word. Let A be the set of such α (including X0 itself), and let L be the set of those intermediate strings that loop with probability 1. Define a probabilistic regular grammar G? using a non-terminal Xα for each α ∈ A, in addition to a special non-terminal Λ. For each pair α1, α2 ∈ A, if there is a production in G that would rewrite α1 as α2, add to G? a production (Xα1 → Xα2). Likewise, if G has α rewrite in one step to a string in L, include a production (Xα → Λ). Finally, add a production (Xaki → a ki ) for each aki ∈ S+G . G? clearly generates the same distribution on S+G as the original grammar G. By Proposition 13 we know that every such value PG(aki ) = PG?(aki ) must be rational. Using Proposition 18 we can also show that PCFGs, as we have defined them, are not in general closed under conditioning (though see Nederhof and Satta 2003 for a proof that PCFGs are closed under conditioning with regular sets if we allow irrational weights): Proposition 19. PCFGs are not closed under conditioning, even with finite sets. Proof. Consider the distribution in Example 17 together with the finite set {a, aa}. Evidently, P(a | {a, aa}) = 20−2 √ 2 21 , which is not a rational number. Because this distribution has finite support, Proposition 18 shows it cannot be defined by a PCFG. 5.1 Algebraic Generating Functions The probabilities in Examples 13-17 are all algebraic numbers. This is an instance of a more general result about the pgf for any PCFG G. Assume Σ = {a} and N = {X0, . . . , Xn}. We will define a polynomial equation xi = Qi(z, x0, . . . , xn) in n + 2 variables for each nonterminal Xi. For a string α ∈ (N ∪ Σ)∗ let α be the result of replacing a with z, and Xi with xi for each non-terminal Xi (and let α = 1 if α = ε). Suppose in G we have both Xi 1/2→ α1 and Xi 1/2→ α2. Then our equation for Xi is: xi = 1 2 α1 + 1 2 α2 (6) with concatenation interpreted as multiplication. Likewise, if G has Xi 1→ α, then the equation for Xi is simply xi = α. G thus produces a system of n + 1 polynomial equations:x0... xn  = Q0(z, x0, . . . , xn)... Qn(z, x0, . . . , xn)  (7) 21 Example 18. Returning to Examples 3, 13, we obtain equation: x = 1 2 x2z + 1 2 z Solving for x gives an expression for the pgf, G(z) = ( 1− √ 1− z2 ) /z. By Theorem 15, even though the distribution in Example 3 only involves rational probability values, we have (see Kornai 2008; Bhattiprolu et al. 2017 for related observations): Proposition 20. The symmetric random walk distribution from Examples 3 and 13 cannot be defined by any probabilistic regular grammar. Toward a similar general limitative result for PCFGs, denote by gi the generating function GXiG (z) = ∑ ∞ k=0 P Xi G (a k)zk corresponding to the probability function PXiG , and let g be the vector (g0, . . . , gn)T . Lemma 21 now follows by a routine verification. (We leave off the subscript G in what follows.) Lemma 21. The vector g is a solution to the system of equations in (7); in other words, gi = Qi(z, g0, . . . , gn) for all i ≤ n. Proof. Suppose there is a single production for Xi, rewriting to a string with j occurrences of a and non-terminals Xj0 , . . . , Xjm (with possible repetitions). First note that: PXi (aj+k) = ∑ (l1+***+lm=k) ∏ t≤m P Xjt (alt) This implies that GXi (z) = ∞ ∑ k=0 PXi (aj+k)zj+k = ∞ ∑ k=0 ( ∑ (l1+***+lm=k) ∏ t≤m P Xjt (alt) ) zj+k = zj ∞ ∑ k=0 ( ∑ (l1+***+lm=k) ∏ t≤m P Xjt (alt) ) zk = zj ∏ t≤m ( ∞ ∑ k=0 P Xjt (ak)zk ) = zj ∏ t≤m GXjt (z) But zjxj0 . . . xjm is the exactly the monomial Qi. Similarly, if Xi has two productions, each with probability 1/2, a very similar argument goes through by appeal to Eq. 6. In particular, the first component g0 = GG(z) is the pgf for G overall. Lemma 21 does not quite show that g0 is an algebraic function in the sense of §2.2. We need to show that there is a polynomial equation 0 = Q(y, z) in variables y and z such that y = g0 is a solution. However, it is known from elimination theory that for any system like (7) there is such a polynomial Q(y, z) such that the first component of any solution to (7) is also a root of Q(y, z). See the Elimination Theorem on p. 16 of Cox et al. (2000). (See also the closely related discussions in Kuich and Salomaa 1986; Flajolet and Sedgewick 2001; Panholzer 2005.) Thus, we have the following result (cf. Booth and Thompson 1973; Yao 1985): 22 Theorem 22. The probability generating function for any PCFG on Σ = {a} is algebraic. In particular this means that there is no PCFG encoding a Poisson distribution (Example 1). The fact that PCFGs cannot represent all algebraic pgfs of course follows from Proposition 18 (cf. Proposition 24 below). Note that Theorem 22 is importantly different from the classic Chomsky-Schützenberger Theorem for non-probabilistic grammars (see Chomsky and Schützenberger 1963; Kuich and Salomaa 1986). The latter concerns word length counts, and states that the associated generating functions are algebraic for unambiguous context-free grammars. Indeed, the fact that context-free languages may possess transcendental generating functions is a useful tool for showing inherent ambiguity of a context-free language (Flajolet, 1987). By contrast, Theorem 22 applies to all PCFGs. At the same time, it has been shown that ambiguity is necessary for PCFGs to go beyond the power of PRGs for a one-letter alphabet: any distribution represented by a PCFG that is merely polynomially ambiguous-meaning that the number of parses for each word is bounded by a fixed polynomial in the word's length-can be represented by a PRG (Bhattiprolu et al., 2017), and hence will possess a rational probability generating function. It of course follows that the distributions in Examples 13-17 are all exponentially ambiguous. Finally, observe that essentially the same method used here to prove Theorem 22 could provide an alternative method of proof for Theorem 15, since for a PRG the system in (7) would be one of linear equations, and Gaussian elimination would produce a polynomial equation of degree 1. 6 Probabilistic Indexed Grammars Many grammar formalisms in between context-free and context-sensitive have been explored in computational linguistics (see, e.g., Kallmeyer 2010 for an overview covering many of them, including probabilistic extensions), and some of these have featured in psychological models of language processing (e.g., Levy 2008; Nelson et al. 2017). Yet there has been almost no study of their expressive capacity for defining probability distributions. Among the most well studied in the non-probabilistic setting are the indexed grammars, due to Aho (1968). The presentation here is a variation on that in Hopcroft and Ullman (1979). To N and Σ we add a finite set I of indices. Non-terminals are associated with a stack of indices and can pass on this stack to other non-terminals, in addition to pushing and popping indices from the stack at each step. Productions apply now to a pair X[l] of non-terminal together with a topmost index l ∈ I ∪ {ε} (which may be empty) on its stack. Productions may be of three types, where the third is relevant only when l 6= ε: 1. X[l]→ α[l] (copy indices to all non-terminals in α) 2. X[l]→ α[kl] (push index k and copy the result) 3. X[l]→ α (pop index l and copy the rest) In a parse, each non-terminal is tagged with a stack of indices, with the start symbol X0 initially carrying the empty index stack. The stack attached to the non-terminal on the left is then copied to all of the non-terminals appearing on the right-hand-side of the production, modulo a pop or push, while elements of Σ do not carry index stacks. 23 As in §2.3, a probabilistic indexed grammar satisfies the restriction that each pair of a nonterminal X and a top index l ∈ I ∪ {ε} appears on the left of 0, 1, or 2 productions, again with the usual probabilistic interpretation. All of the other definitions from §2.3 similarly remain unchanged. The main point about these grammars is the following: Proposition 23. Probabilistic indexed grammars can define distributions with transcendental pgfs. Proof. Here is a grammar defining P(a2 k ) = 2−k: X0[] 1→ Y[l] Y[l] 1/2→ Y[ll] Y[l] 1/2→ Z[l] Z[l] 1→ ZZ Z[] 1→ a We observed in Lemma 1 that its pgf is transcendental. This shows that we have gone beyond the expressive capacity of PCFGs, even for a one-letter alphabet. There are still relatively simple distributions that probabilistic indexed grammars cannot define. For example, the factorial language {ak! : k > 0}, while contextsensitive, has been shown beyond the capability of indexed grammars (Hayashi, 1973). A fortiori no probabilistic indexed grammar can define a distribution with this set as its support. Before moving to probabilistic context-sensitive grammars we first consider a natural and important restriction. 6.1 Probabilistic (Right-)Linear Indexed Grammars A notable proper subclass of the indexed grammars are the linear indexed grammars (Duske and Parchmann, 1984; Gazdar, 1988), where we assume-similar to a regular grammar (§2.3)-that at most one non-terminal appears on the right-hand-side of a production. This is an example of a mildly context-sensitive formalism, weakly equivalent to other well studied grammatical formalisms like tree-adjoining grammar and combinatory categorial grammar (Joshi et al., 1991). Despite the restriction, it is straightforward to show that the these grammars also extend PCFGs (see Duske and Parchmann 1984 for the nonprobabilistic case). That they do so properly is the next result. Proposition 24. Probabilistic linear indexed grammars can represent distributions that cannot be expressed by PCFGs. Proof. The following grammar defines a distribution with finite support, but also with irrational probabilities. X0[] 1/2→ a Y[l] 1/4→ Y[ll] Y[l] 1/2→ Y X0[] 1/2→ aY[l] Y[l] 1/4→ a Y[] 1→ ε With 1/2 probability X0 rewrites to aY[l], while Y[l] in turn rewrites to ε with irrational probability 2− √ 2 (recall Examples 14 and 17). Thus, P(a) = 3− √ 2 2 , while P(aa) = √ 2−1 2 . By Proposition 18, P cannot be defined by any PCFG. In fact, this grammar is not only linear, it is even right-linear, meaning that any nonterminal on the right-hand-side appears to the right of all terminal symbols (as in our definition of regular grammars from §2.3-in that case, right-linearity is not a substantive restriction; see Hopcroft and Ullman 1979). In the non-probabilistic setting, such grammars define exactly the context-free languages (Aho, 1968). But in the probabilistic setting they are evidently more expressive. As another example of a probabilistic right-linear indexed grammar, recall the tortoise and hare program defined earlier in Example 8: 24 Example 19 (Tortoise & Hare). We can mimic this program as follows: X0[] 1→ Y[l] Y[l] 1/6→ aY[l] Y[l] 1/6→ aZ Y[] 1→ ε Y[l] 1/2→ aY[ll] Y[l] 1/6→ aY Z[l] 1→ Y Z[] 1→ ε The probability that X0[] rewrites to ak is exactly the probability that the program in Example 8 returns k, i.e., that the hare catches up in k steps. Although the distribution is rational-valued, we conjecture that it is not PCFG-definable. Given aforementioned results from the literature, Proposition 24 may seem surprising. Right-linear indexed grammars can be seen as grammatical versions of counter or pushdown automata (Duske et al., 1992), and there are several proofs implying that probabilistic pushdown automata and PCFGs are equally expressive (Abney et al. 1999; Chi 1999; see also the discussion in Smith and Johnson 2007). The apparent tension is resolved by observing that the proofs in Abney et al. (1999) and Chi (1999) require solutions to nonlinear equations in order to define the requisite probabilities in the corresponding equivalent PCFG. Proposition 18 simply shows that this cannot always be done if we only have recourse to rational weights. The correspondence thus breaks down in our setting. Probabilistic right-linear indexed grammars may therefore provide a better match to probabilistic pushdown automata or the equivalent ("multi-exit") recursive Markov chains. Linear indexed grammars are unable to define the language {a2k : k > 0} (they define only semi-linear languages in the sense of Parikh 1966; see Duske and Parchmann 1984); a fortiori probabilistic (right-)linear indexed grammars cannot define the distribution P(a2 k ) = 2−k, and thus fall short of general indexed grammars. In fact, following from their correspondence with pushdown automata (Duske et al., 1992), and drawing on existing results for the latter (Kuich and Salomaa, 1986, Theorem 14.15), these grammars can also be associated with algebraic generating functions. 7 Probabilistic Context-Sensitive Grammars Grammars applied to natural language have typically been less powerful than the indexed grammars, and certainly less powerful than context-sensitive. In fact, over the decades there have been numerous explicit arguments that context-sensitive grammars are too complex (Chomsky, 1959; Savitch, 1987; Joshi et al., 1991). Probabilistic context-sensitive grammars (PCSGs) have rarely been considered, although they have occasionally appeared, e.g., in vision (Zhu and Mumford, 2007) and planning (Pynadath and Wellman, 1998). Propositions 29 and 30 below, together offer some further explanation for this relative absence. In the classical hierarchy, context-sensitive grammars properly extend the indexed grammars (Aho, 1968), even in the case of a one-letter alphabet, witness the factorial language {ak! : k > 0} (Hayashi, 1973). Correspondingly, there are distributions definable by PCSGs that elude any probabilistic indexed grammar, as shown below in Proposition 28. To gain a better understanding of PCSGs, a helpful first observation is that, as in the classical case (Hopcroft and Ullman, 1979), the requirement on PCSGs given in §2.3 is equivalent to the intuitive stipulation that |α| ≤ |β|whenever (α→ β) ∈ Π. Such a non-contracting grammar may also include X0 → ε if X0 does not appear on the right-hand-side of any production. Lemma 25. Any distribution defined by a non-contracting probabilistic grammar G1 can also be defined by a PCSG G0. 25 Proof. For each a ∈ Σ include a new non-terminal Xa and add production Xa → a to G0. Replace a throughout G1 with Xa. For each production in G1 of the form (Y1 . . . Yn → Z1 . . . Zm) with 2 ≤ n ≤ m, add n non-terminals W1, . . . , Wn, and 2n productions to G0: Y1Y2 . . . Yn−1Yn → W1Y2 . . . Yn−1Yn W1Y2 . . . Yn−1Yn → W1W2 . . . Yn−1Yn ... W1 . . . Wn−1Yn → W1 . . . Wn−1WnZn+1 . . . Zm W1 . . . WnZn+1 . . . Zm → Z1 . . . Wn−1WnZn+1 . . . Zm ... Z1 . . . WnZn+1 . . . Zm → Z1 . . . ZnZn+1 . . . Zm The PCSG G0 thus defines the same distribution as G1. Lemma 25 suggests a natural class of PTMs corresponding to PCSGs, namely those that never write a blank symbol t, so called non-erasing PTMs. The non-probabilistic version of these machines was studied early on by Wang (1957) (see also Minsky 1967), though the connection to context-sensitive grammars seems not to have been noted in the literature. In this section we allow using one more symbol C, and assume the convention for a PTM to output σ is having BσC on the tape followed by an infinite sequence of blank symbols. It is evident that nothing from §3 will be affected by this. Theorem 26. PCSGs and non-erasing PTMs are equivalent. Proof. The proof of Proposition 2 nearly already shows that any non-erasing PTM can be emulated by a PCSG. Since a non-erasing PTM will never write t, we require only a slight modification of the construction so that Xn+1 moves to the right of the string and finally rewrites to C. All rules in this modified construction are non-contracting. For the other direction, we need to show that a non-erasing PTM can identify the highest priority substring, flip a coin to determine whether to rewrite it and what to rewrite it as, and then finally to rewrite it, possibly moving the remainder of the string to the right in case the rewrite is longer. Identifying the highest priority substring α can be done without changing the string at all, provided we are always writing C at the end. When a rule (α → β) is identified the machine enters a fixed subroutine which involves going to the end of α and checking whether that is also the end of the string. If it is, we move C over |β| − |α| places and then easily perform the fixed rewrite. If it is not the end, then we first replace the last symbol of α with another C; then we start shifting all of the extra symbols to the right |β| − |α| places until we hit C to the left. At that point we know we are |α| places to the right of the start of α, so we return to the beginning of α and simply write out β, finally returning to the beginning of the string. Proposition 27. PCSGs can define transcendental pgfs. Proof. There is a PCSG defining the distribution P(a2 k ) = 2−k, which we know by Lemma 1 has a transcendental pgf. This could be shown in two ways. First, we could explicitly define the PCSG, for instance by massaging the grammar in Example 7 into context-sensitive form (cf. Example 9.5 in Hopcroft and Ullman 1979). Alternatively, we can describe a nonerasing PTM that defines P(a2 k ) = 2−k and appeal to Theorem 26. The machine first writes 26 aa. From this point it iteratively flips a coin and every time we see heads we double the string. This latter operation can be done without ever writing t: rewrite the first a as C and then move to the right until seeing t, rewriting it too as C. Write a to the right of C and then go back until seeing the first a. If the next symbol to the left of that a is also an a, then repeat, rewriting it as C and moving to the end of the string writing another a. But if the next symbol to the left of the a is C, then we know we are done, in which case we rewrite each C as a and move back to the B symbol. Enter s# upon seeing a first tails. Invoking Theorem 26 again, it is also straightforward to show that a Turing machine can copy a sequence of 1s an increasing number of times, continuing again until witnessing a tails, without ever erasing any symbols. This means that there is a PCSG defining the measure P(ak!) = 2−k for k > 0, which implies: Proposition 28. PCSGs can define distributions that elude probabilistic indexed grammars. PCSGs can thus define complex distributions. The following proposition gives a further sense of how complex they can be. The statement is similar to an earlier result on nonprobabilistic context-sensitive grammars due to Savitch (1987): Proposition 29. Consider any computably enumerable semi-measure P : Σ∗ → [0, 1]. There is a PCSG (equivalently, non-erasing PTM) on augmented vocabulary Σ ∪ {C} defining a semimeasure P such that P(σ) = ∑n P(σCn) for all σ ∈ Σ∗. Proof Sketch. In the construction of a probabilistic grammar from a (possibly erasing) PTM in the proof of Theorem 2, whenever the PTM would write a t, instead write a C. That is, the probability that a PTM returns σ is exactly the same as the probability that the PCSG returns σ together with some extra "dummy" symbols tacked on to the end. Despite the fact that PCSGs in some sense encompass all of the complexity of enumerable semi-measures, there is another sense in which they are even weaker than PCFGs. Proposition 30. For every PCSG F and every word σ, the probability PG(σ) is a rational number. Proof. We again invoke Theorem 26 to prove the result. Suppose we are given a non-erasing PTM T . We show that PT (σ) is rational for every σ. The critical observation is that any non-erasing PTM T that produces a string BσC will only ever write to |σ|+ 2 tape cells, on any possible successful execution. So we can consider the finite set C of all possible configurations [s, η, i] leading up to BσC being on the tape in state s# while reading B. Here, s is the current state, η is the string written on the |η| = |σ|+ 2 many tape cells, and i < |σ|+ 2 is the index of the symbol currently being read. From this description we can naturally define a PRG over alphabet {a} as follows. Include a non-terminal Xc for each configuration c ∈ C other than the final one, and let X0 correspond to the initial configuration [s0,Bt|σ|+1, 0]. If configuration c2 follows configuration c1 when T is reading random bit 0, then-unless c2 is the final configuration-include a rule Xc1 → Xc2 ; and likewise when T is reading random bit 1. If in either case c2 is the final configuration, then include a rule Xc1 → a. Evidently, PT (σ) = PG(a), and so the result follows from Proposition 13. Proposition 30 may seem perplexing in light of the fact that the context-sensitive languages properly extend the context-free languages, and even the indexed languages. The crux of the matter is the treatment of the empty string. Going back to Chomsky (1959), 27 the context-sensitive languages only extend the context-free provided we stipulate that we can always add the empty string to a language, e.g., by allowing (X0 → ε) when X0 never occurs on the right-hand-side of any production. Examples 14-17 from §5 and Proposition 30 together show that this maneuver reverberates in a serious way once we turn to the probabilistic setting. Perhaps unintuitively, PCSGs cannot even define the seemingly simple distributions in Examples 14 and 17, for instance. Thus, while it may be that "almost any language one can think of is context-sensitive" (Hopcroft and Ullman, 1979), this is evidently not true of distributions defined by probabilistic context-sensitive grammars. From Corollary 9 and Propositions 13, 18, and 30 we obtain: Corollary 31. PRGs, PCFGs, and PCSGs all define exactly the same finite-support distributions, namely the rational-valued finite-support distributions. By this point we have substantiated all of the qualitative relationships in the probabilistic hierarchy depicted in Figure 1. The fact that there are distributions defined by probabilistic linear indexed grammars but by neither PCSGs nor PCFGs follows from Propositions 24 and 30. Perhaps less obviously, we also now know that there are distributions defined by probabilistic indexed grammars that elude both their linear variant and PCSGs. To see this, let G4 be a probabilistic indexed grammar with PG1(a 2k ) = 2−k for k > 1 (easily definable by a variation on the construction in the proof of Proposition 23), and let G5 be the grammar presented in the proof of Proposition 24. Define a new grammar G6 employing a new start symbol that rewrites to the start symbols of G4 and G5, each with probability 1/2. Evidently PG6 assigns probability 3− √ 2 4 to a, probability √ 2−1 4 to aa, and probability 1/2k+1 to every string a2 k , k > 1. Clearly PG6 cannot be defined using a linear indexed grammar or by any PCSG. Furthermore we require only a one-letter alphabet. 8 Conclusion and Further Issues The hierarchy of expressible distributions that emerges in Figure 1 reveals how much the probabilistic setting can differ from the classical setting of formal language theory. Proper inclusions going up the hierarchy mirroring the classical case might have been expected; yet we reach incomparability already between the context-sensitive and context-free distributions, a pattern that continues through the indexed languages. Furthermore, grammar classes that are classically equivalent-such as the context-free and right-linear indexed grammars-come apart in the probabilistic setting. And unlike in the classical setting, all of these relationships can be observed even with distributions on one-letter alphabets, pace Parikh's theorem. A third theme is the significance of finite-support distributions. Probabilistic context-free grammars define algebraic probability generating functions and probabilistic context-sensitive grammars can define transcendental pgfs; yet when it comes to finite-support distributions they both collapse into the rational-valued measures, already definable by probabilistic regular grammars. Of the grammars studied here, only probabilistic (right-linear) indexed (and of course unrestricted) grammars can define irrationalvalued measures with finite support. 8.1 Outstanding Mathematical Questions Despite clarifying all of the inclusion/exclusion relationships among the classes in Figure 1, and establishing a partial correspondence between the probabilistic grammar hierarchy 28 and the analytical hierarchy (rational, algebraic, transcendental pgfs), a number of fundamental open questions remain. Some of the most significant technical questions include: 1. We have provided a full characterization of the distributions defined by probabilistic grammars and by almost-surely terminating grammars in general. But is it possible to provide full and informative characterizations any of the proper subclasses? 2. In particular, are the distributions defined by PRGs with rational weights exactly the rational-valued distributions with rational pgfs? 3. What (proper) subclass of algebraic pgfs do PCFGs define? 4. Are the distributions defined by probabilistic right-linear indexed grammars exactly the algebraic-number-valued distributions with algebraic pgfs? Or is there another class of grammars that would define this class of distributions? 5. Which subclasses of transcendental pgfs do PCSGs and indexed grammars define? Can we show that distributions like that in Example 8 cannot be defined by PCFGs? 6. What other closure results for conditioning can be obtained, aside from Theorems 6, 7, and 17, and Proposition 19? 7. Do we obtain more interesting distributions by going beyond the indexed languages to higher levels of the so called hierarchy of indexed languages (Maslov, 1976)? 8. How high in the hierarchy do we need to go in order to define a Poisson distribution (Example 1), or the distribution in Example 9, among others? 9. What other natural operations defined on grammars make sense in the context of probabilistic modeling? For instance, suppose we added a special primitive nonterminal P that produces a string ak with probability given by a Poisson distribution? What would be obtain by adding this to the probabilistic regular grammars, or to other grammar classes? 10. Which distributions can be defined by adding probabilities in the so called subregular hierarchy, including classes that do not correspond to any natural grammar notions (Schützenberger, 1965; Jäger and Rogers, 2012)? 11. What can be said about classes between regular and context-free grammars, such as the linear or the "simple" context-free grammars (Hopcroft and Ullman, 1979)? 12. How might the results reported here shed light on questions about how tractably distributions at one level of the hierarchy can be approximated by distributions defined at lower levels? (See, e.g., Mohri and Nederhof 2000 for some results on this.) To be sure, one can imagine many more natural questions still to be answered. 8.2 Generative Models in Psychology Conceptually, what does the pattern of results reported here mean for psychological modeling? Questions about the tradeoff between expressivity and complexity, along various dimensions, of psychological models are quite familiar in the study of natural language, at 29 least since Chomsky (1959, 1965). But they are also of interest in nearly every other psychological domain. A guiding methodological principle is to give special attention to the simplest candidate models-those that require least of the agent being modeled-among those that adequately capture the phenomena of interest (see, e.g., Feldman 2016). Human learning is assumed to abide by a similar maxim, preferring the simplest hypotheses that account for observed patterns (Chater and Vitányi, 2003). The (probabilistic) Chomsky-Schützenberger hierarchy highlights a salient notion of complexity, one that harmonizes well with other independent and potentially relevant notions of complexity (e.g., the computational cost of parsing; see Pratt-Hartmann 2010). Parts of the hierarchy have furthermore been used to explain differences in the processing of quantifier expressions in natural language (Szymanik and Zajenkowski, 2010), and have even been claimed to demarcate a meaningful boundary between human and non-human thought (e.g., Berwick et al. 2011; for a dissenting view see, for instance, Jackendoff 2011). It is often asserted that we essentially know without any further ado that the human mind can at most be a (probabilistic) finite-state machine, if only because the brain itself is finite (see, e.g., Eliasmith 2010; Petersson et al. 2012 for different expressions of this view). On this picture the entire hierarchy collapses into the finite-state/regular. At the other extreme we see claims to the effect that the phenomena force us to the top of the hierarchy: Formalizing the full content of intuitive theories appears to require Turingcomplete compositional representations, such as probabilistic first-order logic and probabilistic programming languages (Tenenbaum et al., 2011, p. 1284). Our study lends support to both of these positions. On the one hand, Theorem 3 shows definitively that the class of all probabilistic grammars-which also express exactly the distributions defined by Turing-complete probabilistic programming languages-can encode virtually any discrete distribution that has ever been used for modeling, including those that strictly elude lower levels in the hierarchy. On the other hand, Corollary 9 shows that the much simpler probabilistic regular grammars can already define a number of prominent distributions, and are capable in principle of providing effective approximations to any distribution whatsoever; this is noteworthy insofar as approximation is inevitable when encoding continuous distributions anyway (recall the discussion in §4.1). Furthermore, both of these classes of distributions are closed under conditioning with the corresponding natural classes of events (Theorems 7 and 17). Needless to say, for many purposes neither extreme may be apt. Feasible finite-state distributions may provide too poor approximations for targets of interest, whereas the enumerable semi-measures-perhaps learnable in theory (Chater and Vitányi, 2003; Vitányi and Chater, 2017)-may form too large a class for tractable learning. In between the two extremes are natural classes capturing useful and intuitive distributions such as those associated with random walks (Examples 3, 8) or those associated with complex but constrained grammatical phenomena in natural language (Chomsky, 1965; Joshi et al., 1991). A recent trend has been to construe much of learning, even outside the domain of language, as a matter of inducing stochastic procedures, formalized as grammars or programs (see, e.g., Lake et al. 2015). Here the tradeoff between expressivity and tractability becomes especially poignant: some bias toward simpler programs is highly desirable, but it should not be so strong that it frustrates discovery of a good enough probabilistic model. Results like those reported here help us understand one side of this essential tradeoff. At the same time, from a skeptical viewpoint, the pattern of results may cast doubt on whether the framework overall is appropriate for capturing the most important computa30 tional distinctions in cognition. As mentioned at the outset, the instantaneous firing rate of cortical neurons is assumed to be approximately Poisson distributed. Thus, in some sense, the Poisson distribution appears at what is plausibly a very basic level of cortical computation. In sharp contrast, this distribution evades expression until only the top level of the probabilistic Chomsky-Schützenberger hierarchy. The source of this discrepancy is not the restriction to rational parameters either, for instance, to be addressed by adding e−λ as a production weight; rather, the issue is structural (Theorem 15, Proposition 22). To be sure, there are a variety of computational frameworks founded on more brainlike temporal and network dynamics (e.g., Maass et al. 2002, among many others). Such frameworks may ultimately carve the space of computational models along different dimensions. However, even within these research programs some of the most pressing questions concern how such frameworks might plausibly encode probabilistic generative models (Buesing et al., 2011) and other combinatorial generative mechanisms (Dehaene et al., 2015; Nelson et al., 2017). For much of psychology and cognitive science, theorizing in terms of generative models is intuitive, simple, and productive. We would like a comprehensive theoretical understanding of the capabilities and limitations of these models. Acknowledgements Part of this work was supported by the Center for the Study of Language and Information, Stanford University. The author would like to thank audiences at the Chennai Institute of Mathematical Sciences, Indiana University, Stanford University, and the Center for Brains, Minds, and Machines at MIT. Thanks especially to the editors and reviewers at Journal of Mathematical Psychology, and to Johan van Benthem, Roger Levy, Alex Lew, Larry Moss, Milan Mosse, R. Ramanujam, and Josh Tenenbaum for helpful comments and questions. References Abbott, J. T., Austerweil, J. L., and Griffiths, T. L. (2015). Random walks on semantic networks can resemble optimal foraging. Psychological Review, 122(3):558–569. Abney, S., McAllester, D. A., and Pereira, F. (1999). Relating probabilistic grammars and automata. In Proceedings of the 37th Annual Meeting of the Association for Computational Linguistics (ACL), pages 542–549. Ackerman, N. L., Freer, C. E., and Roy, D. M. (2019). On the computability of conditional probability. Journal of the ACM, 66(3):1–40. Aho, A. (1968). Indexed grammars-an extension of context-free grammars. Journal of the ACM, 15(4):647–671. Berwick, R. C., Okanoya, K., Backers, G. J., and Bolhuis, J. J. (2011). Songs to syntax: the linguistics of birdsong. Trends in Cognitive Sciences, 15(3):113–121. Bhattiprolu, V., Gordon, S., and Viswanathan, M. (2017). Parikh's Theorem for weighted and probabilistic context-free grammars. In Bertrand, N. and Bortolussi, L., editors, Quantitative Evaluation of Systems (QEST 2017). Lecture Notes in Computer Science, vol 10503. Springer. 31 Billingsley, P. (1999). Convergence of Probability Measures. Wiley Series in Probability and Mathematical Statistics, 2 edition. Booth, T. L. and Thompson, R. A. (1973). Applying probability measures to abstract languages. IEEE Transactions on Computers, C-22(5):442–450. Buesing, L., Bill, J., Nessler, B., and Maass, W. (2011). Neural dynamics as sampling: A model for stochastic computation in recurrent networks of spiking neurons. PLoS Computational Biology, 7(11). Busemeyer, J. R. and Diederich, A. (2002). Survey of decision field theory. Mathematical Social Sciences, 43:345–370. Chaitin, G. J. (1975). A theory of program size formally identical to information theory. Journal of the ACM, 22(3):329–340. Chater, N. and Manning, C. D. (2006). Probabilistic models of language processing and acquisition. Trends in Cognitive Sciences, 10(7):335–344. Chater, N. and Oaksford, M. (2013). Programs as causal models: Speculations on mental programs and mental representation. Cognitive Science, 37(6):1171–1191. Chater, N. and Vitányi, P. (2003). Simplicity: a unifying principle in cognitive science? Trends in Cognitive Sciences, 7(1):19–22. Chi, Z. (1999). Statistical properties of probabilistic context-free grammars. Computational Linguistics, 25(1):131–160. Chomsky, N. (1959). On certain formal properties of grammars. Information & Control, 2:137–167. Chomsky, N. (1965). Aspects of the Theory of Syntax. MIT Press. Chomsky, N. and Schützenberger, M. P. (1963). The algebraic theory of context-free languages. In Hirschberg, D. and Braffort, P., editors, Computer Programming and Formal Systems, pages 118–161. North-Holland. Cox, D., Little, J., and O'Shea, D. (2000). Ideals, Varieties, and Algorithms. Springer Verlag. Dal Lago, H. and Zorzi, M. (2012). Probabilistic operational semantics for the lambda calculus. RAIRO Theoretical Informatics and Applications, 46(3):413–450. Dehaene, S., Meyniel, F., Wacongne, C., Wang, L., and Pallier, C. (2015). The neural representation of sequences: from transition probabilities to algebraic patterns and linguistic trees. Neuron, 88:2–19. Denison, S., Bonawitz, E., Gopnik, A., and Griffiths, T. L. (2013). Rational variability in children's causal inferences: the sampling hypothesis. Cognition, 126:285–300. Droste, M., Kuich, W., and Vogler, H., editors (2009). Handbook of Weighted Automata. Springer. Dupont, P., Denis, F., and Esposito, Y. (2005). Links between probabilistic automata and hidden Markov models: probability distributions, learning models and induction algorithms. Pattern Recognition, 38:1349–1371. 32 Duske, J., Middendorf, M., and Parchmann, R. (1992). Indexed counter languages. Theoretical Informatics & Applications, 26(1):93–113. Duske, J. and Parchmann, R. (1984). Linear indexed languages. Theoretical Computer Science, 32:47–60. Eilenberg, S. (1974). Automata, Language, and Machines. Academic Press. Eliasmith, C. (2010). How we ought to describe computation in the brain. Studies in History & Philosophy of Science Part A, 41(3):313–320. Etessami, K. and Yannakakis, M. (2009). Recursive Markov chains, stochastic grammars, and monotone systems of nonlinear equations. Journal of the ACM, 65(1):1–66. Faisal, A. A., Selen, L. P. J., and Wolpert, D. M. (2008). Noise in the nervous system. Nature Reviews Neuroscience, 9:292–303. Feldman, J. (2016). The simplicity principle in perception and cognition. Wiley Interdisciplinary Reviews: Cognitive Science, 7(5):330–340. Flajolet, P. (1987). Analytic models and ambiguity of context-free languages. Theoretical Computer Science, 49:283–309. Flajolet, P., Pelletier, M., and Soria, M. (2011). On Buffon machines and numbers. In Proceedings of the 22nd Annual ACM-SIAM Symposium on Discrete Algorithms (SODA 2011), pages 172–183. Flajolet, P. and Sedgewick, R. (2001). Analytic combinatorics: Functional equations, rational and algebraic functions. Technical Report RR4103, INRIA. Freer, C. E., Roy, D. M., and Tenenbaum, J. B. (2014). Towards common-sense reasoning via conditional simulation: Legacies of Turing in artificial intelligence. In Downey, R., editor, Turing's Legacy. ASL Lecture Notes in Logic. Gács, P. (2005). Uniform test of algorithmic randomness over a general space. Theoretical Computer Science, 2005:91–137. Gazdar, G. (1988). Applicability of indexed grammars to natural languages. In Reyle, U. and Rohrer, C., editors, Natural Language Parsing and Linguistic Theories. Springer Verlag. Gershman, S. J. and Blei, D. M. (2012). A tutorial on Bayesian nonparametric models. Journal of Mathematical Psychology, 56(1):1–12. Glimcher, P. W. (2005). Indeterminacy in brain and behavior. Annual Review of Psychology, 56:25–56. Goodman, N. D. and Tenenbaum, J. B. (2016). Probabilistic Models of Cognition. http: //probmods.org/v2. Accessed: 2019-8-5. Griffiths, T. L., Daniels, D., Austerweil, J. L., and Tenenbaum, J. B. (2018). Subjective randomness as statistical inference. Cognitive Psychology, 103:85–109. Griffiths, T. L., Steyvers, M., and Tenenbaum, J. B. (2007). Topics in semantic representation. Psychological Review, 114(2):211–244. 33 Harris, T. E. (1963). The Theory of Branching Processes. Springer. Hayashi, T. (1973). On derivation trees of indexed grammars. Publications of the Research Institute for Mathematical Sciences, 9(1):61–92. Hinton, G. E. and Sejnowski, T. J. (1983). Optimal perceptual inference. In Proceedings of the IEEE Conference on Computer Vision & Pattern Recognition, pages 448–453. Hopcroft, J. E. and Ullman, J. D. (1979). Introduction to Automata Theory, Languages, and Computation. Addison-Wesley, 1st edition. Icard, T. (2019). Why be random? Mind. DOI: 10.1093/mind/fzz065. Icard, T. F. (2017a). Beyond almost-sure termination. In Proceedings of the 39th Annual Meeting of the Cognitive Science Society. Icard, T. F. (2017b). From programs to causal models. In Cremers, A., van Gessel, T., and Roelofsen, F., editors, Proceedings of the 21st Amsterdam Colloquium, pages 35–44. Jackendoff, R. (2011). What is the human language faculty? Two views. Language, 87:586– 624. Jäger, G. and Rogers, J. (2012). Formal language theory: Refining the Chomsky hierarchy. Philosophical Transactions of the Royal Society B, 367:1956–1970. Johnson, M. (2010). PCFGs, topic models, adaptor grammars and learning topical collocations and the structure of proper names. In Proceedings of the 48th Annual Meeting of the Association for Computational Linguistics (ACL), pages 1148–1157. Johnson, N. L., Kemp, A. W., and Kotz, S. (2005). Univariate Discrete Distributions. Wiley Series in Probability and Statistics, 3rd edition. Joshi, A. K., Vijay-Shanker, K., and Weir, D. J. (1991). The convergence of mildly contextsensitive grammar formalisms. In Sells, P., Shieber, S. M., and Wasow, T., editors, Foundational Issues in Natural Language Processing. MIT Press. Jungen, R. (1931). Sur les séries de Taylor n'ayant que des singularités algébricologarithmiques sur leur cercle de convergence. Commentarii Mathematici Helvetici, 3:226– 306. Kallmeyer, L. (2010). Parsing Beyond Context-Free. Springer Verlag. Kaminski, B. L. and Katoen, J.-P. (2015). On the hardness of almost-sure termination. In Mathematical Foundations of Computer Science, pages 307–318. Kim, Y., Dyer, C., and Rush, A. M. (2019). Compound probabilistic context-free grammars for grammar induction. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics (ACL), pages 2369–2385. Klein, D. and Manning, C. D. (2003). Accurate unlexicalized parsing. In Proceedings of the 41st Meeting of the Association for Computational Linguistics (ACL), pages 423–430. Knill, D. C. and Pouget, A. (2004). The Bayesian brain: the role of uncertainty in neural coding and computation. Trends in Neurosciences, 27(12):712–719. 34 Knuth, D. E. and Yao, A. C. (1976). The complexity of nonuniform random number generation. In Algorithms and Complexity, pages 357–428. Academic Press. Kornai, A. (2008). Mathematical Linguistics. Springer Verlag. Kress, R. (1998). Numerical Analysis. Springer. Kuich, W. and Salomaa, A. (1986). Semirings, Automata, Languages. Springer Verlag. Lake, B. M., Salakhutdinov, R., and Tenenbaum, J. B. (2015). Human-level concept learning through probabilistic program induction. Science, 350(6266):1332–1338. de Leeuw, K., Moore, E. F., Shannon, C. E., and Shapiro, N. (1956). Computability by probabilistic machines. In Automata Studies, pages 183–212. Princeton University Press. Levy, R. (2008). Expectation-based syntactic comprehension. Cognition, 106:1126–1177. Li, Y., Schofield, E., and Gönen, M. (2019). A tutorial on Dirichlet process mixture modeling. Journal of Mathematical Psychology, 91:128–144. Liang, P., Jordan, M. I., and Klein, D. (2010). Probabilistic grammars and hierarchical Dirichlet processes. In O'Hagan, T. and West, M., editors, The Handbook of Applied Bayesian Analysis, pages 776–822. Oxford University Press. Lin, H. W. and Tegmark, M. (2017). Critical behavior in physics and probabilistic formal languages. Entropy, 19(299). Maass, W., Natschläger, T., and Markram, H. (2002). Real-time computing without stable states: A new framework for neural computation based on perturbations. Neural Computation, 14:2531–2560. MacKay, D. J. C. (1996). Equivalence of linear Boltzmann chains and hidden Markov models. Neural Computation, 8(1):178–181. Maslov, A. N. (1976). Multilevel stack automata. Problemy peredachi informatsii, 12(1):55–62. Miller, G. A. (1952). Finite Markov processes in psychology. Psychometrika, 17(2). Minsky, M. (1967). Computation: Finite and Infinite Machines. Prentice Hall. Mohri, M. and Nederhof, M.-J. (2000). Regular approximation of context-free grammars through transformation. In Junqua, J.-C. and van Noord, G., editors, Robustness in Language and Speech Technology, pages 252–261. Kluwer. Nederhof, M.-J. and Satta, G. (2003). Probabilistic parsing as intersection. In Proceedings of the 8th International Conference on Parsing Technologies. Nelson, M. J., El Karoui, I., Giber, K., Yang, X., Cohen, L., Koopman, H., Cash, S. S., Naccache, L., Hale, J. T., Pallier, C., and Dehaene, S. (2017). Neurophysiological dynamics of phrase-structure building during sentence processing. Proceedings of the National Academy of Sciences, 114(18):3669–3678. Nishioka, K. (1996). Mahler Functions and Transcendence. Springer Verlag. 35 Nosofsky, R. M. and Palmeri, T. J. (1997). An exemplar-based random walk model of speeded classification. Psychological Review, 104(2):266–300. O'Cinneide, C. A. (1990). Characterization of phase-type distributions. Communications in Statistics. Stochastic Models, 6:1–57. Olmedo, F., Kaminski, B. L., Katoen, J.-P., and Matheja, C. (2016). Reasoning about recursive probabilistic programs. In Proceedings of the 31st Annual IEEE Symposium on Logic in Computer Science (LICS), pages 672–681. Orbán, G., Berkes, P., Fiser, J., and Lengyel, M. (2016). Neural variability and samplingbased probabilistic representations in the visual cortex. Neuron, 92:530–543. Panholzer, A. (2005). Gröbner bases and the defining polynomial of a context-free grammar generating function. Journal of Automata, Languages & Combinatorics, 1:79–97. Parikh, R. (1966). On context-free languages. Journal of the ACM, 13(4):570–581. Paz, A. (1971). Introduction to Probabilistic Automata. Academic Press. Pearl, J. (1988). Probabilistic Reasoning in Intelligent Systems: Networks of Plausible Inference. Morgan Kaufmann. Petersson, K.-M., Folia, V., and Hagoort, P. (2012). What artificial grammar learning reveals about the neurobiology of syntax. Brain & Language, 120:83–95. Petre, I. (1999). Parikh's theorem does not holds for multiplicities. Journal of Automata, Languages, & Combinatorics, 4(3):17–30. Pratt-Hartmann, I. (2010). Computational complexity in natural language. In Clark, A., Fox, C., and Lappin, S., editors, The Handbook of Computational Linguistics and Natural Language Processing, pages 43–73. Blackwell. Putnam, H. (1967). Psychological predicates. In Capitan, W. H. and Merrill, D. D., editors, Art, Mind, and Religion. Pittsburgh University Press. Pynadath, D. V. and Wellman, M. P. (1998). Generalized queries on probabilistic contextfree grammars. IEEE Transactions on Pattern Analysis & Machine Intelligence, 20(1):65–77. Rabin, M. O. (1963). Probabilistic automata. Information & Control, 6(3):230–245. Ratcliff, R. (1978). A theory of memory retrieval. Psychological Review, 85(2):59–108. Salomaa, A. and Soittola, M. (1978). Automata-Theoretic Aspects of Formal Power Series. Springer. Sanborn, A. N., Griffiths, T. L., and Navarro, D. J. (2010). Rational approximations to rational models: Alternative algorithms for category learning. Psychological Review, 117(4):1144–1167. Savitch, W. J. (1987). Context-sensitive grammar and natural language syntax. In Savitch, W. J., Bach, E., Marsh, W., and Safran-Naveh, G., editors, The Formal Complexity of Natural Language, pages 358–368. Springer (Studies in Linguistics and Philosophy). 36 Schützenberger, M. P. (1961). On the definition of a family of automata. Information & Control, 4:245–270. Schützenberger, M. P. (1965). On finite monoids having only trivial subgroups. Information & Control, 8:190–194. Smith, N. A. and Johnson, M. (2007). Weighted and probabilistic context-free grammars are equally expressive. Computational Linguistics, 33(4):477–491. Soittola, M. (1976). Positive rational sequences. Theoretical Computer Science, 2:313–321. Stanley, R. P. (2011). Enumerative Combinatorics, volume 1. Cambridge University Press. Szymanik, J. and Zajenkowski, M. (2010). Comprehension of simple quantifiers: Empirical evaluation of a computational model. Cognitive Science, 34(3):521–532. Tenenbaum, J. B., Griffiths, T. L., and Kemp, C. (2006). Theory-based Bayesian models of inductive learning and reasoning. Trends in Cognitive Sciences, 10(7):309–318. Tenenbaum, J. T., Kemp, C., Griffiths, T., and Goodman, N. D. (2011). How to grow a mind: Statistics, structure, and abstraction. Science, 331:1279–1285. Townsend, J. T. and Ashby, F. G. (1983). The Stochastic Modeling of Elementary Psychological Processes. Cambridge University Press. Turing, A. M. (1950). Computing machinery and intelligence. Mind, 59:433–460. Vitányi, P. M. B. and Chater, N. (2017). Identification of probabilities. Journal of Mathematical Psychology, 76(A):13–24. von Neumann, J. (1951). Various techniques used in connection with random digits. Journal of Research of the National Bureau of Standards, Applied Mathematics Series, 12:36–38. Vul, E., Hanus, D., and Kanwisher, N. (2009). Attention as inference: Selection is probabilistic; responses are all-or-none samples. Journal of Experimental Psychology: General, 138(4):546–560. Wang, H. (1957). A variant to Turing's theory of computing machines. Journal of the ACM, 4(1):63–92. Wilson, R. C., Geana, A., White, J. M., Ludwig, E. A., and Cohen, J. D. (2014). Humans use directed and random exploration to solve the explore-exploit dilemma. Journal of Experimental Psychology: General, 143(6):2074–2081. Wood, I., Sunehag, P., and Hutter, M. (2011). (Non-)equivalence of universal priors. In Dowe, D., editor, Solomonoff 85th Memorial Conference, pages 417–425. Springer LNCS. Yao, A. C. (1985). Context-free grammars and random number generation. In Apostolico, A. and Galil, Z., editors, Combinatorial Algorithms on Words, volume 12, pages 357–361. Springer. Zhu, S.-C. and Mumford, D. (2007). A stochastic grammar of images. Foundations & Trends in Computer Graphics & Vision, 2(4):259–362. Zvonkin, A. K. and Levin, L. A. (1970). The complexity of finite objects and the development of the concepts of information and randomness by means of the theory of algorithms. Uspekhi Matematicheskikh Nauk, 25(6):85–127.