{'fraction_non_alphanumeric': 0.03476949334180079, 'fraction_numerical': 0.00494155470439977, 'mean_word_length': 4.352097716409984, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Algorithmic Pseudorandomness in Quantum Setups

The Church-Turing thesis is one of the pillars of computer science; it postulates that every classical system has equivalent computability power to the so-called Turing machine. While this thesis is crucial for our understanding of computing devices, its implications in other scientific fields have hardly been explored. Here we start this research programme in the context of quantum physics and show that computer science laws have profound implications for some of the most fundamental results of the theory. We first show how they question our knowledge on what a mixed quantum state is, as we identify situations in which ensembles of quantum states defining the same mixed state, indistinguishable according to the quantum postulates, do become distinguishable when prepared by a computer. We also show a new loophole for Bell-like experiments: if some of the parties in a Bell-like experiment use a computer to decide which measurements to make, then the computational resources of an eavesdropper have to be limited in order to have a proper observation of non-locality. Our work opens a new direction in the search for a framework unifying computer science and quantum physics.

The Church-Turing thesis is one of the pillars of computer science; it postulates that every classical system has equivalent computability power to the so-called Turing machine. While this thesis is crucial for our understanding of computing devices, its implications in other scientific fields have hardly been explored. Here we start this research programme in the context of quantum physics and show that computer science laws have profound implications for some of the most fundamental results of the theory. We first show how they question our knowledge on what a mixed quantum state is, as we identify situations in which ensembles of quantum states defining the same mixed state, indistinguishable according to the quantum postulates, do become distinguishable when prepared by a computer. We also show a new loophole for Bell-like experiments: if some of the parties in a Belllike experiment use a computer to decide which measurements to make, then the computational resources of an eavesdropper have to be limited in order to have a proper observation of nonlocality. Our work opens a new direction in the search for a framework unifying computer science and quantum physics.
Quantum theory stands as one of the most successful and experimentally confirmed theories to date, with not a single experiment shown to be in disagreement. Its foundations, intensely debated in the early days of the theory [1,2], remain an active area of research with many recent insightful results, such as the possibility to derive quantum theory from physical axioms [3], proving the completeness of quantum theory [4], or establishing that quantum states are real [5].
On the other hand, computability theory studies which functions can be calculated by algorithmic means and which cannot, and, more generally, their degree of uncomputability. The field emerged in the 1930s with the independent works of Alan Turing [6] and Alonzo Church [7] who introduced two equivalent formalizations of the intuitive concept of algorithm. The fact that both models of computation turned out to be equivalent lead Stephen Kleene [8] to postulate what is now known as the Church-Turing thesis: any function 'naturally to be regarded as computable' (i.e. calculable by algorithmic means) is computable by the formal model of Turing machines.
This thesis has been greatly strengthened by the fact that all the formal models of computation defined so far have been shown to be at most as expressive as the classical Turing machines in terms of the class of functions they compute.
Until now, the relationship between quantum mechanics and the Church-Turing thesis has been concerned on how the first one can affect the latter (see, for instance, [9]). In this article, however, we introduce an opposed and new research program: implications of computer science principles for quantum physics.
As the first steps in that direction, we present two results. First we show that computers impose a limitation when it comes to producing a mixed state as a classical mixture of pure quantum states. It turns out that with the sole knowledge that the classical mixture is performed by a computer, situations that seem not to be distinguishable turn out to be so. This has direct implications since mixed states are prepared this way in many experiments [10,11]. Secondly, when it comes to Bell-like experiments to test non-locality, another distinctive feature of quantum mechanics, we show that if the measurement independence between the two parties [12][13][14][15] is achieved via private computable pseudo random number generators, an eavesdropper can start guessing their inputs from the information on their previous inputs, thus leading to a new computability loophole for Bell tests.
Formally, our results apply only to computers. This has already considerable practical consequences, since almost every experimental setup is controlled by computers. However, one can argue that, due to the widely accepted physical interpretation of the Church-Turing thesis: the behaviour of any discrete physical system evolving according to the laws of classical mechanics is computable by a Turing machine, our results, in fact, apply to every classical system and hence, the limitations that we show are fundamental.

I. PROPER MIXED STATE PREPARATION AND THE CHURCH-TURING THESIS
We start by considering one of the basic parts of quantum theory: the concept of a mixed state [16]. We will see that although well understood by physicists, their nature and origin can lead to apperent paradoxes when confronted against common computer science tenets.
Let us present now the following preparation of a mixed state: A classical computer in an unknown configura-tion and with unbounded memory is running an unknown and presumably very convoluted algorithm to prepare a mixed state. We have the promise that the computer, understood as a black box, is mixing evenly either the single qubit eigenstates of σ z {|0 , |1 } or the states {|+ , |− }, where |± = 1 √ 2 (|0 ± |1 ) as seen in Fig. 1. Is there any operational procedure to decide which of the two ensembles are being mixed for an experimenter (Bob) who cannot open the black box? Even though one would be tempted to assign to both preparations the identity state ρ = I 2 , our results show that the fact that the mixing procedure was performed in a computable way leaves a trace which allows us to distinguish both mixtures in finite time and with arbitrarily high success probability. It is worth mentioning that having a computer mixing the state doesn't imply that the sequence in which it mixes the state is periodic or anything. In fact, there exist normal sequences (e.g. those which satisfy the law of large numbers in a generalized way), or other even 'more random' sequences which are computable in polynomial time [17].
FIG. 1: Scheme for the preparation of mixed states via classical mixing. Alice uses a computer to choose between |0 and |1 (or |+ and |− ). From Bob's perspective, since he doesn't know the computer program Alice is using, it's a mixed state ρ. To distinguish both possible preparations he measures alterantively σx and σz and sends the resulting sequences to a computer that will be able to tell which of the sequences is computable (corresponding to the basis in which Alice prepared the state) and which is a fair coin tossing (corresponding to the other basis).
In order to solve this problem, Bob measures every qubit that comes out of the black box on an odd position in the basis of eigenstates of σ z , yielding a binary sequence of measurement results Z. He also measures every qubit on an even position in the basis of eigenstates of σ x obtaining a binary sequence X. This way Bob obtains two binary sequences, as can be seen in Fig.  1. The one corresponding to the choice of measurement that matches the preparation basis is computable, and the other one corresponds to a fair coin tossing. Therefore we need an algorithm that given two sequences, one computable and one arising from a fair coin tossing, is able to tell us which is which. We will show now one such algorithm, that can perform this task in finite time and with an arbitrarily high probability of success.
To distinguish which of the two sequences is computable we dovetail between program number (the pro-grams are computably enumerable) and maximum time steps that we allow each program to run (that is, we run program 1 for 1 timestep, then programs 1 and 2 for 2 timesteps and so on), as is a common technique in computability theory. For each program p of length |p| we will compare the first k|p| output bits with the corresponding prefixes of both sequences, where k is an integer constant depending on the probability of success we are looking for. Whenever we find a match for the first k|p| bits, we halt. Fig. 2 depicts the dovetailing algorithm. It is straightforward to see that this algorithm always gives an answer, and the probability of making a mistake is less than O(2 −k ). Therefore we can guess in finite time and with an arbitrarily high probability of success (by setting k we adjust the probability of success).
The complete algorithm to distinguish a fair coin from a computable sequence is Algorithm 1 below, where X k|p| denotes the fist k|p| bits of the sequence X.

Algorithm 1
The distinguishing protocol. U t (p) is a universal Turing machine that runs program p for t timesteps. The two 'for' loops correspond to the dovetailing.
Input: k ∈ N and X, Z ∈ 2 ω , two bit sequences with the promise that one of them is computable and other is not. Output: 'X' or 'Z' as the candidate for being computable; wrong answer with probability bounded by O(2 −k ). for t = 0, 1, 2 . . . do for p = 0, . . . , t do if Ut(p) = X k|p| then output 'X' and halt if Ut(p) = Z k|p| then output 'Z' and halt Note that, at a given iteration of the algorithm, it may perfectly be the case that program p has not been able to produce in t time steps the k|p| symbols needed to check the halting condition. If this is the case, the algorithm simply keeps running and moves to the next program. However, the algorithm will for sure halt as it will run the actual program used in the blackbox at some finite time. For a detailed explanation on how Algorithm 1 works and its probability of success, see Appendix A.
It is an interesting open question to study the effect of noise in the previous algorithm. As a first step, we have considered a rather simple noise model in the state preparations and measurements described by a flip probability in the observed symbols r. That is, we consider the situation in which those results obtained when measuring the quantum states in the actual basis used by the box are correct with probability 1 − r (this simple noise has no effect on the results of measurements performed in the wrong basis). As shown in Appendix A, there is another slightly more complex algorithm that still halts with arbitrarily small error probaility whenever r 0.21.
The previous algorithm is of course very demanding, but proves that ensembles of states defining the same mixed state are in principle distinguishable when pre-FIG. 2: To decide which of the two sequences is computable, we dovetail between program number and timesteps that each program is allowed to run. On green we show the actual program pA that was used to prepare the state, and the number of timestpes tA it takes to generate a k|pA| long prefix. The latest halting condition for our algorithm is shown in red, although it might halt before that with either a wrong recognition or a correct one. pared by classical computing devices. This questions our understanding of mixed quantum states and leaves quantum mixtures (either by using a part of a larger etangled system or a quantum random number generator) as the only way to create them.

II. BELL INEQUALITY LOOPHOLE
Non-locality is another of the most intrinsic features of quantum mechanics [2,18,19]. The standard Bell scenario is described by two distant observers who can perform m possible measurements of d possible outputs on some given devices. The measurements are arranged so that they define space-like separated events. It is convenient for what follows to rephrase the standard Bell scenario in cryptographic terms, as in [20][21][22]. In this approach, Alice and Bob get the devices from a nontrusted provider Eve. The standard local EPR models correspond to classical preparations in which the devices generate the measurement results given the choice of measurements, but independently of the input chosen by the other party. Bell inequalities are conditions satisfied by all these preparations, even when having access to all the measurement choices and results produced in previous steps [20]. In turn, quantum correlations, obtained for example by measuring a maximally entangled two-qubit state with non-commuting measurements, can violate these inequalities. The violation of a Bell inequality witnesses the existence of non-local correlations and can be used by Alice and Bob to certify the quantum nature of their devices.
In what follows, it is shown how a classical Eve can mimick a Bell inequality violation when the measurement choices on Alice and Bob are performed following an algorithm, which is a standard practice in many Bell experiments to date. As above, it is not assumed that the algorithm is known by the eavesdropper. The result can be seen as a new loophole, named the computability loophole. For this loophole to apply, Eve has to make use of the inputs and outputs produced by the parties in previous steps [20][21][22], as shown in Fig. 3. Using the information from all previous choices of inputs for both parties, Alice's box makes a prediction on what the next round inputs will be by using the presented algorithm. For simplicity in the notation, the attack is shown for a Bell test involving two measurements per party. As long as Alice, Bob or both use a computable sequence for their choice, the guess will start being correct after a number of rounds. Once this happens, the boxes can simulate any probability distribution, both local and non-local. Therefore Alice and Bob can not rule out an eavesdropper having prepared their boxes.
The computability loophole is rather simple and works as follows: one of the devices, say Alice's, uses all the inputs chosen in previous steps by both parties to guess the next ones. For that, a time complexity class C is initially chosen by Eve. Since algorithms in such a class are computably enumerable, Alice's device will check all of them until it finds one that matches Alice's (or Bob's) bits given so far. A guess for the next inputs is done based on that algorithm (see Fig. 4 for a representation of the algorithm) and communicated to the other device. If Eve's class C includes Alice's and/or Bob's algorithms, at some point the device will start guessing correctly and will keep doing so forever. Of course, once the devices are able to guess the inputs of at least one of the parties, they can easily produce non-local correlations.

FIG. 4: Algorithm to predict bits from previously seen ones.
For simplicity it is presented for the case of 2 inputs. Alice's box enumerates all sequences si from the complexity class C and picks the first one whose first bits coincide with the ones seen. The guess Eve will make is the next bit from that sequence. If the actual sequence one wants to predict belongs to class C, at some point, after seeing enough bits, all the predictions will be correct.
It should be noticed that since Alice's and Bob's algorithms belong to some time complexity class, they can never rule out such an eavesdropper. On the other hand, the eavesdropper, when choosing the class C, is imposing how hard it is for Alice and Bob to avoid the loophole. The algorithm is shown as Algorithm 2, and for a more detailed description the reader is refered to Appendix B.
Algorithm 2 A next-value algorithm for a time class C with bound t Input: n ∈ N Output: g(n), the next-value function for C. Let Me be an enumeration of all Turing machines. Let n = m0, . . . , mn−1 be the already seen bits from the sequence. Let e, c be the least number such that i. for i ∈ {0, . . . , n}, Me(i) halts after at most c · t(|i|) many steps, where Me evaluates function number e from C and t is the computable time bound for class C.
ii. for i ∈ {0, . . . , n − 1} Me(n) outputs mi Output Me(n) Apart from being very demanding, a criticism to this loophole is that it only works in the long run, meaning that Alice and Bob will not see a fake violation of a Bell inequality unless they run their experiment for long enough. But this brings the question of what's the validity of a violation that, in the long run, would have admited a local model. The only way to escape this loophole is by using a quantum random generator for the inputs, however, it is highly undesirable to depend on a non-local theory to test non-locality.

III. DISCUSSION
The Church-Turing thesis is one of the most accepted postulates from computer science. As such, one can wonder what consequences would it have if it were, indeed, a law of Nature. We started here this research program in the context of quantum physics by showing how it questions the understanding of what a proper mixed quantum state is and introducing a new loophole for Bell tests. The study of these questions is essential in any attempt to create a unifying theory merging information laws and quantum physics. In this section we discuss with details the protocol to distinguish two ensembles of pure states that apparently yield the same density matrix, given the assumption that the mixture has been prepared in a computable way. To do so, we will first reduce this scenario to a different problem in classical information theory relating infinite binary sequences, which we show to be solvable. Then we see how this second problem can be solved in finite time with arbitrarily small error probability. Finally, we present a slight modification of the algorithm that makes it robust against a simple noise model.

The distinction protocol
The distinguishability scenario we are interested in is as follows: Alice is presented with two bags of quantum systems, one having systems in the state |0 and the other having systems in the state |1 . At random, she chooses one bag at a time and sends a state from that bag to Bob. Bob's state is ρ = I/2, as he has no information on the prepared state. Now imagine the same scenario, but instead of those two bags Alice has one with the state |+ and another with the state |− , and she proceeds in the same way. It is clear that these two situations are indistinguishable from Bob's point of view, as they are supposed to define the same mixed quantum state.
Consider the same two situations, but now, in order to choose from which bag to pick the state, Alice uses the bits of a computable binary sequence, that is, a binary sequence produced by an algorithm. Ideally such algorithm is a pseudo-random number generator, whose output 'looks like' typical coin tossing (i.e. satisfying for instance the law of large numbers, as well as any other reasonable law of randomness [23]). We next see that, if Alice's sequence is computable, Bob can distinguish between both situations in finite time and with an arbitrarily high probability of success.
Bob's protocol works as follows: he measures Alice's first qubit in the basis of eigenstates of σ x , the second qubit in the basis of eigenstates of σ z , and so on, measuring every odd qubit in the σ x basis and every even qubit in the σ z basis. The output of the measurements yields in the limit two infinite binary sequences: X, obtained from the measurements on the odd qubits and Z, obtained from the even qubits. Now X and Z have a distinctive feature: when Bob measures in the same basis as Alice prepared the states, the sequence obtained is computable (because it is either the odd or the even bits of a computable sequence), and when the measurement is performed in the other basis the sequence is similar to one obtained from tossing a fair coin. Thus, if Bob can distinguish a computable sequence from a fair coin he can tell what was the basis in which Alice prepared the state. We will see that this is indeed the case with arbitrarily high probability of success. Both preparations are, thus, distinguishable. It should be noticed that, since Bob will only need finite prefixes from both sequences to achieve the distinction, he just needs to measure a finite number of qubits received from Alice.
As mentioned, after his measurements, Bob is left with the problem of distinguishing a computable sequence from a fair coin tossing. We present an algorithm that can do this with an arbitrarily high probability of success: given two sequences X and Z and a desired error probability e, our algorithm decides in finite time which of the two sequences is the computable one, giving a wrong answer with a probability smaller or equal than e. The hand-wavy idea of the algorithm is to check every program (the set of Turing machines is enumerable) on an universal Turing machine U until finding one that reproduces a sufficiently long prefix of either X or Z, say X. It is then claimed that X is the computable sequence, that is, the basis used by Alice for encoding.

Distinguishing a fair coin from a computer
In this Section we show the algorithm that can distinguish, with arbitrarily small error probability, a computable sequence from one arising from a fair coin.

a. Background on computability theory
Let us first fix some notation. The set of finite strings over the alphabet {0, 1} is denoted 2 * and denotes the empty string. The set of infinite sequences over {0, 1} is denoted 2 ω . If S ∈ 2 ω then S n denotes the string in 2 * formed by the first n symbols of S. If x, y ∈ 2 * then x y represents that x is a prefix of y. Any natural number n can be seen as a string in 2 * via its binary representation.
First we introduce formally the computing model used throughout this Section. All in all, it is nothing but a particular model equivalent to a Turing machine, thus having the same computational power as any computer with unbounded memory. Specifically, we consider Turing machines M with a reading, a working and an output tape (the last two being initially blank). The output of M on input x ∈ 2 * is denoted M (x) ∈ 2 * , and if t ≥ 0, M t (x) ∈ 2 * consists of the content of the output tape in the execution of M on input x by step t -notice that this execution needs not be terminal, that is, M (x) needs not be in a halting state at stage t. A monotone Turing machine (see e.g. [24, §2.15]) is a Turing machine whose output tape is one-way and write-only, meaning that it can append new bits to the output but it cannot erase previously written ones. Hence if M is a monotone machine M t (x) M s (x) for t ≤ s. The computing model of monotone machines is equivalent to ordinary Turing machines, and for ease of presentation we work with the former.
A sequence S ∈ 2 ω is computable if there is a (monotone) Turing machine M such that for all n, M (n) = S n. Equivalently, S is computable if there is a monotone machine M such that M ( ) "outputs" S, in the sense that (∀n)(∃t) M t ( ) = S n. (A1) Let (M i ) i≥0 be an enumeration of all monotone Turing machines and let U be a monotone Turing machine defined by U ( i, x ) = M i (x), where ·, · : N 2 → N is any computable pairing function (i.e. one that codifies two numbers in N into one and such that both the coding and the decoding functions are computable). The machine U is universal for the class of all monotone machines. In other words, U is an interpreter for the class of all monotone Turing machines, and the argument p in U (p) is said to be a program for U , encoding a monotone Turing machine and an input for it. The notion of computability makes sense when applied to infinite sequences, as any finite string can be trivially computed by a very simple (monotone) Turing machine which just hard-codes the value of the string. Any finite binary string can be extended with infinitely many symbols in order to obtain either a computable or an uncomputable sequence. For instance, if s is a finite string then s followed by a sequence of zeroes is computable; however s followed by the (binary representation of) the halting problem [6] is not. Since in finite time a Turing machine can only process finitely many symbols, one cannot decide in finite time if an infinite sequence is computable or not.
In the following subsection we deal with a related problem: distinguishing a computable sequence from the output of a 'fair coin' (such as the result of measuring a σ z eigenstate in the σ x basis, under the assumption that quantum physics is correct). Notice that since there are countably many computable sequences, the output of tossing a fair coin gives a non-computable sequence with probability one. We show that one can distinguish both cases in finite time and with arbitrarily high success probability and that this fact has consequences on how mixed states in quantum mechanics are described.

b. The protocol
As mentioned, the idea of the algorithm is to check every program until finding one that reproduces a sufficiently long prefix of either X or Z. There are three key points that have to be taken into account in this idea, namely: • It is impossible to know if a program halts or not [6]. Therefore, checking each single program one after another is not possible.
• It is still not clear what we mean by sufficiently long prefix.
• We might get a false positive, i.e. find a program that reproduces a prefix of the sequence which came form the coin tossing (even if it was not computable).
We deal with the first issue by dovetailing between programs and execution time. Recall that programs for U can be coded by (binary representations of) natural numbers. The idea of dovetailing is that we first run program 0 for 0 steps, then we run programs 0 and 1 for 1 step, then we run programs 0, 1 and 2 for 2 steps and so on.
To solve the second problem, we check if program p of length |p| generates (within the time imposed by the dovetailing) either of the prefixes X j (that is, the first j bits of X) or Z j, where j = k|p|. That is, every program is checked against a prefix k times longer than its length. Since a fair coin generates sequences with mostly non-compressible prefixes, it most likely will not have a prefix that can be generated by a k times shorter program, thus allowing us to detect the computable sequence. And as we will see, the probability of getting a false positive can be bounded only by a function of k that goes to 0 as k goes to infinite, solving also the third issue.
The pseudo-code for the algorithm that decides which of the sequences is computable will be the following:

Algorithm 3 The distinguishing protocol
Input: k ∈ N and X, Z ∈ 2 ω , one of them being computable Output: 'X' or 'Z' as the candidate for being computable; wrong answer with probability bounded by O(2 −k ) for t = 0, 1, 2 . . . do for p = 0, . . . , t do if Ut(p) = X k|p| then output 'X' and halt if Ut(p) = Z k|p| then output 'Z' and halt Note that X and Z are infinite sequences, and hence they must be understood as oracles [25,§III] in the effective procedure described above. Provided that at least one of X or Z is computable, the above procedure always halt -and so it only queries finitely many bits of both X and Z. Indeed, in case S ∈ {X, Z} is computable, there is a monotone Turing machine M = M i such that M ( ) outputs S in the sense of (A1). Hence for program p = i, we have that U t (p) = S k|p| for some t.
It is important to recall that although both X and Z are infinite sequences, we only need to query finite prefixes. From a physical point of view this means that only finitely many qubits will be needed by Bob to discover how Alice was preparing the state. Now, we bound the probability of having a missrecognition, that is, the probability P error that the above procedure outputs 'Z' when X was computable, or viceversa. To do so, we bound the probability that S ∈ 2 ω has the property that for the given value of k there is p such that (∃t) U t (p) = S k|p|. (A2) Since there are 2 programs of length , the probability that there is a program p of length such that (A2) holds is at most 2 /2 k . Adding up over all possible lengths we obtain which goes to zero exponentailly with k.
The protocol would then work as follows: given a tolerated error probability e, one chooses a k large enough so that the previous bound is smaller than e, and then run the described algorithm with inputs k, X and Z.

Noise robustness
We now show how to modify the previous algorithm to make it robust against noise. We can consider a very natural noise model in which random bit flips are applied to the measured sequences, resulting for instance from imperfect preparations or measurements. Therefore, we modify the algorithm so that it tolerates a fraction q ∈ Q of bit flips in the prefixes. The modified algorithm is as follows:

Algorithm 4 The noise tolerant distinguishing protocol
Input: q ∈ Q, k ∈ N and X, Z ∈ 2 ω , one of them being computable Output: 'X' or 'Z' as the candidate for being computable; wrong answer with probability bounded by O(2 −k ) for t = 0, 1, 2 . . . do for p = 0, . . . , t do if dH (Ut(p), X k|p|) < qk|p| then output 'X' and halt if dH (Ut(p), Z k|p|) < qk|p| then output 'Z' and halt where d H is the Hamming distance between two strings, which counts the number of different bits in both strings. The first thing to notice is that when q = 0 Algorithms 3 and 4 coincide.
We need to show now that, again, the success probability can be made as close to one as desired by choosing the parameter k and that the algorithm always halts. Instead of bounding the number of sequences that can be generated with a program of length , we need to bound the number of sequences that have a Hamming distance smaller than qk from a computable one. One possible bound is 2 k q k 2 q k , where the first exponential term counts the number of different programs of length , the combinatorial number corresponds to the number of bits that can be flipped due to errors, and the last exponential term gives which of these bits are actually being flipped. This estimation may not be tight, as we may be counting the same sequence several times. However, using this estimation we derive a good enough upper bound on the final error probability, as we get If we consider that q < 1/2, we can remove the integer part function and use the generalization of combinatorial numbers for real values. Then, by using that a b ≤ ea b b , we obtain This geometric sum can be easily computed yielding Now, it can be shown numerically that for q 0.21 the probability of mis-recognition tends to zero exponentially with k.
Finally, we need to show that the noise tolerant algorithm always halts. Let r < q be the probability of a bit flip. By the definition of probability we now have that for every δ there exist an m 0 such that for every m > m 0 the portion of bit flips in both X m and Z m are less than (r + δ)m. This means that if we go to long enough prefixes (or programs), the portion of bit flips will be less than q. And since any computable sequence is computable by arbitrarily large programs, this ensures that our algorithm will, at some point, come to an end.

Discussion
We have shown that if Alice uses a computing device satisfying the Church-Turing thesis thesis to prepare a seemingly proper mixture of |0 and |1 or a seemingly proper mixture of |+ and |− , both apparently yielding the maximally mixed state, Bob can distinguish both situations.
It is worth noticing that, although our algorithm halts in finite time, it can take extremely long, depending on the length of the shortest program that generates the needed prefix and the time it takes to find it. Nonetheless, what we have shown with this is that in both preparations, somehow, the resulting state has information on how it was prepared. Our algorithm can be thought of as a tool to prove that both preparations are indeed distinguishable, but there might be protocols that finish in shorter times. And even if there are not, the fact that both situations are distinguishable still holds, showing that having a computable preparation leaves a mark on the states it produces.
This apparent paradox can be easily resolved the following way: computable sequences have correlations that we are not taking into account. This means that Alice's choice is not given, as needed, by a set of independent and identically distributed random variables but by a computable sequence. The evident consequence of this is that Bob can distinguish both situations and our main results is to provide such an algorithm.
It is not clear whether a proper quantum state can be associated to each qubit leaving Alice's box. Let us imagine a situation in which Alice has already given Bob several qubits (as many qubits as Bob wanted to request from Alice), and we ask Bob to guess the next qubitunknown to him-, with the sole promise that Alice, in the limit, will pick as many states from one bag as from the other (i.e. it is a balanced sequence). Since every prefix can be extended to a computable sequence, no matter what Bob already knows about Alice's preparation, he cannot say anything about the next qubit. For instance, he can already know in what basis Alice is preparing each state (via the presented algorithm), and an extremely long prefix of the computable sequence that Alice is using. Still, he does not know if the next qubit will be |0 or |1 (if Alice prepares in the computational basis). The best description for that single qubit state that Bob can give, from the balanced sequence promise, is ρ = I/2.
Interestingly, our results easily extend to other ensembles, and can for instance be applied to the mixed states experimentally produced using a classical random number generator of [10,11]. Our classical algorithm is also suitable for performing other seemingly impossible tasks. If Bob is presented with two states, one that is a proper computable mixture of the states |0 and |1 each with equal weight, and the other is an improper mixture yielding the maximally mixed state (for instance, one of the parts of a maximally entangled state), Bob can distinguish which is which by a slight modification of our algorithm. He just obtains two sequences, each by measuring σ z to each state. Again, the problem is reduced to distinguishing, with high probability, a fair coin from a computable sequence, a task that we have already shown how to solve.

Appendix B: The Bell test computability loophole
In this section we discuss how the knowledge that measurement settings are chosen using a device that satisfies the Church-Turing thesis opens a new loophole in Bell tests. We focus our attention on the simplest Bell scenario although generalizations are straightforward: let us consider a bipartite scenario in which the two parties, Alice and Bob, have a box each with two input buttons (left and right) and a binary output. A source between them is sending physical systems sequentially to each party. Upon arrival, Alice and Bob choose what input buttons to press thus performing different measurements on the particles. Our object of interest is the probability distribution describing the process P (a, b|x, y) where x and y are inputs for Alice and Bob's box respectively and a and b are their outputs which can be derived from the statistics.
Let us also imagine that the input-output events at each site define space-like separated events so that Bob's input cannot influence Alice's output and viceversa. Focusing on a particular round of the experiment, let us describe by λ a complete set of variables (some of which could be hidden or unknown) that characterize the physical systems such that the outcomes of the measurements are deterministic P (a, b|x, y, λ) = δ a f (x,λ) δ b g(y,λ) where the functions f (x, λ) and g(y, λ) map determinstically inputs x, y to outputs a, b, using the complete description λ. Different rounds of the experiment may be described with different set of variables λ drawing from a probability distribution p(λ|x, y) ≡ p(λ) where the equality condition is termed measurement independence or free choice. This crucial condition implies that the complete description λ is independent from the choice of settings x, y of Alice and Bob will use to measure the systems. Thus, we say that a probability distribution is local if it can be written as It can be shown that any probability distribution that violates the following Bell inequality, namely a CHSH inequality [26], is not a local distribution: a,b,x,y∈{0,1} (−1) a+b+x·y P (a, b|x, y) ≤ 2. (B2) Remarkably, quantum correlations, obtained for example by measuring a maximally entangled two-qubit state with non-commuting measurements, can violate this inequality. The violation of a Bell inequality witnesses the existence of non-local correlations which in turn can be used in many device-independent applications such as randomness expansion or for establishing a secure key between distant locations. Hence, checking whether the experimental data truly violates a Bell Inequality is of outmost importance for device-independent information science.
In order to present the computability loophole, we introduce an eavesdropper named Eve. Eve will be able to prepare Alice's and Bob's local boxes at the beginning of the experiment as shown in Fig. 5. Alice's box will then have access to the inputs of both parties after the measurements are done (Alice's input in a straightforward way, and Bob's input via classical communication). This scenario was first termed the two-sided memory loophole in the literature [20]. An equivalent scenario has been used more recently in [21,22] so as to perform deviceindependent randomness expansion where they allow the boxes behaviour to adapt depending on the information of previous rounds. Interestingly, local models exploiting this past information have been shown to be of no help to violate the Bell Inequality in the asymptotic limit. Indeed, the probability that a local model reproduces some observed violation despite using past inputs and outputs goes exponentially fast to zero in the number of rounds [22].
As mentioned earlier, a crucial condition for Bell tests to establish nonlocality and randomness is to assume measurement independence p(λ|x, y) ≡ p(λ), which in our context is independence between the boxes prepared by Eve and the measurement choices of Alice and Bob. Let us imagine that Alice and Bob chose their measurement settings following an algorithm which is a standard practice in all Bell experiments to date. Trivially, if Alice's box knows which algorithms Alice and Bob are using, she can fake a Bell violation. We assume that the algorithms used by Alice and Bob are fully unknown to each other and to Eve, thus uncorrelated to the boxes she initially prepared.
Our result is to show that if either Alice or Bob (or both) choose their measurements following an algorithm -or equivalently, because of the Church-Turing thesis, following any classical mechanical procedure-, even under the assumption that such algorithm is fully unknown to Eve and hence uncorrelated to the boxes she initially prepares, there is an attack that, in the asymptotic limit, produces a Bell inequality violation between Alice and from purely deterministic boxes, thus providing the aforementioned loophole. prediction on what the next round inputs will be by using the presented algorithm. For simplicity in the notation, the attack is shown for a Bell test involving two measurements per party. As long as Alice, Bob or both use a computable sequence for their choice, the guess will start being correct after a number of rounds. Once this happens, the boxes can simulate any probability distribution, both local and non-local. Therefore Alice and Bob can not rule out an eavesdropper having prepared their boxes.
Before proceeding, we need a few more tools from computer science. We say that a class C of computable functions is a time [resp. space] complexity class if there is a computable function t such that each function in C is computed by a Turing machine that, for every input x, runs in time [resp. space] O(t(|x|)). Examples of such classes include the well-known P, BQP, NP, PSPACE where the complexity time bound is a simple exponential function and the much broader class PR of the primitive recursive functions where the time bound is Ackermannian [27,§VIII.8] (see [28] for an inclusion diagram of the most well-studied complexity classes).
Let us now say that one party, say Alice without loss of generality, will be using an algorithm to produce her measurements choices. In formal terms, this means that there is a computable function f A : N → {left, right} such that f A (i) tells Alice to press the left or the right button at the i-th round.
As we previously pointed out, it is clear that if Eve knows (any algorithm for) f A , her task becomes trivial. In our setting, however, function f A is unknown to Eve when she prepared the boxes. However, we assume the following further hypothesis: Eve knows some time or space bound t of a complexity class containing f A and f B (the corresponding function for Bob's inputs). For instance, Eve knows that Alice and Bob use at most, say, time O(t(n)), for t(n) = 2 2 n (though the algorithms that Alice is actually running may take, say, O(n 2 )). It is important to note that this hypothesis is quite mild, because every computable function belongs to some time or space complexity class -given a program there is a computable interpreter which executes it on some given input by stages and counts the number of steps that such execution takes to terminate or the number of cells used in the tape. In other words, for every computable function g there is a computable function t g that upper bounds the running time or space of some algorithm for g.
Knowing this time or space bound t, Eve can program a computing device in one of the boxes, say Alice's, to predict the functions f A and f B from some point onwards. This means that Alice's box has an effective procedure that, after having seen f A (0), f A (1), . . . , f A (k) for large enough k, allows her to correctly guess f A (k + 1), f A (k + 2) . . . and the same for f B . The existence of such k will be guaranteed by Alice's box procedure; however it will not be able to effectively determine when this k has arrived. The idea behind this is that every time bounded class is computably enumerable, allowing Eve to pick, every time, the first program for a function from that class that reproduces the inputs given by Alice (or Bob) so far. Since the function used by Alice (or Bob) belongs to that class, at some point the first program that Alice will find reproducing the inputs given so far will be one which computes the function used by Alice (or Bob), therefore allowing Alice's box to predict every input to come. See Sec. B 1 for a detail of Alice's box procedure.
Back to the loophole, under these assumptions, Eve is able to prepare both boxes so as to fake a Bell Inequality violation. Moreover, she could even prepare boxes that seem to be more non-local than what quantum mechanics allows. To see how, notice that any no-signaling bipartite probability distribution, local or not, can always be written as where again functions f, f , g, g are deterministic functions (See Sec. B 1 a for a prove). This means that, given that Eve learns either Alice's input x or Bob's input y, she can prepare deterministic (local) boxes to simulate any probability distribution and hence fake any Bell Inequality violation.

Predicting computable functions from initial segments
The theory of predicting computable functions started with the seminal works by Solomonoff [29,30] on inductive inference, and Gold [31] on learnability. It studies the process of coming up with, either explanations (in the form of computer programs) or next-value predictions, after seeing some sufficiently big subset of the graph of a computable function. Many possible formalizations, depending on how the data is presented and how the learning process converges, have been considered in the literature (see [32] for a comprehensive survey). The most suitable model for our purposes is called identification by next value, and follows by elementary arguments from computability theory.
A class of total computable functions C is identifiable by next value (C ∈ NV) [33] if there exists a computable function g (called a next-value function for C) such that for every f ∈ C, Here x 1 , . . . , x n is any computable codification of an n-tuple with a natural number, whose decoding is also computable. Condition (B5) formalizes the idea that given the past values of f (namely (f (0), . . . , f (n − 1))), g can predict the forthcoming value of f (namely, f (n)), provided n is large enough -how large depends on the function f that we want to learn.
It follows from a simple diagonal argument that the class of all computable functions is not in NV. However, any time or space complexity class is NV. Indeed, suppose C is a time complexity class with (computable) time bound t. The following algorithm computes a next-value function for C. Let (M i ) i∈N be an enumeration of all Turing machines.
Both e and c are unknown, and the idea of Algorithm 5 is to try different candidates e and c for e and c respectively, until one is found. On input n = f (0), . . . , f (n − 1) the algorithm proposes a candidate Turing machine M e which 'looks like' f on 0, . . . , n − 1, and then guesses that f (n) is the value computed by M e (n). To be a candidate means not only to compute the same first n values, but also to do it within the time bound imposed by C, which is c · t. Of course, the chosen candidate may be incorrect because, for instance, on input f (0), . . . , f (n − 1), f (n) we may realize that f (n) was not equal to M e (n). In this case, the algorithm changes its mind and proposes as candidate a new pair e, c . The existence of the correct candidates e and c satisfying (B6) guarantees that: 1. For each n and each input f (0), . . . , f (n − 1) the algorithm will find some e, c meeting conditions i and ii.
2. Along the initial segments f (0), . . . , f (n − 1) for larger and larger n there can only be finitely many mind changes. Indeed, if the number of mind changes were infinite, then e , c would be ruled out and this is impossible, as conditions i and ii are true for e = e and c = c .
Hence there is n 0 such that for all n ≥ n 0 , the algorithm makes no more mind changes, and it stabilizes with values e, c , which may not necessarily be equal to e , c , but will satisfy that M e (x) computes f (x) with time bound c · t(|x|). Thus on input f (0), . . . , f (n − 1) the algorithm will return f (n), and hence (B5) will be satisfied. Observe that although the algorithm starts correctly predicting f from one point onwards, it cannot detect when this begin to happen. In other words, n 0 is not uniformly computable from e and c .
The algorithm for a space complexity class with bound t is analogous, but condition i must be modified to i'. for i ∈ {0, . . . , n}, M e (i) halts after at most 2 t(|i|) many steps and uses at most t(|i|) many cells of the work tape during its computation.
Observe that any halting computation which consumes t(n) many cells of the work tape runs for at most 2 t(n) many steps, as this is the total number of possible memory configurations. In condition i' we add the statement on the number of steps in order to avoid those computations which use at most t(n) many cells but are nonterminating.
a. Simulation of no-signaling correlations from deterministic boxes For completeness, we give a simple proof of the wellknown fact that, if the input of one party in a Bell test is known, one can simulate any no-signaling distribution by using deterministic boxes. Let us imagine without loss of generality that it is Bob's box the one that has access to Alice's input x. First, notice that any no-signaling box can be written in the following way P (a, b|x, y) = P (a|x)P (b|y; a, x) ≡ P (a|x)P a,x (b|y).
Notice that since a is a deterministic function of x and λ, given that λ includes the information of λ, the function on Bob's side does not need to depend explicitly on a.

Discussion
We have shown that if either Alice or Bob choose their inputs for a Bell experiment in a computable way, an eavesdropper restricted to prepare deterministic devices can make them believe to have non-local boxes, thus creating a computability loophole. Notice that this scenario is equivalent to letting the boxes communicate before the runs and adapt accordingly, as is the case in the randomness expansion protocols [21,22] where our loophole would also apply if either Alice or Bob would use pseudorandomness. There is no way of preventing this form of communication, unless some assumptions on shielding of the devices are enforced.
From a fundamental perspective, our result answers the question about what type of randomness is necessary for having a valid violation of a Bell inequality: Alice and Bob's behaviour need to be non-algorithmic. Therefore no computable pseudo randomness criterion will suffice for a proper Bell inequality violation. It is natural to ask, at this point, where can Alice and Bob find sources of true randomness for their inputs. If they assume quantum mechanics, then flipping a quantum coin would suffice (with probability one). However, it is not desirable to assume a non-local theory like quantum mechanics, in order to test non-locality. Ruling out quantum mechanics, the other source of true randomness that is usually mentioned is free will. However, there is no present evidence that the human brain is able to produce non-algorithmic randomness.