We want to find smallest circuits that compute the parity and majority functions
ID: 3605957 • Letter: W
Question
We want to find smallest circuits that compute the parity and majority functions. For this problem we will consider circuits that use AND gates, OR gates, and NOT gates. The size of the circuit is the number of gates in graph/circuit. Write the following functions using Python API for Z3:
(a) def minSizeParity(n): Returns the minimal size that a circuit must have to compute the parity of n bits.
(b) def minSizeMajority(n): Returns the minimal size that a circuit must have to compute thee majority of n bits. Majority of n bits is 1 if strictly more than n/2 bits are 1.
Hint 1: Without loss of generality, you can constrain the connections in the circuit so that a gate is never connected to a gate with smaller index, only to gates with strictly larger indices. This way you do not need to write constraints ensuring that the circuit is acyclic.
Hint 2: Note that AND and OR gates in this problem have no constraints on how many incoming or outgoing connections they can have.
Hint 3: For large n it might take prohibitively long to find a minimal circuit, but do try to make it work for n = 1, 2, 3.
Explanation / Answer
# Python code to find smallest K-digit
# number divisible by X
def answer(X, K):
# Computing MAX
MIN = pow(10, K-1)
if(MIN%X == 0):
return (MIN)
else:
return ((MIN + X) - ((MIN + X) % X))
X = 83;
K = 5;
output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.