On the complexity of hazard-free circuits

The problem of constructing hazard-free Boolean circuits dates back to the 1940s and is an important problem in circuit design. Our main lower-bound result unconditionally shows the existence of functions whose circuit complexity is polynomially bounded while every hazard-free implementation is provably of exponential size. Previous lower bounds on the hazard-free complexity were only valid for depth 2 circuits. The same proof method yields that every subcubic implementation of Boolean matrix multiplication must have hazards. These results follow from a crucial structural insight: Hazard-free complexity is a natural generalization of monotone complexity to all (not necessarily monotone) Boolean functions. Thus, we can apply known monotone complexity lower bounds to find lower bounds on the hazard-free complexity. We also lift these methods from the monotone setting to prove exponential hazard-free complexity lower bounds for non-monotone functions. As our main upper-bound result we show how to efficiently convert a Boolean circuit into a bounded-bit hazard-free circuit with only a polynomially large blow-up in the number of gates. Previously, the best known method yielded exponentially large circuits in the worst case, so our algorithm gives an exponential improvement. As a side result we establish the NP-completeness of several hazard detection problems.


Introduction
We study the problem of hazards in Boolean circuits.This problem naturally occurs in digital circuit design, specifically in the implementation of circuits in hardware (e.g.[Huf57,Cal58]), but is also closely related to questions in logic (e.g.[Kle52,Kör66,Mal14]) and cybersecurity ([TWM + 09, HOI + 12]).Objects are called differently in the different fields; for presentational simplicity, we use the parlance of hardware circuits throughout the paper.
A Boolean circuit is a circuit that uses and-, or-, and not-gates, in the traditional sense of [GJ79, problem MS17], i.e., and and or have fan-in two.The standard approach to studying hardware implementations of Boolean circuits is to use the digital abstraction, in which voltages on wires and at gates are interpreted as either logical 0 or 1.More generally, this approach is suitable for any system in which there is a guarantee that the inputs to the circuit and the outputs of the gates of the circuit can be reliably interpreted in this way (i.e., be identified as the Boolean value matching the gate's truth table).

Kleene Logic and Hazards
Several independent works ( [Got48], [YR64] and references therein) observed that Kleene's classical three-valued strong logic of indeterminacy K 3 [Kle52, §64] captures the issues arising from non-digital inputs.The idea is simple and intuitive.The two-valued Boolean logic is extended by a third value u representing any unknown, uncertain, undefined, transitioning, or otherwise non-binary value.We call both Boolean values stable, while u is called unstable.The behavior of a Boolean gate is then extended as follows.Let B := {0, 1} and T := {0, u, 1}.Given a string x ∈ T k , a resolution y ∈ B k of x is defined as a string that is obtained by replacing each occurrence of u in x by either 0 or 1.If a k-ary gate (with one output) is subjected to inputs x ∈ T k , it outputs b ∈ B iff it outputs b for all resolutions y ∈ B k of x, otherwise it outputs u.In other words, the gate outputs a Boolean value b, if and only if its output does not actually depend on the unstable inputs.This results in the following extended specifications of and, or, and not gates: not 0 u 1 1 u 0 and 0 u 1 0 0 0 0 By induction over the circuit structure, a circuit C with n input gates now computes a function C : T n → T.
Unfortunately, in some cases, the circuit might behave in an undesirable way.Consider a multiplexer circuit (MUX), which for Boolean inputs x, y, s ∈ B outputs x if s = 0 and y if s = 1.A straightforward circuit implementation is shown in Figure 1a.Despite the fact that MUX(1, 1, 0) = MUX(1, 1, 1) = 1, one can verify that in Figure 1a, MUX(1, 1, u) = u.Such behaviour is called a hazard: 1.1 Definition (Hazard).We say that a circuit C on n inputs has a hazard at x ∈ T n iff C(x) = u and there is a Boolean value b ∈ B such that for all resolutions y of x we have C(y) = b.If C has no hazard, it is called hazard-free.
The name hazard-free has different meanings in the literature.Our definition is taken from [DDT78].In Figure 1b we see a hazard-free circuit for the multiplexer function.Note that this circuit uses more gates than the one in Figure 1a.The problem of detecting hazards and constructing circuits that are hazard-free started a large body of literature, see Section 2. The question whether hazards can be avoided in principle was settled by Huffman.1.2 Theorem ( [Huf57]).Every Boolean function has a hazard-free circuit computing it.
He immediately noted that avoiding hazards is potentially expensive [Huf57, p. 54]: "In this example at least, the elimination of hazards required a substantial increase in the number of contacts." Indeed, his result is derived using a clause construction based on the prime implicants of the considered function, which can be exponentially many, see e.g.[CM78].There has been no significant progress on the complexity of hazard-free circuits since Huffmann's work.Accordingly, the main question we study in this paper is: What is the additional cost of making a circuit hazard-free?

Our Contribution
Unconditional lower bounds.Our first main result is that monotone circuit lower bounds directly yield lower bounds on hazard-free circuits.A circuit is monotone if it only uses and-gates and or-gates, but does not use any not-gates.For a Boolean function f , denote (i) by L(f ) its Boolean complexity, i.e., the size of a smallest circuit computing f , (ii) by L u (f ) its hazard-free complexity, i.e., the size of a smallest hazard-free circuit computing f , and (iii), if f is monotone, by L + (f ) its monotone circuit complexity, i.e., the size of a smallest monotone circuit computing f .We show that L u properly extends L + to the domain of all Boolean functions.
We consider this connection particularly striking, because hazard-free circuits are highly desirable in practical applications, whereas monotone circuits may seem like a theoretical curiosity with little immediate applicability.Moreover, to our surprise the construction underlying Theorem 1.3 yields a circuit computing a new directional derivative that we call the hazard derivative1 of the function at x = 0 in direction of y, which equals the function itself if it is monotone (and not constant 1).We consider this observation to be of independent interest, as it provides additional insight into the structure of hazard-free circuits.
We get the following (non-exhaustive) list of immediate corollaries that highlight the importance of Theorem 1.3.
1.4 Corollary (using monotone lower bound from [Raz85]).Define the Boolean permanent function 1.5 Corollary (using monotone lower bound from [Tar88]).There exists a family of functions In particular, there is an exponential separation between L and L u , where the difference does not originate from an artificial exclusion of not gates, but rather from the requirement to avoid hazards.We even obtain separation results for non-monotone functions!1.6 Corollary.Let det n : B n 2 → B be the determinant over the field with 2 elements, that is, Another corollary of Theorem 1.3 separates circuits of linear size from their hazard-free counterparts.

Corollary (using monotone lower bound from [AB87]
).There exists a family of functions for some c > 0, where the number of input variables of As a final example, we state a weaker, but still substantial separation result for Boolean matrix multiplication.
1.8 Corollary (using monotone lower bound from [Pat75,MG76], see also the earlier [Pra74]).Let f : B n×n × B n×n → B n×n be the Boolean matrix multiplication map, i.e., f (X, Y ) = Z with z i,j = n k=1 x i,k ∧y k,j .Every circuit computing f with fewer than 2n 3 −n 2 gates has a hazard.In particular, every circuit that implements Strassen's algorithm [Str69] or any of its later improvements (see e.g.[LG14]) has a hazard.
Since our methods are based on relabeling circuits only, analogous translations can be performed for statements about other circuit complexity measures, for example, the separation result for the circuit depth from [RW92].The previously best lower bounds on the size of hazard-free circuits are restricted to depth 2 circuits (with unbounded fan-in and not counting input negations), see Section 2.
Parametrized upper bound.These hardness results imply that we cannot hope for a general construction of a small hazard-free circuit for f even if L(f ) is small.However, the task becomes easier when restricting to hazards with a limited number of unstable input bits.
1.9 Definition (k-bit hazard).For a natural number k, a circuit C on n inputs has a k-bit hazard at x ∈ T n , iff C has a hazard at x and u appears at most k times in x.
Such a restriction on the number of unstable input bits has been considered in many papers (see e.g.[YR64, ZKK79, Ung95, HOI + 12]), but the state-of-the-art in terms of asymptotic complexity has not improved since Huffman's initial construction [Huf57], which is of size exponential in n, see the discussion of [TY12,TYM14] in [Fri17, Sec."Speculative Computing"].We present a construction with blow-up exponential in k, but polynomial in n.In particular, if k is constant and L(f n ) ∈ poly(n), this is an exponential improvement.
1.10 Corollary.Let C be a circuit with n inputs, |C| gates and depth D. Then there is a circuit with ne k 2k (|C|+6)+O(n 2.71k ) gates and depth D+8k+O(k log n) that computes the same function and has no k-bit hazards.
Further results.We round off the presentation by a number of further results.First, to further support the claim that the theory of hazards in circuits is natural, we prove that it is independent of the set of gates (and, or, not), as long as the set of gates is functionally complete and contains a constant function, see Corollary A.4.Second, it appears unlikely that much more than logarithmically many unstable bits can be handled with only a polynomial circuit size blow-up.
1.11 Theorem.Fix a monotonously weakly increasing sequence of natural numbers k n with log n ≤ k n and set j n := k n / log n.If Boolean circuits deciding j n -CLIQUE on graphs with n vertices require a circuit size of at least n Ω(jn) , then there exists a function f n : B n 2 +kn → B with L(f n ) = poly(n) for which circuits without k n -bit hazards require 2 Ω(kn) many gates to compute.
In particular, if k n = ω(log n) is only slightly superlogarithmic, then Theorem 1.11 provides a function where the circuit size blow-up is superpolynomial if we insist on having no k n -bit hazards.In this case j n is slightly superconstant, which means that "Boolean circuits deciding j n -CLIQUE require size at least n Ω(jn) " is a consequence of a nonuniform version of the exponential time hypothesis (see [LMS11]), i.e., smaller circuits would be a major algorithmic breakthrough.
We remark that, although it has not been done before, deriving conditional lower bounds such as Theorem 1.11 is rather straightforward.In contrast, Theorem 1.3 yields unconditional lower bounds.
Finally, determining whether a circuit has a hazard is NP-complete, even for 1-bit hazards (Theorem 6.5).This matches the fact that the best algorithms for these tasks have exponential running time [Eic65].Interestingly, this also means that if NP = coNP, given a circuit there exists no polynomial-time verifiable certificate of size polynomial in the size of the circuit to prove that the circuit is hazard-free, or even free of 1-bit hazards.

Related work
Multi-valued logic is a very old topic and several three-valued logic definitions exist.In 1938 Kleene defined his strong logic of indeterminacy [Kle38,p. 153], see also his later textbook [Kle52,§64].It can be readily defined by setting u = 1 2 , not x := 1 − x, x and y := min(x, y), and x or y := max(x, y), as it is commonly done in fuzzy logic [PCRF79,Roj96].This happens to model the behavior of physical Boolean gates and can be used to formally define hazards.This was first realized by Goto in [Got49, p. 128], which is the first paper that contains a hazard-free implementation of the multiplexer, see [Got49, Fig. 7•5].The third truth value in circuits was mentioned one year earlier in [Got48].As far as we know, this early Japanese work was unnoticed in the Western world at first.The first structural results on hazards appeared in a seminal paper by Huffman [Huf57], who proved that every Boolean function has a hazard-free circuit.This is also the first paper that observes the apparent circuit size blow-up that occurs when insisting on a hazard-free implementation of a function.Huffman mainly focused on 1-bit hazards, but notes that his methods carry over to general hazards.Interestingly, our Corollary 1.10 shows that for 1-bit hazards the circuit size blow-up is polynomially bounded, while for general hazards we get the strong separation of Corollary 1.5.
The importance of hazard-free circuits is already highlighted for example in the classical textbook [Cal58].Three-valued logic for circuits was introduced by Yoeli and Rinon in [YR64].In 1965, Eichelberger published the influential paper [Eic65], which shows how to use three-valued logic to detect hazards in exponential time.This paper also contains the first lower bound on hazard-free depth 2 circuits: A hazard-free and-or circuit with negations at the inputs must have at least as many gates as its function has prime implicants, which can be an exponentially large number, see e.g.[CM78].Later work on lower bounds was also only concerned with depth 2 circuits, for example [ND92].
Mukaidono [Muk72] was the first to formally define a partial order of definedness, see also [Muk83b,Muk83a], where it is shown that a ternary function is computable by a circuit iff it is monotone under this partial order.In 1981 Marino [Mar81] used a continuity argument to show (in a more general context) that specific ternary functions cannot be implemented, for example there is no circuit that implements the detector function Nowadays the theory of three-valued logic and hazards can be found for example in the textbook [BS95].A fairly recent survey on multi-valued logic and hazards is given in [BEI01].
Recent work models clocked circuits [FFL18].Applying the standard technique of "unrolling" a clocked circuit into a combinational circuit, one sees that the computational power of clocked and unclocked circuits is the same.Moreover, lower and upper bounds translate between the models as expected; using r rounds of computation changes circuit size by a factor of at most r.However, [FFL18] also models a special type of registers, masking registers, that have the property that if they output u when being read in clock cycle r, they output a stable value in all subsequent rounds (until written to again).With these registers, each round of computation enables computing strictly more (ternary) functions.Interestingly, adding masking registers also breaks the relation between hazard-free and monotone complexity: [FFL18] presents a transformation that trades a factor O(k) blow-up in circuit size for eliminating k-bit hazards.In particular, choosing k = n, a linear blowup suffices to construct a hazard-free circuit out of an arbitrary hazardous implementation of a Boolean function.
Seemingly unrelated, in 2009 a cybersecurity paper [TWM + 09] was published that studies information flow on the Boolean gate level.The logic of the information flow happens to be Kleene's logic and thus results transfer in both directions.In particular (using different nomenclature) they design a circuit (see [TWM + 09, Fig. 2]) that computes the Boolean derivative, very similar to our construction in Proposition 4.10.In the 2012 follow-up paper [HOI + 12] the construction of this circuit is monotone (see [HOI + 12, Fig. 1]) which is a key property that we use in our main structural correspondence result Theorem 1.3.
There is an abundance of monotone circuit lower bounds that all translate to hazard-free complexity lower bounds, for example [Raz85, AG87, Yao89, RW92] and references in [GS92] for general problems, but also [Weg82] and references therein for explicit problems, [Pra74, Pat75, MG76] for matrix multiplication and [Blu85] for the Boolean convolution map.This last reference also implies that any implementation of the Fast Fourier Transform to solve Boolean convolution must have hazards.
On a very high level, some parts of our upper bounds construction in Section 5 are reminiscent to [NW96, Prop.6.5] or [Gol11].

Definitions
We study functions F : T n → T that can be implemented by circuits.The Boolean analogue is just the set of all Boolean functions.In our setting this is more subtle.First of all, if a circuit gets a Boolean input, then by the definition of the gates it also outputs a Boolean value.Thus every function that is computed by circuits preserves stable values, i.e., yields a Boolean value on a Boolean input.Now we equip T with a partial order such that u is the least element and 0 and 1 are incomparable elements greater than u, see [Muk72].We extend this order to T n in the usual way.For tuples x, y ∈ T n the statement x y means that y is obtained from x by replacing some unstable values with stable ones.Since the gates and, or, not are monotone with respect to , every function F computed by a circuit must be monotone with respect to .It turns out that these two properties capture precisely what can be computed: preserves stable values and is monotone with respect to .
A function F : T n → T that preserves stable values and is monotone with respect to shall be called a natural function.A function Observe that any natural extension F of a Boolean function f must satisfy the following.If y and y ′ are resolutions of x (in particular x y and x y ′ ) such that F (y) = F (y ′ ), it must hold that F (y) = 0 and F (y ′ ) = 1 (or vice versa), due to preservation of stable values.Bymonotonicity, this necessitates that F (x) = u, the only value "smaller" than both 0 and 1.Thus, one cannot hope for a stable output of a circuit if x has two resolutions with different outputs.In contrast, if all resolutions of x produce the same output, we can require a stable output for x, i.e., that a circuit computing F is hazard-free.
3.2 Definition.For a Boolean function f : B n → B, define its hazard-free extension f : T n → T as follows: Hazard-free extensions are natural functions and are exactly those functions that are computed by hazard-free circuits, as can be seen for example by Theorem 1.2.Equivalently, f is the unique extension of f that is monotone and maximal with respect to .
We remark that later on we will also use the usual order ≤ on B and B n .We stress that the term monotone Boolean function refers to functions B n → B monotone with respect to ≤.

Lower bounds on the size of hazard-free circuits
In this section, we prove that L u (f ) = L + (f ) for monotone functions f , from which Corollaries 1.4 to 1.8 follow.Our first step is to show that L u (f ) ≤ L + (f ), which is straightforward.

Conditional lower bound
In this section we prove Theorem 1.11, which is a direct consequence of the following proposition and noting that n Ω(kn/ log n) = 2 Ω(kn) .
4.1 Proposition.Fix a monotonously weakly increasing sequence of natural numbers j n with j n ≤ n.There is a function f n : B n 2 +jn log n → B with L(f n ) = poly(n) and the following property: if f n can be computed by circuits of size L n that are free of (j n log n)-bit hazards, then there are Boolean circuits of size 2L n that decide j n -CLIQUE.
Proof.The function f n gets as input the adjacency matrix of a graph G on n vertices and a list ℓ of j n vertex indices, each encoded in binary with log n many bits: 1 if ℓ encodes a list of j n vertices that form a j n -clique in G, 0 otherwise.
Clearly L(f n ) = poly(n).Let C compute f n and have no (j n log n)-hazards.By the definition of (j n log n)-hazards, it follows that C(G, u jn log n ) = 0 iff G contains a j n -clique.From C we construct a circuit C ′ that decides j n -CLIQUE as follows.We double each gate and each wire.Additionally, after each doubled not-gate we twist the two wires so that this not construction sends (0, 1) to (0, 1) instead of to (1, 0).Stable inputs to C are doubled, whereas the input u is encoded as the Boolean pair (0, 1).It is easy to see that the resulting circuit simulates C. Our circuit C ′ should have n 2 inputs and should satisfy C ′ (G) = 1 iff C(G, u jn log n ) = 0, thus we fix the j n log n rightmost input pairs to constants (0, 1) to obtain C ′ .From the two output gates, we treat the right output gate as the output of C ′ , while dismissing the left output gate.
Monotone circuits are hazard-free 4.2 Lemma.Monotone circuits are hazard-free.In particular, for monotone Boolean functions f we have Proof.We prove the claim by induction over the number of computation gates in the circuit.
Trivially, a monotone circuit without computation gates is hazard-free, as it merely forwards some input to the output.For the induction step, let C be a monotone circuit computing a function F : T n → T such that the gate computing the output of C receives as inputs the outputs of two hazard-free monotone subcircuits C 1 and C 2 .We denote by F 1 and F 2 the natural functions computed by C 1 and C 2 , respectively.The gate computing the output of C can be an and-or an or-gate and we will treat both cases in parallel.Let x ∈ T n be arbitrary with the property that F (y) = 1 for all resolutions y of x.Denote by y 0 the resolution of x in which all u's are replaced by 0. The fact that F (y 0 ) = 1 implies that F 1 (y 0 ) = F 2 (y 0 ) = 1 (F 1 (y 0 ) = 1 or F 2 (y 0 ) = 1).By monotonicity of F 1 and F 2 , this extends from y 0 to all resolutions y of x, because y ≥ y 0 and thus F (y) ≥ F (y 0 ) = 1.Since C 1 and C 2 are hazard-free by the induction hypothesis, we have ).As basic gates are hazard-free, we conclude that The case that F (y) = 0 for all resolutions y of some x ∈ T n is analogous, where y 0 is replaced by y 1 , the resolution of x in which all u's are replaced by 1.
The following sections show a much deeper relationship between monotone and hazard-free circuits.A key concept is the derivative, which we will discuss next.

Derivatives of natural functions
Let F : T n → T be a natural function and x ∈ B n be a stable input.If x x, that is, if x is obtained from x by replacing stable bits by u, then F (x) F (x).This means that there are two possibilities for F (x) -either F (x) = F (x) or F (x) = u.
We can encode in one Boolean function the information about how the value of F changes from F (x) to u when the bits of the input change from stable to unstable.It is reminiscent of the idea of the derivative in analysis or the Boolean derivative, which also show how the value of the function changes when the input changes.To make the connection more apparent, we introduce a notation for replacing stable bits by unstable ones: if x, y ∈ B n , then x + uy denotes the tuple that is obtained from x by changing the values to u in all positions in which y has a 1, and keeping the other values unchanged.Formally, This notation is consistent with interpreting the addition and multiplication on T as the hazard-free extensions of the usual addition modulo 2 and multiplication on B (xor and and).
Any tuple x x can be presented as x + uy for some y ∈ B n .As we have seen, F (x + uy) is either F (x) or u.This condition can also be written as F (x + uy) = F (x) + u∆ for some ∆ ∈ B.
4.3 Definition.Let F : T n → T be a natural function.The hazard derivative (or just derivative for short) of F is the Boolean function dF : In other words, For a Boolean function f we use the shorthand notation df := df .
Consider for example the disjunction or.The values of (x 1 + uy 1 )or(x 2 + uy 2 ) are as follows: Similarly, we find dnot(x; y) = y, (4.5b) dand(x 1 , x 2 ; y 1 , y 2 ) = x 1 y 2 ∨ x 2 y 1 ∨ y 1 y 2 , (4.5c) dxor(x 1 , x 2 ; y 1 , y 2 ) = y 1 ∨ y 2 .(4.5d) Caveat: Since natural functions F are exactly those ternary functions defined by circuits, we can obtain dF from the ternary evaluations of any circuit computing F .For Boolean functions f it is more natural to think of df as a property of the function f , because the correspondence to circuits is not as close: we can obtain df from the ternary evaluations of any hazard-free circuit computing f on Boolean inputs.
In general, we can find the derivative of a Boolean function as follows: 4.6 Lemma.For f : B n → B, we have df (x; y) = z≤y [f (x) + f (x + z)].In particular, if f (0) = 0, then df (0; y) = z≤y f (z).
Proof.Resolutions of x + uy coincide with x at positions where y has a 0 and have arbitrary stable bits at positions where y has a 1.Therefore, each resolution of x + uy can be presented as x + z for some z such that z i = 0 whenever y i = 0, that is, z ≤ y.Hence, the set of all resolutions of x + uy is S(x + uy) The derivative df (x; y) = 1 if and only if f (x + uy) = u.By definition of hazard-freeness, this happens when f takes both values 0 and 1 on S(x + uy), in other words, when the f (x + z) = f (x) for some z ∈ S(x+uy).The disjunction z≤y [f (z)+f (x+z)] represents exactly this statement.
As a corollary, we obtain a surprisingly close relation between monotone Boolean functions and their derivatives.For a natural function F and any fixed x ∈ B n , let dF (x; .)denote the Boolean function that maps y ∈ B n to dF (x; y), and define the shorthand df (x; .):= df(x; .)for a Boolean function f .4.7 Corollary.Suppose that f : B n → B is monotone with f (0) = 0. Then df (0, .)= f .4.8 Lemma.For natural F : T n → T and fixed x ∈ B n , dF (x; .) is a monotone Boolean function.
The following statement is the analogue of the chain rule in analysis.
and the claim follows with another application of (4.4).

Using monotone circuits to compute derivatives
In this section we show how to efficiently compute derivatives by transforming circuits to monotone circuits.Our main tool is the chain rule (Lemma 4.9).
For a circuit C and a gate β of C, let C β denote the natural function computed at the gate β.
4.10 Proposition.From a circuit C we can construct a circuit C ′ by independently replacing each gate β on t inputs α 1 , . . ., α t (0 ≤ t ≤ 2) by a subcircuit on 2t inputs α 1 , . . ., α t , α ′ 1 , . . ., α ′ t and two output gates β, β ′ (the wiring between these subcircuits in C ′ is the same as the wiring between the gates in C, but in C ′ we have two parallel wires for each wire in C) such that C ′ β (x, y) = C β (x) and C ′ β ′ (x, y) = dC β (x; y) for Boolean inputs x, y ∈ B n .
Proof.To construct C ′ , we extend C with new gates.For each gate β in C, we add a new gate β ′ .If β is an input gate x i , then β ′ is the input gate y i .If β is a constant gate, then β ′ is the constant-0 gate.The most interesting case is when β is a gate implementing a function ϕ ∈ {and, or, not} with incoming edges from gates α 1 , . . ., α t (in our definition of the circuit, the arity t is 1 or 2, but the construction works without modification in the general case).In this case, we add to β a subcircuit which takes α 1 , . . ., α t and their counterparts α ′ 1 , . . ., α ′ t as inputs and β ′ as its output gate, which computes For the sake of concreteness, for the gate types not, and, or according to (4.5) this construction is depicted in Figure 2.
and and and and or or or not not and and and or or Clearly C ′ β (x, y) = C β (x).By induction on the structure of the circuit, we now prove that C ′ β ′ (x, y) = dC β (x; y).In the base case, if β is an input or constant gate, the claim is obvious.If β is a gate of type ϕ ∈ {and, or, not} with incoming edges from α 1 , . . ., α t , then By the chain rule, dC β (x; y) = dϕ(C α 1 (x), . . ., C αt (x); dC α 1 (x; y), . . ., dC αt (x; y)).
Note that this construction can be seen as simulation of the behavior of the circuit C on the input x + uy: the value computed at the gate β on this input is C β (x) + u dC β (x; y), and in C ′ the gates β and β ′ compute the two parts of this expression separately.
By fixing the first half of the input bits in C ′ we now establish the link to monotone complexity.In the following theorem the case x = 0 will be of particular interest.
4.11 Theorem.For f : B n → B and fixed x ∈ B n , it holds that L + (df (x, .))≤ L u (f ).
Proof.Let C be a hazard-free circuit for f of minimal size and let x ∈ B n be fixed.We start by constructing the circuit C ′ from Proposition 4.10 and for each gate in C we remember the corresponding subcircuit in C ′ .For each subcircuit we call the gates α i the primary inputs and the α ′ i the secondary inputs.From C ′ we now construct a monotone circuit C x on n inputs that computes df (x; .)as follows.We fix the leftmost n input bits x ∈ B n in C ′ .This assigns a Boolean value C ′ α (x) = C α (x) to each primary input α in each constructed subcircuit.Each constructed subcircuit's secondary output β ′ now computes some Boolean function in the secondary inputs α ′ i .If the values at the secondary inputs are y), then the value at the secondary output is ψ(u 1 , . . ., u t ) = dϕ(C α 1 (x), . . ., C αt (x); u 1 , . . ., u t ).Lemma 4.8 implies that ψ is monotone (which can alternatively be seen directly from Figure 2, where fixing all primary inputs makes all not gates superfluous).However, the only monotone functions on at most two input bits are the identity (on one input), and, or, and the constants.Thus, we can replace each subcircuit in C ′ by (at most) one monotone gate, yielding the desired monotone circuit C x that has at most as many gates as C and outputs df (x; .)= d f (x; .)= dC(x; .)= C ′ (.), where the second equality holds because C is hazard-free.
We now use this construction to prove Theorem 1.3.
Proof of Theorem 1.3.The claim is trivial for the constant 1 function.Note that this is the only case of a monotone function that has f (0) = 0. Hence assume that f is monotone with f (0) = 0.By Lemma 4.2, we have that L u (f ) ≤ L + (f ).The other direction can be seen via L + (f ) Cor. 4.7 = Theorem 1.3 shows that the hazard-free complexity L u can be seen as an extension of monotone complexity L + to general Boolean functions.Thus, known results about the gap between general and monotone complexity transfer directly to hazard-free complexity.

Unconditional lower bounds
Corollaries 1.4, 1.5, and 1.8 are immediate applications of Theorem 1.3.Interestingly, however, we can also derive results on non-monotone functions, which is illustrated by Corollary 1.6.
Proof of Corollary 1.6.The fact that the determinant can be computed efficiently is well known.
Consider the derivative d det n (0; y) = z≤y det n (z) (Lemma 4.6).If there exists a permutation π ∈ S n such that all y iπ(i) are 1, then, replacing all the other entries with 0 we get a matrix z ≤ y with det n (z) = 1, and d det n (0; y) = 1.If there is no such permutation, then all the summands in the definition of det n (y) are 0, and this is also true for all matrices z ≤ y.In this case, d det n (0; y) = 0. Combining both cases, we get that d det n (0; .)equals the Boolean permanent function f n from Corollary 1.4.The lower bound then follows from [Raz85] and Theorem 4.11 (as in Corollary 1.4).
We can combine this technique with the ideas from the proof of Theorem 1.11 to show even stronger separation results, exhibiting a family of functions for which the complexity of Boolean circuits is linear, yet the complexity of hazard-free circuits grows almost as fast as in Corollary 1.5.
4.12 Lemma.Let f : B n → B be a monotone Boolean function with f (0) = 0 and g : Proof.Using Lemma 4.6, we obtain dg(0, 0; x, 1) = which means that the circuit for f can be obtained from the circuit for dg(0; .)by substituting 1 for some inputs.The statement then follows from Theorem 4.11.
Proof of Corollary 1.7.We use the NP-complete family POLY(q, s) from the paper of Alon and Boppana [AB87].Let GF(q) denote a finite field with q elements.We encode subsets E ⊂ GF(q) 2 using q 2 Boolean variables in a straightforward way.The function POLY(q, s) maps E ⊂ GF(q) 2 to 1 iff there exists a polynomial p of degree at most s over GF(q) such that (a, p(a)) ∈ E for every a ∈ GF(q).
Alon and Boppana proved that for s ≤ 1 2 q ln q the monotone complexity of this function is at least q cs for some constant c.For simplicity, we choose q = 2 n and s = ⌊ 1 4 q log q ⌋ = ⌊ 2 n/2 4 √ n ⌋.In this case, L + (POLY(q, s)) ≥ 2 cq 1/2 √ log q .We define f n as the verifier for this instance of POLY.The function f n takes q 2 + sq = O(q 2 ) variables.The first q 2 inputs encode a subset E ⊂ GF(q) 2 , and the second sn inputs encode coefficients of the polynomial p of degree at most s over GF(q), each coefficient using n bits.The value f n (E, p) = 1 iff (a, p(a)) ∈ E for all a ∈ GF(q).To implement the function f n , for each element a ∈ GF(q) we compute the value p(a) using finite field arithmetic.Each such computation requires O(sn 2 ) gates.Then we use p(a) as a selector in a multiplexer to compute the value indicating whether (a, p(a)) is contained in E, choosing it from all the bits of the input E corresponding to pairs of form (a, b).This multiplexer requires additional O(q) gates for each element a ∈ GF(q).The result is the conjunction of the computed values for all a ∈ GF(q).The total size of the circuit O(q 2 + qsn 2 + q) is linear in the size of the input.
The lower bound on the hazard-free complexity follows from the Alon-Boppana lower bound and Lemma 4.12.
We fix some reasonable binary encoding of circuits and define the following languages: A circuit C is called satisfiable if there is a Boolean input for which C outputs 1. Otherwise C is called unsatisfiable.We define a promise problem UnsatFixedHazard: Given an unsatisfiable circuit C and i ∈ [n], accept if C has a fixed hazard at position i.
Proof.We reduce from circuit satisfiability as follows: To decide if a circuit C on n inputs is satisfiable, construct a circuit C ′ = C ∧ (x n+1 ∧ ¬x n+1 ) where x n+1 is a new variable.Note that C ′ is unsatisfiable by construction.We claim that C is satisfiable if and only if C ′ has a fixed hazard at position n + 1. "⇒": Let a be an assignment that satisfies C. Then C ′ evaluates to u on input (a, u) and hence has a fixed hazard at position n + 1.
"⇐": If C is unsatisfiable, then C ′ (a, y) = 0 for all a ∈ B n , y ∈ T, and hence does not have a fixed hazard at position n + 1.
Proof.Since UnsatFixedHazard is NP-hard, the more general problem FixedHazard is also NP-hard.We show that deciding the languages OneBitHazard and Hazard is at least as hard as solving UnsatFixedHazard.Let C(x 1 , . . ., x n ) be an unsatisfiable circuit.Construct the circuit C ′ = C(x 1 , . . ., x n ) ⊕ x 2 ⊕ • • • ⊕ x n .We claim that C ′ has a hazard if and only if C has a fixed hazard at position x 1 ."⇒": Suppose C ′ has a hazard.Note that since C computes the constant 0 function, If any of the input variables x 2 , . . ., x n has value u, then C ′ correctly outputs u.Thus, C ′ can have a hazard only on inputs a ∈ T n that have exactly one u occuring in the input position 1.In this case C(a) = u because otherwise C ′ (a) would be a Boolean value.Hence C has a fixed hazard at position 1.
"⇐": If C has a fixed hazard at position 1, then by definition, C outputs u when x 1 = u while all other inputs are stable.In this case, C ′ also outputs u on this input.This is a hazard, since the Boolean function computed by C ′ does not depend on x 1 .
Thus, Hazard is NP-hard.Note that in the first part of this proof we actually proved that for the circuit C ′ all hazards are 1-bit hazards.So, the language OneBitHazard is also NP-hard.
6.4 Lemma.The languages FixedHazard, OneBitHazard and Hazard are in NP.
Proof.For FixedHazard and OneBitHazard we can take the input on which the circuit has a hazard as a witness.The verifier then has to check that the circuit actually outputs u on this input and that the outputs on the two stable inputs obtained by replacing u by 0 and 1 match.
For Hazard, the verifier cannot check the definition directly, since the number of resolutions can be exponential.However, if a circuit C has a hazard, then there exists an input x ∈ T n with C(x) = u such that on the inputs x (0) and x (1) that are obtained from x by replacing the leftmost u by 0 and 1 respectively the circuit C outputs the same stable value b.This can be seen as follows.Let H C ⊂ T n be the set of all inputs on which C has a hazard.Any element x that is maximal in H C with respect to satisfies the requirement: since x is a hazard, C(x) = u and the output of C on all resolutions of x is the same stable value b.Thus the output of C on all resolutions of x (0) and of x (1) is b.Since x is maximal, both x (0) and x (1) do not lie in H C , which implies C(x (0) ) = C(x (1) ) = b.Such x with C(x) = u and C(x (0) ) = C(x (1) ) = b can be used as a witness for Hazard.
From Lemma 6.3 and Lemma 6.4, we conclude: 6.5 Theorem.The languages FixedHazard, OneBitHazard and Hazard are NP-complete.

Future directions
Hazard-free complexity is an interesting subject that arises in practice when constructing physical circuits.Theorem 1.3 sends the strong message that hazard-free complexity is of interest even without its application in mind.As a theoretical model of computation, hazard-free circuits are at least as interesting as monotone circuits.Section 5 hints towards the fact that there is a rich intermediate landscape of k-hazard free circuits to be analyzed for different ranges of k.This can potentially be very illuminating for our understanding of the nature and limits of efficient computation in general.
Given the lower bound corollaries to Theorem 1.3 and the circuit construction in Corollary 1.10, one dangling open question is the fixed parameter tractability of k-hazard-free circuits: Does there exist a function ϕ such that for all sequences of Boolean functions f n : B n → B there exist khazard-free circuits of size ϕ(k) • poly(n)?
A further direction of interest is to understand the power of masking registers [FFL18], both in terms of computational power and efficiency.It is neither known precisely which functions can be computed by a clocked circuits within r rounds, and it is not clear whether a factor Ω(k) overhead for computing the closure with masking registers is necessary.

A Circuits with different basic gates
In the main part of this paper we used circuits with and-, or-and not-gates, because this is one of the standard models in circuit complexity.But we have also already seen that the circuit transformations we use for proving lower bounds rely only on the general construction of the derivative and can be performed on circuits with arbitrary gates, not just and-, or-, and not-gates.In this appendix we show that any other functionally complete set (in the sense of e.g.[End01]) can be used to give an equivalent theory of hazard-free complexity and natural functions, see the upcoming Corollary A.4.A priori it is not obvious that every function can be implemented by a hazard-free circuit over some set of gates, even if the set of gates is functionally complete in the Boolean sense.We prove that everything works properly if we allow constant input gates.This subtlety is unavoidable, since any nontrivial natural function outputs u if all inputs are u, so any circuit without constant gates also has this property.Therefore, the constant function is not computable by hazard-free circuits without the use of constant gates.
[Brz99, Theorem 2] shows that every natural function can be implemented over the set of functions Φ = {and, or, not, 1}.Using the fact that a hazard-free implementation of or can be achieved via the standard De Morgan implementation x or y = not((not x) and (not y)), it follows that every natural function can be implemented over the set of functions {and, not, 1}. (A.1) Otherwise f is called nonlinear.The composition of linear functions is linear, but not all Boolean functions are linear.Thus every functionally complete set must contain a nonlinear function.
Variants of the following lemma are often used as a part of proof of Post's theorem characterizing functionally complete systems.
A.2 Lemma.Let f : B n → B be a nonlinear Boolean function.Then n ≥ 2.Moreover, by substituting constants for some input variables of f , we can obtain a function of 2 variables of the form Proof.Using the fact that over the field F 2 with two elements we have x i and x j = x i • x j and not x i = x i ⊕ 1, we can represent f as a polynomial over F 2 .Using that (x i ) k = x i for k ≥ 1, we can represent f in its algebraic normal form where each a I ∈ B. We call I a monomial and call |I| its degree.Since f is nonlinear, there is at least one monomial of degree at least 2 with nonzero coefficient a I .Thus we proved n ≥ 2. Among monomials of degree at least 2, choose one monomial of minimal degree and set all the variables not contained in this monomial to 0. Without loss of generality, the chosen monomial is x 1 • • • x t , t ≥ 2. The resulting function has the form x 1 . . .x t ⊕ a 1 x 1 ⊕ • • • ⊕ a t x t ⊕ a 0 .Setting all variables except x 1 and x 2 to 1, we obtain x 1 x 2 ⊕a 1 x 1 ⊕a 2 x 2 ⊕a ′ 0 , or (x 1 ⊕c 1 )(x 2 ⊕c 2 )⊕c 0 where c 1 = a 2 , c 2 = a 1 and c 0 = a ′ 0 ⊕ a 1 a 2 .
A.3 Theorem.Let Φ be a set of natural functions such that their restrictions to B form a functionally complete set.Suppose Φ contains an extension of a nonlinear Boolean function that is free of 1-bit hazards.Then every natural function can be computed by a circuit over Φ using the constant 1.
Proof.In the light of (A.1), it is enough to show that hazard-free circuits for not and and can be implemented over Φ.The statement is trivial for the negation: since not has only one natural extension, any circuit that computes it is automatically hazard-free.Using not, we can obtain the constant 0 from the constant 1.By Lemma A.2, we obtain from the 1-hazard-free nonlinear function contained in Φ a function of the form (x 1 ⊕ c 1 )(x 2 ⊕ c 2 ) ⊕ c 0 by substituting constants 0 and 1 into this nonlinear function.Constant substitution does not introduce hazards.Since not x = x ⊕ 1, we can transform the circuit C computing (x 1 ⊕ c 1 )(x 2 ⊕ c 2 ) ⊕ c 0 to a circuit C ′ computing x 1 x 2 by placing not on input x i if c i = 1 and on the output if c 0 = 1.In other words, C ′ (x 1 , x 2 ) = C(x 1 ⊕ c 1 , x 2 ⊕ c 2 ) ⊕ c 0 .
Let us check that C ′ is hazard-free.The circuit C ′ is computing the conjunction and thus can have hazards only on two inputs: (0, u) and (u, 0).If C ′ (0, u) = u, then C(c 1 , u) = u.This is a 1-bit hazard, since (c 1 ⊕ c 1 )(x ⊕ c 2 ) ⊕ c 0 = c 0 for all x ∈ B. The other case is analogous.
A.4 Corollary.Given a functionally complete set of Boolean functions, let Φ be the set of their hazard-free extensions.Every natural function can be computed by a circuit over Φ using the constant 1.
Proof.Since a functionally complete set cannot only consist of linear functions, at least one function must be nonlinear.A hazard-free function in particular does not have a 1-hazard.Thus Theorem A.3 applies.
B Improved upper-bounds for k-bit hazard-free circuits In this section, we show how to improve the analysis in the proof of Theorem 5.3 to show an improved upper-bound of O(t 2.46 ) on the number of majority gates in the circuit.This yields the bound L T (f ) ≤ ne k 2k (L(f ) + 6) + O(t 2.46 ) on the overall size of the circuit.The depth of the circuit is unchanged.
The majority tree in the proof of Theorem 5.3 is constructed by dividing the problem denoted by the set T of size t into three subproblems denoted by subsets T A , T B , and T C each of size 2t/3.The improved upper-bound is obtained by analysing these recursive subproblems at larger depths and observing that many of them coincide.For example, the number of distinct recursive subproblems at depth three is only 25 instead of 27 because ((T A ) A ) A = ((T C ) A ) A (Both these sets are the first 8t/27 elements of T ) and ((T B ) B ) B = ((T C ) B ) B (Both these sets are the last 8t/27 elements of T ).This yields the recurrence F (t) ≤ 25F (8t/27) + O(1) = O(t 2.65 ) on the number of majority gates.A similar analysis of the recursive subproblems using a computer program shows that there are only 410040 distinct recursive subproblems at depth 13 yielding the recurrence F (t) ≤ 410040F ((2/3) 13 t) + O(1) = O(t 2.46 ) on the number of majority gates.The improved upper-bound follows.
After this paper got accepted, a new construction of circuits that are free of k-bit hazards was discovered that uses only ne k 2k (L(f ) + 6) + O(t 2 ) gates, thus improving further on Corollary 1.10.This new construction is sufficiently different from the one used in Theorem 5.3 and we plan to develop it further in an extended version of this work.

Figure 1 :
Figure1: Two circuits that implement the same Boolean multiplexer function.One has a hazard, the other one is hazard-free.

Figure 2 :
Figure 2: Gates in C get replaced by subcircuits in the construction of C ′ .