<jupyter_start><jupyter_text>NOT Gate<jupyter_code># NOT gate = X gate
q = QuantumRegister(1)
c = ClassicalRegister(1)
qc = QuantumCircuit(q, c)
qc.x(q)
qc.measure(q, c)
qc.draw()<jupyter_output><empty_output><jupyter_text>AND Gate<jupyter_code># AND gate = CCX gate
qc = QuantumCircuit(3)
qc.ccx(0, 1, 2)
qc.measure_all()
qc.draw()<jupyter_output><empty_output><jupyter_text>OR Gate<jupyter_code># OR gate = CX (to check first qubit) + CX (to check second qubit)  + CCX (to check both qubits together)
qc = QuantumCircuit(3)
qc.cx(0, 2)
qc.cx(1, 2)
qc.ccx(0, 1, 2)
qc.measure_all()
qc.draw()<jupyter_output><empty_output><jupyter_text>XOR Gate<jupyter_code># XOR gate = OR + NOT = CX + CX (smart!)
qc = QuantumCircuit(3)
qc.cx(0, 2)
qc.cx(1, 2)
qc.measure_all()
qc.draw()<jupyter_output><empty_output><jupyter_text>NAND Gate<jupyter_code># NAND gate = AND + NOT = CCX gate + NOT gate
qc = QuantumCircuit(3)
qc.ccx(0, 1, 2)
qc.x(2)
qc.measure_all()
qc.draw()<jupyter_output><empty_output><jupyter_text>NOR Gate<jupyter_code># NOR gate = OR + NOT = CX + CX + CCX + NOT gate
qc = QuantumCircuit(3)
qc.cx(0, 2)
qc.cx(1, 2)
qc.ccx(0, 1, 2)
qc.x(2)
qc.measure_all()
qc.draw()<jupyter_output><empty_output><jupyter_text>Half Adder<jupyter_code># Half Adder = Sum + Carry = XOR + AND
qc = QuantumCircuit(4, 2)

# XOR (Sum)
qc.cx(0, 2)
qc.cx(1, 2)

# AND (Carry)
qc.ccx(0, 1, 3)

qc.measure([2, 3], [0, 1])
qc.draw()<jupyter_output><empty_output><jupyter_text>Full Adder<jupyter_code># Full Adder 
# Full adder using 2 half-adders!

qc = QuantumCircuit(8, 2)

# Half Adder 1 (A and B)
qc.cx(0, 3)    # 3 is sum
qc.cx(1, 3)
qc.ccx(0, 1, 4)    # 4 is carry

qc.barrier()

# Half Adder 1 (3 sum and X)
qc.cx(1, 5)    # 5 is sum and final sum
qc.cx(2, 5)
qc.ccx(1, 2, 6)    # 6 is carry

qc.barrier()

# OR on carry (4 and 6)
qc.cx(4, 7)
qc.cx(6, 7)
qc.ccx(4, 6, 7)    # 7 is final carry

qc.barrier()
qc.measure([5, 7], [0, 1])
qc.draw('mpl')
# Full Adder traditional

qc = QuantumCircuit(8, 2)

# XOR (A and B)
qc.cx(0, 3)
qc.cx(1, 3)

qc.barrier()

# XOR (3 and X)
qc.cx(2, 4)
qc.cx(3, 4)    # 4 is final sum

qc.barrier()

# AND (A and B)
qc.ccx(0, 1, 5)

# AND (3 and X)
qc.ccx(2, 3, 6)

qc.barrier()

# OR (5 and 6)
qc.cx(5, 7)
qc.cx(6, 7)
qc.ccx(5, 6, 7)    # 7 is final carry

qc.barrier()

qc.measure([4, 7], [0, 1])
qc.draw('mpl')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18193384223918574, 'fraction_numerical': 0.04961832061068702, 'mean_word_length': 4.373576309794989, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '538022', 'license': 'Apache-2.0', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1137, 'n_words': 282, 'path': 'qiskit-ibm/qcircuit-classical_gates.ipynb', 'repo_name': 'SaashaJoshi/quantum-computing', 'size': '2358'}