Simulating the classical log-depth, AND, OR, NOT circuits for threshold gates
As Figure 1 shows, the input for the threshold gate is a 0-1 vector of A=(a1, a2,...,an) and a threshold value k, the output is a 0/1 value, which is:
The value of the above threshold gate Ta1, a2,..,ank can be evaluated in the following recursive way:
Thus, we can construct a circuit with classical AND and OR gates to simulate a threshold gate. It is easy to see that the depth of this evaluation is log(n). We use the above algorithm to implement our program.
In this implementation, we use three classes. A CAND class is used for defining and operating a classical AND gate. Similarly, a COR class is created for OR gate. Finally, a CThreshold class is used for describing a threshold gate. We first construct a classical circuit consist of AND and OR gates for threshold gate. Then given input bits and a threshold value m, we evaluate the circuit and output the result.