Message complexity of population protocols

The standard population protocol model assumes that when two agents interact, each observes the entire state of the other agent. We initiate the study of $\textit{message complexity}$ for population protocols, where the state of an agent is divided into an externally-visible $\textit{message}$ and an internal component, where only the message can be observed by the other agent in an interaction. We consider the case of $O(1)$ message complexity. When time is unrestricted, we obtain an exact characterization of the stably computable predicates based on the number of internal states $s(n)$: If $s(n) = o(n)$ then the protocol computes semilinear predicates (unlike the original model, which can compute non-semilinear predicates with $s(n) = O(\log n)$), and otherwise it computes a predicate decidable by a nondeterministic $O(n \log s(n))$-space-bounded Turing machine. We then introduce novel $O(\mathrm{polylog}(n))$ expected time protocols for junta/leader election and general purpose broadcast correct with high probability, and approximate and exact population size counting correct with probability 1. Finally, we show that the main constraint on the power of bounded-message-size protocols is the size of the internal states: with unbounded internal states, any computable function can be computed with probability 1 in the limit by a protocol that uses only $\textit{1-bit}$ messages.


Introduction
Population protocols, introduced by Angluin, Aspnes, Diamadi, Fischer, and Peralta [6], are a class of algorithms that model ad hoc networks of finite-state mobile agents.At each step, a pair of agents is picked uniformly at random to interact, each observing the other's state and updating its own state in response.The original model [6] limited the agents to O(1) states, independent of the population size n.This limited the computational power (to only semilinear predicates [7]) and the time efficiency possible in performing fundamental tasks (such as the linear-time lower bound for leader election [29]).
The original model supposes that agents can view the entirety of the other's local state upon interacting with another agent, which we call an open protocol.We introduce a new variant of this model that draws a distinction between the state of the agent and the segment of the state that is externally visible to its interacting partner, called the message.This variant generalizes previous work in the context of consensus that examines the particular case of binary signaling [5,42], where the message is limited to a single bit.We study the computational power of population protocols that have O(1) message complexity and varying local state complexity, ranging from O(1) to unbounded.

Motivation
The population protocol framework was conceived to model passively mobile ad hoc sensor networks.In this setting the amount of communication bandwidth can be a tighter constraint than the local computation performed by a sensor.These two constraints-bandwidth efficiency and energy efficiency-are viewed as distinct in the networking literature.In some scenarios it makes more sense to optimize for one or the other, or to strike a balance [24,38,49].The restriction to O(1) messages but ω(1) internal states is germane when the communication in an interaction is more costly than the accompanying local computation.
Synthetic chemistry is another domain in which population protocols are an appropriate abstract model of computation.They are a subclass of chemical reaction networks, which are known to have similar computational power [22,45].Using a physical primitive known as DNA strand displacement [51], every chemical reaction network with O(1) species (states in the language of population protocols) can be theoretically implemented by a set of DNA complexes [46], justifying the use of chemical reactions as an implementable programming language.Using this approach, nontrivial chemical systems have been synthesized in the wet lab, resulting in pure DNA implementations of a chemical oscillator [47] and the "approximate majority" population protocol [9,23].Some theoretical [43] and experimental [50] systems are able to assemble unbounded-length heteropolymers such as DNA in an algorithmic way.For such systems, reactions may best be modeled as allowing arbitrarily many states (exponential in the polymer length) but only O(1) messages modeling the smaller "locally visible region" near one or both ends of the polymer.
Finally, our model of ω(1) internal states and O(1) external messages is a natural mathematical intermediate between the original O(1) states/messages model and the more recent ω(1) states/messages model.Because population protocols with superconstant states and messages are provably more powerful [21], it is intrinsically interesting to determine how powerful this new intermediate model is.

Our Contribution
We introduce this new variant of population protocols and show three main results: We first (Section 3) completely resolve the question of the computational power of O(1) messages, with Theorem 3.2.In the positive direction, with poly(n) states (O(log n) bits), we give a simulation of Ω(1)-bit messages (Theorems 3.3 and 3.5).Corollary 3.9 is an  1 Summary of positive results: Above, the event of "not error" means that the answer is correct and the stated time and state bounds hold, unless the error probability is 0, in which case it refers only to the output being correct.In that case, the time and state bounds are in expectation, but still hold with high probability: in all cases, the probability of error is O(1/n).(It should be straightforward to extend to O(1/n k ) for any k, but for simplicity in proof statements we fix k = 1.We rely on [15, Theorem 1] that, as stated, holds only for a fixed exponent k, though it seems a more detailed analysis could achieve arbitrary k.)Note that when the probability of computing the correct output is 1 (i.e. the protocol stabilizes), the Time column denotes time to convergence.State complexities are accurate with high probability.|M | is the number of messages, either a constant larger than 1, or exactly 2 (1-bit).Compute log n means computing either log n or log n .In the first row t P is the expected convergence time for P .asymptotically sharp negative result: O(1)-message, o(n)-state (log n − ω(1) bits) protocols compute only semilinear predicates.
Secondly (Section 5), we focus on time-efficient computation.We develop novel O(log 2 n)time algorithms for junta election (the key primitive to leader election) and exact population size counting (naturally suited to this model, where O(n) local states and O(1) messages are the minimal power to make this problem solvable).The counting protocol can specialize with fewer states to estimate the size (count log n), and also generalize with more states to count the entire input configuration (so any predicate can be locally computed).
Thirdly (Section 6), we explore the extreme limits of the model where message complexity is limited to 1 bit.We construct a 1-bit broadcast primitive, showing it is powerful enough to simulate a Turing Machine with probability 1 correctness using unbounded local memory.

Comparison to existing work and new techniques required
Most protocols using ω( 1) states [1-3, 13, 14, 17-20, 26, 32, 33, 39, 41, 48] crucially use ω(1)-size messages.Key transitions in such protocols involve comparing two integers/ids of size ω(1) in a single step, which is not possible with O(1)-size messages.Sending a superconstantsize message over multiple interactions is not efficient (though it is a trick we employ for unbounded time results such as Theorem 3.3), since there is not enough time for the two agents to wait for another interaction (which takes Θ(n) expected time), nor is there any way to distinguish each other in future interactions.We introduce new techniques that rely on timing of internal counters to get around this limitation.
Protocol 2, "junta election", is our primary fast leaderless protocol, used to make other leader-driven protocols leaderless.It elects a junta, a group of O( √ n) agents, in O(log 2 n) time.As with many other existing protocols [16,32,33,48], this is used to drive a junta-driven phase clock [8] that allows agents to synchronize in a downstream computation.The cited protocols have agents choose an integer "level" , propagating by epidemic the maximum level (Θ(log log n) [16,32,33] as in our case, or Θ(log n) [48]).Agents who chose the maximum level are in the junta.Lacking the ability to communicate the levels in 1-bit messages, we rely on timing of internal counters of agents to detect whether a higher level exists: Agents with level count up to ≈ 4 , (roughly) telling all other agents to continue counting up, and stop at ≈ 4 , unless another agent (with high probability with a higher level) tells them to continue counting.The actual details are more involved and require intricate choice of timing and analysis to conclude that all agents with high probability stop at the same counter value.
We push the technique of communication via timing further, showing that only 1-bit messages suffice to elect a leader, broadcast arbitrary messages, and simulate a Turing Machine.
The majority problem means deciding which of two opinions in a population is more numerous.Existing protocols [2,4,13,14,19] use an O(1)-message "doubling/cancelling" technique, which works on top of a synchronization primitive, but these protocols use ω (1) messages to achieve synchronization.Thus, our O(1)-message junta-election protocol can be composed with the doubling/cancelling technique to give a high-probability, uniform (unlike [2,4,13,19]) O(1)-message majority protocol.In fact, the doubling/cancelling technique can be viewed as another special case of our general population counting algorithm.
All of our protocols are uniform (requiring no estimate of n), in contrast to several existing ω(1)-state protocols [1-4, 13, 17, 19, 20, 33, 39, 41, 48].Many of our protocols could be simplified greatly by allowing nonuniformity.Briefly, an estimate of log n within a constant factor allows agents to run a leaderless phase clock in which they count up to c • log n (for some large constant c), which aids in synchronizing agents in rounds r = 0, 1, 2, . . .based on the number of times they have counted from 0 up to c log n; the lack of such synchronization is a major challenge in devising correct, efficient O(1)-message protocols.

Model
We write log n to denote log 2 n, and ln n to denote log e n.The original population protocol model [6] involves a population of n agents, each of which holds a state in a state space Q.Interactions between agents update the states of both agents according to a transition function δ that takes both states as input and returns new states for both agents as output.
Interactions are asymmetric: in each interaction, one of the agents is the initiator of the interaction, and one the responder.

Uniform versus nonuniform protocols.
The original model [6] considered |Q| to be constant, but later works [1-4, 13, 17, 19, 27, 32, 39, 41, 48] let |Q| scale with the population size n.Some protocols have been nonuniform, where δ implicitly depends on n, but it is preferable for a protocol to be uniform, with an identical δ over all population sizes n.The work of [21] gave one formalization of uniform population protocols with superconstant state space. 1e consider a refinement of the model in which the state of an agent is explicitly divided into an internal component that is not visible to other agents, and an external component that is.The internal component of the state is drawn from the state space I and the external component, or message, is drawn from a message space M .The set of states Q is the Cartesian product I × M .The transition function δ is modified to enforce the restriction that an agent in an interaction cannot observe the internal state of the other agent: δ is now a function from Q × M × {initiator, responder} to Q.When an agent in state q 1 = i 1 , m 1 initiates an interaction with an agent in state q 2 = i 2 , m 2 , the new states of the agents are given by q 1 = i 1 , m 1 = δ(q 1 , m 2 , initiator) and q 2 = i 2 , m 2 = δ(q 2 , m 1 , responder).
The set of producible states Q(n) and the set of producible messages M (n) can both depend on n.The function s : N → N defined as s(n) = |Q(n)| is the state complexity 2 of a population protocol.The function n → |M (n)| is the message complexity.If |I| = 1 and each agent's state is merely defined by its message (the original model [6] and its superconstant state generalization), we say the protocol is open, so |Q(n)| = |M (n)| for all n.We will mostly be interested in population protocols with modest state complexity (at most polynomial in n, and often only polylogarithmic in n) and constant message complexity.Given two functions s, m : N → N, a s(n)-state, m(n)-message population protocol is one with state complexity s and message complexity m.Note that the complexity bounds we discuss are worst-case: s(n) is the most number of states that can be produced in any population of size n under any execution.
We will also place high probability bounds on the state complexity (such as Protocol 2 where each agent generates a geometric random variable, which may take on any positive integer value).These are not statements about the set of producible states, so our impossibility results (Theorem 3.8) on state and message complexity do not apply.
Problems solved by population protocols.A configuration gives the state of all agents.Population protocols have some problem-dependent notion of "correct" configurations.For example, for leader election a configuration with a single leader is correct.For computation of a predicate φ : N d → {yes, no} (a.k.a., decision problem), the initial state of each agent is from a d-element subset Σ of states, states are partitioned into two subsets representing "yes" and "no", and a configuration is correct if all agents give the answer φ( i), where i ∈ N d represents the initial counts of agents in each state in Σ.A population protocol is leaderdriven if its states have a Boolean field leader ∈ {L, F } (i.e. the state set Q = {L, F } × Q ), such that in every valid initial configuration, exactly one agent has leader = L. Time complexity.For measuring time complexity, we assume random scheduling, where at each interaction two agents are chosen uniformly at random from all n(n − 1) possible ordered pairs of agents.Time complexity is defined by parallel time, the number of interactions divided by n/2 which we henceforth simply refer to as time 3 .
Machine, and their model counts the space cost of this local computation.Formally, our model can be viewed as a special case of this model, where we restrict the message tape to O(1) bits.For the purpose of brevity, however, we give a more intuitive definition based on a transition function δ.Also, to talk about time complexity, we use the standard uniform random interaction scheduler and assume the local computation happens instantaneously. 2 This definition of state complexity abstracts away the space used for the local computation of δ as counted in [21].It can be thought of as a simpler information-theoretic measure of how many different memory configurations agents can be in before and after-but not during-their transitions.Also, the space overhead to compute δ will always use O(log |Q|) bits, so the asymptotic size Θ(log |Q|) of the state space in bits will be unchanged.Because the results of [21] are all asymptotic statements about the number of bits of memory, they can apply directly. 3This scaling n/2 has each agent participate in an expected k interactions after k time steps, convenient for later proofs.
Convergence/stabilization. A configuration c is stably correct if every configuration reachable from c is correct.An execution E = ( c 0 , c 1 , . ..) is picked at random according to the scheduler explained above.We say E converges (respectively, stabilizes) at interaction i ∈ N if c i−1 is not correct (resp., stably correct) and for all j ≥ i, c j is correct (resp., stably correct).The (parallel) convergence/stabilization time of a protocol is the number of iterations to converge/stabilize, divided by n/2.Convergence can happen strictly before stabilization, although a protocol with finite reachability (i.e., for each c, finitely many configurations are reachable from c) converges from c with probability p ∈ [0, 1] if and only if it stabilizes from c with probability p.For a computational task T equipped with some definition of "correct", we say that a protocol stably computes T with probability p if, with probability p, it stabilizes (equivalently, converges).Note that detecting that the protocol has reached a correct output configuration is generally not possible.

Other notions of computation
The problems we consider in this paper (predicate computation, junta and leader election, and Turing machine simulation) all consider the setting of a constant-sized input alphabet Σ, where each agent starts with a symbol from Σ. Since we allow ω(1) internal states, this could in principle model problems allowing non-constant input per agent, e.g., agents each start with an integer, and we want to calculate their median.There is also a notion of function computation with population protocols [12,22,28] in which the natural number output, rather than being fully written into the internal state of each agent, is distributed across the population "in unary", i.e., the output is k if exactly k agents are in a special state state Y .However, we do not consider such problems in this paper.

Computability with unrestricted time
In this section we study s(n)-state, O(1)-message protocols, when the time is not restricted.Theorem 3.2 is our main result in this section, which completely characterizes the power of such protocols in terms of the number of bits required to store the states.
Let CMPP(f (n)) be the set of all predicates stably computed by an s(n)-state, O(1)message population protocol, where s(n) = 2 O(f (n)) (using O(f (n)) bits of memory) 4 .Let SNSPACE(g(n)) be the set of all predicates φ : N d → {0, 1} decidable by a nondeterministic O(g(n))-space-bounded Turing machine, when inputs are given in unary. 5The results of [21] considered a similar complexity class PMSPACE(f (n)) of stably computable predicates using O(f (n)) bits of memory and O(f (n)) bit messages. 6Let SL be the set of all semilinear predicates [7].Their main result is the following characterization: presented to the Turing machine as a i -length string of symbols from an input alphabet Σ with |Σ| = d, with the same answer on all permutations of the string. 6In fact, to obtain their positive result for large space bounds, they do not need fully open protocols.
Their simulation of nondeterministic nf (n)-space-bounded Turing machines just requires O(log n) bit messages to exchange unique IDs, even if Since the memory is expressed in Theorem 3.1 as number of bits (exponentially smaller than number of states), the multiplicative constants hidden in the O() notation become polynomial-factor terms in number of states.Theorem 3.2 is a similar dichotomy theorem for O(1)-message population protocols, which is sharper in that it holds for all values of f (n).
Proof.First note that 2 O(f (n)) -state O(1)-message population protocols are a special case of the Passively Mobile Machines from [21] with space bound f (n) (since we assume the space overhead to compute When f (n) = Ω(log n), we will show via Theorem 3.5 and Theorem 3.3, that 2 O(f (n))state O(1)-message population protocols can simulate a open protocols, with a polynomial state overhead (ie. a constant overhead in f (n) which does not change the definition of the complexity classes).The ability to simulate large messages then implies PMSPACE(f (n)) ⊆ CMPP(f (n)), and then using Theorem 3.1 we have CMPP(f Finally, when = o(n) and we will show via Corollary 3.9 that CMPP(f (n)) = SL.Note that our necessary condition s(n) = o(n) in Corollary 3.9 is actually even sharper than log(s(n)) = o(log n).Quadratic state blowup in Theorem 3.3.

Leader-driven O(s(n)
The quadratic state blowup of Theorem 3.3 is an artifact of definitional choice, in a sense, owing to each agent a needing to write down the state of another agent b, bit by bit over many interactions, before a can execute the transition δ.However, the model from [21] explicitly counts the space required to store the other agent's message against the total space required, so there is no space blowup in that case.
Intuitively, the construction of Theorem 3.3 chooses two agents to "mark" as initiator and responder, which then successively pass a bit string as they interact, until they have transmitted the full message of size log m(n) bits.Crucially, starting with a leader allows only one simulated transition to be taking place at a time.

Simulation of a population protocol by another.
Formal definitions of simulation in population protocols exist [36,44] (for the strictly more general model of chemical reaction networks), but such definitions are complex and have to cover many corner cases when applied to arbitrary systems.Since we study just a single simulation construction in Theorem 3.3, we avoid a completely formal definition in this paper.Let P, S be population protocols and c P , c S be configurations of P and S, respectively.Intuitively, we say that S from c S simulates P from c P if, for every execution E P of P starting at c P , there is an execution E S of S starting at c S that "looks like" E P , and furthermore every fair execution E S of S starting at c S "looks like" some fair execution E P of P starting at c P .
Here, "looks like" is a tricky concept that can be formalized in a few ways.Intuitively, we imagine that the states of P are projections of the states of S, i.e., each state of S is a pair (p, e), where p is a state of P and e is extra "overhead" information that S requires for the simulation.Furthermore, if we project states from E S onto only the first state element p for each agent, and we remove those transitions that appear null from the point of view of P (i.e., the p portion of the state does not change in any agent), and we similarly remove null transitions from E P , then the resulting executions E S and E P are identical (i.e., go through the exact same sequence of configurations of P ).Theorem 3.3.For every s(n)-state, m(n)-message protocol P , there is a leader-driven, 8 protocol S that simulates P , and each interaction of P takes expected O(n 2 log m(n)) interactions of S to simulate.
Proof.Let M P be the messages of the simulated protocol P , and δ P : Q P × M P × {initiator, responder} → Q P be its transition function.Intuitively, we will simulate δ P by marking two agents to exchange bit strings over O(log |Q P |) interactions, so each learns the message of the other and can locally compute δ P .
We now define Q = I × M , the state set of the simulating protocol S. The internal state I contains two fields: 1. a value p ∈ Q P representing the state of this agent in the simulated protocol P 2. a value m o ∈ M P representing a message of the "other" agent.It is easiest to think of the messages in M P as binary strings in {0, 1} * , because this field will be built up bit-by-bit in interactions to learn the other agent's full message.Thus, λ (the empty string) will represent having no information about any other agent's message.
S is leader-driven, so there is a field leader ∈ {L, F } within the message state M .M also contains a field token ∈ {True, False}, a field mark ∈ {r, i, u} (responder,initiator,unmarked), and a field bit ∈ {0, 1, end}.
To represent an initial configuration c P of P , we define the initial configuration c S (with c S = c P ) of S as follows.Each agent in S has its field p representing a state in Q P in the obvious way, λ for p o , token = False and mark = u (unmarked).Because S is leader-driven, exactly one agent starts with leader = L.
We now describe the transition function δ of S, at a high level.All non-null interactions are between an agent with token = True.The leader L, on its first interaction, immediately becomes a follower F , and the other agent sets token = True.
If the initiator agent has token = True with mark u, then it marks itself as i and the other agent with r; otherwise it marks itself as r and the other agent with i.The other agent now knows it is a receiver/initiator in the simulated transition.All agents have null transitions now, except for two marked agents.(They could be picked in the opposite order on subsequent transitions and still carry out the following protocol; the initiator-responder distinction in S only matters for the very first transition of S simulating a transition of P .) Now, the responder and initiator communicate their messages from M P one bit at a time, storing the other agent's message by appending the received bits to the field p o , using the field bit, sending the value end to indicate their message string has ended.Once both agents have received the other's full message, they can compute δ P to change their simulated state p.Finally, they both set their mark value to u, and the agent with token = True sets token = False and leader = L.It is now ready to pass the token to the next agent it sees to simulate another transition of P .
Note that there is one form of asymmetry in the sense that no agent can have the token twice in a row; hence the probabilities of transitions S simulates are different from the original transition probabilities in P .Still, at each new step in the simulation (when an agent who had the token sets leader = L and then passes off the token), every possible transition can be simulated (since the new token recipient can pick the old token holder to mark for the next interaction as well, giving them either r or i).After this nondeterministic choice, the protocol S stably simulates the transition is has committed to by the assignment of mark.
Since all possible transitions can be chosen at each step, and the transition will be stably executed (in expected O(n 2 log m(n)) interactions for the i and r mark to meet enough to pass the whole message), S faithfully simulates P .
We note that execution probabilities are not preserved by this simulation.The agent with the token in the current simulated interaction is half as likely to be chosen in the next simulated interaction as the rest of the population.Section 3 focuses on probability-1 results, which are robust to this change.By passing the initial token a larger number of times, the agent-pair probabilities are closer, but not equal, to uniform.We leave open whether there is a simulation as in Theorem 3.3 that exactly preserves execution probabilities.
The next corollary applies to open protocols, where each agent's message is its full state.
Corollary 3.4.For every s(n)-state, open population protocol P , there is a leader-driven, O(s(n) 2 )-state, O(1)-message population protocol S that simulates P , and each interaction of P takes expected O(n 2 log s(n)) interactions of S to simulate.
It is known that Ω(log n)-state open protocols have computational power beyond that of O(1)-state protocols (limited to semilinear predicates [7] and functions [22]), and Corollary 3.4 grants this same computational power to leader-driven O(1)-message protocols.Theorem 3.8 in subsection 3.4 shows that Corollary 3.4 crucially depends on the assumption of an initial leader in the simulating protocol, by demonstrating that leaderless O(1)-message, o(n)-state protocols are no more powerful than O( 1)-state open protocols.

Leader election can be composed with leader-driven, s(n)-state, O(1)-message protocols using O(n 3 log n) state overhead
Leader election is possible in linear time with 1-bit messages by "fratricide": , → , f .A downstream leader-driven protocol P will not work unaltered if composed with this leader election, because the presence of multiple leaders prior to convergence causes incorrect transitions of P .A straightforward fix using O(n) messages involves exact size counting via transitions i , j → i+j , f i+j (requiring Ω(n) messages) and each transition between agents with respective values n and i < n resets the latter agent to its initial state in P .At the moment the last agent is reset with value n, the protocol at that point faithfully executes a tail of an execution of P from i, i.e., an execution starting at a configuration c reachable from i. Thus if P is correct with probability 1, the composed protocol is also correct with probability 1. Theorem 3.5 shows how to achieve a similar "composition by resetting" strategy using only O(1) messages.
Protocol 1 StablyComposableLeaderElection(Agent v seeing message m).P is the downstream protocol with state set QP , message set MP , and transition function δP : QP × MP × {initiator, responder} → QP .P is leader-driven, with a field leaderP ∈ {L, F } and possible input states ΣP .State set Q of composed protocol S is QS × QP , where QS = N × N × N × ΣP × MS is the overhead of the composition.The fields are named c0 ∈ N, c1 ∈ N, count ∈ N, iP ∈ ΣP (representing the input symbol for protocol P ), and MS has fields role ∈ { S , fS}, phase ∈ {0, 1} and signal ∈ {restart, go}.
// all counted agents have been restarted

For any leader-driven, s(n)-state, O(1)-message protocol P , there is a leaderless, O(s(n)n 3 log n)-state, O(1)-message protocol S (Protocol 1) that, after O(n log n) expected time, executes a tail of an execution of P .
Proof sketch.Briefly, we elect a leader in O(n) time by fratricide.The leader counts the followers using the O(n log n)-time counting protocol of [10], which is self-stabilizing under the assumption (proven necessary in [11]) of a "base-station": a leader that is initialized (starts in a pre-determined state), though other agents can start in arbitrary states.That paper does not use the term "self-stabilizing" explicitly, but the assumptions we claimed are stated in their introduction.In our case, the remaining leader resets to the initial state whenever it kills another leader, so after the last such transition, the unique leader is initialized, and other agents are in arbitrary states, exactly the setting handled in [10].Whenever the leader's population count increases, it tries to reset each follower.Once the leader has counted the whole population and knows n, its count will never change, and it will reset every follower to its initial state of P by direct interaction (using its knowledge of n to ensure all n − 1 followers are reset), at which point a tail of P executes.
Proof.First observe that the field role updates via the standard "fratricide" leader election.Thus there exists some first time t 1 , (with E(t 1 ) = O(n)), where there is a unique agent a.role = S .By line 8, a has reinitialized with c 0 = c 1 = count = phase = 0. Now agent a acts as the base-station in the self-stabilizing counting protocol of [10], communicating with the other agents via the field phase.In each phase b ∈ {0, 1}, a counts the other agents it sees in phase = b, moving them into phase 1 − b, decrementing its counter c b (if possible) and incrementing c 1−b .By the results of [10], the count c 0 + c 1 increases monotonically, and stabilizes at a maximum value of n − 1 in O(n log n) expected time.
Let t 2 be the first time c 0 + c 1 = n − 1, with a.phase = b.Then c 1−b just incremented to n − 1, and c b = 0 and failed to decrement.The if condition in line 14 was true, so a.signal = restart.In all future interactions, c 0 and c 1 accurately count the number of follower agents in each phase, so the condition of line 14 will never be met again.Now consider the next time t 3 when a changes to phase 1 − b and brings the count c 1−b = 0.By [10] this will also take an expected O(n log n) time.Then, since time t 2 , a has interacted with all agents, who now have v.signal = restart.By line 21, a.signal = go for the first time since t 2 .Then every agent v who interacts with a will have v.signal = go for all future interactions.
Let i denote the configuration in protocol P when every agent has their original input state i P , alongside a.leader P = L and v.leader P = F for all v = a.Now observe that when each agent sets v.signal ← go for the last time, they have the same configuration as in i.They only execute transitions in P via line 3 with other agents with signal = go.
Let t 4 be the next time when every agent has signal = go, and c the configuration within P at t 4 .Then the only transitions that have made c different from i were between two agents with signal = go, who began from an initialized state.Thus c is reachable from the correctly initialized configuration i.Finally, all future transitions execute δ P on both agents, so the composed protocol now exactly implements P , i.e., executes an execution of P from c, i.e., a tail of an execution from i.
Note that we assume that (as is the case in most population protocols, even with ω(1) states), that only a O(1)-size subset Σ of states appear in valid initial configurations, thus i P in Protocol 1 gives at most a constant-factor overhead to the simulation.If instead agents could start with more states, then the factor would be |Σ P |.

Deterministic Broadcast
The construction used in Protocol 1 can be modified to also give the leader the ability to stably broadcast a message to the entire population.After the last restart, the leader agent a counts the entire population by moving them between phases.We can view these phases now as deterministically synchronized rounds (each expected time O(n log n) [10]).Add a field bit ∈ {0, 1} to the message.The leader a can then communicate a bit string to the population by sending one bit during each round.This lets the entire population stably compute the population size n, by having the leader send n as a bit string in O(log n) rounds (stabilizing in expected O(n log 2 n) time).It uses O(log n) state overhead to store the number of bits it has broadcast, so O(n 3 log 2 n) states total.We can thus conclude: Corollary 3.6.There is an O(n 3 log 2 n)-state, O(1)-message protocol that stably computes the population size n (storing in every agents state), in expected O(n log 2 n) time.
Building on the ideas used in Corollary 3.6, we can have the leader assign unique IDs to the agents, for example marking a new unmarked agent in each synchronized round.On top of this deterministic broadcast primitive, we could set up a nondeterministic Turing Machine simulation equivalent to the construction in [21].This gives a direct constructive proof of Theorem 3.2, rather than relying on the simulation arguments via Corollary 3.4 and Theorem 3.5.

Leaderless o(n)-state, O(1)-message protocols compute only semilinear predicates
Theorem 3.8 is broad and does not apply to a particular "mode of computation" (e.g., deciding predicates [6,7], computing functions [12,22,28], leader election [16,31]).It does, however, assume a problem-specific notion of valid initial configurations. 9We say a protocol is additive if the set of valid initial configurations is closed under addition.This rules out, for instance, protocols with an initial leader.Indeed, Corollary 3.9 is false if an initial leader is allowed, by applying Theorem 3.3 to let a leader-driven O(1)-message protocol simulate any o(n)-state open protocol that stably computes a non-semilinear predicate/function. 10 lower bound result in [21] shows that with an absolute space bound 11 of o(log n) states, their model is limited to only stably computing the semilinear predicates. 12The core of their argument bounds the number of reachable memory states.

Theorem 3.7 ( [21]). Let s : N → N and consider an additive, s(n)-state, open population protocol. Then either s(n) = O(1) or s(n) = Ω(log n).
As a corollary, if s(n) = o(log n), then s(n) is in fact constant, reducing to the original O(1)-state model, which can only stably compute semilinear predicates [7].We use a similar proof technique to show an exponentially stronger result in the model of O(1) messages.Let c be the smallest population size n such that M (n) is the set of all messages M .We do not require all messages to be producible simultaneously, only that for each m ∈ M (n), there is a valid initial configuration i m such that m can be produced from i m .Let = 1/c.Inductively assume for some n There is some state b ∈ S(n) producible by an interaction of an agent in state a ∈ S(n) with some message m ∈ M .Let i n be a valid initial configuration of size n from which a is producible, and let i c be a valid initial configuration of size c from which m is producible.Define i n = i n + i c , which is valid because the protocol is additive.Since a is producible from i n and m is producible from i c , a and m are simultaneously producible from i n .By interacting the agent in state a with the agent with message m, the state b ∈ S(n) is produced.
Proof.Let c ∈ N + and consider the protocol where each agent's internal state is a natural number k ∈ N, initially 1, representing a number of "balls."Each message m ∈ {0, 1, c} × {L, F } represents a number of balls to give away and a leader bit.Each state is a leader bit and a counter k.Agents conduct leader election by fratricide (L, L → L, F ).The leaders will collect balls from only the followers, and only in units of c balls.Thus all followers with counter k ≥ c display the message m = (c, F ), and only interact with a leader.In this interaction, the leader increments k by c and the follower decrements k by c.This guarantees the leader's counter k only actually uses values {1 + ic : i ∈ N}.Finally, followers with counter 1 ≤ k < c display the message m = (1, F ).If two agents with m = (1, F ) interact, the initiator gives one ball to the responder (i.e. one increments k, one decrements k).
It is straightforward to show that eventually this protocol will stabilize to a single leader with count "about n": k . The sum of counts are clearly preserved.Followers with k ≥ c balls must eventually give all units of c balls to the leader, who never decreases its count.While there are still j ≥ c total balls among the followers, eventually some follower will collect c balls to give to the leader.
Notice that this protocol can only achieve counter values k ∈ {0, 1, . . ., c, = 2 j is a power of two 13 ), and use its message bit to tell the output to the rest of the population.(So a follower seeing message m = (i, L) sets its output bit to i.)

Timing Lemmas
The following technical lemmas are about the relationship between agents' local counts and the global number of interactions, and the time it takes to spread information by epidemic.They are used in the runtime analysis of our time efficient protocols.

Clock Drift Lemma
Lemma 4.1.Consider some interval of an execution of a population protocol with uniform random scheduling.Let A is be the indicator variable for the event that agent i is one of the two agents that interact in step s of this interval.Let C it = t s=1 A is be the cumulative number of interactions involving agent i during the first t steps of the interval.Fix two agents i and j, and let τ be the first time at which Proof.Because only steps involving at least one of i or j change C is and C js , we can restrict our attention to the sequence of steps s 1 , s 2 , . . .at which at least one of i or j interacts.Let , by the Azuma-Hoeffding inequality.Corollary 4.2.For any agents i and j, and any m and b, Pr [∃t : and because this is the first time at which

Drift Fraction Lemma
Recall that µ units of time is defined as n 2 • µ interactions.Lemma 4.3.Consider some set S of agents and interval of length T = n 2 • µ interactions.Let L ⊆ S be the subset of S who have less than µ − l interactions during the interval.
Likewise, let H ⊆ S be the subset of S who have more than µ + h interactions during the interval, where h ≤ µ.Then for Proof.For each agent v and step t of the interval, let A v,t be the indicator variable for the event that agent v is one of the two agents that interact in step t (with Pr [A v,t = 1] = 2 n ).For each agent v, let L v , H v to be the indicator variables for the events that agent v participates in fewer than µ − l interactions and more than µ + h interactions, respectively.Then L = {v ∈ S : Since each step is independent, we can apply standard Chernoff bounds on the probability Likewise, we can get an upper bound on the probability and Pr follow simply from the union bound over all v ∈ S. It is less straightforward to place high probability bounds on |L| and |H|, because the indicator variables L v and H v are not independent.Intuitively, however, they have negative dependence, since if L v = 1, that agent had a small number of interactions, making other agents more likely to have more.We formalize this intuition by showing that the joint distributions {L v : v ∈ S} and {H v : v ∈ S} are each negatively associated, which allows Chernoff bounds to be applied [30,Section 3.1].
First we show that for fixed t, the distribution {A v,t : v ∈ [n]} is negatively associated, since precisely two variables will have value 1 and the rest 0. Theorem 2.11 of [35] shows that all permutation distributions (random variables X 1 , . . ., X n whose values are a random permutation of x 1 , . . ., x n ) are negatively associated.The distribution {A v,t : v ∈ [n]} is a special case of a permutation distribution where the variables are a random permutation of 0, . . ., 0, 1, 1, and thus is negatively associated.Therefore the entire distribution {A v,t : v ∈ [n], t ∈ [T ]} is negatively associated as the union of independent negatively associated variables (over the independent steps of the uniform scheduler).
and we can apply the Chernoff bound to get where we also assumed The same argument, for

Epidemics
Recall an epidemic process in a population protocol starts with a single agent infected (i) and all others susceptible (s), and every encounter between an infected and uninfected agent causes the latter to become infected (i.e., the transition i, s → i, i).Let H k = k i=1 1 i ∼ ln n be the k'th harmonic number.The following lemma, due to [40], was proved in its current form in [20].
The following lemma generalizes to a susceptible subset of the population, and considers a symmetric middle interval of an epidemic process, to be used in the analysis of Protocol 2. γ n ln γ α with probability 1 − (γn) −2 .Proof.The number of infected agents i will increase monotonically from a to b + 1.At each stage, when there are i infected agents and b + a − i susceptible agents, there are i(b + a − i) pairs of agents whose interaction increases the number of infected agents, so the next interaction is one of these with probability . Thus T = b i=a G i where G i is a geometric random variable with parameter p i .Then where and because γ ≥ α > 0 we can bound Then by Theorem 2.1 of [34], we have the large deviation bound where Now observe that α ln(1/α) is increasing for all α ∈ (0, 1).Since α ≥ 1/n, we can take this minimum value to get

Computability with polylogarithmic time complexity
In this section we study O(1)-message population protocols when the goal is "fast" computation (polylog(n) time).

High-probability junta election using 1-bit messages
In this section, we describe a uniform protocol using 1-bit messages that, with high probability, elects a "junta" of O( √ n) agents in polylogarithmic time.The protocol also lets each agent compute an integer k ∈ N + that is the same for all agents and is one of log log n , log log n , or log log n + 1.Thus 2 k is an estimate of log n within a multiplicative factor 2.
Furthermore, JuntaElection is composable, in that we can use the protocol as a black box to initialize other protocols that require either a junta for a phase clock, or an approximation of log n (e.g. for a leaderless phase clock).Thus, for any nonuniform protocol that requires k-bit messages, we can compose it with our JuntaElection protocol and achieve a uniform protocol that uses (k + 1)-bit messages with an additive time overhead of O(log 2 n).For example, we can compose the JuntaElection protocol with the the leader election protocol of [32] using 1  2 -coin flips to convert the O( √ n)-size junta to size 1, i.e., elect a unique leader, in expected O(log 2 n) time and O(1) messages, or with majority protocols that use O(1) messages for doubling/cancelling phases, synchronized by the junta-driven phase clock [14].
Our protocol has a positive probability of failure.
It is an open question if there exists an O(1)-message protocol that can stably (i.e., with probability 1) approximate log n or elect a junta of size n for some 0 < < 1 in sublinear stabilization time.

High-level description of protocol
The protocol is described formally in Protocol 2. Intuitively, it works as follows.Most other leader/junta election protocols generate an id, where the agents generating the maximum id are the junta.In our protocol, we also generate an id (called level), but O(1) messages prevent direct communication of levels, so we employ a timing-based strategy for agents to learn the maximum level.The message consists of a single bit, taking values Go and Stop.
Each agent initially generates a local geometric random variable G (number of fair coin flips until the first heads, i.e., an immediate heads results in G = 1) and computes its level as log G .(We can also use synthetic coin techniques [1] to simulate fair coin flips and increment their level from i to i + 1 as they flip 2 i consecutive tails.) We define consecutive disjoint intervals G 0 , R 0 , G 1 , R 1 , . . .⊂ N (green and red) partitioning the natural number line.We call R i 's last element d i = max R i a door.(See Figure 1, formal definition below.)Each agent keeps a local counter, initially 0, that is incremented on some interactions.An agent is in round i if its counter is in G i ∪ R i .The goal is to get every agent to count up until the round equal to the maximum level k generated by any agent and stop its counter at d k .An agent with level l in round i is eager if i < l and cautious otherwise.Intuitively, eager agents race through doors until their own level, telling all other agents to keep going, but become cautious at and beyond their own level, advancing past a door into the next round only if another agent tells them to do so (via a message m = Go).More formally, an eager agent always sends a message of Go and increments its counter on every interaction.A cautious agent sends message Go if and only if its counter is in G i for some i, increments its counter on every interaction in G i ∪ R i \ {d i } unconditionally, and increments its counter beyond d i if and only if the other agent's message is Go.Agents drop out of the junta when they leave their own level, so (assuming no agent leaves the maximum level) those who generated the maximum level are the eventual junta.
To formally defined the intervals, let c ∈ N + .Each G i , with is larger by a constant multiplicative factor than the union of all the previous intervals.The max level k is Θ(log log n) with high probability, so its corresponding interval |G k | = Θ(4 log log n ) = Θ(log 2 n).Thus, with high probability, the agents will use O(log 2 n) states for their counters and stop at the door d k after O(log 2 n) time.
To compose JuntaElection with a downstream protocol P , agents can simply restart P whenever they move beyond a d i , and then wait to start simulating P until they reach the next d i+1 (Restarting is a common technique in distributed computing for composition and is not original to this paper, e.g., [32].)In the early stages of JuntaElection, the downstream protocol gets restarted many times, but eventually, all agents will move past d k−1 , after which they will restart the downstream protocol for the last time.The agents will all simultaneously be in the last interval G k ∪ R k before stopping at d k .Thus all simulated downstream interactions of P will be between agents that agree on k.Proof sketch.We must show the agents remain synchronized.By the time the interval lengths are Ω(log n), we could argue that the number of interactions of each agent are tightly concentrated enough for agents to by synchronized in the same interval.However, the main challenge is how to reason about agents that might be stuck behind at a door.
Our argument shows that a constant fraction n/4 of agents stay synchronized in each green interval, up until near the max level (Lemma 5.4).Then, we argue that during the later green intervals, straggler agents are able to catch up, because they have a constant probability of passing through each door and the length of the green interval is more than the sum of all previous intervals.We then show the entire population in synchronized within the last few intervals (Lemma 5.5).Thus all agents will have a Stop message when the population reaches the final door d k , and the agents will stop their counters at d k .
Our proof techniques require setting |G i | = 700 • 4 i .However, simulation results (Figure 2) show successful convergence when |G i | = 16 • 2 i .Scaling the intervals this way would let |G M | = Θ(log n), so the protocol would take O(log n) time and O(log n) internal states.

Distribution of levels
For each j ∈ {1, . . ., n}, let I j be the indicator for the event By independence of the V j 's and the Chernoff bound, Letting δ = 1/2, and noting n/2 2 i−1 +1 < µ < n/2 2 i−1 −1 , gives the following corollary.
Note that Corollary 5.3 is useful as long as i ≤ log log n.There is a Θ(1) failure probability when i = 1 + log log n, and a very large failure probability when i ≥ 2 + log log n.But for i = log log n (and smaller), the failure probability is at most 2 exp −n 1/2 /32 .Of course, i is an integer and log log n in general is not; nevertheless, with appropriate rounding we conclude that k = max j∈{1,...,n} log V j is very likely to be log log n , log log n , or log log n + 1.
In the following we use the fact that E i is the number of agents choosing exactly level i.For any field field of an agent v and any t ∈ N, let v.field(t) denote the value of field in agent v at time t ( n 2 t interactions).Write v.field when the time is clear from context (or v.field is constant over time, e.g.v.level).
Define u i , τ i to be the points 1 16 and 1 8 of the way through interval G i (see Figure 1).
At time τ i , the average number of interactions is τ i , and we hope for most agents' counters to also be near τ i .S i denotes the cautious agents that, at time τ i , are synchronized with counters in the interval G i .The following lemma shows that a constant fraction of the population are in S i : Lemma 5.4.Let i ∈ {0, 1, . . ., log log n − 1}.Let S i be the set of agents v such that v.level ≤ i (cautious by round i) and v.count Proof.We prove this by induction on i. Base case.S 0 is the set of agents v with v.level = 0 and v.count(τ 0 ) ∈ G 0 .Then E [E 0 ] = n/2, and taking δ = 1/4 in Lemma 5.2, we get We now show that of these level 0 agents, we only lose an additional fraction of 1/3 due to drift in the first τ • n/2 interactions (τ units of time).We apply Lemma 4.3, with S as the agents at level 0, µ = τ 0 = c/8, and µ + h = max G i = c.Then S = S 0 , and the error fraction H = 2 2 ln n/|S| + exp(−h 2 /3µ) ≤ 2 2 ln n/(3n/8) + exp(−49c/24) ≤ 1/3, for sufficiently large values of n.Then by Lemma 4.3, |S 0 | ≥ (1 − 1/3)(3n/8) = n/4 with probability 1 − 1/n 2 .Inductive case.Assume |S i | ≥ n/4, recalling that for all v ∈ S i , v.level ≤ i and v.count(τ i ) ∈ G i .We will first wait until time u i+1 , and consider the agents from S i and also those at level i + 1 that have at least made it to the door d i < u i+1 .
Let A i+1 be the set of agents v with v.level = i + 1 and v.count(u i+1 ) Intuitively, the agents in B i+1 have had enough interactions to at least be at the door d i , but could be stuck waiting to see the signal.The agents in A i+1 are broadcasting a signal and moving the agents in B i+1 through the door.This process will be stochastically dominated by a section of an epidemic process.We must ensure |A i+1 | + |B i+1 | > n/4 so that we can wait for |S i+1 | ≥ n/4 agents to finish this epidemic.
First, we must bound the size |A i+1 |.Let E i+1 be the set of agents v with v.level = i + 1.
Then by Corollary 5.3, Pr Now A i+1 is the subset of E i+1 that have at least d i interactions between time 0 and time u i+1 .We apply Lemma 4.
Next we must bound the size |B i+1 | again using Lemma 4.3.S = S i , since we are starting from the agents in S i at time τ i (who have v.count(τ i ) < d i−1 ).We will consider the drift during the interval between time τ i and u i+1 , so might be stuck at the door, but they will advance past as soon as they encounter an agent from A i+1 or another agent from B i+1 that has already past the door.Thus this looks like an epidemic process where |A i+1 | + |B i+1 | agents are participating, and we start with at least |A i+1 | infected agents.We will wait τ i+1 − u i+1 time and hope to reach at least n/4 infected agents.
However, there is the added complication that agents might drift past G i+1 , so they can't get counted in S i+1 and will no longer be acting as an infected agent in the epidemic.We will again use Lemma 4.3 to bound the count |D| of any agents that have more than max G i+1 interactions by time τ i+1 .We use , so h 2 /3µ > 49 184 c4 i+1 > c4 i .We will consider the worst case for the size of |D|, with |S| = n agents possible to drift.Lemma 4.3 gives that |D| ≤ D n, where Now we will make a worst case assumption that all drifted agents come from the initially infected agents A i+1 , and argue about an epidemic starting from We will use the bound broken up with two terms that will dominate each of the terms in B and D .
Then we can bound for sufficiently large values of n (since √ n ln n = o(n 3/4 )), and for c ≥ 700 (since the rightmost difference is minimized at i = 0 at positive for c ≥ 700).
These calculations also show that |A i+1 | − |D| ≥ n/2 5+2 i .Thus, the true process will be stochastically dominated by a two-way epidemic, starting from a = n/2 5+2 i infected agents and n/4 susceptible agents.Recall we are waiting Now we can apply Lemma 4.5 (with α = 2 −5−2 i and γ = 1/4) to conclude this process will reach s + 1 > n/4 infected agents after T interactions, where Proof.Notice that i ≥ (log log n) − 2, so 4 i > 1  16 log 2 n, and for any constant a > 0, we have exp(−a4 i ) < exp(− a 16 log 2 n) < 1/n 2 for sufficiently large n.Thus we will find that all error terms of the form exp(−l 2 /3µ) and exp(−h 2 /3µ) from Lemma 4.3 will now be small enough that we can use the union bound result and conclude |L| = 0 and |H| = 0.
First we consider i = log log n − 1.By Lemma 5.4, |S i | ≥ n/4, meaning at time τ i , there are at least n/4 agents at level ≤ i in G i .Now let Ω = d i−1 + 47c 48 4 i be the point 47  48 of the way through the interval G i .Let D be the set of agents that have more than max G i interactions by time Ω.We apply Lemma 4.3 with |S| = n, µ = Ω < (1 + 5 6 )c4 i < 2c4 i and µ + h = max G i , so h = c 48 4 i .Now we have h 2 /3µ = Θ(4 i ), so as observed above exp(−h 2 /3µ) < 1/n 2 and we can conclude that |D| = 0 with probability 1 − O(1/n).
Now we consider the time between τ i and Ω.Since no agent has had more than max G i interactions, there are at least n/4 agents in G i during this entire interval.We can now show that every agent will enter G i by the time Ω.In the worst case, an agent v could still have v.count(τ i ) = 0.If v has an interaction while at a door during this interval, the chance of increasing its counter is at least n 4 /n = 1/4.The probability of taking more than 8 ln n interactions to pass a door is at most (1 − 1/4) 8 ln n < exp − 8 4 ln n = 1/n 2 .The probability of taking more than 8 ln n log log n interactions to pass all doors is then at most log log n/n 2 .This number of interactions is negligible compared to Now we are waiting time and need to have d i + o(log 2 n) interactions.Thus we can again apply Lemma 4.3, where again µ = Θ(4 i ) and l = Θ(4 i ).This will show that with probability 1 − O(1/n 2 ), every agent has enough interactions between τ i and Ω to reach the interval G i .
We have now shown that v.count(Ω) ∈ G i for all v. Then the number of interactions for an agent to enter R i is at most |G i | = c4 i and the number of interactions to reach d i is at least |R i | = 3c 2 4 i , so we can find some time t ∈ R i when Lemma 4.3 will give that with probability 1 − O(1/n 2 ), every agent will have at least enough interactions to enter R i but not enough interactions to reach d i .
While i < k, there will be at least one agent at level i + 1.We can then make the same epidemic argument as in the proof of Lemma 5.4.Now, we can assume in the worst case we have an epidemic that starts with one agent that must reach the whole population.By either Lemma 4.4 or Lemma 4.5, this takes O(log n) time (O(n log n) interactions, with probability 1 − 1/n 2 .This is now negligible compared to the Θ(log 2 n) time during each green interval.
Thus we can inductively claim that for all intervals G i+1 , R i+1 , . . ., G M , R M there is some time t when all agents are synchronized with counts in that interval.Both yielded maximum level k = 6.The horizontal axis shows parallel time ( n 2 -interactions).The vertical axis represents the value v.count for agents (summarized for the whole population by min, max, and average).The purple line, the orange line, and the green line are respectively showing the maximum, average, and minimum v.count for agents.As shown in the figures the maximum count and minimum count drift in the middle of the protocol but eventually they all converge to d k , where k represents the maximum level.

Leader-driven, O(log 2 n)-convergence-time exact size counting
In this section we show a O(log 2 n) time, high-probability protocol for a problem that is natural for agents with non-constant memory: exact population size counting.The probability of error can be reduced to 0 with standard techniques; see Corollary 5.9.This problem has been studied in the context of open protocols, in both the exact [18,27] and approximate [18,26] settings, where it is known that open protocols can approximate n within multiplicative factor 2, by computing either log n or log n , using O(log n log log n) states, and O(log 2 n) time [18], and open protocols can compute the exact value of n, using O(n log n log log n) states, and O(log n) time [18].Both protocols can be changed to probability-1, with a multiplicative factor increase of O(log n) states in case, i.e., O(log 2 n log log n) states for calculating log n or log n , and O(n log 2 n log log n) states for exactly computing n.However, note that our results below are leader-driven, so direct comparison with the leaderless results of [18] is not appropriate.Proof sketch.It uses the "fast averaging" technique that has been useful in other population protocols [4,18,27,39,41], in which each agent holds an integer and computes the transition i, j → i+j 2 , i+j 2 .In the O(1)-message setting, of course, this will not work exactly as described.

Theorem 5.7. There is an O(1)-message leader-driven population protocol (Protocol 3) that, with probability 1 − O(1/n), exactly counts the population size n (storing it in each agent's internal state), in O(log
Intuitively, the leader will distribute 1 unit of what we can imagine is a continuous mass into the population.Rational-valued averaging of this mass would result in each agent  converging to 1/n, from which n can be computed.O(1) messages cannot represent arbitrary rationals.Instead, we allow agents to communicate a few bits of their number at a time, while ensuring that before moving on, they agree on an interval containing the true average, which shrinks by half each round, synchronized by a leader-driven phase clock [8]).
Figure 3  is what requires r + 2 bits after the binary point).The leader is initialized with w = 4 (and mass = 0 + 4 4•1 = 1), and the followers are initialized with w = 0 (and mass = 0).The full proof shows that, with high probability, every agent will always have the same value of a.This implies, via the averaging rule for weights, that mass is conserved and the sum of mass in the population is 1.Thus for all agents at all times, it holds that the true average 1 n stays within the interval [a, b].Once the interval contains only a single integer reciprocal 1  n , the protocol terminates with all agents knowing n.
Proof.Protocol 3 shows pseudocode.The protocol works as follows.It uses the "fast averaging" technique that has been useful in other population protocols [4,18,27,39,41], in which each agent holds an integer and computes the transition i, j → i+j 2 , i+j 2 .In the O(1)-message setting, of course, this will not work exactly as described.
Intuitively, the leader will distribute 1 unit of what we can imagine is a continuous mass into the population.Real-valued averaging of this mass would result in each agent converging to 1/n, from which n can be computed.Of course, we cannot store arbitrary-precision real numbers in states, though we can store rational approximations.But we cannot communicate arbitrary rationals using O(1) messages.Instead, we allow agents to communicate a few bits of their number at a time, while ensuring that before moving on, they agree on an interval containing the true average, which shrinks by half each round (where synchronized rounds come from the leader-driven phase clock of [8]).Each agent's state will represent an interval [a, b] ⊆ [0, 1], where b − a = 2 −r during round r ∈ N (initialized to r = 0).a will be a dyadic rational, initialized to a = 0.00, containing r + 2 bits after the binary point.There is a message field W = {0, 1, 2, 3, 4} describing varying amounts of extra weight.The value w ∈ W counts for w 4•2 r units of mass in round r.An agent is interpreted as having mass = a is what requires r + 2 bits after the binary point).The leader is initialized with w = 4 (and mass = 0.00 + 4 4•1 = 1.00), and the followers are initialized with w = 0 (and mass = 0.00).We will prove that with high probability every agent will always have the same value of a.This will imply, via the averaging rule for weights, that mass is conserved and the sum of mass in the population is 1.Thus for all agents at all times, it holds that the true average 1 n stays within the interval [a, b].
We first discuss the guarantees of the leader-driven phase clock from [8].The agents will go through consecutive rounds, where each round contains an Averaging phase followed by an Updating phase.Choosing appropriate constant parameters, we can ensure with probability 1 − O(1/n) that for time Ω(n), all agents are synchronized within each phase for Θ(log n) time, and no two agents are ever more than one phase apart (thus we can be sure that two agents in the same type of phase are also in the same round).

Averaging phase
When two agents meet and both are in the Averaging phase, they each update just their weights via the standard averaging rule i, j → i+j 2 , i+j 2 for any i, j ∈ W .Note that assuming the invariant that every agent agrees on a, this rule preserves the sum of mass in the population.
Averaging takes time Θ(n) to converge in the worst case, where convergence happens when all agents agree on one of two consecutive integers a and a + 1. (Thus further interactions are null.)However, Berenbrink, Friedetzky, Kaaser, and Kling [15] show that with probability 1 − O(1/n 2 ) it takes only O(log n) time to reach a configuration where all agents share three consecutive integers, two of which are a and a + 1.The third could be either a − 1 or a + 2, depending on the true population-wide average; full convergence happens when all remaining a − 1's encounter a + 1's in the former case, and when all remaining a + 2's all encounter a's in the latter case.Thus, for appropriate constant parameters of the phase clock, with probability 1 − O(1/n), every Averaging phase lasts long enough such that at the end of each Averaging phase, we have max w ≤ min w +2.

Updating phase
During the Updating phase, each agent spreads by epidemic the minimum weight w min they have seen since the start of the Updating phase.By Lemma 4.4, we can guarantee with probability 1 − O(1/n) that every Updating phase lasts long enough for every agent to learn the minimum remaining message.(To ensure the w min , w min + 1, w min + 2 ∈ W in case w min > 3 we take min(w min , 3)).
At the end of the Updating phase, the agents update their lower bound to a r+1 = a + wmin 4•2 r .Because all agents agree on w min , they still agree on the value a as desired.Assuming the weight in round r was w r , the weight updates to w r+1 = 2(w r − w min ).Because we have max w ≤ w min + 2 after the successful Averaging phase, the set of weights at the start of every round will be in {0, 2, 4} (see Figure 3).Notice that mass = a r+1 + mr+1 4•2 r+1 = a + m 4•2 r is preserved during the update as desired.
Thus we have finished proving the invariant that all agents store the same interval [a, b], and the sum of mass is conserved, so 1 n ∈ [a, b].Finally, we can consider the time and space complexity, assuming that with probability 1 − O(1/n), this invariant holds and each round is Θ(log n) time.
We first analyze the first round r when the minimum weight w min > 0, so through this round we have a = 0 for all agents.Since the minimum weight w min ≥ 1, the minimum mass is at least 0 + 1 4•2 r ≤ 1 n , so r ≥ log n − 2. The maximum mass is at most 0 + 4 4•2 r ≥ 1 n , so r ≤ log n.Thus we will have w min > 0 for the first time, increasing the lower bound a after the Updating phase, at the end of round r, where log n ≤ r ≤ log n + 2. Corollary 5.8 argues how to use this fact to obtain a O(log n)-state protocol for estimating log n.
We next analyze the first round r when the interval [a, b] contains a unique reciprocal 1 n .It is necessary and sufficient to have , so r ≤ log(n(n + 1)) + 1.Thus the protocol will terminate at the start of round r = 2 log n + O(1), and will take O(log 2 n) time.
Next, we analyze the space complexity.Naively storing a (with r + 2 bits after the binary point) would use 2 2 log n+O (1) = O(n 2 ) states.However, by the arguments given above, we have a = 0 until round r 1 ≈ log n, so simply store the counter r 1 to denote how many leading zeros a has.The protocol will terminate at round r 2 ≈ 2 log n, so we can store a with log n + log log n + O(1) bits.Including the counter r and all constant space overhead gives a space bound of log n + 2 log log n + O(1) bits, so the total number of states is O(n log 2 n).
Terminating Protocol 3 early gives a more space efficient protocol for estimating log n: Proof sketch.We run Protocol 3 until the interval [a, b] contains exactly one power of two 2 −k , and then output k, unless it contains no powers of two, in which case we output arbitrarily either of the powers of 2 contained in the interval of the previous round.If n = 2 k , then k = log n exactly.Otherwise, since the interval contains no other power of 2, but it contains 1/n, then k ∈ { log n , log n }.
Proof.We run Protocol 3 until the interval [a, b] contains exactly one power of two 2 −k , and then output k (with one exception described below).If n = 2 k , then k = log n exactly.Otherwise, since the interval contains no other power of 2, but it contains 1/n, then k ∈ { log n , log n }.
The interval [a, b] endpoints are eventually arbitrary dyadic rationals.However, as observed in the proof of Theorem 5.7, in the first log n − 1 rounds, the interval is of the form [0, 2 −j ], storable using only O(log n) states, because the minimum weight w min = 0.In the next round, depending on w min , the interval becomes one of is the only power of two in the interval.
If I 2 , then one more round must pass.Note I 2 has only two powers of 2, the endpoints, and the interval will shrink to I 1 in the next round, containing one of the endpoints (if w = 0 or 2), or neither (if w = 1).If I 1 contains neither, then we know n is not a power of 2, so we output 2 −(j+1) or 2 −j arbitrarily, since j = log n and j + 1 = log n .
Only O(1) extra states are needed to advance one more round, so O(log n) total states suffice.
Protocol 3 ExactCounting (Agent v seeing message m) is leader-driven with message fields leader ∈ {L, F }, w, wmin ∈ {0, 1, 2, 3, 4}, and internal field a ∈ Q. Subroutine LeaderDrivenPhaseClock gives internal field round r ∈ N, message field phase ∈ {Averaging, Updating}, and uses O(1) message overhead to communicate the current phase.Because our protocol is leader-driven, we can use standard tricks to have the leader set a timer (see [8]) for when to tell all agents via epidemic to change their output to the deterministic backup.With probability 1 − O(1/n), the fast Protocol 3 will correctly compute n, and the timer will not go off until the backup has also stabilized.The probability O(1/n) for errors add an expected O((n log 2 n)/n) = O(log 2 n) convergence time to wait for the slow backup.Note the stabilization time is Ω(n log 2 n) because until the slow backup has stabilized, there is a chance of switching to the backup before it is correct.
The case of size estimation is similar, although unlike the case of exact counting, in this The next corollary shows that Protocol 3 can be made leaderless by composing with the leader election protocol derived from junta election (Protocol 2).Proof.Both protocols work similarly.We can use JuntaElection (Protocol 2) to get a leader election protocol as in [32].This will use O(log 2 n) state overhead and take O(log 2 n) parallel time.With probability 1 − O(1/n), all agents in Protocol 2 will restart when they enter the last level together with the same constant-factor estimate of log n.They can use this estimate to set a timer to wait for the leader election to converge after O(log 2 n) time.Then we can start the downstream Protocol 3 to count the population, either exactly as in Theorem 5.7 or approximately as in Corollary 5.8.

Leader-driven, O(log 2 n)-time predicate computation
We can use techniques from Theorem 5.7 to show how to compute, using a leader and with high probability, any predicate on a constant alphabet Σ, up to the space bounds allowed by the agents.We assume that there is one leader agent, and that every other agent has a state from a fixed alphabet Σ. Exactly the semilinear predicates are computable with probability 1 by O( 1)-state open protocols [7] (with > log n states, more predicates are possible [21]).Proof sketch.Agents first run the Protocol 3 of Theorem 5.7 to store locally the value n.Agents then use a similar strategy to Protocol 3 to count how many agents have input x for each symbol x ∈ Σ.Having now stored the entire initial population's input in their internal state, they can simply compute any computable predicate φ locally.
Proof.First, agents run the Protocol 3 of Theorem 5.7 to store locally the value n.This protocol is terminating (i.e., agents signal when they are done and with high probability, no agent signals before all agents have converged), so it can be straightforwardly composed with the subsequently described protocol.Note that the state bound was O(n log 2 n), but we can store n in a separate field that will only contribute O(n) additional state overhead.
Next, we iterate over each element x ∈ Σ, counting the number of elements with symbol x in the population, using the same transitions as Protocol 3, except now each agent storing x starts with weight w = 4 and other agents start with w = 0.The same argument as the proof of Theorem 5.7, only now the total mass is |x|, and the agents will wait until the interval [a, b] contains only one number k n for k ∈ N. (Note this will only require an interval of length O( 1n ) and thus take log n + O(1) rounds).After each of these sub-protocols terminates, the agents store the number k = |x| in their internal state.Finally, note that the last element does not need to be counted, as it can recovered as the difference between n and the counts of the other inputs.
It follows that this protocol will take O(d log 2 n) time and use O(n d log 2 n) states.Alternately, we could run all these steps in parallel, which would reduce the time by a constant factor d, but increase the amount of messages used (to have d independent copies of the weight and min weight fields w, i for Protocol 3).The error probability follows from that of Theorem 5.7, taking a union bound over each of the d + 1 instances of Protocol 3.
If an agent can locally store the entire initial configuration, it can compute any predicate computable by the transition function δ.Formally, we required that δ be computable by a Turing Machine with O(log s(n)) bits of memory, to make our model comparable with [21].Thus we can compute all predicates computable by O(log n) bit space-bounded Turing Machines via Corollary 5.11.

6
Computability with one-bit messages We will show that with one-bit messages, it is possible to simulate a synchronous system that provides a one-bit broadcast channel.This in turn will be used to simulate more complex systems.The price is that we sacrifice stabilization for convergence, and rely on unbounded counters to ensure convergence in the limit with probability 1.
Let us begin by defining the simulated system.A synchronous broadcast system consists of n synchronous agents that carry out a sequence of rounds.In a broadcast round, each agent generates a one-bit outgoing message.These outgoing messages are combined using the OR function to produce the outcome for this round.
Broadcast operations can be used to detect conditions such as the presence of a leader, or ordinary message transmission if a unique agent is allowed to broadcast in a particular round.However, because broadcast operations are symmetric, they cannot be used for symmetry breaking.For the purpose of electing a leader, we assume that agents have the ability to flip coins; once we have a leader, further agents may be recruited for particular roles using an auxiliary protocol that allows the leader to select a single agent from the population in some round.The broadcast and selection protocols are mutually exclusive: either all agents participate in a broadcast in some round or all agents participate in selection.This is possible by showing that all agents eventually agree on the round number forever with probability 1.
Simulating this model in a population protocol requires (a) enforcing synchrony across agents, so that each agent updates its state consistently with the round structure; (b) implementing the broadcast channel that computes the OR of the agents' outputs; and (c) implementing the selection protocol.We show how to do this in the following section.

Implementing the core primitives
Broadcasts are implemented by epidemics that propagate 1 messages, separated by barrier phases in which all agents display 0. Selection is implemented by having the leader display a 1 to the first agent it meets.Both protocols depend on the number of steps at each agent being approximately synchronized with high probability; after t(n/2) steps, all agents' step counts should be within the range t ± O( √ t log n) with high probability (see Lemma 4.1).The time to carry out a broadcast is also O(log n) with high probability (see Lemma 4.5).By increasing the length of each round over time, the total probability across all rounds of an error occurring in either the broadcast or selection protocol due to out-of-sync agents or slow broadcasts converges to a finite value.Applying the Borel-Cantelli lemma then shows that there is a round after which no further failures occur with probability 1.

Details
Observe that the probability that a particular agent i participates in an interaction is exactly 2/n, and that the events that i participates in distinct interactions are independent.If we let X t i be the indicator variable that agent i participates in the t-th interaction, then S t i = t j=1 X t i is a sum of independent Bernoulli random variables, and obeys the Chernoff bound Pr The execution of each agent is organized as a sequence of rounds, where each round r for r = 1, 2, . . .consists of exactly 5r 2 steps.The first 2r 2 steps will be a barrier phase during which the agent displays message 0 and updates its state during an interaction only by incrementing its step counter.The remaining 3r 2 steps will be an interaction phase in which the agents may execute one of two protocols.In a broadcast phase, each agent will propagate an epidemic represented by message 1, recording if it observed such an epidemic and possibly initiating the epidemic itself if instructed to do so by the protocol.In a selection phase, a leader agent displays 1 for its first encounter, and the agent interacting with the leader receives a special mark.The choice of broadcast/selection phase is determined by the controlling protocol and is the same for all agents.As in a barrier phase, an agent in an interaction phase continues to update its step counter with each interaction.
The controlling protocol updates the state of the agent at the end of each round.Each agent v has a state v.state that is one of broadcasting (agent is initiating a broadcast of value 1) receiving (agent is waiting to detect a 1), received (agent has detected a 1), selecting (agent is attempting to select another agent), candidate (agent is a candidate for selection), selected (agent has been selected), or idle (agent has selected another agent and is now waiting for the end of the round).We assume that the controlling protocol assigns consistent values to the agents in each phase: if one or more agents start in state broadcasting, the rest should start in state receiving; while if some agent starts in state selecting, the rest should start in state candidate.Pseudocode for the communication protocol is given in Algorithm 4 in 6.2.1, followed by a proof of its correctness in 6.2.2.The correctness of this protocol relies on carefully chosen phase interval lengths which allow us to simulate synchronous rounds wherein the above operations are executed in sequence.δ = r 2 /O(n log n) − 1 and thus Pr [D ir ] = e −Ω(r 2 /n log n) ln n = e −Ω(r 2 /n log n) .
Call a round r safe if none of the events A ir , B ir , C ir , or D ir occur for any i ∈ {1, . . ., n}.These events are not even remotely independent, but the the union bound still applies, giving a probability that round r is not safe of at most 3ne −Ω(r) + ne −Ω(r 2 /n log n) = e Ωlog n−r + e Ωlog n−r 2 /n log n .The sum of of these bounds over all rounds converges to a finite value for any fixed n, so by the Borel-Cantelli lemma, with probability 1 all but finitely many rounds are safe.
The following lemmas demonstrate that the protocol does what it is supposed to, once we reach the suffix of the execution containing only safe rounds.We start by excluding false positive broadcasts.Lemma 6.1.If rounds r and r + 1 are both safe, then no process observes a 1 in round r unless some process initiates a broadcast or selection in round r.
Proof.If rounds r and r + 1 are both safe, then the events A ir and A i,r+1 do not occur for any i.In particular, this means that at time t = (n/2)a r , all agents have an internal clock S t i that is within the interval a r ± r 2 − 1, which lies within the barrier phase for round r.So at this time all agents display message 0, have completed the interaction phase for round r − 1, and have not yet started the interaction phase for round r.A similar constraint holds at time t = (n/2)a r+1 .It follows that any 1 observed by an agent during its round-r interaction phase must result from some process setting its message to 1 either because it initiated an epidemic or selection during its own round-r interaction phase, or because it is propagating an epidemic initiated by such a process.
Similarly, a safe round has no false negative broadcasts: Lemma 6.2.If round r is safe and all agents start round r in either a broadcasting or receiving state, then any epidemic initiated in round r is observed by all agents.
Proof.Because B ir does not occur for any i, after (n/2)b r steps, all agents are in their round-r interaction phase, and because C ir does not occur for any i, all agents remain in their round-r interaction phase until at least (n/2)c r steps.If some agent i initiates an epidemic in round r, then i.state = broadcasting after (n/2)b r steps, and under the assumptions, of the lemma every other agent is either in the broadcasting, receiving, or received state.A simple induction shows that the set of infected agents in the real process throughout the [(n/2)b r , (n/2)c r ] interval is bounded below by the set of infected agents in the hypothetical epidemic considered in the definition of D ir .This means that if D ir does not occur, both such sets contain all processes after (n/2)c r interactions.
And a safe round allows selection.Selection is not necessarily uniform conditioned on safety, but each agent has an Ω(1/n) chance of being selected when r is sufficiently large: Lemma 6.3.If round r is safe, exactly one agent i starts round r in a selecting state, and all other agents start round r a candidate state, then exactly one agent finishes round r in a selected state.For each agent j, the probability p that its is chosen conditioned on the safety of round r and the events of previous rounds is at least 1 2n for sufficiently large r.
Proof.Use the non-occurrence of any B ir or C ir to argue that agent i reaches tick 3r 2 while all agents are in the interaction phase.Then the next interaction between i and any j causes j to observe a 1 and switch to a selected state.We would like to argue that the next interaction between i and another agent j chooses each j with independent probability 1/n.Unfortunately, we are conditioning on safety of round r.Let A be the event that i selects j and B the event that round r is unsafe.Then Pr 2n for sufficiently large r.

Convergent computation of arbitrary symmetric functions
Early rounds produce incorrect results, so we need an error-recovery mechanism.We describe a basic protocol for electing a leader and having it gather inputs from the other agents.This in principle allows the leader to compute the output of an arbitrary symmetric function and broadcast it to the other agents.The protocol guarantees termination with probability 1 even in executions where some of the rounds exhibit errors in the underlying broadcast mechanism.By restarting the protocol when it terminates, we can guarantee that the protocol eventually runs without errors, thus converging to the correct output.
Each agent v maintains a Boolean field v.leader that marks it as a leader (or candidate leader) and a field v.processed that marks whether it has reported its input v.input to the leader.All agents rotate through a repeating sequence of 7 rounds, where the round number for the purposes of the protocol is r mod 7.These are organized as follows: Round 0 Any leader broadcasts 1.A non-leader that receives 0 sets its leader bit.This round allows recovery from states with no leaders.Round 1 Any leader broadcasts 1 with probability 1/2.A leader that does not broadcast but receives a 1 clears its leader bit.Round 2 Any agent that cleared its leader bit in the previous round broadcasts 1.This causes any remaining leaders that receive a 1 to restart the information-gathering protocol and causes any non-leaders that receive a 1 to clear their processed bits.Broadcasting a 1 in this round is also used by the leader to restart the protocol after completion.Round 3 Any agent v with v.processed = 1 broadcasts 1.This is used by the leader and other agents to detect unprocessed inputs.Round 4 If a leader received a 1 in the previous round, and there is no transmission in progress from a non-leader agent, the leader executes a selection operation.The selected agent sets its processed bit and transmits its input if its processed bit is not already set.
If the processed bit is set, the agent transmits nothing in the following two rounds.Rounds 5 and 6 These are used to transmit either (a) one bit of a selected agent's input, or (b) one bit of the protocol output.In either case the bit is encoded as two bits using the convention 01 = 0, 10 = 1, 00 =stop.Note that the absence of a broadcast in both rounds is interpreted as stop, which both allows a selected agent to signal it has already been processed and guarantees eventual termination after an agent finishes transmitting its input even if some of the broadcasts are garbled.It is possible for two agents to be transmitting simultaneously (this can occur if there are multiple surviving leaders).This requires that agents be prepared to handle receiving 11.
The simplest way to handle 11 may be to have agents just interpret it as a fixed value: 11 = 1.Alternatively, we could implement an optimization where any agent that observes 11 triggers a restart of the protocol by broadcasting a 1 in the next Round 2.
The protocol terminates when the leader has collected all inputs (detected by the absence of a signal in Round 3) and transmits the computed output to all agents (using Rounds 5 and 6 over however many iterations are needed).We assume that the computed output has finite length for any combination of inputs.After transmitting the output, the leader broadcasts a 1 in Round 2 to restart the information-gathering component of the protocol.Lemma 6.4.In any execution with finite errors in the underlying broadcast protocol, with probability 1, the above protocol converges to a single leader and then restarts infinitely often.Lemma 6.4 is proven correct by demonstrating that, as defined, this protocol elects exactly one leader by Round 2 which correctly processes all non-leader agents with probability 1 by the end of Round 6.The full proof can be found in 6.4 6.4 Proof of Lemma 6.4 Proof.Consider a sequence of iterations in which no errors occur.
If there are no leaders initially, the first execution of Round 0 sets the leader bit in all agents.The only way that an agent can lose its leader bit is if it sees another leader broadcast a 1 in Round 1.But this always leaves at least one leader.If there is more than one leader, half the remaining leaders on average will drop out in each execution of Round 1.This guarantees that there will eventually be exactly one leader with probability 1.
If there is a leader, the leader believes that there is no transmission in progress, and at least one agent v with v.processed = false, then v is selected with probability at least 1 2n for sufficiently large r in Round 3 (Lemma 6.3).This causes some agent to be selected in Round 3 eventually with probability 1, reducing the number of unprocessed agents by one.
If there is a transmission in progress, each transmitting agent sends finitely many bits before stopping.Once all transmitting agents have stopped, any agent waiting for a transmission to finish will observe 00 in Rounds 5 and 6.
It follows that starting from an arbitrary initial configuration, with probability 1 the protocol reaches a configuration with exactly one leader, the leader finishes waiting for any outstanding transmissions, and the leader then selects an unprocessed agent and collects its input until no unprocessed agents are left.After the leader transmits its computed (though possibly incorrect) output, the protocol restarts.
Once the protocol restarts with a single leader, any subsequent error-free execution produces correct output.This follows from the fact that the leader collects the input from every agent exactly once.Since each agent records as its output the last output broadcast by the leader, this causes all agents to converge to holding the correct output with probability 1.
Because the leader has unbounded states, it can simulate an arbitrary Turing machine.This allows the output to converge to the value of any computable symmetric function.The restriction to symmetric functions follows from uniformity of the agents in the initial configuration, but can be overcome, assuming inputs include indexes.We have thus shown: Theorem 6.5.For any computable symmetric function f , there is a population protocol using 1-bit messages and unbounded internal states that starts in an initial configuration where each agent i is distinguished only by its input x i , that converges to having each agent holding output f (x 1 , . . ., x n ).
Our construction exploits the unbounded state at each agent to allow the leader to simulate the entire computation.While the probability-1 convergence property requires unbounded state in the limit (otherwise there is a nonzero probability that any round fails), it may be desirable to put off expanding the state as long as possible.In 6.5, we argue that with some small tweaks, the construction can be adapted to distribute the contents of a Turing machine tape of s bits across all agents of the population as in [21], reducing the storage overhead at each agent for the Turing machine computation to O(s/n + log s) bits.
is the transition function for the simulated Turing machine.Algorithm 6 is written from the perspective of a non-leader and describes how it responds to transmissions from the leader.
The simulation starts by organizing the agents into a Turing machine tape.This involves selecting agents one at a time and assigning them indices.Because an agent might be selected more than once, the expected number of rounds to find all agents scales as O(n log 2 n), where O(n log n) comes from the expected time to finish a coupon collector process and the extra O(log n) comes from the time to transmit indexes one bit at a time.We assume that counting n is also enough for the leader to compute a bound f (n) on the number of steps used by the Turing machine; this is needed to enforce restarts if the simulated machine does not terminate on its own.
For simplicity we assume that inputs can be placed in arbitrary order on the first n − 1 cells of the tape (this will require special handling of any input on the leader, which we omit for simplicity of presentation).A complication is that inputs to the protocol might exceed the size of the constant tape alphabet.This does not affect the simulation directly, since no restriction on tape alphabet is assumed, but it may require adding a preamble to the Turing machine computation that unpacks large-alphabet inputs into the constant-size TM alphabet.We leave the details of this tedious and unenlightening preamble to the imagine of the reader.
The analysis of Algorithms 5 and 6 essentially follows the proof of Theorem 6.5.Once the simulation reaches the safe phase of the construction, it reaches a configuration with one leader after some finite time with probability 1.At this point the leader may already have an inaccurate estimate n of n, but whether the estimate is accurate or not, each iteration of the main loop will require at most O(log f (n)) rounds to finish, leading to a restart after at most O(n log 2 n + f (n) log f (n)) rounds on average.Each subsequent iteration will run the Turing machine to completion and produce the correct output.The space complexity at each agent, measured in bits, is bounded by O(s/n + log s) during non-faulty simulations, where s is the largest tape cell index used.For faulty executions, we accept a small probability that a larger estimate of n at some leader agent may leader to larger space overhead.In either case the state complexity is dominated in the limit by the unbounded round and tick counters.Theorem 6.6.Algorithms 5 and 6 use the synchronous broadcast primitive to simulate a Turing machine with known time complexity f (n), converging to the correct output with probability 1.In any execution, the additional space required at each agent to simulate a Turing machine that uses s tape cells is bounded after an initial prefix by O(s/n + log s) with probability 1.

Open problems
Probability-1 computation.Many of our protocols have a positive probability of error.
Common techniques for achieving zero error probability in ω(1)-state protocols require ω(1) messages.Based on this, we conjecture that probability-1 leader election using O(1) messages requires Ω(n) time to stabilize.This is known to hold for O(1) states [29], though sublinear-time convergence is possible with O(1) states [37].Time lower bounds.A tool for time lower bounds (e.g., probability-1 leader election [1,29]) is a "density lemma" [1,25] showing that when the state complexity is ≤ 1 2 log log n, all states appear in "large" count.This is false for s(n) > log log n, which is the key to the fastest space-optimal leader election protocols [16,32,33].A density lemma applies to the messages of O(1)-message protocols, no matter the state complexity (derivable from [26,Lemma 4.2]).Does this imply that O(1)-message leader election requires linear stabilization time?

Theorem 3 . 8 .
Let s : N → N and consider an additive, s(n)-state, O(1)-message population protocol.Then either s(n) = O(1) or s(n) = Ω(n).Proof sketch.A fixed population i c suffices to produce any of the O(1) messages.Consider a population i n of size n.If s(n) = O(1), then for some state b not producible from i n , b is producible by sending some message m to a state a producible from i n (though a and m cannot appear simultaneously in a configuration reachable from i n ).By combining i n with i c , we have a population of size n + O(1) that can produce b.Thus the number of producible states grows at least linearly with n.Proof.If s(n) = O(1) we are done, so assume s(n) grows without bound.Let M (n) (respectively, S(n)) be the set of all messages (respectively, states) producible from a valid initial configuration of size n.Note |M (n)| = O(1) and |S(n)| = s(n).It suffices to show that for some constant > 0 depending on the protocol, there are infinitely many n such that |S(n)| ≥ n.

Finally, the
distribution {L v | v ∈ S} is a collection of monotone functions each defined on a disjoint subset of the distribution {A v,s : v ∈ [n], s ∈ [T ]}.This is precisely the property of disjoint monotone aggregation ( [30]), which shows that {L v | v ∈ S} is negatively associated.The same argument also holds for {H v : v ∈ S}.Now we will actually apply Chernoff bounds to the complements |S \ L| = v∈S (1 − L v ) and |S \ H| = v∈S (1 − H v ), which are justified by negative association.Then by linearity of expectation, σ = E [|S \ L|] ≥ (1 − exp(−l 2 /2µ))|S|.Now letting δ = 2 2 ln n/|S| and L = δ + exp(−l 2 /2µ), we have

Lemma 4 . 4 (
[40]).Starting from a population of size n with a single infected agent, let T n be the number of interactions until all agents are infected.Then E [T n ] = (n−1)H n−1 ∼ n ln n, and for n ≥ 8 and δ ≥ 0,

Lemma 4 . 5 .
Consider the two way epidemic process starting from a configuration of n agents with a = αn infected agents and b = γn ≥ a susceptible agents (and n − a − b agents not participating).Let T be the number of interactions to reach b + 1 infected agents (with a − 1 susceptible agents left).Then T ≤ 5

u 2 τ 2 Figure 1 4 . 5 . 1 .
Figure1Agents, represented as dots, increment their counters through the G0, R0, G1, R1, G2, R2 intervals.Agents in green intervals or any interval before their own level have message Go.Agents in red intervals at their own level or later have message Stop.At the end of a red interval (the door d i , shown with black horizontal line) at their own level or later, the agents (black dots) wait to increment their counter until they see a message Go.The special times marked u i , τ i are used in proving Lemma 5.4.

Finally, we establish 1 . 5 . 6 .
the state complexity bound for Protocol 2 stated in Theorem 5.Lemma With probability1 − O(1/n), Protocol 2 uses O(log 2 n) internal states.Proof.Note the space is dominated by the field count = O(log 2 n) with probability 1−O(1/n).All the intervals are properties of the transition function δ not the state.Finally, as written holding the level would take O(log log n) state overhead, but we could actually compute the level on the fly and only need to track if we are still eager or cautious in each interval.

Figure 2
Figure 2 Data from two simulations on n = 2 • 10 7 agents, with different values of |Gi| and |Ri|.Both yielded maximum level k = 6.The horizontal axis shows parallel time ( n 2 -interactions).The vertical axis represents the value v.count for agents (summarized for the whole population by min, max, and average).The purple line, the orange line, and the green line are respectively showing the maximum, average, and minimum v.count for agents.As shown in the figures the maximum count and minimum count drift in the middle of the protocol but eventually they all converge to d k , where k represents the maximum level.
2 n) time and using O(n log 2 n) states.

Figure 3
Figure 3 Update rule for fast exact counting protocol.All agents start with a mass of 0 and weight w = 0, except the leader, who starts with mass = 1 and w = 4.They conduct averaging on weight w for one round, at which point (with high probability) three consecutive weights remain.The figure shows how the remaining masses map to the next subinterval, with the weight w updating to 2(w − wmin) where wmin is the minimum value of w at the end of the Averaging phase.The right side shows the subintervals to scale.Each agent updates its internal state to represent the interval [a, b].Once [a, b] contains only a single number of the form 1 n , the protocol terminates, and each agent knows the value n.The first log n rounds would always have 0 as the minimum remaining weights, but we allow other values to show concretely how the updating rule works.
shows the updating rule.Each agent's state represents an interval [a, b] ⊆ [0, 1], where b − a = 2 −r during round r ∈ N (initialized to r = 0).a is a dyadic rational, initialized to a = 0.0, containing r + 2 bits after the binary point.One message field W = {0, 1, 2, 3, 4} describes varying amounts of extra weight.The value w ∈ W counts for w 4•2 r units of mass in round r.An agent is interpreted as having mass = a + w 4•2 r ∈ [a, b] (note representing w 4•2 r

Corollary 5 . 10 .
There is a leaderless, O(1)-message population protocol that exactly counts the population size n in O(log 2 n) time and O(n polylog n) states, succeeding with probability 1−O(1/n).There is also a leaderless, O(1)-message population protocol that computes log n or log n in O(log 2 n) time and O(polylog n) states, succeeding with probability 1 − O(1/n).

Corollary 5 . 11 .
Let d ∈ N + and let Σ be a d-symbol input alphabet.Then there is an O(1) message leader-driven population protocol that, with probability 1 − O(1/n), exactly counts the input vector i ∈ N d (storing it in each agent's internal state), in O(d log 2 n) time and using O(n d log 2 n) states.

10 then 11
fratricide leader election 7 else 8 reinitialize v ; // surviving leader goes back to initial state 9 else if v.role = S and m.role = f S ; // base-station counting from [10] thus this counter uses n c + O(1) states.Counting the 6 messages gives as long as c ≥ 333).Thus by time τ i+1 , at least n/4 agents have passed the door d i without leave G i+1 .Therefore we have showed |S i+1 | ≥ n/4 with probability 1 − O(1/n 2 ), completing the inductive case.Note that we considered i < log log n levels, where each of these inductive steps added an error probability O(1/n 2 ).Therefore we have Pr[|S i | ≥ n/4] > 1 − O log log n Let i ∈ { log log n − 1, . .., k},where k = max v v.level.Then with probability 1 − O(1/n), there is some time t such that v.count(t) ∈ G i for all agents v, and also some time t such that v.count(t) ∈ R i for all agents v.

1 initial state of agent
v: w ← 0 if leader = F , w ← 4 if leader = L // w is a weight with a shrinking 2 −2−r units of mass 2 a ← 0.00, r ← 0, phase ← Averaging ; // each agent has mass = a + w/2 2+r There are O(1)-message, leader-driven population protocols that, with probability 1, respectively count the exact population size n and estimate it by computing log n or log n , both with expected O(log 2 n) convergence time and O(n log 2 n) stabilization time.With probability 1 − O(1/n), they use O(n 4 log 4 n) and O(log 2 n) states, respectively.First consider the case of exact size counting.We can compose Protocol 3 with a slow stable counting algorithm.As a backup, we could use the deterministic broadcast mechanism sketched in Corollary 3.6, which stably counts the population with O(n 3 log 2 n) states in expected O(n log 2 n) time.Together with the O(n log 2 n) states of Protocol 3, this is O(n 4 log 4 n) states.
paper we do not have a O(1)-message protocol that directly computes log n with probability 1.However, there is a simple open O(log n)-state protocol that computes log n : All agents start in state 1 , and for each i and j < i we have the transitions i , i → i+1 , f i+1 and f i , f j → f i , f i .This takes expected time O(n) to elect a leader log n by the first type of transition and expected time O(log n) to propagate the value log n to all agents by epidemic.Theorem 3.3 shows how any open, s(n)-state protocol can be simulated by a leaderdriven, O(1)-message protocol with O(n log s(n)) expected slowdown.This implies a leaderdriven, probability-1 protocol for calculating log n with expected time O(n 2 log log n).By combining this with the fast, error prone protocol described in Corollary 5.8, and setting the phase clock parameters of Protocol 3 to ensure probability of error at most 1/n 2 , the contribution to the expected time of the slow, probability-1 protocol is negligible, and the whole protocol runs in expected time O(log 2 n) time as in Corollary 5.8.It contributes O(log n) state complexity, so the total number of states is O(log 2 n).