ConceptioArchivearXiv CS
arXiv CSopen access

Complexity Theory of Randomised Testing

Unknown · 2026 · arxiv_cs
arXiv CS · Papers · License: Open Access · 2026
Open Source ↗Direct PDF ↓
softwarearchitecturesoftwareengineeringtesting
software engineering, software architecture, testing

Complexity Theory of Randomised Testing

arXiv:2607.11811v1 [cs.PL] 13 Jul 2026

PINGSHI YU, Imperial College London, United Kingdom CHENGSONG TAN, Kaihong, China NICOLAS WU, Imperial College London, United Kingdom ALASTAIR DONALDSON, Imperial College London, United Kingdom Randomised testing is a widely-used approach to software validation, yet despite years of practical development its theoretical foundations remain thin. In particular, the fundamental question of what it means for a set of inputs to be generable has gone unanswered in both the literature and folklore. We present, for the first time, complexity-theoretic foundations for random generators in software testing. We model generators as Turing machine transducers that consume random bits and produce string-encoded outputs, and show that the theoretically generable languages coincide exactly with the recursively enumerable languages. This has direct implications for testing at the boundaries of decidability, such as in the field of compiler testing. Turning to efficient generation, we show that the polynomial-time generable languages lie within NP, that certain important NP-complete languages admit efficient generators, and that—under standard cryptographic assumptions—there are languages in P for which no efficient generator exists: the complexity of efficienct generation and of efficient decision are not the same. We then show that space-bounded complexity is the natural framework for generators producing correlated samples, capturing methodologies such as coverageguided fuzzing and symbolic execution. Beyond classification, we characterise efficient generability: a language has a polynomial-time generator iff it admits a certificate scheme over a verifier—so witness planting, the folklore technique behind generators to test SAT solvers, is in a sense the only route to efficient generation. Our theory also yields design principles for property-based testing libraries: we prove no library can compositionally derive efficient generators from logical predicates involving conjunction or negation, under standard assumptions. However, restricted classes like NL (equivalently, linear Datalog predicates) would admit such a compilation.

1

Introduction

At first sight, software testing, concerned with the observed behaviour of particular programs on particular inputs, is far removed from complexity theory, which distinguishes what can be computed in principle from what can be computed by an efficient algorithm. Yet, in property-based testing (PBT) [10, 33], where a system under test (SUT) is executed on many automatically generated inputs, a critical component to the success of a testing campaign is the generator, a randomised algorithm. Due to the intricacies of realistic generators, much work has gone into their implementation [31, 50], library tooling [10, 20, 33, 52], and on automatic derivation of generators from predicates [16, 17, 28]. But despite their importance, little is known about the theoretical limits of generator expressivity: what can be generated at all, and what can be generated efficiently? We give the first complexity-theoretic formalisation of generators in randomised testing, establishing a number of results about what can and cannot be generated, and why. Our formulation is applicable to the majority of generators found in testing practice: generators are modelled as Turing machine transducers that consume bitstrings and must eventually produce string-encoded outputs. Once generators are cast within this framework, each generator associates with a formal language—the set of outputs it can produce. This allows rigorous investigation of the limits of generation in general, as well as under a variety of time and space constraints. In establishing our novel framework, we build upon previous theoretical work on language generation that predates PBT (and which in our view deserves more attention) [44, 45]. Authors’ Contact Information: Pingshi Yu, [email protected], Imperial College London, London, United Kingdom; Chengsong Tan, [email protected], Kaihong, Shenzhen, China; Nicolas Wu, [email protected], Imperial College London, London, United Kingdom; Alastair Donaldson, [email protected], Imperial College London, London, United Kingdom.

0:2

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

// [a=19, b=4] void foo(int a, int b) { unsigned i = 0; while(i != a) { i += b; } }

(a) Nonterminating C program.

(declare-const p Bool) (declare-const r Bool) (declare-const q Bool) ; from unsat generator (assert (=> (and q r) (and (not q) r))) ; from sat generator ; by e.g. [p=F, q=T, r=F] (assert (=> (and p q) r))

// [a=21219] // halts in 100 steps void bar(int a) { int i; for (i = 0; i < 100; i++) { if (i == a) break; } }

(b) (Un)satisfiable formulas.

(c) Terminating C program.

Fig. 1. Possible test cases produced by example generators.

To illustrate the kinds of questions our theoretical framework allows us to ask and answer, we give three examples in the context of programming languages research. Example: testing a termination checker. Suppose we are presented with a termination checking tool for C-programs, which is claimed to be conservative: the tool should emit a “may not terminate” diagnostic for at least those (program, input) pairs where the program does not terminate on the input. To apply PBT to this tool we thus need a generator of elements from the set NonTerm = {(𝑝, 𝑖) : 𝑝 a C program, 𝑖 an input, 𝑝 does not terminate on 𝑖}. If testing finds a (𝑝, 𝑖) pair for which the checker does not emit a diagnostic, it has found a bug in the checker. Figure 1a illustrates one such pair that should be producible by the generator. While of course we can create a generator that produces many such pairs of examples (possibly including Figure 1a), our theory tells us that it is impossible to create such a generator without sacrificing some part of the NonTerm space: we show that the recursively enumerable (RE) languages are precisely the generable ones, and since NonTerm is not in RE (assuming an unbounded memory semantics for C), it cannot be generable. Example: testing a SAT solver. To apply PBT to a SAT solver we would like two generators, generating satisfiable (unsatisfiable) formulas: if the solver claims that any are unsatisfiable (satisfiable) this is a bug. Figure 1b uses SMT-LIB syntax to sketch simple formulas that such generators might be expected to produce. Our theory confirms that generators covering the full space of satisfiable or unsatisfiable problems can exist, and that a generator of satisfiable problems that runs in polynomial time can be constructed (even though deciding satisfiability is NP-complete). However, we show that (unless P = NP) a fully general polynomial-time generator of unsatisfiable problems cannot exist. Furthermore, if we move from SAT to QBF instances by allowing quantifiers, a fully general polynomial-time generator cannot exist even for the satisfiable case. Example: time-bounded differential compiler testing. As a final motivating example, a campaign for randomised differential compiler testing typically requires (program, input) pairs where the program does terminate on the input. To make such a campaign efficient we might further want the generator to provide a time bound for each generated program, avoiding the need for arbitrarily-selected timeout values. We would thus like to generate (𝑝, 𝑖, 𝑘) triples comprising a program 𝑝 that is guaranteed to terminate on input 𝑖 within 𝑘 time steps1 (see Figure 1c). Although this input space is generable, we show that unless standard complexity-theoretic assumptions turn out to be false, a time-efficient generator cannot cover the set of all such programs: no generator of independent samples exist that uses 𝑞(𝑛) time to generate programs of size 𝑛, for some polynomial 𝑞. Not only that, polynomial generation remains out of reach even if the generator had access to an efficient SAT solver. The results established in Section 6 show that polynomial space 𝑞(𝑛) would 1 Assuming that each basic operation of the program takes one time step.

Complexity Theory of Randomised Testing

EPG

generator classes

PG

0:3

LG

classical classes

NL

P

NP

classical and generator classes coincide

PSPACEG = PSPACE

GEN = RE

P ⊈ PG, EPG (*)

Fig. 2. Complexity relationships between the new generators classes and known classes. Purple dotted boundaries denote generator classes that do not coincide with classical ones; purple solid boundaries denote generator classes that do coincide with classical ones; black dashed boundaries denote classical complexity classes that do not coincide with generator classes. The generator classes are LG: logspace generable, PG: polynomial-time generable, EPG: expected polynomial-time generable, PSPACEG: polynomial-space generable, and GEN: all generable languages. P contains NL, intersects PG and EPG, and is contained in NP. (*) Noncontainment of P is contingent on standard cryptographic assumptions.

also not be sufficient to produce all such programs of size 𝑛—limiting the use of feedback-driven generation techniques such as concolic execution [7, 8] and coverage-guided fuzzing [5] for this particular set. A practical solution would have to make some engineering trade-offs. Beyond classification, our framework yields a characterisation of efficient generability: we show that a language has a polynomial-time generator if and only if it has a verifier admitting a certificate scheme—a way to sample certificates and reconstruct random instances around them. This shows that some form of witness planting (including one based on a trivial verifier)—the folklore technique behind generators for SAT and graph reachability—is used by all time-efficient generators. Separately, a long-standing goal in the PBT literature is to automatically derive efficient generators from predicates [9, 16, 28]. We prove a negative result in this context: under standard assumptions, no library can compositionally map predicates from a logic containing conjunction or negation to polynomial-time generators—any homomorphic translation must give up either expressivity or efficiency. On the other hand, we show that restricted classes like NL (equivalently, predicates in linear Datalog) can in principle be compiled compositionally to polynomial-time generators. By studying the power of generators under various resource constraints, we establish a wide range of results about testing that fall out naturally. Some confirm intuitions from testing folklore; others are novel insights that were previously inaccessible without such a formal model. Contributions. In summary, our main contributions are: • We provide the first complexity-theoretic foundations of generators for randomised testing (Section 2), and derive expressivity bounds applicable to all generators (Section 3). • We propose a notion of time/space constraints for generators, and derive theoretical limits of efficient generation (Section 4, Section 5, Section 6). • We establish general principles for constructing time-efficient generators, and limitations on the design of composable testing libraries (Section 7). Throughout the paper, we introduce several generator-specific complexity classes: LG (log-space generable), PG (polynomial-time generable), EPG (expected polynomial-time generable), PSPACEG (polynomial-space generable) and GEN (everything that can be generated). Figure 2 serves as a roadmap to the complexity landscape established in our work.

0:4

2

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

Modelling Generators

A generator in randomised testing produces structured inputs for an SUT [35], e.g. inputs that the SUT is supposed to accept, or deliberately malformed inputs designed to stress the SUT. These structured inputs can be viewed as strings in a language. For generality, and to allow the application of complexity theory, we formulate generators as Turing machines, and their outputs as string encodings of data. We model randomness as an explicit input bitstring supplied to a deterministic Turing machine, where random selections are made during computation by reading from this bitstring. This is in line with how randomness is implemented in common randomised testing libraries such as Hypothesis [33].2 In practice, generation is driven by a pseudorandom number generator (PRNG), which we idealise as an inexhaustible supply of independent, unbiased random bits: a generator consumes some finite prefix of an infinite stream and produces an output. There are two caveats with the informal description, which we make formal below. First, we permit a generator that produces nothing for every stream, characterising generators of the empty set, and is useful for our theoretical model. Second, a generator being productive “given an infinite stream” is too strong if interpreted as “given every infinite stream”. We show in Section 2.3 that reasonable generators can still fail to produce a value in extreme, albeit probability 0 events—so we require producivity only almost surely. Although it is natural to define generators to take infinite streams as input, infinite streams are not a natural input space for Turing machines. To reconcile this, we proceed in three steps: (1) We define bitstring transducers, which operate on finite bitstrings, together with a halting condition. A halting transducer either accepts, producing an output, or rejects, where a rejection only occurs when the transducer runs out of its finite input (Section 2.1). (2) We lift a halting transducer to infinite streams. Because rejection only occurs after input exhaustion, acceptance is monotone under extension of the input, thus every accepting run belongs to an equivalence class represented by a unique minimal accepting prefix. This lets us define what a transducer does on an infinite stream, and lets us measure the set of accepted bitstreams (Section 2.2). (3) We define the notion of eventual productivity as almost-sure acceptance of infinite streams under the measure of infinite sequences of fair coin-flips, and obtain the definition of a generator (Section 2.3).3 Preliminaries. Unless stated otherwise, all tapes of a Turing machine (TM) are assumed to be infinite (to the right), initially empty, with the head pointed at some fixed, designated initial cell. The alphabet on all tapes of Turing machines is finite, and includes the “ ” symbol to represent blank spaces. The blank symbol will never be written. When we make the statement “tape with alphabet Γ”, we implicitly mean it has alphabet Γ ⊎ { }, and all empty cells on the tape are populated by symbols. We say a tape is read-once-only if the head never moves left and the machine never writes to the tape. Similarly, a tape is write-once-only if the head never moves left, and after any write operation the tape head is immediately moved to the right. For a Turing machine 𝑀 with a single input tape, we say “𝑀 ran on 𝑥”, or “𝑀 ran with input 𝑥”, or “𝑀 (𝑥)”, to mean the computation performed by 𝑀 in the initial state, with the input tape populated using 𝑥 starting from the initial cell. This also extends to machines with multiple input tapes. For example, 2 It is also possible to model randomness using nondeterministic Turing machines, which would result in an equivalent model. We choose deterministic Turing machines with an explicit random input to stay in line with practical implementations, and because it makes later definitions more convenient. The results for the deterministic case translate directly to the nondeterministic case. 3 In Appendix A.1 we discuss an alternative natural notion of eventual productivity based only on Turing machines.

Complexity Theory of Randomised Testing

0:5

on a machine 𝑀 with two input tapes, 𝑀 (𝑥, 𝑦) means the computation performed by 𝑀 in the initial state, with the first input tape populated using 𝑥 and the second using 𝑦. 2.1

Transducers on finite bitstrings

Definition 2.1 (Bitstring Transducer). A bitstring transducer 𝑇 is a Turing machine with three tapes: a read-once-only input tape with alphabet {0, 1}, a working tape with alphabet Σ, and a write-once-only output tape with alphabet Γ. For a bitstring 𝑏 ∈ {0, 1}∗ , if 𝑇 (𝑏) accepts, the contents of the output tape (disregarding empty cells) 𝑥 ∈ Γ ∗ are said to be produced by 𝑇 , denoted 𝑇 (𝑏) = 𝑥. If there is no ambiguity, we may say transducer for short. Definition 2.2 (Random Selection). During an execution, we say that the transducer 𝑇 makes a random selection whenever a transition moves the input tape head right—that is, it reads a bit from the input bitstring. Multiple random bits can be combined together in a procedure to make more refined random selections (e.g. conditional dependence, or selections among more than two possibilities). Procedures are computations (potentially with side effects) that consume randomness in the sense of Definition 2.2, and generators are special cases of procedures that write values to the output tape. Procedures are used to modularise algorithmic descriptions and help with clarity of exposition. Example 2.1. A transducer 𝑁 can select any 𝑛 ∈ N at random via the following iterative procedure. 𝑁 reads the input in pairs of bits. In each round it reads a continuation bit; if it is 1, 𝑁 reads a further data bit, appends it to a buffer on the working tape, and begins a new round; if it is 0, 𝑁 halts and outputs the buffer, interpreted as a binary numeral. Writing the input stream as 𝑏 0𝑏 1𝑏 2 . . ., the Í −1 transducer computes 𝑘𝑖=0 𝑏 2𝑖+1 2𝑖 where 𝑘 = min{𝑖 : 𝑏 2𝑖 = 0}, whenever this 𝑘 exists. Note that the only way 𝑁 rejects is when it runs out of input bits, e.g. on 1 or 101 (the continuation bit promises another bit that is not supplied), or on 10 (no continuation bit is supplied). The accepting runs of Example 2.1 consume 2𝑘 + 1 bits for some 𝑘 ≥ 0, and rejections occur due to the stream ending prematurely. This is the behaviour we now generalise to our halting condition. Definition 2.3 (Halting Transducer). A bitstring transducer 𝑇 is halting if (1) for every input 𝑏 ∈ {0, 1}∗ , 𝑇 (𝑏) halts; and (2) 𝑇 rejects iff the input head attempts to read a blank cell (a cell containing ). The second clause prevents premature rejections and is a necessary precursor for the formal definition of “eventual productivity” below. From Definition 2.3, we can immediately observe the following, useful for the upcoming generalisation to infinite streams. Observation 2.1 (Monotonicity). Let 𝑇 be halting and suppose 𝑇 (𝑏) accepts. Then the run 𝑇 (𝑏) reads no cell beyond the |𝑏 |-th, since by Definition 2.3 reading a blank would force rejection. Hence for every 𝑏 ′ having 𝑏 as a prefix, the run of 𝑇 on 𝑏 ′ is identical, so 𝑇 (𝑏 ′ ) accepts and 𝑇 (𝑏 ′ ) = 𝑇 (𝑏). 2.2

From finite bitstrings to infinite streams

By Observation 2.1, the accepting behaviour of a halting transducer 𝑇 is completely determined by the shortest bitstrings on which it accepts. Definition 2.4. For a halting transducer 𝑇 , the minimal accepted bitstrings 𝐴𝑇 are 𝐴𝑇 = { 𝑏 ∈ {0, 1}∗ : 𝑇 (𝑏) accepts ∧ ∀𝑏 ′ . 𝑏 ′ a strict prefix of 𝑏 =⇒ 𝑇 (𝑏 ′ ) rejects }. Again by Observation 2.1, no element of 𝐴𝑇 is a prefix of another, i.e. 𝐴𝑇 is prefix-free, and 𝑇 accepts a finite bitstring 𝑏 exactly when some element of 𝐴𝑇 is a prefix of 𝑏. Note that 𝐴𝑇 is defined for conceptual convenience, and is not intended to be computed directly.

0:6

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

We can now assign a natural semantics of 𝑇 on an infinite bitstream bs ∈ {0, 1}𝜔 : its behaviour is identical to 𝑇 (𝑏), where 𝑏 ∈ 𝐴𝑇 is a prefix of 𝑏𝑠, if 𝑏 exists. Definition 2.5. For a halting transducer 𝑇 and an infinite bitstream bs, define 𝑇 (bs) as: (1) 𝑇 (𝑏), if 𝑏 ∈ 𝐴𝑇 and 𝑏 is a prefix of bs; (2) divergent, if no 𝑏 ∈ 𝐴𝑇 is a prefix of bs. This is well-defined: as 𝐴𝑇 is prefix-free, at most one 𝑏 ∈ 𝐴𝑇 is a prefix of bs. To speak of the probability that 𝑇 produces an output, we use the standard measure of infinite sequences of fair coin-flips, which models the PRNG that drives generators in practice. Definition 2.6 (Distribution of Random Bitstreams). Let I denote the distribution of bitstreams {0, 1}𝜔 , where for a random variable 𝑋 distributed according to I (written 𝑋 ∼ I), all bits of 𝑋 are independently and identically distributed (i.i.d.) following a fair Bernoulli distribution Ber(0.5). For a set of bitstreams 𝐵 ⊆ {0, 1}𝜔 , denote the probability of 𝐵 under I by 𝜇 (𝐵). Definition 2.7. For a bitstring 𝑏 ∈ {0, 1}∗ , define the cylinder 𝑆𝑏 as: 𝑆𝑏 = {𝑏 ++ bs : bs ∈ {0, 1}𝜔 }. Definition 2.8. The accepted infinite bitstreams of a halting transducer 𝑇 are Ø 𝐴𝑇𝜔 = 𝑆𝑏 . 𝑏 ∈𝐴𝑇

Since 𝐴𝑇 is prefix-free, the cylinders 𝑆𝑏 for 𝑏 ∈ 𝐴𝑇 are pairwise disjoint. 𝐴𝑇 is also countable, thus 𝐴𝑇𝜔 is a countable disjoint union of cylinders, and is measurable with ∑︁ 𝜇 (𝐴𝑇𝜔 ) = 2− |𝑏 | . 𝑏 ∈𝐴𝑇

This quantity is the probability that 𝑇 , when driven by an idealised PRNG, produces an output. 2.3

Eventual productivity

We are now ready to formalise the “eventual productivity” requirement of a generator. The strongest interpretation of eventual productivity is that 𝑇 (bs) is defined for every bs ∈ {0, 1}𝜔 , equivalently 𝐴𝑇𝜔 = {0, 1}𝜔 . However, this is too strong in practice. Consider the natural number transducer 𝑁 of Example 2.1. It diverges on exactly the streams in: 𝑋 = {𝑏 0𝑏 1 . . . : ∀𝑖 ∈ N. 𝑖 even ⇒ 𝑏𝑖 = 1}, that is, streams in which every continuation bit is 1, so that 𝑁 never stops asking for another data bit. Ruling out transducers like 𝑁 would make it impossible to sample from an infinite set—any transducer with infinitely many possible outputs must have infinitely many accepting prefixes, and so there must exist streams on which the transducer is never productive. This would severely limit the applicability of our model. Observe however, that the set 𝑋 has trivial measure, as 𝜇 (𝑋 ) = lim𝑖→∞ 2−𝑖 = 0. We therefore formalise eventual productivity as almost-sure acceptance. 𝜔 ) = 1 or 𝜇 (𝐴𝜔 ) = 0. Definition 2.9 (Generators). A halting transducer 𝐺 is a generator if 𝜇 (𝐴𝐺 𝐺 𝜔 ) = 0 iff 𝐴 = ∅ iff 𝐺 rejects every finite bitstring. Observation 2.2. 𝜇 (𝐴𝐺 𝐺 𝜔) = Í − |𝑏 | = 0 iff 𝐴 is empty. By Proof. Each 𝑆𝑏 has 𝜇 (𝑆𝑏 ) = 2− |𝑏 | > 0, so 𝜇 (𝐴𝐺 𝐺 𝑏 ∈𝐴𝐺 2 Observation 2.1, 𝐴𝐺 = ∅ iff 𝐺 accepts no finite bitstring. □

Complexity Theory of Randomised Testing

0:7

𝜔 ) = 1 or 0) are for the two behaviours permitted of generators: the first The two cases (𝜇 (𝐴𝐺 characterises almost-sure productivity; the second describes the case where all inputs are rejected (corresponding to a generator for the empty set). It is undecidable to check whether a given transducer is a generator, but this is not an issue since we show generator conditions on a caseby-case basis throughout this work.4 For added intuition, it may help to consider the transducers that are not generators. These are the transducers that fail to halt on some finite bitstring, or that diverge on a non-negligible — but not co-negligible — set of streams. To illustrate the definition, we verify that it matches our intuitions on Example 2.1, and that rejection sampling yields true generators.

Proposition 2.1. The transducer 𝑁 of natural numbers described in Example 2.1 is a generator. Proof. 𝑁 is clearly halting: on any finite bitstring it either meets a 0 continuation bit and accepts, or exhausts its input and rejects. The set of bitstreams not accepted by 𝑁 is 𝑋 as above, so 𝐴𝜔𝑁 = {0, 1}𝜔 \ 𝑋 and 𝜇 (𝐴𝜔𝑁 ) = 1 − 𝜇 (𝑋 ). Since 𝜇 (𝑋 ) = 0, 𝜇 (𝐴𝜔𝑁 ) = 1 and 𝑁 is a generator. □ Definition 2.10 (Generator by Rejection Sampling). Let 𝑓 be a total computable predicate on {0, 1}∗ . The generator 𝐺 𝑓 based on rejection sampling on 𝑓 is defined as follows. (1) Sample an 𝑛 (e.g. using Example 2.1), then sample a string 𝑤 of length 𝑛. (2) Compute 𝑓 (𝑤). If 𝑓 (𝑤) returns true, output 𝑤. Otherwise restart from step 1. Proposition 2.2. If 𝑓 is a computable predicate on {0, 1}∗ such that 𝑓 holds for at least one 𝑤 ∈ {0, 1}∗ , then 𝐺 𝑓 is a generator. Proof. See Appendix A.2. 3

A Framework for Generability

In testing, randomness is an essential tool to enable systematic exploration of the input space. The goal of randomised testing can be viewed as the validation of a certain property that must hold on the program when executed on the random inputs. The commonly practised paradigm of property-based testing (PBT) validates properties of the form ∀𝑥 .Pre(𝑥) =⇒ Post (𝑥), which suits the vast majority of use cases. For instance, fuzzing can be seen as validating the property: “for all inputs 𝑥, the program should not crash”. Differential testing can be seen as validating: “for all valid inputs 𝑥, the two implementations 𝑇 ,𝑇 ′ must have 𝑇 (𝑥) = 𝑇 ′ (𝑥)”. The key to the successful application of randomised testing is an effective generator, whose job is to generate inputs that satisfy the preconditions of the property, which then enables the property to be checked on the program. We now show a few example scenarios below of programs and their properties that may be tested, and will be referring back to them throughout this section. Example 3.1 (Binary Search Trees). Program 𝑃 takes as input a binary search tree 𝑇 and an index 𝑖, and outputs the 𝑖th smallest element within the tree. 𝑃 should satisfy the following property, where bst (𝑇 ) is a predicate checking that 𝑇 is a binary search tree, and 𝑖, 𝑗 are integers: ∀𝑇 , 𝑖, 𝑗 .bst (𝑇 ) ∧ 0 ≤ 𝑖 ≤ 𝑗 < |𝑇 | =⇒ 𝑃 (𝑇 , 𝑖) ≤ 𝑃 (𝑇 , 𝑗) Example 3.2 (Counting SAT Assignments). Program 𝑃 takes as input a CNF boolean formula 𝜓 and outputs the number of satisfying assignments of 𝜓 . 𝑃 should satisfy the following property, where sat is the predicate for the satisfiability of the formula, and 𝜓 [𝑥/𝐴] is the substitution of 𝐴 for 𝑥 in 𝜓 : ∀𝜓 .sat (𝜓 ) =⇒ 𝑃 (𝜓 ) > 0 ∧ 𝑃 (𝜓 ) = 𝑃 (𝜓 [𝑥 0 /𝑇 ]) + 𝑃 (𝜓 [𝑥 0 /𝐹 ]) 4 In a similar vein, the undecidability of the Halting problem does not prevent people from developing useful algorithms.

0:8

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

Example 3.3 (Tensor Decomposition). Program 𝑃 takes a tensor 𝑇 over field 𝐹 , and outputs a decomposition of 𝑇 as a product of rank-1 tensors. 𝑃 should satisfy the following: Ì ∀𝑇 , 𝑟 . rank(𝑇 ) = 𝑟 =⇒ length(𝑃 (𝑇 )) = 𝑟 ∧ (∀𝑖 < 𝑟 . rank(𝑃 (𝑇 )𝑖 ) = 1) ∧ 𝑃 (𝑇 )𝑖 = 𝑇 . 𝑖<𝑟

Example 3.4 (C Compiler). Program 𝑃 is a compiler for the C language, taking an optimisation flag (0 or 1) as the first argument and a C program as the second argument. 𝑃 should satisfy the following property, where wd (𝑐) is a predicate checking 𝑐 is a C program with well-defined semantics (assume it doesn’t take inputs), and 𝑃 (𝑜, 𝑐) () denotes executing the executable produced by compiling 𝑐 using 𝑃 on optimisation 𝑜: ∀𝑐.wd (𝑐) =⇒ 𝑃 (0, 𝑐) () = 𝑃 (1, 𝑐) () In each case, for a property Prop = ∀𝑥 .Pre(𝑥) =⇒ Post (𝑥), the ideal generator should implement a distribution on the elements of the set Precond = {𝑥 : Pre(𝑥)}. 3.1

The Design Space of Generability

We first address some nuances in the design space of the formal language associated with a generator. This is an important step, since languages are the central object of study in any complexity theory. Allow generators to sample only a subset of Precond? Sampling from a strict subset of Precond would mean there exist elements 𝑥 ∈ Precond that can never be generated. Such a generator can still find bugs, but never ones triggered only by inputs outside its range. Thus the generator of a subset of Precond would not be appropriate to fully test Prop. As a pragmatic choice, it is common in practice to create generators that sample from only a subset of inputs that satisfies a property’s precondition. For instance, when the precondition is seemingly too complex5 to write a generator for, such as the property described in Example 3.4, generators typically focus on specific subsets of the input space heuristically understood to contain potential bug triggers [12, 31]. Although existing literature refers to these as “generators” of Cprograms for validating compilers, the property they are testing for is more accurately understood as a different from the one in Example 3.4, with a more restrictive precondition: ∀𝑐.producible(𝑐) =⇒ 𝑃 (0, 𝑐) () = 𝑃 (1, 𝑐) () where producible is to denote the predicate corresponding to the targeted subset of inputs the generator produces. For example, restricted C-programs amenable to implemented analyses [50], or C-programs containing constrained forms of loops [32]. Allow generators to sample a superset of Precond? Generators sampling from a superset of Precond would be able to trigger all possible property violations, but risk false positives from inputs outside of Precond. Rejection sampling is required to filter the inputs, selecting only ones that satisfy the precondition. Depending on requirements, this filter can be applied either as a final step of generation, or after a bug-triggering input has been found to check for false-positivity. While filtering works well when deciding the precondition is easy (Example 3.1), the precondition itself can be hard to decide, and is not in general related to the complexity of the algorithm under test. For example, checking the precondition is NP-hard in Example 3.2 and Example 3.3, and undecidable in Example 3.4 (deciding if a C program is well-defined is undecidable [11]). Example 3.3 is worth highlighting here: computing the rank of 𝑇 is NP-hard, but if rank(𝑇 ) is known, the decomposition is computable in time polynomial in the size of the tensor. The runtime of the test campaign can 5 Note this is only an empirical understanding, which is thus far not formalised. When is a set really too complex to generate?

We will look to give theoretical answers to this question in the coming sections.

Complexity Theory of Randomised Testing

0:9

thus be dominated by the filtering stage. These filters also need to be provided separately, and when the filter is complex, it can be an additional source of complexity and bugs in the testing system. Moreover, test case throughput is an important factor for the effectiveness of a testing campaign [4, 34]. Spending significant time deciding the validity of inputs can often mean fewer or missed bugs. If a precondition-satisfying input is produced rarely by a generator, for instance, using a generator of random ASTs (or even random strings) for Example 3.4, then it can be the case that no tests are ever run, due to the low probability of finding a satisfying input! Indeed, if the generator produces precondition-satisfying inputs with probability 𝑝, then one expects 1/𝑝 attempts to find a usable input—and 1/𝑝 can easily scale exponentially with the size of the generated test case. In the Example 3.4 case, a random AST would have vanishingly low probability of satisfying the language specification [23], and a random string even more so. What distributions should generators implement? A generator implements a particular distribution over the set of inputs, and in practice impacts the effectiveness of a testing campaign. Randomised testing employs a wide range of distributions, which can also be adjusted as testing progresses [18, 36]. However, there is no canonical distribution around which to build a complexity theory. The uniform distribution (on elements of a given size) is commonly studied theoretically, but fail to capture the diversity of distributions used in practice. Indeed, in the design of generators, the distribution implemented is often an orthogonal concern to samplability itself. Therefore, as a first step towards a complexity-theoretic model of generators, we remain agnostic to distributions, and aim to gain fundamental understanding of which sets can be generated at all. This serves as a prerequisite to the harder question of generability under prescribed distributions, and also ensures generality of our results. The “no-go” results we derive, a type of result common in complexity theory, apply to generators implementing any computable distribution, rather than being contingent on distributional assumptions. The only requirement we impose is distributional support [37]: the support of the implemented distribution must equal the whole set. One natural concern is that the weak assumption of only distributional support may be overly permissive, since it allows distributions that assign negligible weight to parts of the set. However, distributional support is a stronger guarantee than it may first appear—once an input is producible, however improbably, practical techniques can often amplify the probability of producing desirable outcomes. For example, the bitstring input to a generator can be viewed as an optimisation parameter, and this insight was used in previous works [17, 33, 36] to tune generators, producing outputs that would have otherwise been infeasible due to their low probability weights. 3.2

Unconstrained Generability

In light of the insights from the above discussion, we give the following definition for the language associated with a generator. Definition 3.1 (Generated Language). For a generator 𝐺, the language generated by 𝐺 is: L (𝐺) = {𝑥 | ∃ 𝑏 ∈ {0, 1}+ . 𝐺 (𝑏) = 𝑥 } The following is the most general class of languages that is generable. The only requirement is that there exists an algorithm (generator) to generate the elements. Definition 3.2 (Generable Languages). For an alphabet Σ, we define the set of generable languages, GEN, as follows: GEN = {L (𝐺) : 𝐺 is a generator} A language 𝐿 is generable if 𝐿 ∈ GEN.

0:10

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

For a language 𝐿, we have defined our generators to associate with 𝐿 a surjective computable function {0, 1}∗ → 𝐿 that constructs instances of 𝐿 from randomness. On the other hand, one of the most commonly studied objects in complexity theory is Turing recognisers, which implement a (potentially partial) predicate for some language 𝐿. Turing recognisers associate a language 𝐿 with a function of type Σ∗ → B, which accepts 𝑥 ∈ Σ∗ iff 𝑥 ∈ 𝐿. The standard class of RE, or recursively enumerable languages, is the set of all languages whose elements can be recognised by a Turing machine (predicate). Definition 3.3 (Recursively Enumerable Languages). For a given alphabet Σ, the recursively enumerable languages are: RE = {𝐿 ⊆ Σ∗ : ∃ a Turing machine 𝑀. ∀𝑥 ∈ Σ∗,

𝑥 ∈ 𝐿 ⇔ 𝑀 halts and accepts 𝑥 }

In Definition 3.3, 𝑀 refers to a standard Turing machine that accepts/rejects an input, rather than the transducer style within Definition 2.1. 𝑀 can be seen as a membership predicate for some set 𝑆, where 𝑀 (𝑥) accepts if and only if 𝑥 ∈ 𝑆 (but importantly may loop instead of rejecting if 𝑥 ∉ 𝑆). The RE sets/languages with a membership predicate algorithm that always halts are called decidable, and the complement of the decidable languages in P (Σ∗ ) is called undecidable. The well-definedness of a C-program (wd in Example 3.4) is an undecidable problem, making it a “hard” member of RE. As noted earlier, the natural approach of rejection sampling cannot be used within any generator of well-defined C-programs (programs 𝑥 satisfying wd (𝑥)), since generators must terminate on any finite input, and the test for a string 𝑥 satisfying wd (𝑥) may never terminate. The inability to use rejection sampling of course extends to all RE languages. This raises the natural question: is it actually possible to write a generator for well-defined C-programs, or indeed any undecidable set? The question is not limited to a single generation algorithm that one may write: any conceivable procedure, or combinations of procedures whose set of outputs equals the set of well-defined C-programs would be a generator. We now show that in the resource unconstrained case, the generable languages are precisely the recursive enumerable languages. This is consistent with the known fact that standard transducers have images equalling the RE languages—the additional constraints of a generator do not sacrifice any expressive power. However, for testing this already leads to interesting conclusions, which we discuss in more detail later in the section: programs such as compilers often do deal with undecideability, and this places fundamental constraints on the types of properties that can be fully tested on such programs. Later in Section 5 and Section 6, we will see that additional resource (time or space) constraints lead to situations where the generator and their corresponding decision complexity classes do not coincide. Theorem 3.1 (Generability is Recursive Enumerability). RE = GEN. Proof. We defer the full proof to Appendix A.4. Intuitively, GEN ⊆ RE is due to the RE machine being able to enumerate through all finite bitstrings (as random seeds 𝑏) to check if the generator can produce some 𝑥. RE ⊆ GEN is due to the generator being able to perform dovetailing to find a single accepted string by the recogniser, which can then be used as fallback for a nondeterministic guess of the membership certificate for some randomly chosen 𝑥. □ Consequences for PBT: When testing a property for which the set of acceptable inputs is recursively enumerable, Theorem 3.1 implies that a generator for the complete input format exists—i.e., ambition in generator-writing is at least theoretically justified. However, properties whose preconditions are not recursively enumerable cannot be fully tested by any generator, no matter how it is engineered.

Complexity Theory of Randomised Testing

0:11

For instance, it is possible to write a generator that will output, with non-zero probability, all instances of seemingly very hard problems, such as: Definition 3.4. The language of halting computations on Turing machines: HALT = {⟨𝑀, 𝑤⟩ : Turing machine 𝑀 halts on input 𝑤 } The equality also yields a class of non-generable languages—ones that lie outside of RE. Corollary 3.1. All languages outside of RE are not generable. Non-RE languages are a large set, and one way to obtain languages in it is via complementing languages known to be in RE. A language 𝐿 is undecidable if there is no Turing machine that halts on all inputs and accepts exactly the strings in 𝐿. Rice’s theorem [39] is a well-known result that states all (non-trivial) semantic properties on Turing machines are undecidable. Hence, at least one of the language itself, or its complement, is non-RE. The result also extends from Turing machines to Turing-complete programming languages, and we will quote this version. For a Turing-complete programming language 𝐾, let 𝑃𝐾 be the set of encodings of well-defined programs written in 𝐾, and for 𝑀 ∈ 𝑃𝐾 let L (𝑀) be the set of strings 𝑤 such that 𝑀 (𝑤) executes without rejection (crashes or errors). A semantic property is a set 𝑆 ⊆ 𝑃𝐾 that depends only on program semantics: if L (𝑀) = L (𝑁 ) then 𝑀 ∈ 𝑆 ⇐⇒ 𝑁 ∈ 𝑆. It is non-trivial if 𝑆 ≠ ∅ and 𝑆 ≠ 𝑃𝐾 , and its complement is 𝑆 𝑐 = 𝑃𝐾 \ 𝑆. Rice’s theorem [39] implies every non-trivial semantic property is undecidable, yielding the following: Corollary 3.2. Let 𝑆 ⊆ 𝑃𝐾 be a non-trivial semantic property over programs written in a Turing complete language 𝐾. Then at least one of 𝑆 or 𝑆 𝑐 is not in GEN. Proof. Suppose for a contradiction both 𝑆 and 𝑆 𝑐 are generable, then both are also recursively enumerable by Theorem 3.1, thus 𝑆 is actually decidable. This contradicts Rice’s Theorem. □ These results are particularly applicable to software that can come face-to-face with non-RE languages, such as compilers. In this context, it means that there are properties of the compiler implementation that can never be completely tested, due to the lack of a generator for the property. This includes the use of rejection sampling. For example, in C++, termination is a property relevant for the well-definedness of programs, defined by the language specification. One might be interested in building a generator to test the compiler (its inputs being programs) for the following: programs that do not terminate should nonetheless not crash the compiler. However, although the terminating programs are generable, there are no generators of all non-terminating programs: Corollary 3.3. For a Turing-complete language 𝐾, the set of non-Halting programs, LOOP, is not generable, where LOOP = {𝑀 ∈ 𝑃𝐾 : 𝑀 takes no inputs and does not terminate} Consequences for PBT: You cannot fully test compiler properties with non-RE preconditions, e.g., the behaviour on non-terminating programs (Corollary 3.3). Any generator of a producible subset is testing a different, weaker property—a trade-off that should be made explicitly, not discovered accidentally. Of course, the existence of generators is only one of the concerns of PBT practitioners. We now turn to another important consideration: their efficiency.

0:12

4

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

Generator Families

We cannot wait all day for a generator to produce an output for an SUT: an effective generator needs to rapidly produce a large corpus of inputs for the SUT. Thus, as with algorithms, it is helpful to associate resource constraints with generators. But, unlike algorithms, generators do not have a natural input parameter on which the input size can be defined, and hence there also lacks a definition of resource constraint, which are based on the input size. In practice, PBT libraries like QuickCheck indeed include an optional size parameter, which a generator implementation can use to control the sizes of the generated objects. We introduce a similar parameter in our model, which allows a priori specification of the output size—from which we can then define the notion of resource usage for generators. Adding these constraints would allow our model to be applicable to generators that use the size parameter. The following aims to capture the notion of parameterised generators, namely a family of generators that each generates a portion of the intended language (instances of a particular size), and where the union of their generated languages is the whole language. Definition 4.1 (Implementation of a Family of TMs). Let (𝑀𝑖 )𝑖 ∈𝐶 be a family of TMs indexed by strings 𝐶 ⊆ {0, 1}∗ . We say that 𝑀 implements (𝑀𝑖 )𝑖 ∈𝐶 , written 𝑀 = (𝑀𝑖 )𝑖 ∈𝐶 , if (𝑀𝑖 )𝑖 ∈𝐶 is a uniform family as follows: • 𝑀 has an extra read-only input tape compared to each 𝑀𝑖 . • For all 𝑖 ∈ 𝐶, 𝑀 (𝑖) = 𝑀𝑖 . That is, with 𝑖 on the input tape of 𝑀, 𝑀 behaves exactly as 𝑀𝑖 . Definition 4.2 (Family of Generators). Let 𝐿 be a language, and (𝐿𝑖 )𝑖 ∈𝐶 a partition of 𝐿 indexed by the set 𝐶 ⊆ {0, 1}∗ . 𝐺 = (𝐺𝑖 )𝑖 ∈𝐶 is a generator for 𝐿 if for each Ð 𝑖 ∈ 𝐶, L (𝐺𝑖 ) = 𝐿𝑖 . The language generated by 𝐺, L (𝐺) is defined as L (𝐺) = 𝑖 ∈N L (𝐺𝑖 ). For the special case where 𝐶 = {1𝑖 : 𝑖 ∈ N} is used to partition a set 𝐿 into 𝐿𝑖 = {𝑤 ∈ 𝐿 : |𝑤 | = 𝑖}, we will also denote 𝐶 as N, and 𝐿1𝑛 as 𝐿𝑛 , for brevity. This will be used when we consider lengthbased partitions of a language 𝐿 in the following sections. Using this, we can define the generable languages under space and time constraints. Definition 4.3. For a time constructible function 𝑡 : N → N, the generator family 𝐺 = (𝐺𝑖 )𝑖 ∈N is time bounded by 𝑡 if for all 𝑖 ∈ N, 𝐺𝑖 terminates within time 𝑡 (𝑖). Define the class of languages GTIME(𝑡 (𝑛)) generable by some 𝑡-time bounded generators as: GTIME(𝑡 (𝑛)) = {L (𝐺) : ∀𝑖.𝐺𝑖 is time bounded by 𝑡 (𝑖)} Definition 4.4. For a space constructible function 𝑠 : N → N, the generator family 𝐺 = (𝐺𝑖 )𝑖 ∈N is space bounded by 𝑠 if for all 𝑖 ∈ N, 𝐺𝑖 uses no more than 𝑠 (𝑖) cells on its work tape. Define the class of languages GSPACE(𝑠 (𝑛)) generable by some 𝑠-space bounded generators as: GSPACE(𝑠 (𝑛)) = {L (𝐺) : ∀𝑖.𝐺𝑖 is space bounded by 𝑠 (𝑖)} The following is immediate for both time and space bounded generators: Proposition 4.1. Suppose 𝑠 : N → N is space-constructible with 𝑠 (𝑖) > log(𝑖), and 𝑡 : N → N is time-constructible with 𝑡 (𝑖) > 𝑖, then: GSPACE(𝑠 (𝑛)) ⊆ NSPACE(𝑠 (𝑛))

GTIME(𝑡 (𝑛)) ⊆ NTIME(𝑡 (𝑛))

Proof. By simulation. For a full proof, see Appendix A.5. 4.1

Alternative Notions of Size

In our formalisation, a generator 𝐺 for a language 𝐿 will produce, on input 𝑛, a random element 𝑥 ∈ 𝐿 of length exactly 𝑛. We discuss here some alternative possible formalisations of instance size, inspired by testing practice.

Complexity Theory of Randomised Testing

0:13

4.1.1 On generating elements of size |𝑥 | ≤ 𝑛. Some generators in practice produce, given an 𝑛 ∈ N, elements of size |𝑥 | ≤ 𝑛 rather than |𝑥 | = 𝑛. These generators can fit within our framework by observing that such generator 𝐺 of the language 𝐿 can be mapped to an equivalent generator of the following language: 𝐿pad = {𝑥#0𝑖 : 𝑥 ∈ 𝐿 ∧ 𝑖 ∈ N} where 0𝑖 denotes 𝑖 repetitions of the reserved element 0, and # is a dedicated separator element. If 𝐿pad is generable by the |𝑥 | = 𝑛 scheme (for a given 𝑛, produce elements of length exactly 𝑛), then 𝐿 is generable by the |𝑥 | ≤ 𝑛 scheme (for a given 𝑛, produce elements of length at most 𝑛). Moreover, observe that the decision complexity of 𝐿𝑝𝑎𝑑 is the same as 𝐿, hence the later no-go results from connections to decision complexity classes also applies for |𝑥 | ≤ 𝑛 generation schemes. 4.1.2 Other parameterisations of size. Apart from string length, there can also be other concievable notions of size for a language 𝐿, in forms of some computable function 𝑠𝑧 : 𝐿 → N. For instance, for CNF formulas, the number of clauses or variables can both be useful notions of size. However, it is difficult to define notions of complexity on metrics like the clauses or variables count. This is because formulas with a fixed number of clauses or variables can, in general, describe formulas of arbitrary size in terms of their string representations. Grouping these together in a complexity-theoretic formalisation would mean assigning the same measure of complexity to all such elements—yet the arbitrary lengths of their string representations would genuinely take vastly different (particularly time) resources to produce. For 𝑠𝑧 based on the number of clauses or variables, the string representations of 𝑥 with 𝑠𝑧 (𝑥) = 𝑚 has unbounded ratios: ∀𝑛 ∈ N.∃𝑚 ∈ N.∃𝑥 ∈ 𝐿𝑚 . |𝑥𝑚| > 𝑛, where 𝐿𝑚 = {𝑥 ∈ Σ∗ : 𝑠𝑧 (𝑥) = 𝑚}. Alternatively, consider another 𝑠𝑧 where 𝑠𝑧 (𝑥) is within some range of |𝑥 |, e.g. (1 − 𝛿)|𝑥 | ≤ 𝑠𝑧 (𝑥) ≤ (1 + 𝛿)|𝑥 | In these cases, we can recover the fixed-length paradigm by padding all elements with 𝑠𝑧 (𝑥) = 𝑚 to a string of length exactly (1 + 𝛿)𝑚: the 𝑠𝑧-𝑚 elements are generable in the 𝑠𝑧-based paradigm if and only if length (1 + 𝛿)𝑚 elements are generable in the fixed-length paradigm. 5

Polynomial-Time Generators

In this section, we discuss generators that run in polynomial time, which corresponds to the class of realistically implementable generators. We note that prior work [44, 45] also considered polynomial-time generators, and actually predates PBT [10] itself. In the course of establishing a number of new results, we will also walk through some previously known results (Corollary 5.1, Proposition 5.1, Proposition 5.3) within our framework to highlight the links between modern-day PBT and complexity theory. An equivalent version of the following definition was first introduced in Definition 3.1 of [44]. Definition 5.1 (Polynomial-Time Generators). The generator family 𝐺 = (𝐺𝑖 )𝑖 ∈N runs in polynomial time if there exists a polynomial 𝑝 such that for all 𝑖 ∈ N, 𝐺𝑖 terminates in time 𝑝 (𝑖). Remark 1. We do not need the empty set clause of Definition 3.1 in [44], because we define the generator of an empty set as one that rejects all inputs, and we can use its rejection within 𝑝 (𝑖) steps (on a length 𝑝 (𝑖) input bitstring) to determine the emptiness of L (𝐺𝑖 ). On the other hand, if L (𝐺𝑖 ) ≠ ∅, then it can never reject when provided with a length 𝑝 (𝑖) input bitstring. Definition 5.2. The class of languages generable by some polynomial-time generator is: Ø PG = GTIME(𝑛𝑖 ) 𝑖 ∈N

0:14

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

Generators in randomised testing often use rejection sampling to produce generators for properties that are difficult to write explicit generators for. However, this approach trades ease in development for runtime during generation. If a property 𝑡 is satisfied by the generator with probability 𝑝, then the expected samples (time) to find such an instance is 1/𝑝—and this can easily be exponential if 𝑡 occurs rarely enough. The polynomial time constraint implies that for realistic generators, the use of such rejection sampling is only possible in controlled cases where 1/𝑝 is at most a polynomial. We will first see that the polynomial time generable languages are wholly contained within NP. Corollary 5.1. PG ⊆ NP. Proof. Consequence of Proposition 4.1.

Consequences for PBT: Corollary 5.1 shows that NP membership of the precondition is a necessary condition for efficient generation: if a precondition is PSPACE-hard or coNP-hard (e.g. quantified formulas, unsatisfiable formulas), there is no hope in seeking a fast, fully general generator—one must resort to rejection sampling or restrictions. Example 5.1. If NP ≠ PSPACE, then the following PSPACE-complete language is not generable in polynomial time: QBF = {𝜙 : 𝜙 is a satisfiable quantified boolean formula} where a quantified boolean formula is a propositional boolean formula with quantifiers. Example 5.2. If NP ≠ coNP, then the following coNP-complete language is not generable in polynomial time: TAUT = {𝜙 : 𝜙 is true for all assignments} The natural follow up question is whether the containment PG ⊆ NP is strict. We see that PG does contain some of the hardest problems in NP, namely CNF-SAT. Proposition 5.1. CNF-SAT ∈ PG. Proof. We give a sketch of the key ideas, and defer full detail to Appendix A.6. Consider a generator that first samples a random assignment x, then generates the formula 𝜙 based on x clause-by-clause. For each clause, we pick a random literal to evaluate to True, referring to the earlier chosen assignment x. The other literals in the clause are chosen at random. By construction, as 𝜙 is in CNF, each clause of 𝜙 is satisfied by x, and thus 𝜙 [x] also evaluates to True. Any satisfiable CNF-SAT formula 𝜓 has a chance of being sampled this way: if 𝜓 is satisfied by y, then the above procedure has a chance of choosing y and then constructing 𝜓 around y. □ Consequences for PBT: A precondition that is hard to decide can still be easy to generate: you can fully test properties on a #SAT solver (Example 3.2) without ever solving SAT, for example by using the generator in Proposition 5.1. Thus, testing difficulty cannot be inferred from decision difficulty. However, having an efficient generator for an NP-hard language does not directly yield a way to sample from easier languages, due to the lack of natural reductions for generators (as far as we know). The reduction used in NP-hardness embeds the easier language into the harder language. For generators, we would like the opposite: to surjectively map from instances of the hard language to the easier one, which is what is needed to implement a generator for the easier language. In fact, despite having a generator for an NP-complete problem, we will show below an example of a language in NP (in fact, 𝑃) that is unlikely to have a polynomial-time generator.

Complexity Theory of Randomised Testing

5.1

0:15

PG vs. NP

We now introduce a concrete problem in NP that is likely not in PG, as its membership in PG would contradict cryptographic assumptions that have withstood decades of scrutiny. Following [43], we will base our construction on so-called collision-resistant hash functions. Definition 5.3 (Hash Functions [43]). A hash function ℎ is a collection of functions (ℎ𝑛 )𝑛∈N , ℎ𝑛 : {0, 1}𝑛+1 → {0, 1}𝑛 , such that there exists a computable function ℎ : N × {0, 1}+ → {0, 1}+ with ℎ(𝑛, 𝑥) = ℎ𝑛 (𝑥) for all 𝑛 ∈ N, and ℎ runs in time polynomial in 𝑛. Definition 5.4 (Collision-Resistant Hash Functions). Hash function ℎ is considered collisionresistant if there exists no polynomial-time bounded randomised algorithm 𝐴 : N → {0, 1}∗ × {0, 1}∗ and polynomial 𝑞 such that for infinitely many 𝑛 ∈ N: P(𝐴(𝑛) = (𝑥, 𝑦) ∧ 𝑥 ≠ 𝑦 ∧ ℎ𝑛 (𝑥) = ℎ𝑛 (𝑦)) >

1 𝑞(𝑛)

If a randomised collision-finding algorithm of Definition 5.4 exists for the polynomial 𝑝-bounded hash function ℎ, then one can find size-𝑛 hash collisions of ℎ in expected polynomial time. Remark 2 (Unkeyed hashes and uniform attacks). In cryptographic literature [27], keyed hash families (ℎ𝑘 )𝑘 ∈𝐾 are more commonly used, with security against non-uniform attacks. We instead use unkeyed hash functions (Definition 5.3) with security against uniform attacks (Definition 5.4). Unkeyed hashes capture practical algorithms like SHA-256, but cannot resist non-uniform attacks: a hash collision is guaranteed to exist for each 𝑛 by the pigeonhole principle, and it is possible to hard-wire them into non-uniform circuits. Uniform attacks [40] are a formalisation of the security guarantees in practice: collisions exist, but there exist no efficient algorithms to find them. As we shall see later, the uniformity of generators and the resistance of unkeyed hashes against uniform attacks are precisely what give us the non-generability result of Proposition 5.2. Define the following language for a hash function ℎ: Definition 5.5. For hash function ℎ: COLLISIONℎ = {(𝑥, 𝑦) ∈ {0, 1}+ × {0, 1}+ : 𝑥 ≠ 𝑦 ∧ |𝑥 | = |𝑦| ∧ ℎ |𝑥 | (𝑥) = ℎ |𝑥 | (𝑦)} Clearly, for any hash function ℎ (collision-resistant or not), given (𝑥, 𝑦), a Turing machine 𝑀 can execute ℎ(𝑥) and ℎ(𝑦), and accept if they compute the same hash. Since ℎ executes in time polynomial in its input size, 𝑀 will terminate in polynomial time. Lemma 5.1. For all hash functions ℎ, COLLISIONℎ ∈ 𝑃. Proposition 5.2. If for all hash functions ℎ, COLLISIONℎ ∈ PG, then collision resistant hash functions do not exist. Proof. Suppose COLLISIONℎ ∈ PG, then there exists a polynomial-time generator 𝐺 = (𝐺𝑖 )𝑖 ∈N with L (𝐺) = COLLISIONℎ . For a given 𝑛 ∈ N, we can find a collision of ℎ𝑛 by running 𝐺 2𝑛+1 (assuming 1 character is used as a separator) to obtain a pair (𝑥, 𝑦) ∈ COLLISIONℎ of size 2𝑛 + 1. Note this is possible due to the uniformity of (𝐺𝑖 )𝑖 ∈N . Since |𝑥 | = |𝑦| we know that |𝑥 | = |𝑦| = 𝑛, and hence the pair found is a collision of ℎ𝑛 : ℎ𝑛 (𝑥) = ℎ𝑛 (𝑦). As 𝐺𝑖 runs in polynomial time, we have therefore a randomised algorithm that finds hash collisions in polynomial time, for infinitely many 𝑛, and with success probability 1. □ Theorem 5.1 (Cryptographic Separation). If collision-resistant hash functions exist, then PG ⊊ NP. In fact, P ⊈ PG.

0:16

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

Consequences for PBT: Simple software may be infeasible to test efficiently, in full generality. Easyto-decide preconditions (here, checking a hash collision in Theorem 5.1) can still be difficult to generate satisfying inputs for. Easy decision complexity is neither necessary nor sufficient for generability. (For a classification of what is efficiently generable, see our certificate scheme of Theorem 7.1.) So, the power of efficient generators has an interesting relationship with the classical decision classes: PG contains some of the hardest problems in NP, yet it also does not contain some problems in P. We thus see that the complexity of the language for generation is a related but different concept from the complexity of the language for decision algorithms. Some generators in testing literature also make use of SAT solvers [6, 32, 46, 48], to increase expressivity. Here we quote a result first shown in [44]: with a SAT oracle, one can generate all NP problems in a polynomial number of steps. Let Σ𝑖𝑃 denote the 𝑖th level of the polynomial hierarchy with an NP base machine. For a generator class 𝑋 with constraints 𝑌 and language 𝐿, define 𝑋 𝐿 as the class of languages generable by generators with constraints 𝑌 and oracle access to a decider for 𝐿. For a generator complexity class Ð 𝑋 and a decision complexity class 𝐶, define 𝑋 𝐶 = 𝐿∈𝐶 𝑋 𝐿 . Proposition 5.3. ΣP1 = NP ⊆ PGNP ⊆ NPNP = ΣP2 Proof. A case from a more general result in [45]. See Appendix A.8 for a proof of this case.

Consequences for PBT: Although using a SAT/SMT solver during generation allows NP preconditions to be satisfied, Proposition 5.3 shows it is not a panacea: for example, PSPACE-hard or EXPTIME-hard preconditions remain out of reach even with a perfect SAT or SMT solver, respectively. 5.2

Expected Polynomial-Time Generators

Since sampling is inherently a random process, another feasible resource constraint on generators is via the expected time to produce a sample, rather than a deterministic time bound. The following defines expected polynomial time generators: Definition 5.6. The generator family 𝐺 = (𝐺𝑖 )𝑖 ∈N runs in expected polynomial time if there exists a polynomial 𝑝 such that for all 𝑖 ∈ N, 𝐺𝑖 terminates in expected time 𝑝 (𝑖). Moreover, for all 𝑤 ∈ L (𝐺𝑖 ), there exists at least one bitstream where 𝑤 is produced before time 𝑝 (𝑖). The condition that there exists at least one path of polynomial length for any 𝑤 ensures that there are no fundamentally difficult instances in the language.6 Our definition does not collapse to PG, since execution paths longer than polynomial are still permitted. Intuitively, expected polynomial time describes repeated retries of a polynomial process with bounded chance of failure: a generator version of BPP. On lucky runs, the process takes polynomial time, which corresponds to the existence of a polynomial-length path. Definition 5.7. The class of languages generable by some expected polynomial-time generator is: EPG = {L (𝐺) : 𝐺 is an expected polynomial-time generator} Proposition 5.4. PG ⊆ EPG ⊆ NP. Proof. A generator that terminates in deterministic time 𝑝 (𝑖) will also terminate in expected time at most 𝑝 (𝑖), thus PG ⊆ EPG. EPG ⊆ NP follows by simulation—for a full proof, see Appendix A.7. □ 6 Such an issue of hard instances hiding in long runs was also noted in [25], where interestingly, the modelling choice made

by Jerrum et al. [25] was to ignore the expected-time case and only focus on deterministic time bounds.

Complexity Theory of Randomised Testing

0:17

Consider the language PRIMES, defined as follows: Definition 5.8. Assume 𝑥 is interpreted in its binary representation, define: PRIMES = {𝑥 ∈ {0, 1}∗ : 𝑥 > 1 ∧ ∀𝑦.1 < 𝑦 < 𝑥 =⇒ 𝑔𝑐𝑑 (𝑥, 𝑦) = 1} We show that PRIMES ∈ EPG: an interesting case as it is an open problem in mathematics to determine whether there exists a PG algorithm for PRIMES [49]. That is, an algorithm which always produces a prime number of a certain size within polynomial time. However, it does have a natural algorithm running in expected polynomial time, and also does not follow the structure established for PG in Theorem 7.1. It would thus be tempting to conjecture that PG ⊊ EPG. Proposition 5.5. PRIMES ∈ EPG. Proof. This is a straightforward application of the fact that PRIMES ∈ 𝑃 [1], and the Prime Number Theorem on the density of primes. Together, these allow us to use rejection sampling for primes between 2𝑛 and 2𝑛+1 . See Appendix A.9 for a full proof. □ Consequences for PBT: Giving up worst-case polynomial time guarantees can at times result in simpler generator designs, and potentially allow more sets to be sampled (but is an open problem whether this is the case [49]). However, care must be taken to ensure the runtime is truly polynomial in expectation (as in Proposition 5.5), and that no element is intrinsically hard to sample: otherwise the efficiency and soundness (distributional support) guarantees no longer hold. Akin to boosting the probability of deciding a language in probabilistic complexity classes, we can make a similar statement on boosting the probability of generating an instance for EPG. Proposition 5.6. For 𝐿 ∈ EPG, and any 𝜖 > 0, there exists an algorithm 𝐴 that produces a sample 𝑥 ∈ 𝐿 of length 𝑛 with probability > 1 − 𝜖, in polynomial time of 𝑛 and log(1/𝜖). Proof. By considering long runs and using Markov’s inequality to bound the non-generation probability. See Appendix A.10 for a full proof. □ This boosting result means that for EPG languages, we can obtain samples with arbitrarily high probability in polynomial time. Thus, this would also rule out the membership of COLLISIONℎ in EPG, unless collision-resistant hash functions do not exist. Proposition 5.7. If collision-resistant hash functions exist, then EPG ⊊ NP. Moreover, 𝑃 ⊈ EPG. Proof. Suppose for a contradiction that for all hash functions ℎ, COLLISIONℎ ∈ EPG, then there exists an expected polynomial time generator that generates COLLISIONℎ . By Proposition 5.6, for any 𝑘 ∈ N, we can obtain a generator that produces a length-𝑛 sample of COLLISIONℎ with probability at least 1/𝑘, within polynomial time in 𝑛 (with 𝜖 fixed to 1/𝑘, the log(1/𝜖) term becomes a constant factor in the polynomial). Since this is a procedure that violates the collision resistance property (Definition 5.4) of ℎ, no hash functions are collision resistant, which is a contradiction. □ 6

Space Bounded Generators

Space-bounded generators have a limited amount of space to work with, but can exhibit arbitrary running time. Whilst this seems like a rather loose restriction on generators, we note that these constraints actually correspond to a large class of generators implemented in practice. Space-bounded generation can model test-case generation algorithms that produce not only independent outputs in a single run (like in the case of PG or EPG), but also past-dependent outputs in an iterative fashion. That is, algorithms where previous outputs can influence future produced

0:18

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

outputs, for instance by caching some data collected from past outputs to introduce dependence in the generation algorithm. For a given randomised algorithm 𝐴 that produces the correlated sequence (𝑥 1, . . . , 𝑥𝑛 , . . .) one by one, we can define a 𝐺 that first samples for an 𝑛 ∈ N (e.g., using Example 2.1), then simulates 𝐴 until the first 𝑛 − 1 outputs have been emitted, before writing the final 𝑥𝑛 on the output tape. Clearly, 𝑥 is a possible output of the algorithm 𝐴 if and only if 𝑥 ∈ L (𝐺), and that 𝐺 uses the same amount of space as 𝐴 to produce 𝑥. Many prominent examples of practical generators naturally fit this framework of sequenceproducing generators. These include coverage-guided fuzzing [5] and concolic execution [8, 15]— which we will discuss in more detail later on in Section 6.2. In these cases, the time taken by the generator is of orthogonal relevance, as many of these methods are designed to run indefinitely—for instance, as a background process to continuously find bugs [5, 7]. Thus, for these generation algorithms, space bounds can be a more natural theoretical constraint to study. There is a caveat with using space-bounded generators verbatim to model these algorithms: many such algorithms call the SUT, which may be arbitrary computation. Thus, it would make sense to separate the generation algorithm from the SUT call: the generation process should be independent of the SUT it is applied to. This issue will be addressed later in Section 6.2. We start by defining the specific space-bounded generation classes considered in this section. The first is on logspace generators, which have access to pointers and counters up to the size of the generated output. Logspace computations still make sense, since generators have read-once-only input and write-once-only output, preventing them from using the input/output tapes for storing more information than their space bound permits. Though seemingly restrictive, we will see later that logspace still suffices for generating instances of useful predicates, like the set of satisfiable 2-SAT formulae or directed graphs with guaranteed connectivity between two chosen nodes. Definition 6.1. The class of log-space generable languages are denoted as LG. Ø LG = GSPACE(𝑐 log(𝑛)) 𝑐 ∈N

We also consider languages generable within polynomial space. This class is permissive and covers the majority of the state-dependent generation algorithms seen in practice: storing more than a polynomial amount of data in the size of the test input is impractical in most applications. Definition 6.2. The class of languages generable within polynomial space is defined as: Ø PSPACEG = GSPACE(𝑛𝑖 ) 𝑖 ∈N

We begin with some general facts on space-bounded generators, connecting them to existing models of time-bounded generators and decision procedures. The first proposition relates space-bounded decision procedures and time-bounded generators, where a time-bounded generator with much more time can generate samples from a space-bounded NDTM. This is in analogy to a standard result on space-time tradeoffs between NDTMs and DTMs for decision procedures. Proposition 6.1. For space-constructible 𝑠 : N → N, NSPACE(𝑠 (𝑛)) ⊆ GTIME(2𝑂 (𝑠 (𝑛) ) ) Proof. Deferred to Appendix A.13. Intuitively, the extra time on the generator allows for the nondeterministic machine to be simulated by enumerating configurations. Then, by using a complete decision language within NSPACE(𝑠 (𝑛)) (itself decidable on the generator as a procedure) that

Complexity Theory of Randomised Testing

0:19

decides whether an accepting suffix exists for 𝑀, it is possible to generate, for any 𝐿 ∈ NSPACE(𝑠 (𝑛)), any 𝑥 ∈ 𝐿 via repeated queries to this complete language. □ Proposition 6.1 together with Proposition 4.1 relates space and (much higher) time bounds for generators, analogous to the classic time-space tradeoff theorem for deciders. Corollary 6.1 (Time-Space Tradeoff). For a space constructible function 𝑠 : N → N with 𝑠 (𝑛) ≥ log(𝑛), GSPACE(𝑠 (𝑛)) ⊆ GTIME(2𝑂 (𝑠 (𝑛) ) ) For the decision version of Corollary 6.1, a configuration-counting argument is the standard proof. This argument does not carry over immediately, since space-bounded generators can be driven into cycles for an unbounded amount of time by their input. In Appendix A.11, we discuss the issue with the configuration counting argument in more detail and give a fix in an alternative, direct proof of Corollary 6.1. 6.1

Logspace Generators

Proposition 4.1 and Proposition 6.1 together mean that every NL language is generable in polynomial time (i.e., has a PG algorithm). Corollary 6.2. LG ⊆ NL ⊆ PG. This implies properties with preconditions such as 2-SAT, or connected directed graphs, will also have efficient polynomial-time generators. This also gives a practical sufficient condition for PG membership: if the predicate can be decided by an NL machine, then an efficient polynomial-time generation algorithm is guaranteed to exist. We can apply a known result [2] to show that there exists an algorithm in EPG uniformly generating any 𝐿 ∈ LG. The main idea is to view logspace generators as logspace transducers (adapted to our setting), which Arenas et al. [2] proved have uniform samplers with a bounded probability of failure. It is straightforward to adapt such uniform samplers to a generator in EPG. Proposition 6.2. If 𝐿 ∈ LG, then there exists a EPG generator of uniform distributions. Proof. We defer the proof to Appendix A.12.

Consequences for PBT: When a precondition is decidable in NL (e.g. reachability, 2-SAT, and most syntactic well-formedness checks) an efficient generator is guaranteed to exist, and (by Proposition 6.2) even a uniform one. We also see that even in the restricted setting of LG, we are still able to generate NL-complete languages, analogous to how PG contains NP-complete problems. Definition 6.3. Reachability on directed graphs is defined as: REACH = {⟨𝐺, 𝑠, 𝑡⟩ : ∃ path from 𝑠 to 𝑡 in 𝐺 } Proposition 6.3. REACH ∈ LG. Proof. The construction is based on certificate sampling and instance reconstruction, which is generalised by Theorem 7.1 later on. We give a sketch here and defer the details to Appendix A.14. We represent graphs as an edge-list, and partition REACH by the total number of vertices and edges. First, select the source and target as 𝑠 and 𝑡, then generate a random walk from 𝑠 to 𝑡, outputting edges as they are used. Then, add edges to the graph in Erdos-Renyi fashion, again outputting them directly after selection. Every 𝑥 ∈ REACH has a nonzero probability of being sampled. □

0:20

6.2

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

Generators With Feedback

Testing techniques like concolic execution and coverage-guided fuzzing produce a (potentially infinitely long) sequence of test inputs, where the results from executing previous inputs are used to guide the generation of the next using the results from running the SUT. Since the SUT can perform arbitrary computation, we separate the SUT from the generation technique in our model. Definition 6.4 (Function Oracle Turing Machine). A TM 𝑀 𝑓 with oracle access to 𝑓 : Σ∗ → Σ∗ is a standard TM with an additional read-write query tape 𝑡𝑞 , a read-only answer tape 𝑡𝑎 , and a designated state 𝑠𝑜 . When 𝑀 𝑓 enters state 𝑠𝑜 with 𝑥 written on the query tape 𝑡𝑞 , the contents on the answer tape 𝑡𝑎 will be replaced by 𝑓 (𝑥). The language recognised/generated by 𝑀 𝑓 is denoted L (𝑀 𝑓 ). For a Turing machine 𝑀, we denote 𝑀 𝑓 as the same Turing machine with access to an oracle for 𝑓 . When there is no ambiguity, we may drop the subscript 𝑓 from 𝑀 𝑓 for brevity. If 𝑀 is a generator, we will denote it with 𝐺 instead, i.e. 𝐺 𝑓 is a generator 𝐺 with oracle access to 𝑓 . This oracle machine is different from the ones discussed in Proposition 5.3: here oracle access is to a function 𝑓 whereas the previous one gives oracle access to a decider 𝑓 : Σ∗ → {𝑇 , 𝐹 }. The execution of the SUT, together with the computation of data guiding future generation, can be viewed as an oracle available to the generator. We present simplified versions of two prevalent testing methodologies and show how they fit into our framework, noting that real implementations often employ variants and optimisations to reduce time and space usage. Nonetheless, our eventual result still holds: any space-bounded generation process, no matter how it is guided, can only generate languages within some complexity class, thus ruling out all languages outside of the class. Example 6.1 (Concolic Execution). Concolic execution for an SUT 𝑆 is an iterative process that first generates an input 𝑥 0 , then tracks the control flow path taken by the run 𝑆 (𝑥 0 ), collecting path constraints 𝑝 0 along the way. Then, new inputs 𝑥𝑖 are generated to ensure that they reach control-flow paths unexplored by previous inputs 𝑥 0, . . . , 𝑥𝑖 −1 , usually through an SMT solver to produce 𝑥𝑖 that satisfies an alternative path constraint, which forces unexplored paths to be taken. Here, the SUT oracle 𝑓 : Σ∗ → Σ∗ accepts a generated input 𝑥𝑖 , executes the SUT on 𝑥𝑖 , and returns the path information 𝑝𝑖 = 𝑓 (𝑥𝑖 ) observed during that execution. The generator 𝐺 has oracle access to 𝑓 . After generating each output 𝑥𝑖 , 𝐺 calls 𝑓 (𝑥𝑖 ) and stores the paths taken within the codebase as a list 𝑝 0 = 𝑓 (𝑥 0 ), . . . , 𝑝𝑖 = 𝑓 (𝑥𝑖 ). To produce the element 𝑥𝑖+1 , 𝐺 invokes a solver to find an input 𝑥𝑖+1 that satisfies the path condition 𝑝𝑖+1 , distinct from all previous paths 𝑝 0, . . . , 𝑝𝑖 . Example 6.2 (coverage-guided fuzzing). coverage-guided fuzzing produces new inputs by mutating previous inputs that are likely to gain new coverage. Historical input 𝑥 is selectively stored as 𝑦𝑘 together with the code coverage 𝑝𝑘 obtained by 𝑦𝑘 . To generate 𝑥𝑖+1 that may achieve new coverage, inputs 𝑦 that were close to achieving new coverage are selected for mutation. If new coverage has been found by 𝑥𝑖+1 , then it is stored along with the previous inputs that expanded coverage: 𝑦1, . . . , 𝑦𝑘 . Here, the SUT oracle 𝑓 : Σ∗ → Σ∗ accepts inputs 𝑥𝑖 and outputs the coverage data 𝑝𝑘 for the codebase achieved by 𝑥𝑖 . The generator has oracle access to 𝑓 , storing historical inputs 𝑦1, . . . , 𝑦𝑘 . Using these, it produces new inputs by mutating existing inputs for new coverage. Since the oracle contains computation of the SUT, they can realistically be of any complexity (e.g. compilers), and is independent of the generation complexity. Therefore, we do not constrain resource usage of the oracle. However, as the output still needs to be parsed and stored by the generator, the size of the output from the oracle call can affect the complexity of generation. For an oracle, we therefore define the following constraint: Definition 6.5. A function 𝑓 : Σ∗ → Σ∗ is length-bounded by 𝑠 : N → N if for all 𝑥 ∈ Σ∗ , |𝑓 (𝑥)| ≤ 𝑠 (|𝑥 |).

Complexity Theory of Randomised Testing

0:21

Complexity classes can be defined analogously for Turing machines with oracle access. Here, the oracle input tape is under the same space bounds as work tapes. Definition 6.6. For space constructible function 𝑠 : N → N, and a function 𝑓 : Σ∗ → Σ∗ , define the classes of languages decidable/generable within 𝑠 space as follows: DSPACE(𝑠 (𝑛)) 𝑓 = {L (𝑀 𝑓 ) : 𝑀 is space-bounded by 𝑠 } GSPACE(𝑠 (𝑛)) 𝑓 = {L (𝐺 𝑓 ) : 𝐺 is space-bounded by 𝑠 } Note that the space-bound 𝑠 applies both to the work tape and the query tape. Definition 6.7. For a function 𝑓 : Σ∗ → Σ∗ , Ø PSPACE 𝑓 = DSPACE(𝑛𝑐 ) 𝑓 𝑐 ∈N

PSPACEG 𝑓 =

Ø

GSPACE(𝑛𝑐 ) 𝑓

𝑐 ∈N

Both techniques described in Example 6.1 and Example 6.2 can use infinite space in the limit. However, real-world applications are bounded by resource limits, and using polynomial space as a proxy for realism, we ask: what constraints placed on coverage-guided fuzzing and concolic execution ensure that the procedures remain in PSPACEG? Coverage-Guided Fuzzing. Since the codebase is fixed, the coverage information has constant size regardless of the input sizes, thus the output of the oracle is always within a polynomial bound (in fact, constant size). Each new coverage-finding input is stored alongside its coverage information, which consumes space on the work tape. Within a polynomial space bound 𝑝, generators of outputs of sizes up to 𝑛 can store 𝑝 (𝑛)/𝑛 previous inputs (if stored naively). Concolic Execution. The data returned by the oracle consist of the path taken by the generated input 𝑥𝑖 of size (up to) 𝑛. For the oracle to stay within polynomial space bounds, the path taken must therefore have at most polynomially many control flow statements (which is achievable with instrumentation and timeout, for instance). As the previous paths taken are stored by the generator, there can be at most a polynomial number of historical paths stored. The above examples are illustrative for demonstrating the kind of constraints that polynomial space induces on naive implementations of popular generation algorithms. In reality, optimisations would be used on implementations for either technique [3, 38]: the calculus shifts accordingly for the number of paths or test cases one is able to store, but the bottleneck remains in the polynomial space bounds. We show below the limits of generation capability for such feedback-driven approaches when a polynomial space bound is adhered to. The previous complexity results for space-bounded generators still hold with oracle access. Proposition 6.4. Suppose 𝑠 : N → N is both space and time constructible with 𝑠 (𝑛) ≥ log(𝑛), and 𝑓 : Σ∗ → Σ∗ is length-bounded by 2𝑂 (𝑛) . Then: GSPACE(𝑠 (𝑛)) 𝑓 ⊆ NSPACE(𝑠 (𝑛)) 𝑓 ⊆ GTIME(2𝑂 (𝑠 (𝑛) ) ) 𝑓 Proof. Deferred to Appendix A.15. Similar to the non-oracle version of Proposition 6.1. Extra care is needed when counting the configurations of oracle machines: the read-only answer tape and 𝑓 being a function are the two factors that keep the number of configurations at 2𝑂 (𝑠 (𝑛) ) . □ Proposition 6.5. For 𝑓 : Σ∗ → Σ∗ length-bounded by 2𝑂 (𝑛) , PSPACEG 𝑓 = PSPACE 𝑓 Proof. Deferred to Appendix A.17. PSPACEG 𝑓 ⊆ PSPACE 𝑓 follows from a variant of Savitch’s theorem adapted for our oracle machines. PSPACE 𝑓 ⊆ PSPACEG 𝑓 follows since rejection sampling can be performed whilst reusing space. □

0:22

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

If the oracle 𝑓 itself is computable in polynomial space, then both PSPACE 𝑓 and PSPACEG 𝑓 collapse to PSPACE. We thus have the following as a corollary: Theorem 6.1. PSPACEG = PSPACE. If the SUT itself runs in polynomial space, then the polynomial-space generable properties for the SUT are exactly the PSPACE decidable ones. If the SUT does not run in polynomial space, then the polynomial-space generable properties are exactly those with input sets decidable by a PSPACE machine with oracle access to the SUT. Consequences for PBT: Theorem 6.1 implies feedback-driven techniques—coverage-guided fuzzing, concolic execution—are bounded by PSPACE. For example, unless the SUT itself is powerful enough to solve EXPTIME-complete problems, EXPTIME-complete sets remain out of reach regardless of how the feedback loop is engineered. Corollary 6.1 says that any input set a feedback-driven technique can sample in polynomial space is also reachable by a (slower) generator of independent samples. Example 6.3. If PSPACE ≠ EXP, then the following problems are not generable in polynomial space. (1) Board positions of generalised size-𝑛 Chess/Shogi/Draughts games with a winning strategy for the player that moves first. (2) For any programming language, the set of programs that terminate in 𝑘 steps, with the step count specified in binary. 7

Designing Generators and Generator Libraries

In this section, we introduce some practical insights that come from our theoretical framework. We first provide canonical constructions for building efficient generators (that are members of PG), and then apply the results we established in generation complexity to gain understanding of the limitations of compositional library designs for randomised testing. 7.1

Conditions for PG Membership

We propose two characterisations of PG languages, which formalise the main known techniques for obtaining PG generators. 7.1.1 PG Via Basis Extension. The first technique is based on the ability to generate default elements of the language. A difficulty with generating inputs accepted by NP deciders is that the majority of the branches may fail. Thus, a generator would need to find a branch of the NP computation that succeeds in order to confirm a string’s membership—which by naive methods leaves an exponential number of branches needing to be checked. However, if one has the ability to efficiently find a default element as a fallback, a generator is free to try potentially-failing computations, allowing it to generate the remainder of the NP language. Definition 7.1. For the language 𝐿, define the functions that compute a default element of 𝐿 as: DEFAULT(𝐿) = {𝑓 : {1}∗ → 𝐿 : 𝐿𝑖 ≠ ∅ =⇒ 𝑓 (1𝑖 ) ∈ 𝐿𝑖 , 𝐿𝑖 = ∅ =⇒ 𝑓 (1𝑖 ) = 𝜖} Proposition 7.1. For 𝐿 ∈ NP, DEFAULT(𝐿) ∩ FP ≠ ∅ if and only if 𝐿 ∈ PG, where FP denotes polynomial-time computable functions. Proof. The main idea is that being able to compute a default element 𝑥 means we can simulate a branch of the NDTM, falling back to 𝑥 if the branch rejects. For a full proof, see Appendix A.16. □ We can extend the structure of such techniques to a sufficient condition for generating samples from an NP language, by asserting extra structural conditions on the language for efficient extension from a base element.

Complexity Theory of Randomised Testing

0:23

Proposition 7.2. Let 𝐿 be a language and ≼ be a polynomial-time computable partial order on Σ∗ . Let 𝐾 = {𝑠 ∈ 𝐿 : š𝑠 ′ ∈ 𝐿 \ {𝑠}, 𝑠 ′ ≼ 𝑠} be the set of minimal elements in 𝐿 according to ≼. 𝐿 ∈ PG if the following conditions are met: (1) Upward Closure: For any 𝑠 ∈ 𝐿 and string 𝑠 ′ , if 𝑠 ≼ 𝑠 ′ , then 𝑠 ′ ∈ 𝐿. (2) Samplable Minimal Basis: 𝐾 contains every minimal element of 𝐿, and is in PG. (3) Efficient Extension: For every element 𝑠 ∈ 𝐾, there exists a polynomial-time generator 𝐺𝑠 such that L (𝐺𝑠 ) = {𝑠 ′ : 𝑠 ≼ 𝑠 ′ ∧ |𝑠 ′ | = |𝑠 |}. In other words, if there exists a core set of instances in 𝐿 that is efficiently generable, and one can efficiently extend from the core instances to any instances in 𝐿, then the set is efficiently generable. Proof. Deferred to Appendix A.18.

This provides a technique for obtaining PG sampling algorithms, and indeed many NP-hard languages satisfy this property. We give examples applications of Proposition 7.2 in Appendix A.19. 7.1.2 PG Via Certificate Sampling. Many NP decision problems are hard because of the need to find a potentially small set of certificates for the instances. However, we have seen that many hard NP problems nonetheless have efficient generators. The problem of generating satisfying instances of an NP language becomes easier than decision when there is a means of constructing instances from certificates: ensuring that the generated instance is in the language by construction. This is the core insight used by many existing generators of NP-complete languages, which is based on their verifiers: first sample a random certificate, and then sample a random instance that is verified by the certificate. We generalise this and show that the reverse also holds. That is, every generator for 𝐿 is associated with some canonical verifier 𝑉 for 𝐿, a method to sample certificates of 𝑉 , and a method to recover random instances from certificates. Thus, every generator can be viewed as an efficient algorithm to recover instances for each canonical certificate (i.e., the certificate consisting of bitstrings). Definition 7.2 (Polynomial-Time Verifier). 𝐿 has a polynomial-time verifier 𝑉 if: • 𝑉 takes inputs 𝑤#𝑐, where 𝑤 ∈ Σ∗ and 𝑐 ∈ Σ+ is a certificate. • 𝑉 terminates in polynomial time of its input size. • There exists a polynomial 𝑝 where: – If 𝑤 ∈ 𝐿, then there exists a certificate 𝑐 with |𝑐 | ≤ 𝑝 (|𝑤 |) such that 𝑉 accepts 𝑤#𝑐. – If 𝑤 ∉ 𝐿, then for all certificates 𝑐, 𝑉 rejects 𝑤#𝑐. Definition 7.3 (Certified Inputs). For a verifier 𝑉 , and a certificate 𝑐, define the certified inputs of 𝑐, 𝑉𝑓 (𝑐) as: 𝑉𝑓 (𝑐) = {𝑤 ∈ Σ+ : 𝑉 (𝑤#𝑐) accepts} Definition 7.4 (Certificate Generator). Verifier 𝑉 for 𝐿 has a certificate generator 𝑆𝑉 if there exists a polynomial 𝑞, and 𝑆𝑉 = (𝑆𝑛 )𝑛∈N is a uniform family of generators where: Ð (1) Each 𝑆𝑖 is such that 𝐿𝑖 = Σ𝑖 ∩ 𝑐 ∈ L (𝑆𝑖 ) 𝑉𝑓 (𝑐). (2) Each 𝑆𝑖 runs in time 𝑞(𝑖). (3) If 𝐿𝑖 is empty, then 𝑆𝑖 rejects. Ð Note that in the first condition, we constrain 𝑐 ∈ L (𝑆𝑖 ) 𝑉𝑓 (𝑐) to the subset of length-𝑖 strings. This is necessary as a certificate may verify instances of many lengths. As a concrete example, consider a verifier of SAT, taking certificates to be the variable assignment. A specific assignment can be the certificate for formulas of arbitrary length. Definition 7.5 (Certificate Recovery). Verifier 𝑉 for 𝐿 has a certificate recoverer 𝑅𝑉 if there exists a polynomial 𝑝 in two variables, and 𝑅𝑉 = (𝑅𝑖 )𝑖 ∈N is a uniform family of TMs where:

0:24

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

(1) Each 𝑅𝑖 has a read-only input tape for certificates 𝑐 ∈ Σ+ , a read-only input tape of random bits, and an output tape. (2) For all 𝑐, 𝑅𝑖 (𝑐) is a generator for 𝐿𝑖 ∩ 𝑉𝑓 (𝑐). (3) For all 𝑐, 𝑅𝑖 (𝑐) runs in time 𝑝 (𝑖, |𝑐 |). Definition 7.6 (Certificate Scheme). 𝑉 has a certificate scheme (𝑆𝑉 , 𝑅𝑉 ) if there exist a certificate generator 𝑆𝑉 and also a certificate recoverer 𝑅𝑉 . Theorem 7.1 (Generators are Certificate Schemes). The following are equivalent: (1) 𝐿 is generable in polynomial time (𝐿 ∈ PG). (2) There exists a polynomial-time verifier 𝑉 for 𝐿, and 𝑉 has a certificate scheme. Proof. We defer the full proof to Appendix A.20. Intuitively, a certificate scheme yields a polynomial time generator by composing the components together. Conversely, given a PG generator 𝐺, one can derive a verifier 𝑉𝐺 by treating the certificate as the input bitstring of 𝐺. Then, one can validate that there is a certificate scheme for 𝐺 based on the verifier 𝑉𝐺 , by sampling for a random bitstring certificate of length 𝑝 (𝑛), where 𝑝 is the polynomial time-bound of 𝐺. □ Consequences for PBT: A strategy for building an efficient generator for a language is to study its verifier rather than its decider, by sampling a certificate first, then building a random instance around it. Theorem 7.1 shows that every efficient generator actually uses some instance of this strategy. 7.2

Compositional Libraries For Generators

As established earlier, while rejection sampling gives an easy way to automatically derive generators that satisfy a specific predicate, it can quickly become intractable as the probabilities of data satisfying the predicate drop. Moreover, if the predicate is difficult to verify, then the validation step during test-case generation can itself become the dominant factor for a testing campaign. Due to this, property-based testing libraries often also provide combinators for users to specify custom generators, rather than relying on rejection sampling to produce inputs. A desirable characteristic for such libraries is compositionality. In the context of testing, one clear place for compositionality involves the duality of generators and predicates: predicates and generators both correspond to formal languages on the inputs. Where predicates interpret a language 𝐿 as a function of type Σ∗ → B, generators interpret 𝐿 as a surjective computable function {0, 1}∗ → 𝐿 that constructs instances of the language from randomness. Logical predicates are easily specified using existing languages, such as propositional logic, described by the following grammar, where Atomic refer to base predicates taken as fact (e.g. ≤, ≡): 𝑇 := Atomic | 𝑇 ∧ 𝑇 | 𝑇 ∨ 𝑇 | 𝑇 → 𝑇 | ¬𝑇 Compositionality in this context is the requirement for a function 𝑓 to map the logical language into generators homomorphically, such that 𝑓 follows the same structure as the logical language: 𝑓 (𝑎 : Atomic) = 𝑓𝑎 (𝑎)

𝑓 (𝑡 1 → 𝑡 2 ) = gImplies(𝑓 (𝑡 1 ), 𝑓 (𝑡 2 ))

𝑓 (𝑡 1 ∧ 𝑡 2 ) = gAnd (𝑓 (𝑡 1 ), 𝑓 (𝑡 2 ))

𝑓 (¬𝑡) = gNot (𝑓 (𝑡))

𝑓 (𝑡 1 ∨ 𝑡 2 ) = gOr (𝑓 (𝑡 1 ), 𝑓 (𝑡 2 ))

where 𝑓𝑎 maps the base predicate 𝑎 to a generator of values that satisfies the predicate 𝑎, and gAnd, gOr, gImplies, gNot are the functions that implement the generator homomorphisms for logical operators ∧, ∨, →, ¬ respectively. We now show that, based on intuitions imported from complexity theory via our formalisation, such a compositional design for efficient generators is not possible in general—if the logical language for predicates can express predicates equivalent in power to the operations ¬ or ∧.

Complexity Theory of Randomised Testing

0:25

To put it another way: in a compositional library of generators/predicates, either the generators cannot have polynomial runtime guarantees, or the logical operations must be limited in expressivity—it cannot contain anything equivalent to ¬ or ∧ (that is, gAnd and gNot cannot have implementations for generators). Firstly, we show that some operators can be implemented composably for efficient generators. Proposition 7.3. PG is closed under concatenation, Kleene star, and union. Proof. We defer the proof to Appendix A.21.

On the other hand, we see that some logical operators on predicates cannot have composable implementations on generators (under standard complexity constraints). Theorem 7.2 (Efficient Generators are not Composable). If NP ≠ coNP, then PG is not closed under complementation. If collision-resistant hash functions exist, then PG is not closed under intersection. Proof. Complementation follows from Corollary 5.1 and Proposition 5.1. If CNF-UNSAT = CNF-SAT𝑐 ∈ PG, then CNF-UNSAT ∈ NP by Corollary 5.1. Thus NP = coNP and we have a contradiction. See Appendix A.22 for a proof of the intersection case. □ Consequences for PBT: No PBT library can offer a general gAnd or gNot combinator with polynomialtime efficiency guarantees. Theorem 7.2 means library designers must choose: restrict the predicate language (e.g. to NL/linear Datalog, where compositional compilation is possible), or accept rejection sampling—which our results show is then close to optimal. Remark 3 (What is still possible?). Theorem 7.2 does not rule out compositionality on restricted predicates, or on alternative logical languages that do not entail intersection and negation operators. For instance, we know that NL ⊆ PG, and NL is closed under the logical operations discussed in this section (complementation, intersection, union). Thus, it would be feasible in theory to design a composable generator library, restricted to NL predicates Pred : 𝐿 → B that produces polynomial-time composable generators for NL languages. Descriptive complexity gives a path to achieving this: NL Turing machines have an exact correspondence with linear Datalog programs. Thus, it would be possible in theory to write a compiler that composes linear Datalog predicates together, and compiles them into polynomial-time generators of their accepted languages. 8

Related Work

The closest work to ours is [45], which introduced complexity classes for polynomial-time generators and observed several similar results to ours: polynomial-generable languages being in NP, some NP-complete problems are polynomial-time generable, and placing oracle-based generation within the polynomial hierarchy. They also show a conditional separation for PG ⊊ NP, assuming a tally language (one with at most one string per length 𝑛) exists in NP \ P—or equivalently, 𝐸 ≠ NE. Tally language generators, however, have no realistic interpretation in testing: they are decision algorithms in disguise that cannot produce different random instances. In Section 5.1 we show that non-sparse languages can also be non-generable, under a cryptographic assumption not known to be related to the sparse languages assumption. This both elucidates generability for the testing context and offer independent complexity-theoretic intuition linking generability and cryptography. Moreover, [44, 45] do not consider other resource constraints (unconstrained, expected polynomial time, log-space and polynomial-space bounds), generability conditions via core languages and verifiers, or connections to cryptography—unsurprisingly, perhaps, as their work predates PBT, a

0:26

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

common application of randomised testing. Our work can thus be viewed as both an extension and a modern reinterpretation of their earlier work, with practical applications to randomised testing. A classic line of work [24, 25] studies uniform generation and repetition-free enumeration in a different setting: given a relation 𝑅 ⊆ 𝑋 × 𝑌 and an 𝑥 ∈ 𝑋 , one seeks a sampler for Sol(𝑥) = {𝑦 ∈ 𝑌 : (𝑥, 𝑦) ∈ 𝑅}. Jerrum et al. [25] showed that for self-reducible 𝑅, almost uniform generation of Sol(𝑥) is as hard as approximately counting |Sol(𝑥)|; more recently, Arenas et al. [2] showed that if 𝑅 is checkable in logspace, then Sol(𝑥) is almost-uniformly sampleable, approximately countable, and enumerable with polynomial delay. Their setting differs from ours in two ways: they sample certificates for instances 𝑥 ∈ 𝐿, whereas we sample instances of 𝐿 itself; and they require uniformity while permitting failure, whereas we require only full support on 𝐿 but forbid failure. The two lines of work nonetheless intersect in Proposition 6.2, where interpreting logspace generators in the framework of Arenas et al. [2] yields the expected polynomial-time uniform generability for LG languages. Our framework is currently distribution agnostic, and extending it to prescribed distributions on 𝐿, perhaps along the lines of Jerrum et al. [25], is an avenue for future work. Levin’s theory of average-case complexity [30] studies the hardness of problems whose instances are drawn from P-samplable distributions [22]. A polynomial-time generator 𝐺 = (𝐺𝑛 )𝑛∈N for 𝐿 implements a full-support P-samplable distribution for 𝐿, by composing the 𝐺𝑛 with a distribution supported on N. The focus differs, however: Levin [30] studies the hardness of deciding 𝐿 given some distribution 𝜇 (not necessarily full-support), whereas we ask which languages admit a fullsupport sampler at all, and what structure it must have (Section 7.1). Average-case hardness of language-distribution pairs also underpins cryptographic security, e.g. in constructing one-way functions. Generating instances around planted witnesses in Proposition 5.1 for SAT (first observed in [44]) is an instance of the classic planted-assignment construction [13, 26]. In Theorem 7.1, we show that every polynomial-time generator is a certificate scheme: witness planting is not merely a technique for efficient generation, but in some sense the only one. The duality between predicates and generators has previously been investigated in a programming languages and verification context. In [9, 28], generators are derived from implementations of deciders by techniques based on narrowing from logic programming folklore. In our notation, for predicate 𝑃, the derived generator 𝐺 𝑃 generates the same language that 𝑃 recognises: L (𝐺 𝑃 ) = L (𝑃). However, the unconstrained use of rejection sampling in these derivations means the correspondence carries no complexity guarantees, and Section 7.2 limits the complexity of generators from such constructions: no compositional mapping from a logical language containing conjunction or negation to generators can preserve polynomial-time generation guarantees, under standard assumptions. Libraries have also been developed to facilitate proofs on generators within theorem provers [37]. However, these proofs are on a per-generator basis, primarily on soundness (corresponding to our notion of full support on 𝐿), and do not make statements on the complexity of generation—which is our focus. Although software testing was the motivation for our work, random generators of the kind we study are used throughout computational sciences. Many fields rely on non-trivial generators of random data, often as the core part of a larger algorithm or methodology. Markov Chain Monte Carlo (MCMC) is a widely used technique to produce random samples from sets whose membership has a high decision complexity [41]. Designing a Markov chain that converges to the desired distribution on some set can be viewed as a generation problem in our formalisation. Our theory of space-bounded generation for correlated outputs (Section 6) yields statements on the feasibility of designing chains for a given set. Chemical space generation is another field where combinatorial databases for molecules are built, with applications to drug discovery and reaction pathways. For the database to be useful, its elements must satisfy graph-theoretic constraints of molecules [19, 42], feasibility constraints from physical simulations [21, 51], and synthesisability constraints imposed

Complexity Theory of Randomised Testing

0:27

by the domain of application [29]. The combinatorial explosion makes throughput critical for these databases, which are often accessed through sampling rather than enumeration. Our theory provides results connecting the complexity of the constraints (defining the set of molecules) with both the feasibility and efficiency of building such a chemical space (Section 3, Section 5 and Section 6). Many more examples exist. In each case, the generator is the core component of a larger pipeline producing randomised outputs, drawn from a set with nontrivial membership constraints: exactly the central object of study in this work. 9

Conclusion

We formalised generability as a complexity-theoretic notion by modelling generators as resourcebounded transducers, and studied how constraints shape what data can be generated. Without resource bounds, we see that generable languages coincide exactly with the recursively enumerable languages, while under polynomial-time bounds we obtain a structured hierarchy of generability classes contained within NP, with logspace being a more restrictive condition than polynomial-time for generators. Moreover, we find that space-based constraints can be applied naturally to generators of correlated inputs, and derive the limits of their expressivity. We also give characterisations of the polynomial-time generable languages, showing they correspond exactly to a subclass of verifiers. Applying our theory to testing libraries, our framework can rule out whole classes of designs from the realm of possibility. Altogether, our results provide a foundational framework for reasoning about generators in property-based testing using tools from complexity theory. More broadly, our approach also opens avenues for transferring complexity-theoretic techniques to the study of testing, while exposing potential new complexity questions centered on generation. References [1] Manindra Agrawal, Neeraj Kayal, and Nitin Saxena. 2004. PRIMES is in P. Annals of mathematics (2004), 781–793. [2] Marcelo Arenas, Luis Alberto Croquevielle, Rajesh Jayaram, and Cristian Riveros. 2019. Efficient logspace classes for enumeration, counting, and uniform generation. In Proceedings of the 38th ACM SIGMOD-SIGACT-SIGAI Symposium on Principles of Database Systems. 59–73. [3] Thanassis Avgerinos, Alexandre Rebert, Sang Kil Cha, and David Brumley. 2014. Enhancing symbolic execution with veritesting. In Proceedings of the 36th international conference on software engineering. 1083–1094. [4] Marcel Böhme, Cristian Cadar, and Abhik Roychoudhury. 2020. Fuzzing: Challenges and reflections. IEEE Software 38, 3 (2020), 79–86. [5] Marcel Böhme, Van-Thuan Pham, and Abhik Roychoudhury. 2016. Coverage-based greybox fuzzing as markov chain. In Proceedings of the 2016 ACM SIGSAC Conference on Computer and Communications Security. 1032–1043. [6] Alessandro Disney Bruni, Tim Disney, and Cormac Flanagan. 2011. A peer architecture for lightweight symbolic execution. Universidad de California, Santa Cruz (2011). [7] Frank Busse, Martin Nowack, and Cristian Cadar. 2020. Running symbolic execution forever. In Proceedings of the 29th ACM SIGSOFT International Symposium on Software Testing and Analysis. 63–74. [8] Cristian Cadar and Martin Nowack. 2021. KLEE symbolic execution engine in 2019: C. Cadar, M. Nowack. International Journal on Software Tools for Technology Transfer 23, 6 (2021), 867–870. [9] Koen Claessen, Jonas Duregård, and Michał H Pałka. 2014. Generating constrained random data with uniform distribution. In International Symposium on Functional and Logic Programming. Springer, 18–34. [10] Koen Claessen and John Hughes. 2000. QuickCheck: a lightweight tool for random testing of Haskell programs. In Proceedings of the Fifth ACM SIGPLAN International Conference on Functional Programming (ICFP ’00). Association for Computing Machinery, New York, NY, USA, 268–279. doi:10.1145/351240.351266 [11] Chucky Ellison and Grigore Rosu. 2012. An executable formal semantics of C with applications. ACM SIGPLAN Notices 47, 1 (2012), 533–544. [12] Karine Even-Mendoza, Cristian Cadar, and Alastair F Donaldson. 2022. CsmithEdge: more effective compiler testing by handling undefined behaviour less conservatively. Empirical Software Engineering 27, 6 (2022), 129. [13] Vitaly Feldman, Will Perkins, and Santosh Vempala. 2015. On the complexity of random satisfiability problems with planted solutions. In Proceedings of the forty-seventh annual ACM symposium on Theory of Computing. 77–86.

0:28

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

[14] Daniel Gabric and Jeffrey Shallit. 2021. Borders, palindrome prefixes, and square prefixes. Inform. Process. Lett. 165 (2021), 106027. [15] Patrice Godefroid, Nils Klarlund, and Koushik Sen. 2005. DART: Directed automated random testing. In Proceedings of the 2005 ACM SIGPLAN conference on Programming language design and implementation. 213–223. [16] Harrison Goldstein, Hila Peleg, Cassia Torczon, Daniel Sainati, Leonidas Lampropoulos, and Benjamin C Pierce. 2026. The Search for Constrained Random Generators. Proceedings of the ACM on Programming Languages 10, PLDI (2026), 2060–2084. [17] Harrison Goldstein and Benjamin C Pierce. 2022. Parsing randomness. Proceedings of the ACM on Programming Languages 6, OOPSLA2 (2022), 89–113. [18] Alex Groce, Chaoqiang Zhang, Eric Eide, Yang Chen, and John Regehr. 2012. Swarm testing. In Proceedings of the 2012 International Symposium on Software Testing and Analysis. 78–88. [19] Ralf Gugisch, Adalbert Kerber, Axel Kohnert, Reinhard Laue, Markus Meringer, Christoph Rücker, and Alfred Wassermann. 2015. MOLGEN 5.0, a molecular structure generator. In Advances in Mathematical Chemistry and Applications: Volume 1 Revised Edition. Bentham Science Publishers, 113–138. [20] Renáta Hodován, Ákos Kiss, and Tibor Gyimóthy. 2018. Grammarinator: a grammar-based open source fuzzer. In Proceedings of the 9th ACM SIGSOFT international workshop on automating TEST case design, selection, and evaluation. 45–48. [21] Scott A Hollingsworth and Ron O Dror. 2018. Molecular dynamics simulation for all. Neuron 99, 6 (2018), 1129–1143. [22] Russell Impagliazzo and Leonid A Levin. 1990. No better ways to generate hard NP instances than picking uniformly at random. In FOCS, Vol. 90. 31st. [23] ISO. 1998. ISO/IEC 14882:1998: Programming languages — C++. 732 pages. Available in electronic form for online purchase at http://webstore.ansi.org/ and http://www.cssinfo.com/.. http://webstore.ansi.org/ansidocstore/ product.asp?sku=ISO%2FIEC+14882%2D1998;http://webstore.ansi.org/ansidocstore/product.asp?sku=ISO%2FIEC+ 14882%3A1998;http://www.iso.ch/cate/d25845.html;https://webstore.ansi.org/ [24] Mark Jerrum. 2003. Counting, sampling and integrating: algorithms and complexity. Springer Science & Business Media. [25] Mark R Jerrum, Leslie G Valiant, and Vijay V Vazirani. 1986. Random generation of combinatorial structures from a uniform distribution. Theoretical computer science 43 (1986), 169–188. [26] Ari Juels and Marcus Peinado. 2000. Hiding cliques for cryptographic security. Designs, Codes and Cryptography 20, 3 (2000), 269–280. [27] Jonathan Katz and Yehuda Lindell. 2007. Introduction to modern cryptography: principles and protocols. Chapman and hall/CRC. [28] Leonidas Lampropoulos, Zoe Paraskevopoulou, and Benjamin C Pierce. 2017. Generating good generators for inductive relations. Proceedings of the ACM on Programming Languages 2, POPL (2017), 1–30. [29] Itai Levin, Michael E Fortunato, Kian L Tan, and Connor W Coley. 2023. Computer-aided evaluation and exploration of chemical spaces constrained by reaction pathways. AIChE journal 69, 12 (2023), e18234. [30] Leonid A Levin. 1986. Average case complete problems. SIAM J. Comput. 15, 1 (1986), 285–286. [31] Vsevolod Livinskii, Dmitry Babokin, and John Regehr. 2020. Random testing for C and C++ compilers with YARPGen. Proc. ACM Program. Lang. 4, OOPSLA, Article 196 (nov 2020), 25 pages. doi:10.1145/3428264 [32] Vsevolod Livinskii, Dmitry Babokin, and John Regehr. 2023. Fuzzing Loop Optimizations in Compilers for C++ and Data-Parallel Languages. Proc. ACM Program. Lang. 7, PLDI, Article 181 (jun 2023), 22 pages. doi:10.1145/3591295 [33] David R MacIver, Zac Hatfield-Dodds, et al. 2019. Hypothesis: A new approach to property-based testing. Journal of Open Source Software 4, 43 (2019), 1891. [34] Michaël Marcozzi, Qiyi Tang, Alastair F Donaldson, and Cristian Cadar. 2019. Compiler fuzzing: How much does it matter? Proceedings of the ACM on Programming Languages 3, OOPSLA (2019), 1–29. [35] Ali Mili and Fairouz Tchier. 2015. Software testing: Concepts and operations. John Wiley & Sons. [36] Rohan Padhye, Caroline Lemieux, Koushik Sen, Mike Papadakis, and Yves Le Traon. 2019. Semantic fuzzing with zest. In Proceedings of the 28th ACM SIGSOFT International Symposium on Software Testing and Analysis. 329–340. [37] Zoe Paraskevopoulou, Cătălin Hriţcu, Maxime Dénès, Leonidas Lampropoulos, and Benjamin C Pierce. 2015. Foundational property-based testing. In International Conference on Interactive Theorem Proving. Springer, 325–343. [38] Alexandre Rebert, Sang Kil Cha, Thanassis Avgerinos, Jonathan Foote, David Warren, Gustavo Grieco, and David Brumley. 2014. Optimizing seed selection for fuzzing. In 23rd USENIX Security Symposium (USENIX Security 14). 861–875. [39] Henry Gordon Rice. 1953. Classes of recursively enumerable sets and their decision problems. Transactions of the American Mathematical society 74, 2 (1953), 358–366. [40] Phillip Rogaway. 2006. Formalizing human ignorance: Collision-resistant hashing without the keys. In International Conference on Cryptology in Vietnam. Springer, 211–228.

Complexity Theory of Randomised Testing

0:29

[41] Vivekananda Roy. 2020. Convergence diagnostics for markov chain monte carlo. Annual Review of Statistics and Its Application 7, 1 (2020), 387–412. [42] Lars Ruddigkeit, Ruud Van Deursen, Lorenz C Blum, and Jean-Louis Reymond. 2012. Enumeration of 166 billion organic small molecules in the chemical universe database GDB-17. Journal of chemical information and modeling 52, 11 (2012), 2864–2875. [43] Alexander Russell. 1995. Necessary and sufficient conditions for collision-free hashing. Journal of Cryptology 8, 2 (1995), 87–99. [44] Laura A. Sanchis. 1990. On the complexity of test case generation for NP-hard problems. Inform. Process. Lett. 36, 3 (1990), 135–140. [45] Laura A Sanchis and Mark A Fulk. 1990. On the efficient generation of language instances. SIAM J. Comput. 19, 2 (1990), 281–296. [46] Phillip Schanely. 2022. CrossHair: An analysis tool for Python that blurs the line between testing and type systems. https://github.com/pschanely/CrossHair. GitHub repository, accessed 19 January 2026. [47] Michael Sipser. 1996. Introduction to the Theory of Computation. ACM Sigact News 27, 1 (1996), 27–29. [48] Dominic Steinhöfel and Andreas Zeller. 2022. Input invariants. In Proceedings of the 30th ACM joint european software engineering conference and symposium on the foundations of software engineering. 583–594. [49] Terence Tao, Ernest Croot III, and Harald Helfgott. 2012. Deterministic methods to find primes. Math. Comp. 81, 278 (2012), 1233–1246. [50] Xuejun Yang, Yang Chen, Eric Eide, and John Regehr. 2011. Finding and understanding bugs in C compilers. In Proceedings of the 32nd ACM SIGPLAN Conference on Programming Language Design and Implementation (San Jose, California, USA) (PLDI ’11). Association for Computing Machinery, New York, NY, USA, 283–294. doi:10.1145/1993498. 1993532 [51] Pingshi Yu, Alistair J Sterling, and Jotun Hein. 2021. A Novel Automated Screening Method for Combinatorially Generated Small Molecules. Journal of Chemical Information and Modeling 61, 4 (2021), 1637–1646. [52] Pingshi Yu, Nicolas Wu, and Alastair F Donaldson. 2025. Ratte: Fuzzing for Miscompilations in Multi-Level Compilers Using Composable Semantics. In Proceedings of the 30th ACM International Conference on Architectural Support for Programming Languages and Operating Systems, Volume 2. 966–981.

0:30

A.1

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

Alternative notion of eventual productivity

Another candidate for the notion of “eventually productive” may be the following—which in any case would be a desirable necessary property for generators: Definition A.1.1 (Extensible Transducer). A bitstring transducer 𝑇 is extensible if for any 𝑏 ∈ {0, 1}∗ where 𝑇 (𝑏) rejects, there exists an 𝑒 ∈ {0, 1}+ such that 𝑇 (𝑏 ++ 𝑒) accepts. On the surface, this seems to describe the eventually productive property, since no computations are ever “dead”, due to the extension 𝑒 being always available for any rejected 𝑏. However, it is possible that the extension 𝑒 becomes increasingly rare as the computation advances. Consider the following case: Example A.1.1. Define the bitstring transducer 𝐻 to accept and output the binary representation of the string “ nice”, if and only if the input has the form 𝑦 ++ 𝑦 ++ 𝑧 for some finite bitstring 𝑦 ∈ {0, 1}+ and suffix 𝑧 ∈ {0, 1}∗ . 𝐻 clearly satisfies Definition A.1.1. However, when inputs are produced by a uniform-like source of randomness (such as a PRNG), the probability of the input having the form 𝑦 ++ 𝑦 ++ 𝑧 becomes increasingly rare as the length of the input increases. That is, when the input bitstring is sampled from I, Example A.1.1 has a strictly non-zero chance of never terminating. Proposition A.1.1. The transudcer 𝐻 defined in Example A.1.1 has 𝜇 (𝐴𝜔 𝐻 ) < 1. 𝜔 is a union of disjoint sets 𝑆 , we have: Proof. Observe first that since 𝐴𝐺 𝑏 ∑︁ 𝜔 𝜇 (𝐴𝐺 ) = 𝜇 (𝑆𝑏 ) 𝑏 ∈𝐴𝐺 >0 of the We will compute an upper bound for 𝜇 (𝐴𝜔 𝐻 ). 𝐴𝐻 contains bitstrings of length 2𝑘, 𝑘 ∈ N ∗ ∗ form xx, for some 𝑥 ∈ {0, 1} , and such that no prefix of xx is of the form yy, 𝑦 𝑖𝑛{0, 1} .

Below we enumerate all members 𝑏 ∈ 𝐴𝐻 withÍ length |𝑏 | = 2𝑘 for 𝑘 = 1, 2, 3, 4, as well as the total probability of their bitstrings being sampled, |𝑏 |=2𝑘 𝜇 (𝑆𝑏 ): k 1 2

3

4

Bitstring Total Probability 00 2 22 11 01 01 2 24 10 10 010 010 011 011 4 26 100 100 101 101 0110 0110 0111 0111 0100 0100 6 28 1011 1011 1000 1000 1001 1001

Observe that for any 𝑘 ≥ 2, if 𝑏 ∈ 𝐴𝐻 and |𝑏 | = 2𝑘 then 𝑏 cannot have 00 or 11 as a prefix (and thus must have prefix either 01 or 10). For 𝑘 ≥ 2, the number of bitstrings of length 2𝑘 within 𝐴𝐻 is Í 𝑘 −1 at most 2 ∗ 2𝑘 −2 = 2𝑘 −1 . Since there are 22𝑘 length 2𝑘 strings, we know |𝑏 |=2𝑘 𝜇 (𝑆𝑏 ) ≤ 222𝑘 .

Complexity Theory of Randomised Testing

0:31

It follows that: ∞ ∑︁ ∞ ∞ ∑︁ ∑︁ 2 ∑︁ 2𝑘 −1 1 ∑︁ − (𝑘+1) 1 1 3 𝜇 (𝑆 ) ≤ ) = 𝜇 (𝑆 ) = = 2 = + = 𝜇 (𝐴𝜔 + + 𝑏 𝑏 𝐻 22 2 2 4 4 22𝑘 𝑏 ∈𝐴𝐻

𝑘=1 |𝑏 |=2𝑘

𝑘=2

𝑘=2

Hence, the probability of 𝐵 terminating is at most 43 < 1. In fact, a more exact result exists in literature. Let the number of “square” bitstrings without a Í square prefix of length 2𝑘 be the sequence 𝑎𝑘 . In our case, we have 𝑎𝑘 = 22𝑘 |𝑏 |=2𝑘 𝜇 (𝑆𝑏 ). In [14], Í∞ Í∞ the sum is computed as 𝑘=1 𝑐𝑘 = 𝑘=1 𝑎𝑘 2−2𝑘 ≈ 0.72996, compared to our bound of 0.75. □ It is still possible to have practically non-productive computations even if the transducer satisfies Definition A.1.1: it is too weak, and thus the stronger condition of measure-theoretic eventual productivity is needed. We will see that the measure-theoretic condition used is indeed stronger than Definition A.1.1: Proposition A.1.2. If 𝐺 is a generator, then 𝐺 is extensible. Proof. Suppose the generator 𝐺 is not extensible. Then there exists a bitstring 𝑏 where 𝐺 (𝑏) rejects and for all strings 𝑒 ∈ {0, 1}+ , 𝐺 (𝑏 ++ 𝑒) rejects, and thus 𝑏 ∉ 𝐴𝐺 . We know 𝜇 (𝑆𝑏 ) > 0. 𝜔 ) ≤ 1 − 𝜇 (𝑆 ) < 1, which is a contradiction. Therefore 𝜇 (𝐴𝐺 □ 𝑏 A.2

Proof of Proposition 2.2

We will use the following definitions and lemmas in our proof. Definition A.2.1. For a generator 𝐺 and a bitstring 𝑏 ∈ {0, 1}∗ , define 𝑠 : {0, 1}∗ → P ({0, 1}∗ ), the subset of bitstrings that concatenate with 𝑏 to reach 𝐴𝐺 , as: 𝑠 (𝑏) = {𝑒 ∈ {0, 1}∗ : (𝑏 ++ 𝑒) ∈ 𝐴𝐺 } Definition A.2.2. For generator 𝐺 and a bitstring 𝑏, define 𝑒 : {0, 1}∗ → {𝑋 } ∪ {0, 1}∗ , the minimum extension, if one exists, such that 𝐺 (𝑏 ++ 𝑒 (𝑏)) accepts as follows. (1) If 𝐺 (𝑏) accepts, then 𝑒 (𝑏) = 𝜖. (Empty string) (2) If 𝐺 (𝑏) rejects, then (a) If 𝑠 (𝑏) ≠ ∅: 𝑒 (𝑏) = min(𝑠 (𝑏)), where the min is taken lexicographically. (b) If 𝑠 (𝑏) = ∅: 𝑒 (𝑏) = 𝑋 Such an 𝑓 exists, since the set 𝑠 (𝑏) is either empty, or bounded below (in lengths of elements) by 0, thus a lexicographically minimal element of 𝑠 (𝑏) exists for all non-empty 𝑠 (𝑏). We only take the minimum when 𝑠 (𝑏) is non-empty, and 𝑒 (𝑏) is defined for all other cases. Lemma A.2.1. Let 𝐺 be a generator. If for all bitstrings 𝑏 ∈ {0, 1}∗ , 𝑒 (𝑏) ≠ 𝑋 and there exists 𝑐 ∈ N such that |𝑒 (𝑏)| ≤ 𝑐, then 𝐺 will terminate with probability 1. Proof. For event 𝐸, let P(𝐸|𝑏) denote the probability of 𝐸 occurring, given that 𝑏 has been consumed on the input tape of 𝐺. Clear if 𝐺 (𝑏) accepts, then P(𝐺 accepts in 𝑥 steps|𝑏) = 1 for any 𝑥. Thus assume 𝐺 (𝑏) rejects. Note that P(𝐺 accepts in |𝑒 (𝑏)| steps|𝑏) ≥ 2− |𝑒 (𝑏 ) | where the inequality is due to the potential for multiple extensions of the same length as 𝑒 (𝑏). Thus P(𝐺 does not accept in |𝑒 (𝑏)| steps|𝑏) ≤ 1 − 2− |𝑒 (𝑏 ) |

0:32

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

Suppose 𝐺 does not terminate on bitstream bs, we can partition bs into the concatenation of a countable set of finite bitstrings, bs = 𝑏 1 ..., using 𝑓 : 𝑏0 = 𝜖 |𝑏𝑖 | = |𝑒 (𝑏 0𝑏 1 ..𝑏𝑖 −1 )|

𝑖>1

Define 𝑥𝑖 = 𝑏 1 ...𝑏𝑖 , we can decompose the events that 𝐺 does not accept bs as follows, and apply the earlier inequality to get: P(𝐺 does not accept bs) ∞ Ö = P(|𝑏𝑖 | = |𝑒 (𝑥𝑖 −1 )| ∩ 𝐺 does not accept on 𝑏𝑖 |𝑥𝑖 −1 ) 𝑖=1

∞ Ö

(1 − 2− |𝑒 (𝑏𝑖 ) | )

𝑖=1

We see that if each |𝑒 (𝑏𝑖 )| is bounded by some constant 𝑐, then the infinite product is guaranteed to collapse to zero. □ Corollary A.2.1. The generator of natural numbers described in Example 2.1 will terminate with probability 1. Proof. Observe that for any sequence 𝑏 ∈ {0, 1}+ that does not terminate for the natural numbers generator, one of the two extensions 000 or 00 will result in the procedure terminating. Thus |𝑒 (𝑏)| ≤ 3 and Lemma A.2.1 applies. □ Corollary A.2.2 (Rejection Sampling is Sound). Any procedure 𝐹 that performs rejection sampling based on predicate 𝑓 : {0, 1}∗ → {𝑇 , 𝐹 } where there exists 𝑤 ∈ {0, 1}∗ with 𝑓 (𝑤) = 𝑇 will terminate with probability 1. Proof. The set of strings that 𝑓 returns 𝑇 for is fixed. Let 𝑤 be the shortest such string such that 𝑓 (𝑤) = 𝑇 . Thus the shortest extension that causes 𝐹 to terminate has size bound |𝑤 |, and Lemma A.2.1 applies. □ When designing generators, to ensure termination, it is enough to argue if there always exists a short sequence of choices that leads to termination. If the shortest sequence grows with execution time, then the generator has a chance of non-termination. A.3

Generator Acceptance and its Link To The Real Numbers

Observation A.3.1. For a generator 𝐺, consider the set of all finite bitstrings 𝑥 such that 𝐺 (𝑥) accepts. Let this set be 𝐴, then 𝐴 has the following properties: (1) If 𝑥 ∈ 𝐴, then for all 𝑤 ∈ {0, 1}∗, 𝑤 ++ 𝑥 ∈ 𝐴. (2) For all 𝑦 ∈ {0, 1}∗ , there exists a 𝑤 ∈ {0, 1}∗ such that 𝑦 ++ 𝑤 ∈ 𝐴. Consider the map 𝑓 : {0, 1}∗ → [0, 1], defined as: 𝑓 (0 :: 𝑤) = 2−1 (0 + 𝑓 (𝑤))

𝑓 (1 :: 𝑤) = 2−1 (1 + 𝑓 (𝑤))

that is, 𝑓 (𝑏) = 0.𝑏, where 𝑏 here is interpreted as digits in base-2. Clearly 𝑓 is an injection. The set 𝐴 can thus be viewed as regions on the interval [0, 1], through the mapping 𝑓 . 𝐴 is defined on finite sequences, however we can extend 𝐴 to be a set 𝐴+ of infinite sequences by defining: 𝐴+ = {𝑏𝑠 ∈ {0, 1}𝜔 : ∃𝑏.𝑏 is a finite prefix of 𝑏𝑠 ∩ 𝑏 ∈ 𝐴}

Complexity Theory of Randomised Testing

0:33

We can similarly define 𝑓 + on 𝐴+ by taking the fixed point of the computation 𝑓 (i.e. the result 𝑓 + (𝑏𝑠) would be an infinite sum, and would equal the number 0.𝑏 ∈ [0, 1]). 𝑓 + (𝐴+ ) has the nice property that the probability measure 𝜇 (𝑓 + (𝐴+ )) is precisely the probability that 𝐺 eventually terminates. We observe that 𝑓 (𝐴) (and 𝑓 + (𝐴+ )) has the following “dense” property: for any subinterval (𝑎, 𝑏) ⊆ [0, 1], 𝑓 (𝐴) ∩ (𝑎, 𝑏) ≠ ∅, and furthermore contains infinitely many elements of 𝑓 (𝐴). A.4

Proof of Theorem 3.1

The proof will be given in two parts, for the two sides of the inclusion. Proposition A.4.1. RE ⊆ GEN Proof. Suppose 𝐿 ∈ RE. We show that there exists a generator 𝐺 such that L (𝐺) = 𝐿. Let 𝑀 be a Turing machine that accepts 𝑥 in a finite number of steps iff 𝑥 ∈ 𝐿. If |𝐿| is finite, then there exists a generator that produces one of the finite elements of 𝑥 ∈ 𝐿 at random. Thus we assume now |𝐿| is infinite. We describe the generator 𝐺 for 𝐿 as follows: (1) Compute some 𝑥 0 via dovetailing. (2) Sample natural numbers 𝑛 and 𝑚 (e.g. via the procedure in Example 2.1). (3) Sample a random string 𝑥 of length 𝑚, and simulate 𝑀 (𝑥) for up to 𝑛 steps. (4) If 𝑀 accepts during this simulation, then output 𝑥, otherwise output 𝑥 0 . We now show that 𝐺 satisfies the conditions of a generator. Because we are working in the case where 𝐿 ≠ ∅ (in fact |𝐿| is infinite), dovetailing is guaranteed to find some element 𝑥 0 ∈ 𝐿 in finite time. As the simulation of 𝑀 (𝑥) is for a bounded number of steps, the sampling procedure will always halt on any finite bitstrings. For almost sure termination on bitstreams, note 𝐺 is deterministic subject to fixing the results of the two calls to Example 2.1. Thus since Example 2.1 terminates almost surely, so does 𝐺. It clear that 𝐺 halts in an accepting state if and only if it has generated some 𝑥 ∈ 𝐿, from which it follows that L (𝐺) ⊆ 𝐿. For any 𝑥 ∈ 𝐿 there exists 𝑛 such that 𝑀 accepts 𝑥 in 𝑛 0 steps. Both 𝑥 and the corresponding 𝑛 > 𝑛 0 has a set of finite bitsrings that results in them being selected in steps 2 and 3. Thus 𝑥 and 𝑛 being selected occurs with nonzero probability. We therefore have L (𝐺) = 𝐿 as required. □ Proposition A.4.2. GEN ⊆ RE. Proof. Suppose 𝐿 ∈ GEN, and let 𝐺 be a generator such that L (𝐺) = 𝐿. We construct a Turing machine 𝑀 that terminates in an accepting state given input 𝑥 ∈ 𝐿, and loops infinitely given input 𝑥 ∉ 𝐿, as follows. Given an input 𝑥, 𝑀 enumerates finite-length bitstrings in lexicographic order (0, 1, 00, 01, 10, etc.). For a bitstring 𝑏: • 𝑀 simulates the execution of 𝐺 in an initial configuration where the input tape of 𝐺 contains 𝑏. By the definition of a generator (Definition 2.1), this simulation of 𝐺 is guaranteed to lead to 𝐺 halting. • If 𝐺 halts in an accepting state having generated 𝑥 (the input to 𝑀), 𝑀 halts in an accepting state. • If instead 𝐺 halts in a non-accepting state or in an accepting state having generated some 𝑥 ′ ≠ 𝑥, 𝑀 proceeds to consider the next bitstring in lexicographical order. By Definition 3.1, for 𝑥 ∈ L (𝐺) there exists a bitstring 𝑏 such that 𝐺 (𝑏) = 𝑥. Therefore, when executed on input 𝑥, 𝑀 will eventually encounter such a 𝑏, in which case 𝑀 will halt, accepting 𝑥. Conversely, for 𝑥 ∉ L (𝐺) there is no bitstring 𝑏 such that 𝐺 (𝑏) = 𝑥. Therefore, when executed on input 𝑥, 𝑀 will loop forever, simulating the execution of 𝐺 on increasingly-long bitstrings. □

0:34

A.5

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

Proof of Proposition 4.1

Proof. We construct a non-deterministic TM 𝑀 for a generator 𝐺. Give string 𝑥 with |𝑥 | = 𝑛, we decide if it belongs to L (𝐺) on 𝑀 by simulating 𝐺 on 𝑀, branching nondeterministically whenever a random bit is revealed, with a branch for each of the possible outcomes. When the simulation of 𝐺 terminates, accept if it is equal to 𝑥, and otherwise reject. Thus, 𝑥 is accepted by 𝑀 if and only if the simulation of 𝐺 produced 𝑥 on any branch, that is, if and only if 𝑥 ∈ L (𝐺). Since 𝐺 is time bounded by 𝑡 (𝑛) / space bounded by 𝑠 (𝑛), each branch of 𝑀 uses at most 𝑙𝑜𝑔(𝑛)𝑡 (𝑛) + 𝑛 ∈ 𝑂 (𝑡 (𝑛)) time, and/or at most 𝑠 (𝑛) ∈ 𝑂 (𝑠 (𝑛)) space (assuming space is reused after writing each symbol of 𝑥). Thus both claims hold. □ A.6

Proof of Proposition 5.1

Proof. We will define a generator 𝐺𝑚,𝑘,𝑝 for each (𝑚, 𝑘, 𝑝), where 𝑚 is the number of clauses, 𝑘 is the number of literals, 𝑝 is the length of the representation for each variable, with 𝑚 < 𝑘. Note all CNF-SAT formulas have 𝑚 < 𝑘, as if the number of clauses is more than the number of literals (𝑚 > 𝑘), then some clauses must be empty leaving the formula unsatisfiable and therefore not a member of CNF-SAT. Since we fix the number of clauses and literals, we know the exact length of the formula as long as the encoding of the clauses and literals are known. Denote the encoding-dependent length of the formulas by 𝑙 (𝑚, 𝑘, 𝑝), which is polynomial-time computable for any reasonable encodings. For instance, 𝑙 (𝑚, 𝑘, 𝑝) = 𝑚 + (𝑘 + 2)𝑝 is the length of the encoding of the formula as follows: a list of 𝑚 clauses will contain 𝑚 length-1 separator characters; (𝑘 + 1)𝑝 characters will be consumed by 𝑝 literals of length 𝑘 each, with an extra character to encode negation; 𝑘 characters will be consumed by length-1 separators between literals. Thus each string in L (𝐺𝑚,𝑘,𝑝 ) have the same length, and the language of the generators 𝐿𝑚,𝑘,𝑝 = L (𝐺𝑚,𝑘,𝑝 ) forms a partition of the langauge CNF-SAT. With these, we can define generators for CNF-SAT formulas with length exactly 𝑛 by first computing the set 𝐼𝑛 = {(𝑚, 𝑘, 𝑝) : 𝑚 + (𝑘 + 2)𝑝 = 𝑛}, selecting a random (𝑚, 𝑘, 𝑝) ∈ 𝐼𝑛 and running the corresponding 𝐺𝑚,𝑘,𝑝 to obtain a random formula of length 𝑛. It now suffices to show that generators 𝐺𝑚,𝑘,𝑝 of satisfiable CNF formulas exist for any choice of 𝑚, 𝑘, 𝑝 with 𝑚 < 𝑘, in time polynomial in 𝑙 (𝑚, 𝑘, 𝑝). We define 𝐺𝑚,𝑘,𝑝 as follows: (1) Choose an 𝑛 ≤ 𝑘 to be the number of variables. (2) For each variable 𝑥𝑖 , 1 ≤ 𝑖 ≤ 𝑛, choose a random boolean assignment. (3) Keep counters 𝑚 ′, 𝑘 ′ initially set to 𝑚, 𝑘 respectively. (4) Choose an integer 𝑞 ≤ 𝑘 ′ − 𝑚 ′ to be the number of literals included in the clause, with the exception of 𝑚 ′ = 1, in which case 𝑞 = 𝑘 ′ . Decrement counters 𝑘 ′, 𝑚 ′ := 𝑘 ′ − 𝑞, 𝑚 ′ − 1. (5) We form the literals 𝑏 1, ..., 𝑏𝑞 for the clause by selecting each literal to be either 𝑥 𝑗 or ¬𝑥 𝑗 for some randomly 𝑥 𝑗 . Choose a number 1 ≤ 𝑖 ≤ 𝑞, and fix 𝑏𝑖 to be the True based on the preselected assignment. (6) Add the clause 𝑏 1 ∪ ... ∪ 𝑏𝑞 to the formula 𝜙. Throughout the procedure, we only make random selections from finite sets. Each choice of 𝑞 ensures that the remaining clauses will contain at least one literal. The runtime is clearly polynomial in 𝑙 (𝑚, 𝑘, 𝑝). 𝜙 is satisfiable by construction as under the randomly chosen assignment during generation, each clause contains at least one True literal. If 𝜙 is a satisfiable formula in CNF form with 𝑚 clauses, 𝑘 total literals and 𝑛 distinct variables, then some selection of 𝐺𝑚,𝑘,𝑝 will generate 𝜙. □

Complexity Theory of Randomised Testing

A.7

0:35

Proof of Proposition 5.4

Proof. For 𝐺 = (𝐺𝑖 )𝑖 ∈N generating 𝐿 in expected polynomial time, we need to construct a NDTM 𝑀 that decides 𝐿. We define 𝑀 as follows. For input 𝑥 with |𝑥 | = 𝑖: (1) Simulate 𝐺𝑖 on each branch for at most 𝑝 (𝑖) steps. (2) On each of the branches, branch again nondeterministically whenever a bit on the random input tape is read, for its possible contents, 0 or 1. (3) When 𝐺𝑖 enters an accepting state, accept if the output tape contents is equal to 𝑥, otherwise reject. Without loss of generality, assume that 𝑥 ∈ 𝐿𝑖 ⊂ 𝐿. Then we know there exists a bitstream bs where 𝑥 is accepted within 𝑝 (𝑖) steps. Thus there would also be a branch on 𝑀 where 𝑥 is produced by the simulation of 𝐺𝑖 and thus 𝑥 would be accepted. On the other hand, if 𝑥 ∉ 𝐿, then 𝑥 ∉ 𝐿𝑖 for any 𝑖 ∈ N, and no simulations of any 𝐺𝑖 would produce 𝑥. Thus all branches, and hence also 𝑀, would reject 𝑥. □ A.8

Proof of Proposition 5.3

Proof. PGNP ⊆ NPNP : follows since the NPNP machine can simulate the PGNP oracle machine nondeterministically. NP ⊆ PGNP : We use SAT as the NP oracle. For fixed 𝑛 ∈ N and any 𝐿 ∈ NP with NDTM 𝑀 time-bounded by 𝑝, we encode 𝑀 using the parametric SAT formula 𝜙𝑛 , provided by the proof of NP-completeness of SAT [47]. 𝜙𝑛 has 𝑛 variables reserved for the initial contents of the tape, and for 𝑥 ∈ {0, 1} ≤𝑛 , 𝜙𝑛 (𝑥) denotes the formula with those variables substituted for by the bits of 𝑥. Note that if |𝑥 | = 𝑛, then by construction, 𝜙𝑛 (𝑥) is satisfiable if and only if 𝑀 accepts 𝑥 within 𝑝 (𝑛) steps. And if |𝑥 | < 𝑛, then 𝜙𝑛 (𝑥) is satisfiable if and only if there exists an extension 𝑒 with |𝑒 | = 𝑛 − |𝑥 |, and 𝑀 (𝑥 ++ 𝑒) accepts. Using the SAT-solver, we describe a generator 𝐺𝑛 that samples a length-𝑛 𝑥 ∈ 𝐿 as follows (if one exists): (1) Suppose 𝑠 is the string already generated, and is initially the empty string. (2) Run the SAT solver for both 𝜙𝑛 (𝑠 ++ 0) and 𝜙𝑛 (𝑠 ++ 1). (3) If neither accepts, reject; if only 𝜙𝑛 (𝑠 ++ 𝑒) accepts, set 𝑒 ′ := 𝑒; if both accepts, then choose at random one of 0 or 1 to be 𝑒 ′ . (4) Return to step 2 with string 𝑠 := 𝑠 ++ 𝑒 ′ . (5) Write 𝑠 to the output tape when |𝑠 | = 𝑛. Clearly this will terminate within 𝑛 iterations, and each iteration involves at most 2 calls to the SAT solver, for a total of 𝑂 (𝑛) calls. By construction, for any 𝑛, any length-𝑛 𝑥 ∈ 𝐿 can be generated in this fashion, thus L (𝐺) = 𝐿. □ A.9

Proof of Proposition 5.5

Proof. By Bertrand’s Postulate (theorem), there is always a prime between 𝑛 and 2𝑛. Thus, we know that for any 𝑛, the set PRIMES𝑛 = {𝑥 ∈ PRIMES : 2 |𝑛 | ≤ 𝑥 < 2 |𝑛 |+1 } is nonempty. We know from [1] that PRIMES ∈ 𝑃. Let its decider be a function 𝑓 : {0, 1}∗ → B that runs in polynomial time 𝑝 (𝑛). For each 𝑛 ∈ N, define a generator 𝐺𝑛 as follows. (1) Choose a random number 𝑥 between [2𝑛 , 2𝑛+1 − 1] by sampling for 𝑛 bits. (2) If 𝑓 (𝑥) returns Accept, output 𝑥. (3) Otherwise, repeat from step 1. The density of primes in the range [1, 𝑘] is 𝑂 (1/𝑙𝑜𝑔(𝑘)). Assuming almost-uniform distribution 1 of the primes, their density in the range [2𝑛 , 2𝑛+1 −1] is at least 𝑂 (1/𝑙𝑜𝑔(2𝑛+1 )) = 𝑂 ( 𝑛+1 ). Therefore,

0:36

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

an expected 𝑂 (𝑛 + 1) = 𝑂 (𝑛) iterations is needed for the algorithm to find a prime number. Since 𝑓 runs in polynomial time 𝑝, and we make 𝑛 + 1 expected calls to 𝑓 , the expected runtime of the algorithm is 𝑂 (𝑛𝑝 (𝑛)), which is still polynomial. Additionally, for every prime 𝑞 ∈ [2𝑛 , 2𝑛+1 − 1], there exists a bitstream bs which leads us to selecting 𝑥 = 𝑞 in step 1 of the algorithm, and generate 𝑥 in time 𝑂 (𝑝 (𝑛)), lower than 𝑂 (𝑛𝑝 (𝑛)). Thus PRIMES ∈ EPG. □ A.10

Proof of Proposition 5.6

Proof. Suppose 𝐿 is generated by the expected polynomial time generator 𝐺 = (𝐺𝑖 )𝑖 ∈N , with expected time of 𝑝 (𝑖) for 𝐺𝑖 to produce a sample. Let the runtime of 𝐺𝑖 be a random variable 𝑋𝑖 with E(𝑋𝑖 ) = 𝑝 (𝑖). By Markov’s inequality, E(𝑋𝑖 ) P(𝑋𝑖 > 3E(𝑋𝑖 )) < 3E(𝑋 = 13 . That is, the probability of that 𝑋𝑖 runs for 3E(𝑋𝑖 ) = 3𝑝 (𝑖) steps 𝑖) without producing an output is at most 1/3. Therefore, P(𝑋𝑖 ≤ 3𝑝 (𝑖) ≥ 23 . For each 𝐺𝑖 , we define algorithms 𝐻𝑖 (these are operationally generators, but are not strictly generators since they have a nonzero probability of producing nothing—and generators require almost sure production of a value) to repeat for 𝑘 iterations the execution of 𝐺𝑖 , running each 𝑘 execution for 3𝑝 (𝑖) steps. 𝐻𝑖 therefore produces a sample of 𝐿𝑖 with probability at least 1 − 13 , and runs in time 3𝑘𝑝 (𝑖). 𝑘 𝑘 To exceed probability 1 − 𝜖, we have: 1 − 13 > 1 − 𝜖 =⇒ 𝜖 > 31 =⇒ 𝑙𝑜𝑔( 𝜖1 ) < 𝑘𝑙𝑜𝑔(3). Thus 𝑙𝑜𝑔 ( 1 )

𝜖 ⌉ has the desired success probability. choosing 𝑘 = ⌈ 𝑙𝑜𝑔 (3) It remains to show that 𝐻𝑖 can produce all elements 𝑤 ∈ 𝐿𝑖 with nonzero probability. This holds because by definition, for all 𝑤 ∈ 𝐿𝑖 , there exists a bitstream bs that leads to 𝐺𝑖 producing 𝑤 in at most 𝑝 (𝑖) steps. This path can be executed by 𝐻𝑖 , since 𝐻𝑖 simulates 𝐺𝑖 for 3𝑝 (𝑖) > 𝑝 (𝑖) steps on each run, and will produce 𝑤 if bs is on the random tape when 𝐺𝑖 is being simulated. □

A.11

Configuration Counting Argument for Corollary 6.1

Note that for Corollary 6.1, an initial direct proof might be to proceed with a configurations-counting argument similar to the decision version, where the space-bounded machine is also automatically bounded since it must terminate. However, due to the fact that generators take input, the situation is more complicated: the input, although read-only, allows the space-bounded machine to stall without exploring its state configuration space fully. Whereas with the same inputs, the time-bounded machine must terminate in bounded time. As a concrete example, consider a logspace generator 𝑊 which implements waiting for the right bitstring input, as follows: Example A.11.1. Suppose the logspace generator 𝑊 = (𝑊𝑖 )𝑖 ∈N implements the following for each 𝑖: (1) If the input tape header points to a 1, move the input header forward, and the rest of the machine remains in the starting configuration. (2) Otherwise, proceed with a logspace generation algorithm for L (𝑊𝑖 ). The waiting process of step 1 does not consume any space: nothing is written onto the work tape. Hence 𝑊 consumes logspace overall. Clearly, 𝑊 can take more than polynomial number of steps for generation, if given a sufficiently long prefix of 1s on the input bitstring. We give an alternative proof (similar to the proof of decision procedures) to highlight the intuition behind the the time-space tradeoff for generators, and its similarities/differences to the decision case. Alternative Proof to Corollary 6.1. Suppose we are given a logspace generator 𝐺 = (𝐺𝑖 )𝑖 ∈N . We describe a polynomial-time sampling procedure 𝐹𝑖 that works for each L (𝐺𝑖 ).

Complexity Theory of Randomised Testing

0:37

Definition of the DFA: for each 𝐺𝑖 , we produce (based on the transition function of 𝐺𝑖 ) a DFA 𝐷𝑖 . We first define configurations of a generator 𝐻 : Definition A.11.1 (Configuration of 𝐻 ). A configuration 𝑐 of a generator 𝐻 , is an element 𝑐 = (𝑞, 𝑏𝑖 , 𝑚, 𝑤 𝑤𝑜𝑟𝑘 , 𝑐𝑜 ) ∈ 𝑄 × {0, 1} × {0, 1, . . . , 𝑘 } × Σ∗ × Γ, where 𝑞 is the internal state of 𝐻 , 𝑏𝑖 is the current symbol on the input tape, 𝑚 is the worktape head position, 𝑤 𝑤𝑜𝑟𝑘 is the worktape content, 𝑐𝑜 is the current symbol on the output tape. The length of the worktape content is 𝑘. Define 𝑛 = 𝑖. Note that as the work tape of 𝐺𝑖 is space bounded by 𝑓 (𝑛) for a logarithmic function 𝑓 ∈ 𝑂 (𝑙𝑜𝑔(𝑛)), we only need to consider up to 𝑓 (𝑛) elements on the worktape within any configuration of 𝐺𝑖 . We define the nodes of 𝐷𝑖 to be all configurations of 𝐺𝑖 , with up to 𝑓 (𝑛) elements on the work tape. That is, states of 𝐷𝑖 are from the set 𝑄 × {0, 1} × {0, 1, . . . , 𝑘 } × Σ 𝑓 (𝑛) × Γ. Define the starting state of 𝐷𝑖 to be 𝑐 0 . 𝑐 0 has two outward transitions, consuming symbols 0 and 1 respectively, heading towards the two possible starting configurations of 𝐺𝑖 : the starting configurations with either a 0 or a 1 as the first symbol on the input tape. Define also the accepting state of 𝐷𝑖 to be 𝑐 𝐴 , 𝑘 → 𝑐 from all accepting configurations 𝑐 𝑘 a newly added configuration of 𝐺𝑖 , with 𝜖 transitions 𝑐 𝐴 𝐴 𝐴 of 𝐺𝑖 (these are configurations with 𝑞 ∈ 𝑄 in the accepting state). 1

Define a transition on 𝐷𝑖 of 𝑐 → − 𝑐 ′ (that consumes a 1), if 𝑐 to 𝑐 ′ is a valid step based on 𝐺𝑖 ’s ′ transition function, and 𝑐 is identical to 𝑐, except the contents of the input cell is replaced by 0

𝜖

a 1. Define 𝑐 → − 𝑐 ′ and 𝑐 −−→ 𝑐 ′ in a similar way. Define a transition 𝑐 → − 𝑐 ′ for configuration changes that do not move the input tape forward. The use of 𝜖 transitions are for conceptual convenience and do not make our machine an NFA: since 𝐺𝑖 is deterministic, at most one such 𝜖-transition is possible from each configuration, and that 𝜖-transitions cannot coexist with other types of transitions. They can equivalently be replaced by some other reserved symbol, such as □, however such a formulation would be more verbose. Note that since |𝑄 |, |Σ|, |Γ| are constants and 𝑓 is a logarithmic function, the total number of nodes on 𝐷𝑖 are bounded by 𝑝 (𝑛), for some polynomial 𝑝. There can be at most a polynomial number of edges, where a loose bound is the number of edges on a complete graph. Thus, the total number of nodes and edges of 𝐷𝑖 is bounded by a polynomial 𝑞(𝑛). Proposition A.11.1. 𝐷𝑖 is a DFA. Proof. The edges of 𝐷𝑖 are defined exactly according to the transition function of 𝐺𝑖 . Since the nodes of 𝐷𝑖 covers all accessible configurations of the TM (only a single cell for the input and output tapes are needed as the header cannot move back), each transition of 𝐺𝑖 that does not move 𝜖 the input header corresponds to at most one edge 𝑐 → − 𝑐 ′ on 𝐷𝑖 . As 𝐺𝑖 is a deterministic TM (when fixing the input bitstring), there is at most one 𝜖 edge from any configuration. For each transition that moves the input tape forward, there is also a unique next state once the revealed character 𝑏 is fixed. Thus, there cannot exist more than one of each kind of 0, 1, and edge, from each node on 𝐷𝑖 . Altogether, from each configuration there is at most one edge for each consumable symbol {0, 1, }, making 𝐷𝑖 a DFA. □ Polynomial Generation Algorithm: for our PG algorithm 𝐹𝑖 , we describe a traversal of the DFA to find an accepting path, corresponding to an accepting execution of 𝐺𝑖 . We will use the following definitions: 𝑠

Definition A.11.2. A transition 𝑐 → − 𝑐 ′ (𝑠 ∈ {0, 1, 𝜖}) is said to write the symbol 𝑥 ∈ Γ, if 𝑐 points to an empty cell on the output tape, and 𝑐 ′ points to a cell with 𝑥 on the output tape. We also say such a transition is a writing transition.

0:38

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

Definition A.11.3. For the execution path 𝑝 = 𝑐 1 . . . 𝑐𝑘 on 𝑀𝑖 , the output of the path 𝑝 is the output symbol from all writing transitions used, in order of appearance in the execution path. Starting from 𝑐 0 , perform a randomised BFS, without revisiting any nodes, until reaching the accepting state 𝑐 𝐴 . This BFS results in a random, loopless path from 𝑐 0 to 𝑐 𝐴 . The runtime of this algorithm is bounded above by 𝑞(𝑛), the total number of transitions and nodes in 𝑀𝑖 , and thus runs in polynomial time of 𝑛. Correctness: we will show the following: 1) any loopless path from 𝑐 0 to 𝑐 𝐴 on 𝑀𝑖 corresponds to an input 𝑏 and a valid execution 𝐺𝑖 (𝑏), and 2) any string generable by 𝐺𝑖 can be generated by 𝐹𝑖 . That is, L (𝐺𝑖 ) = L (𝐹𝑖 ). Proposition A.11.2. Any path 𝑝 from 𝑐 0 to 𝑐 𝐴 on 𝑀𝑖 corresponds to an input 𝑏 and an execution 𝐺𝑖 (𝑏) = 𝑤, which produces the same output 𝑤 as 𝑝. Proof. Any path from 𝑐 0 to 𝑐 𝐴 , by definition, corresponds to an accepting execution on 𝐺𝑖 . Since 𝑀𝑖 is a DFA, the path 𝑝 corresponds uniquely to a string 𝑡 1 . . . 𝑡𝑘 where 𝑡 𝑗 ∈ {0, 1, 𝜖}, representing the label of each transition that has been taken (since the path was accepting, by definition of 𝐺𝑖 there cannot be an blank symbol consumed). Define 𝑏 to be the subsequence consisting of only symbols from the set {0, 1}. Since 𝐺𝑖 is deterministic, and 𝑀𝑖 simulates the execution of 𝐺𝑖 , 𝐺𝑖 (𝑏) will visit precisely the configurations within 𝑝 during its execution, and produce the same output as 𝑝. □ Proposition A.11.3. Any string generable by 𝐺𝑖 is the output of some loopless path from 𝑐 0 to 𝑐 𝐴 in 𝑀𝑖 . Proof. First, note that if the empty string is being generated, then any loops on the path can be removed to obtain another accepting path. Thus assume now that the generated string is nonempty. Suppose for a contradiction that a loop 𝑟 = 𝑐 1 . . . 𝑐𝑘 on 𝑀𝑖 exists within an accepting path 𝑝, with 𝑠 𝑐 1 = 𝑐𝑘 , and that it contains some writing transition 𝑐 𝑗 → − 𝑐 𝑗+1 (assuming WLOG that 𝑗 ≠ 𝑘). If 𝑝 = 𝑐 0 . . . 𝑟 . . . 𝑐 𝐴 , then repeating the loop 𝑟 within 𝑝 also yields an accepting path through 𝑀𝑖 . That is, 𝑝𝑚 = 𝑐 0 . . . 𝑐 1 (𝑟 ′ )𝑚 . . . 𝑐 𝐴 , with 𝑚 ∈ N are all accepting paths, where 𝑟 ′ = 𝑐 2 . . . 𝑐𝑘 , and (𝑟 ′ )𝑚 denotes the repetition of 𝑟 ′ m times. Each 𝑝𝑚 also corresponds to an accepting execution on 𝐺𝑖 . Since there are writing transitions within 𝑟 , and 𝐺𝑖 is write-once-only, there are at least 𝑚 characters on the output tape of 𝐺𝑖 in the corresponding execution of 𝑝𝑚 . In particular, we can choose 𝑚 > 𝑛 to reach a contradiction, since 𝐺𝑖 is a generator that can only output strings of length 𝑛 = 𝑖. □ Our algorithm 𝐹𝑖 samples a random loopless accepting path on 𝑀𝑖 , and the above propositions together shows that every string from L (𝐹𝑖 ) can be sampled this way. With this, we can form our PG generator 𝐹 = (𝐹𝑖 )𝑖 ∈N to perform, on input 𝑖: (1) Construct 𝑀𝑖 described above. (2) Run the sampling procedure to generate a random string recognised by 𝑀𝑖 . which has a nonzero chance of generating each instance of L (𝐺𝑖 ) in polynomial time. Thus L (𝐺) is in PG, as required. □ A.12

Proof of Proposition 6.2

Proof. First we make some necessary definitions. Definition A.12.1. For a relation 𝑅 ⊆ 𝑋 × 𝑌 , define: 𝐼𝑚(𝑥) = {𝑦 ∈ 𝑌 : (𝑥, 𝑦) ∈ 𝑅}

𝐷𝑜𝑚(𝑅) = {𝑥 ∈ 𝑋 : ∃𝑦.(𝑥, 𝑦) ∈ 𝑅}

Complexity Theory of Randomised Testing

0:39

Definition A.12.2. 𝑀 is a logspace transducer for the relation 𝑅 ⊆ 𝑋 × 𝑌 if, for all 𝑥 ∈ 𝐷𝑜𝑚(𝑅), 𝑀 (𝑥) is a generator for Im(𝑥). That is, L (𝑀 (𝑥)) = 𝐼𝑚(𝑥). Specifically, logspace generators for 𝐿 are logspace transducers for their length partitions, (𝐿𝑖 )𝑖 ∈N . Example A.12.1. A log-space generator 𝐺 = (𝐺𝑖 )𝑖 ∈N is a nondeterministic logspace transducer for the following relation: 𝑅𝐺 = {((𝑖, 1𝑖 ), 𝑥) ∈ 𝐶 × Σ∗ : ∃𝑏 ∈ {0, 1}∗ .𝐺 (𝑖, 𝑏) = 𝑥 } Proposition A.12.1 (Uniform Sampling Of Logspace Transducers [2]). If the relation 𝑅 can be implemented by a logspace transducer, then there exists a polynomial-time sampler, such that on input 𝑥, outputs with success probability > 12 a uniform sample from Im(𝑥). This leads to a straightforward EPG algorithm for generating LG, by applying this procedure repeatedly until a success is reached. □ A.13

Proof of Proposition 6.1

Proof. We will use two lemmas in the proof. The first is the known result of time-space tradeoff for decision machines: Proposition A.13.1 (Decision Time-Space Tradeoff). For space constructible 𝑠 : N → N with 𝑠 (𝑖) > 𝑙𝑜𝑔(𝑖), NSPACE(𝑠 (𝑛)) ⊆ DTIME(2𝑂 (𝑠 (𝑛) ) ) And the following: Lemma A.13.1. For space constructible 𝑠 : N → N, and language 𝐿 ∈ NSPACE(𝑠 (𝑛)), define the decision problem PARTIAL(𝐿) as follows: PARTIAL(𝐿) = {(𝑥, 1𝑘 ) : ∃𝑟 .(𝑥 ++ 𝑟 ) ∈ 𝐿 ∧ |𝑟 | = 𝑘 } Then PARTIAL(𝐿) ∈ NSPACE(𝑠 (𝑛)) Proof. We give an NDTM 𝑀 with space bound 𝑠 that decides PARTIAL(𝐿). Assume 𝐿 is decided by the NDTM 𝐷. Given an input (𝑥, 1𝑘 ) with total length 𝑛 = |𝑥 | + 𝑘, guess nondeterministically on each branch a string 𝑟 of length 𝑘. Due to space constraints when 𝑠 (𝑛) < 𝑛, the string 𝑟 is not stored on the work tape but produced on-demand by nondeterministic branching for each symbol in Σ when the input tape header moves forward. We do not need to worry about the input tape header moving backwards and needing to ensure our choices are consistent, since this is assumed if 𝑠 (𝑛) < 𝑛. Then, simulate branches of 𝐷 on the string 𝑥 ++ 𝑟 , accepting if 𝐷 (𝑥 ++ 𝑟 ) accepts. If there exists a 𝑟 ∈ {0, 1}𝑘 such that 𝑥 ++ 𝑟 ∈ 𝐿 then there is a branch that chooses this 𝑟 , and also there exists an accepting branch on the ensuing simulation of 𝐷 on 𝑥 ++ 𝑟 , thus (𝑥, 1𝑘 ) is accepted. Conversely, if there doesn’t exist such an 𝑟 then all branches on the ensuing simulation will reject for all choices of 𝑟 , thus in this case 𝑀 will reject (𝑥, 1𝑘 ). Hence 𝑀 decides PARTIAL(𝐿). As 𝐷 runs in 𝑠 (𝑛) space, the simulation of 𝐷 on 𝑀 will also run in 𝑠 (𝑛) space. We have argued earlier that guessing the string 𝑟 do not require storing the guess onto the work tape, thus space usage remains 𝑠 (𝑛) for 𝑀. □ Given an NDTM 𝑀 that runs in space 𝑠 (𝑖) on each branch with language 𝐿 = 𝐿(𝑀), we need to produce a generator 𝐺 = (𝐺𝑖 )𝑖 ∈N such that for each 𝑖, 𝐺𝑖 runs in time 2𝑂 (𝑠 (𝑛) ) and has L (𝐺𝑖 ) = 𝐿𝑖 , the strings of 𝐿 with length exactly 𝑖.

0:40

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

Proposition A.13.1 and Lemma A.13.1 together implies that PARTIAL(𝐿) is decideable in time 𝑂 (2𝑂 (𝑠 (𝑛) ) ), thus size-𝑖 instances of PARTIAL(𝐿) can be decided on the generator 𝐺𝑖 . Let its decider be 𝑃. 𝐺𝑖 proceeds as follows: (1) Run 𝑃 (𝜖, 1𝑖 ). If this run rejects, then 𝐺𝑖 also rejects. (2) Initialise 𝑜 = 𝜖. (3) Generate a random permutation of the 𝑚 symbols 𝑐 ∈ Σ, 𝑐 1, . . . , 𝑐𝑘 . (4) For 𝑐𝑖 = 𝑐 1, . . . , 𝑐𝑘 , run 𝑃 (𝑜 ++ 𝑐𝑖 , 1𝑖 − |𝑜 | ) until one of the 𝑐𝑖 s accepts. Write this 𝑐𝑖 to the output tape, and apply the update 𝑜 := 𝑜 ++ 𝑐𝑖 . (5) If |𝑜 | = 𝑖, then terminate. Otherwise continue from step 2. If 𝐿𝑖 = ∅, then 𝑃 (𝜖, 1𝑖 ) will reject on step 1, thus L (𝐺𝑖 ) = ∅ = 𝐿𝑖 . Otherwise there must exist some choice of 𝑠 1, . . . , 𝑠𝑖 at each step, such that 𝑠 = 𝑠 1 ++ . . . ++ 𝑠𝑖 ∈ 𝐿𝑖 . It is safe to fix the 𝑐𝑖 s by writing to the output tape since the run of 𝑃 ensures there exists an extension from that point onwards which belongs in 𝐿𝑖 . A different random permutation is necessary for each iteration to ensure all strings in 𝐿𝑖 have a chance of being sampled: if the same permutation is used for each step then only the first string from the permutation-induced lexicographical ordering will be produced by the algorithm. Altogether we have L (𝐺𝑖 ) = 𝐿𝑖 and hence L (𝐺) = 𝐿 At most |Σ| calls to 𝑃 are made on each iteration, together with the extra call of step 1. Thus 𝑖 |Σ| + 1 ∈ 𝑂 (𝑖) calls to 𝑃 are made in total. Auxillary procedures take time 𝑂 (𝑖). Since 𝑠 (𝑖) > 𝑙𝑜𝑔(𝑖), the total runtime is 𝑂 (𝑖2𝑂 (𝑠 (𝑖 ) ) + 𝑖) = 𝑂 (2𝑂 (𝑠 (𝑖 ) ) ). Therefore 𝐿 = L (𝐺) ∈ GTIME(2𝑂 (𝑠 (𝑛) ) ). □ A.14

Proof of Proposition 6.3

Proof. The construction is based on certificate sampling and instance reconstruction (a la Theorem 7.1). We first define the partition to work on. Let 𝐶 = {(𝑣, 𝑒) ∈ N × N : 𝑒 ≤ 𝑣 2 }, where the tuple (𝑣, 𝑒) ∈ 𝐶 ⊆ {0, 1}∗ is interpreted as the binary encoding of two numbers, with 𝑣 representing the number of vertices and 𝑒 the number of edges. 𝑙 : 𝐶 → N is defined as 𝑙 ((𝑣, 𝑒)) = ⌈𝑙𝑜𝑔(𝑣)⌉ + 2𝑒 ∗ ⌈𝑙𝑜𝑔(𝑣)⌉ + 2⌈𝑙𝑜𝑔(𝑣)⌉. 𝑙 ((𝑣, 𝑒)) computes length of string needed to encode graph with 𝑣 vertices (encoded as a natural number), 𝑒 edges (encodes as an edge list), along with two nodes 𝑖, 𝑗 in the graph. 𝑙 −1 : {1}∗ → P (𝐶), where 𝑙 −1 (1𝑛 ) is defined as a logspace machine that enumerates all possible pairs of integers 𝑣, 𝑒 in their binary representation, with 𝑣, 𝑒 ≤ 𝑛, and checks that 𝑙 ((𝑣, 𝑒)) = 𝑛—output if true, otherwise continues onto the next candidate. 𝑙 −1 runs in logspace of input 1𝑛 , since we are using binary representations. We can iterate through the elements from the set {(𝑣, 𝑒) : 𝑙 (𝑣, 𝑒) = 𝑛} in logarithmic space, choosing a random element to stop at and run some 𝐺 𝑣,𝑒 . It suffices to show that each 𝐺 𝑣,𝑒 exists and runs in logarithmic space of 𝑛 = 𝑙 (𝑣, 𝑒). We now describe a procedure that, when given (𝑣, 𝑒), generates a graph 𝐺 with 𝑣 vertices (labelled by natural numbers), 𝑒 edges, and two nodes 𝑖, 𝑗 within the graph. The generated 𝐺 will, by construction, have a directed path between 𝑖 and 𝑗. Denote 𝑛 = 𝑙 ((𝑣, 𝑒)). The procedure is as follows: (1) Output 𝑣 in unary, to denote the number of vertices in the graph. (2) Select two random nodes 𝑣𝑖 , 𝑣 𝑗 with 𝑖, 𝑗 ≤ 𝑣. (3) Generate a path of length 𝑙 ≤ 𝑣 via a random walk that starts from 𝑣𝑖 and ends at 𝑣 𝑗 : (a) On each step of the random walk, we write the edge taken to the output tape. (b) When 𝑣 𝑗 is reached, stop the random walk. (c) If, by the time we traversed 𝑙 − 1 nodes and still have not reached 𝑣 𝑗 , go directly to 𝑣 𝑗 on the next step. (4) Add 𝑒 random edges to the graph in Erdos-Renyi fashion. Output each chosen edge immediately.

Complexity Theory of Randomised Testing

0:41

(5) Output the earlier 𝑖, 𝑗. The generated graph 𝐺 has a path from 𝑣𝑖 to 𝑣 𝑗 by construction, and thus the full outputted instance is a member of REACH. For any given directed graph 𝐻 with 𝑣 vertices, 𝑒 edges, and a path from 𝑥 to 𝑦 there exists a bitstring that makes the following choices: (1) Chooses exactly 𝑖 = 𝑥, 𝑗 = 𝑦 to be the start/endpoints of the random walk. (2) Chooses exactly the path from 𝑥 to 𝑦 on 𝐻 in the random walk. (3) Fills in exactly the rest of the edges of 𝐻 in step 4. and thus ⟨𝐻, 𝑥, 𝑦⟩ is generable by the above procedure. Throughout the procedure, we store the binary representation of 𝑣, the chosen vertices 𝑖, 𝑗, the counter for the random walk up to 𝑣 in length, and the counter for the number of edges up to 𝑣 2 . All of which are representable in space 𝑂 (𝑙𝑜𝑔(𝑛)). □ A.15

Proof of Proposition 6.4

Proof. GSPACE(𝑠 (𝑛)) 𝑓 ⊆ NSPACE(𝑠 (𝑛)) 𝑓 follows from the same simulation argument as for the non-oracle case. For NSPACE(𝑠 (𝑛)) 𝑓 ⊆ GTIME(2𝑂 (𝑠 (𝑛) ) ) 𝑓 , we need the following lemma for the time-space tradeoff on oracle machines: Lemma A.15.1. For length-bounded 𝑓 : Σ∗ → Σ∗ , NSPACE(𝑠 (𝑛)) 𝑓 ⊆ DTIME(2𝑂 (𝑠 (𝑛) ) ) 𝑓 Proof. Take the nondeterministic oracle machine 𝑀 𝑓 , space-bounded by the polynomial 𝑠 and recognising some 𝐿 ∈ NSPACE(𝑠 (𝑛)) 𝑓 . Suppose we are given an 𝑥 ∈ Σ∗ with |𝑥 | = 𝑛. Note that the query tape has size at most 𝑠 (𝑛), and that the contents of the query tape fixes the contents of the answer tape. Since the largest size query that can be made is of length 𝑠 (𝑛), the answer tape can record at most 2𝑂 (𝑠 (𝑛) ) nonempty cells (as 𝑓 is length-bounded by 2𝑂 (𝑛) ), which is indexable by a pointer of size 𝑂 (𝑠 (𝑛)). As the answer tape is read-only, the number of possible configurations on both the query and the answer tapes is 2𝑂 (𝑠 (𝑛) ) . The work tape and the input tape contribute another 2𝑂 (𝑠 (𝑛) ) configurations to the total state space, meaning the overall possible configurations for 𝑀 𝑓 remain 2𝑂 (𝑠 (𝑛) ) . Querying edges on the configuration graph can be done by querying 𝑀 𝑓 ’s definition. Hence, a standard graph algorithm through the configuration graph can decide whether 𝑥 ∈ 𝐿 in time 2𝑂 (𝑠 (𝑛) ) . □ An identical construction to the proof of Proposition 6.1 then follows: as the oracle variant of 𝑃𝐴𝑅𝑇 𝐼𝐴𝐿(𝐿) is still within NSPACE(𝑠 (𝑛)) 𝑓 , the bit-by-bit construction can be used to construct all elements of 𝐿 ∈ NSPACE(𝑠 (𝑛)) 𝑓 at random. □ A.16

Proof of Proposition 7.1

Proof. Clearly if 𝐿 ∈ PG then DEFAULT(𝐿) ∈ 𝐹 𝑃 by running the generator 𝐺for 𝐿. Suppose now DEFAULT(𝐿) ∈ 𝐹 𝑃. With a computable default element as a fallback, we are free to sample the NP computation even though there is a chance of failure (i.e. finding a rejecting branch). This is similar in idea to the proof of Proposition A.4.1. The following procedure 𝐺 = (𝐺𝑖 )𝑖 ∈N is an algorithm for sampling 𝐿, given an NP machine 𝑀 that decides 𝐿 in polynomial time. Assume DEFAULT(𝐿) is implemented by the machine 𝐷 which, on input 1𝑖 , will output either 𝜖 or a string in 𝐿𝑖 . Define 𝐺𝑖 as: (1) Sample a random string 𝑥 of length 𝑖. (2) Simulate a single branch of 𝑀 (𝑥). Output 𝑥 if 𝑀 (𝑥) accepts. (3) Otherwise, run 𝐷 (1𝑖 ). If 𝐷 (1𝑖 ) = 𝑦 ≠ 𝜖 then output 𝑦, otherwise reject.

0:42

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

𝐺𝑖 runs in polynomial time since both 𝑀 and 𝐷 are polynomial-time bounded. Clearly all of 𝑥 ∈ 𝐿𝑖 is samplable this way. □ A.17

Proof of Proposition 6.5

Proof. For PSPACEG 𝑓 ⊆ PSPACE 𝑓 , we know from Proposition 6.4 that PSPACEG 𝑓 ⊆ NPSPACE 𝑓 . We show that Savitch’s theorem still holds for the oracle case: NPSPACE 𝑓 ⊆ PSPACE 𝑓 , which implies PSPACEG 𝑓 ⊆ PSPACE 𝑓 . Suppose 𝑀 𝑓 is an NDTM deciding some 𝐿 ∈ NPSPACE(𝑠 (𝑛)) 𝑓 , and space-bounded by the polynomial 𝑠. Given any 𝑥 ∈ Σ∗ with |𝑥 | = 𝑛, we want to decide whether 𝑥 ∈ 𝐿. In the proof of Lemma A.15.1 we see that the number of configurations on 𝑀 𝑓 remains 2𝑂 (𝑠 (𝑛) ) . Thus, using the divide-and-conquer method detailed in the proof of Savitch’s theorem, we get a polynomial 𝑂 (𝑠 2 (𝑛)) space deterministic algorithm for 𝐿, using the same oracle 𝑓 , implying 𝐿 ∈ PSPACE 𝑓 . PSPACE 𝑓 ⊆ PSPACEG 𝑓 : suppose 𝑀 𝑓 decides a language 𝐿 ∈ PSPACE 𝑓 . 𝐺 𝑓 is defined as follows: on input 𝑛, choose a enumeration of the strings 𝑥 ∈ Σ𝑛 , and simulate the PSPACE 𝑓 machine on 𝑥. If 𝑀 𝑓 (𝑥) accepts then accept and output 𝑥 with probability 1/2. If all strings 𝑥 are rejected by 𝑀 𝑓 , then 𝐺 𝑓 rejects. If all 𝑥s are exhausted before we chose to accept, loop back to the beginning of the enumeration. Clearly 𝑥 ∈ 𝐿 has length 𝑛 if and only if 𝑥 has nonzero probability of being generated. □ A.18

Proof of Proposition 7.2

Proof. We show that 𝐿 is in PG by constructing a generator 𝐺 𝐿 = (𝐺 𝐿,𝑖 )𝑖 ∈N for it. Since 𝐾 ∈ PG, let 𝐺 𝐾 = (𝐺 𝐾,𝑖 )𝑖 ∈N be the generator for 𝐾, where 𝐺 𝐾,𝑖 runs in time 𝑝 𝐾 (𝑖) for some polynomial 𝑝 𝐾 . Also, let 𝐺𝑠 be the generator from the Efficient Extension condition for 𝑠 ∈ 𝐾. Since 𝐺𝑠 is polynomial-time, it runs in time 𝑝 𝐸 (|𝑠 |) for some polynomial 𝑝 𝐸 . For any index 𝑛 ∈ N, we define 𝐺 𝐿,𝑛 as follows: (1) Use 𝐺 𝐾,𝑛 to generate a sample 𝑠 ∈ 𝐾. Note that since (𝐿𝑛 )𝑛∈N partitions 𝐿 by size, and 𝐾 ⊆ 𝐿, 𝐺 𝐾,𝑛 generates elements in 𝐾 ∩ 𝐿𝑖 . Thus |𝑠 | = 𝑛. (2) Run the extension generator 𝐺𝑠 to obtain a string 𝑠 ′ . (3) Output 𝑠 ′ . The total runtime is dominated by the runtime of 𝐺 𝐾,𝑖 and 𝐺𝑠 . Since both are polynomial in 𝑛, the composed generator runs in polynomial time. By the property of 𝐺𝑠 , 𝑠 ≼ 𝑠 ′ . Since 𝑠 ∈ 𝐾 ⊆ 𝐿, by Upward Closure, 𝑠 ′ ∈ 𝐿. Also |𝑠 ′ | = |𝑠 | = 𝑛, so 𝑠 ′ ∈ 𝐿𝑖 . For any 𝑤 ∈ 𝐿𝑖 , since 𝐾 contains all minimal elements of 𝐿, there exists some 𝑠 ∈ 𝐾 such that 𝑠 ≼ 𝑤. Since we restrict extensions to same-length strings (by the definition of 𝐺𝑠 ), we must have |𝑠 | = |𝑤 | = 𝑛, so 𝑠 ∈ 𝐾 ∩ 𝐿𝑖 . 𝐺 𝐾,𝑖 generates 𝑠 with non-zero probability. 𝐺𝑠 generates 𝑤 from 𝑠 with non-zero probability (since 𝑤 ∈ {𝑠 ′ : 𝑠 ≼ 𝑠 ′ ∧ |𝑠 ′ | = |𝑠 |}). Thus, 𝐺 𝐿,𝑖 generates 𝑤 with non-zero probability. Therefore, 𝐺 𝐿 is a polynomial-time generator for 𝐿, and 𝐿 ∈ PG. □ A.19

Examples of Generators via Basis Extension

Example A.19.1 (CNF-SAT revisited). We show that CNF-SAT is in PG using Proposition 7.2. We define the size of a formula by the number of variables 𝑛 and clauses 𝑚, using a fixed-length encoding. We define the partial order ≼ such that 𝜙 1 ≼ 𝜙 2 if 𝜙 1 and 𝜙 2 have the same number of clauses, and each clause in 𝜙 2 contains the literals of the corresponding clause in 𝜙 1 (i.e., 𝜙 2 is obtained by adding literals to 𝜙 1 ). • Upward Closure: Adding literals to a disjunctive clause makes it strictly easier to satisfy. Thus if 𝜙 1 is satisfiable, 𝜙 2 is also satisfiable.

Complexity Theory of Randomised Testing

0:43

• Samplable Minimal Basis: The minimal elements 𝐾 are satisfiable formulas where no literals can be removed from clauses while maintaining the structure (i.e., unit clauses). This corresponds to consistent partial assignments. We can sample these by generating random consistent assignments for the 𝑛 variables, and using the active literals as the unit clauses. • Efficient Extension: Given a consistent assignment (formula of unit clauses), we can extend it to a full formula of the target size by adding random literals to each clause. Example A.19.2 (Hamiltonian Path). Let HAMPATH be the set of graphs (encoded as adjacency matrices of size 𝑛 2 ) that contain a Hamiltonian path. We define ≼ by subgraph inclusion: 𝐺 1 ≼ 𝐺 2 if 𝐸 (𝐺 1 ) ⊆ 𝐸 (𝐺 2 ). • Upward Closure: Adding edges to a graph preserves the existence of a Hamiltonian path. • Samplable Minimal Basis: The minimal elements are graphs consisting of exactly one Hamiltonian path (and no other edges). These can be sampled efficiently by generating a random permutation of the vertices. • Efficient Extension: Given a graph 𝐺 consisting of a Hamiltonian path, we can extend it to a random graph 𝐺 ′ of the same size (adjacency matrix representation) by setting additional entries in the adjacency matrix to 1 with some probability. A.20

Proof of Theorem 7.1

Proof. (2) =⇒ (1) is clear, as the composition of the certificate generator with the certificate recoverer leads to a polynomial-time generator of 𝐿. That is, suppose the recovery scheme is (𝑆𝑉 , 𝑅𝑉 ). Then 𝐺𝑖 = 𝑅𝑖 ◦ 𝑆𝑖 is the generator for 𝐿𝑖 that runs in time 𝑝 (𝑖, 𝑞(𝑖)), which is polynomial in 𝑖. And thus 𝐿 has a polynomial-time generator. To show (1) =⇒ (2), we need to construct a verifier 𝑉 , along with its associated recovery scheme (𝑆𝑉 , 𝑅𝑉 ), from a polynomial-time generator 𝐺 = (𝐺𝑖 )𝑖 ∈N of 𝐿. Define 𝑉 to use bitstrings as certificates. On input 𝑤#𝑐 with |𝑤 | = 𝑛, simulate 𝐺𝑛 on input 𝑐 until termination, and accept if the output of 𝐺𝑛 is 𝑤, reject otherwise. Since 𝐺𝑛 will terminate in time 𝑝 (𝑛), for a polynomial 𝑝, it will consume at most 𝑝 (𝑛) random bits during any run. We define the certificates 𝑐 of 𝑤 to be any bitstream of length up to 𝑝 (𝑛) that leads to 𝑤 being produced by 𝐺𝑛 . If 𝑤 ∈ 𝐿 then there exists a bitstream (certificate) 𝑐 that leads to 𝑉 (𝑤#𝑐) accepting. On the other hand, if 𝑤 ∉ 𝐿, then 𝑉 (𝑤#𝑐) will always reject for any bitstrings 𝑐. Thus all conditions of 𝑉 being a polynomial-time verifier for 𝐿 is satisfied. We now need to show that the certificate recovery scheme (𝑆𝑉 , 𝑅𝑉 ) exists. Producing a random certificate is easy, as we are using bitstrings as certificates. By definition, 𝐺𝑖 terminates in time 𝑝 (𝑖). For 𝑆𝑉 = (𝑆𝑖 )𝑖 ∈N , we define each 𝑆𝑖 as follows: (1) Simulate 𝐺𝑖 to determine if 𝐿𝑖 is empty. Reject if 𝐿𝑖 = ∅. (2) Output a random bitstring of length 𝑝 (𝑖). To see that 𝑆𝑉 is indeed a certificate generator, suppose firstly 𝑤 ∈ 𝐿𝑖 = L (𝐺𝑖 ). Then there exists some 𝑝 (𝑖)-length bitstring 𝑐 where 𝐺𝑖 (𝑐) = 𝑤, hence 𝑉 (𝑤#𝑐) accepts by definition, and 𝑤 ∈ 𝑉𝑓 (𝑐). We know 𝑐 is samplable from 𝑆𝑖 since it samples all bitstrings of length 𝑝 (𝑖), hence 𝑐 ∈ L (𝑆𝑖 ). Thus 𝑤 ∈ 𝑉𝑓 (𝑐), with 𝑐 ∈ L (𝑆𝑖 ). If 𝐿𝑖 = ∅ then 𝑆𝑖 indeed rejects. Therefore we have Ð 𝐿𝑖 ⊆ Σ𝑖 ∩ 𝑐 ∈ L (𝑆𝑖 ) 𝑉𝑓 (𝑐). By definition of 𝑉 , if 𝑉 (𝑤#𝑐) accepts then 𝑤 ∈ 𝐿. Hence 𝑉𝑓 (𝑐) ⊆ 𝐿, and Σ𝑖 ∩ 𝑉𝑓 (𝑐) ⊆ 𝐿𝑖 for any Ð 𝑐. It follows Σ𝑖 ∩ 𝑐 ∈ L (𝑆𝑖 ) 𝑉𝑓 (𝑐) ⊆ 𝐿𝑖 . Altogether, we have condition 1 of the certificate generator. Condition 2 of the certificate generator clearly holds since 𝑆𝑖 takes exactly 𝑝 (𝑖) steps, which is a polynomial in 𝑖. For 𝑅𝑉 , we define for each 𝑖 ∈ N, 𝑅𝑖 (𝑐, 𝑏) = 𝐺𝑖 (𝑐). That is, each 𝑅𝑖 will simulate 𝐺𝑖 on the certificate 𝑐 it received on the certificate input tape, and ignore its own random tape. Condition 2

0:44

Pingshi Yu, Chengsong Tan, Nicolas Wu, and Alastair Donaldson

of certificate recoverer holds since 𝐿𝑖 ∩ 𝑉𝑓 (𝑐) contains the single string 𝐺𝑖 (𝑐), which is the only output of 𝑅𝑖 (𝑐, 𝑏) for any choices of bitstring 𝑏. Finally, condition 3 of certificate recoverer holds as 𝐺𝑖 accepts within 𝑝 (𝑖) steps, which is a polynomial in parameters 𝑖 and |𝑐 | in the trivial way. Thus 𝑅𝑉 also satisfies all conditions of a certificate recoverer. □ A.21

Proof of Proposition 7.3

Proof. Suppose 𝐺 = (𝐺𝑖 )𝑖 ∈N, 𝐻 = (𝐻𝑖 )𝑖 ∈N with L (𝐺), L (𝐻 ) ∈ PG. Assume 𝐺 and 𝐻 run in polynomial time bounds 𝑝 and 𝑞 respectively. Concatenation. Define 𝐺 ++ 𝐻 as follows. For index 𝑖: Sample a random 𝑗 ∈ 1, . . . , 𝑖 − 1 and define 𝑘 = 𝑖 − 𝑗. Run 𝐺 𝑗 first, followed by 𝐻𝑘 on an empty work tape immediately after 𝐺 𝑗 terminates. If any of 𝐺 𝑗 or 𝐻𝑘 rejected, set 𝑗 := 𝑗 + 1 and retry. If all of 𝑗 ∈ 1, . . . 𝑖 − 1 failed, then reject. The total time is bounded by 𝑖 (𝑝 (𝑖) + 𝑞(𝑖)) to generate an input of size 𝑖, which is still polynomial in 𝑖. Kleene Star. For 𝐺 ∗ , given an index 𝑖, we need to produce a length 𝑖 string that is the concatenation of shorter strings from L (𝐺). √At first sight, this seems difficult, since the partition function for the integer 𝑖 grows at rate 𝑂 (2 𝑛 ), and each partition needs to be checked to determine whether L (𝐺𝑖∗ ) = ∅. However, we can define a polynomial time generator for L (𝐺𝑖∗ ) by reducing to the Knapsack problem. First run all 𝐺 1, . . . , 𝐺𝑖 in sequence to obtain a sequence of 𝑙 1, . . . , 𝑙𝑚 string lengths where for all 𝑗 ∈ 1, . . . 𝑚, L (𝐺𝑙 𝑗 ) ≠ ∅. Then run the dynamic programming algorithm of Knapsack to extract a random way to sum up to 𝑖 using 𝑙 1, . . . , 𝑙𝑚 . Reject if no solution exists. Finally, run each 𝐺𝑙 𝑗 in sequence, concatenating the outputs from each run to produce 𝐺𝑖∗ . This algorithm clearly produces some string in L (𝐺𝑖∗ ) if one exists. On the other hand, each partition 𝑙 1, . . . , 𝑙𝑚 of 𝑖 has nonzero probability of being extracted from the Knapsack algorithm, and for each 𝑗, any string 𝑥 𝑗 ∈ L (𝐺𝑙 𝑗 ) has nonzero probability of being produced by their respective generators. Thus, all members of L (𝐺∗𝑖 ) also have nonzero probability of being sampled. Determining the sequence of 𝑙 𝑗 s takes time 𝑂 (𝑖𝑝 (𝑖)), Knapsack runs in time 𝑂 (𝑚𝑖) = 𝑂 (𝑖 2 ), and the final output stage takes time bounded above by 𝑂 (𝑖𝑝 (𝑖)). Thus the total runtime remains polynomial in 𝑖. Union. For index 𝑖, select one of 𝐺𝑖 or 𝐻𝑖 at random to run first. If the first machine rejects, then run the second machine. Reject if both runs reject, otherwise output what is written on the output tape from the first accepting run. This generates all strings 𝑥 ∈ L (𝐺𝑖 ) ∪ L (𝐻𝑖 ). □ A.22

Proof of Theorem 7.2

Proof. Suppose for a contradiction that given 𝐿1, 𝐿2 ∈ PG, 𝐿1 ∩ 𝐿2 ∈ PG. We will show that PG ⊇ NP, which contradicts Theorem 5.1. Take any 𝐿 ∈ NP, and define the following languages: 𝐿 ∗ = {00𝑥 : 𝑥 ∈ 𝐿}

𝐴 = {01𝑦 : 𝑦 ∈ {0, 1}∗ }

𝐵 = {10𝑦 : 𝑦 ∈ {0, 1}∗ }

Observe that if 𝐿 ∗ ∈ PG, then also 𝐿 ∈ PG by taking a suffix. We claim both 𝐿 ∗ ∪ 𝐴 ∈ PG and 𝐿 ∗ ∪ 𝐵 ∈ PG. To see this, note that DEFAULT(𝐿 ∗ ∪ 𝐴) ∈ 𝐹 𝑃 as the function 𝑓 : {1}∗ → (𝐿 ∗ ∪ 𝐴) defined as 𝑓 (𝜖) = 𝑓 (1) = 𝑓 (11) = 𝜖, and 𝑓 (1𝑘 ) = 010𝑘 −2 for 𝑘 ≥ 2 computes the default elements of 𝐿 ∗ ∪ 𝐴 in time linear in 𝑘. By Proposition 7.1, 𝐿 ∗ ∪ 𝐴 ∈ PG. 𝐿 ∗ ∪ 𝐵 ∈ PG follows by a similar argument. By assumption, 𝐿 ∗ = (𝐿 ∗ ∪ 𝐴) ∩ (𝐿 ∗ ∪ 𝐵) ∈ PG, where the equality comes from the fact that ∗ 𝐿 ∩ 𝐴 = 𝐴 ∩ 𝐵 = 𝐿 ∗ ∩ 𝐵 = ∅. Thus, 𝐿 ∗ ∈ PG, which implies NP ⊆ PG, and we get the desired contradiction. □

Record · ID 363312 · SHA-256 426f7234c8bca564
Retrieved via Conceptio — every document is proof-bundled with source, license, and retrieval metadata.