from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute, Aer, IBMQ
from qiskit.compiler import transpile, assemble
from qiskit.tools.jupyter import *
from qiskit.visualization import *

backend = Aer.get_backend("qasm_simulator")

"""implelement gates from arxiv.org quant-ph/0410184, A new quantum ripple-carry addition circuit"""

def MAJ(circuit, a, b, out):
    """Put out bit into state that majority of a b and out were in"""
    circuit.cx(out, a)
    circuit.cx(out, b)
    circuit.ccx(a,b, out)
    
def UMA(circuit, u, m, a):
    """UnMajority and Add"""
    circuit.x(m)
    circuit.cx(u,m)
    circuit.ccx(u,m,a)
    circuit.x(m)
    circuit.cx(a,u)
    circuit.cx(a,m)

a = QuantumRegister(6, 'a')
b = QuantumRegister(6, 'b')
c = QuantumRegister(1, 'c')
y = QuantumRegister(1, 'z')
y = ClassicalRegister(4, 'y')
qc = QuantumCircuit(m,n,c,y)

MAJ(qc, m[0], n[1], c[0])

qc.draw()

