Two- and three-qubit quantum OR in Qiskit

In the previous chapter, we learned about the two- and three-qubit quantum OR functions. This subsection gives their implementations in Qiskit.

The circuit for the two-qubit quantum OR was given in the last chapter and is the following:

Here, we can see that it can be implemented in Qiskit as the following:

def quantumor_2(qr,qc,w,x,t1):
qc.x(qr[w])
qc.x(qr[x])
qc.x(qr[t1])
qc.ccx(qr[w],qr[x],qr[t1])
qc.x(qr[w])
qc.x(qr[x])
return t1

The three-qubit quantum OR takes a similar form to the quantum AND function, and combines two of the two-qubit quantum ORs with the help of a temporary register. This takes advantage of the fact that a ∨ b ∨ c = a ∨ b ∨ c, meaning that we can first compute a ∨ b, put the result in the temporary register t1, and then compute t1 ∨ c to get the final result, which we store in the temporary register t2:

def quantumor_3(qr,qc,w,x,y,t1,t2):
qc.x(qr[w])
qc.x(qr[x])
qc.x(qr[t1])
qc.ccx(qr[w],qr[x],qr[t1])
qc.x(qr[w])
qc.x(qr[x])

qc.x(qr[y])
qc.x(qr[t1])
qc.x(qr[t2])
qc.ccx(qr[y],qr[t1],qr[t2])
qc.x(qr[y])
qc.x(qr[t1])
return t2