<jupyter_start><jupyter_text>Quantum Half Adder  Classical version1 XOR gate + 1 AND gate<jupyter_code>import SchemDraw as schemdraw
import SchemDraw.logic as logic
d = schemdraw.Drawing(unit=.5)
S = d.add(logic.XOR2, rgtlabel='$S$')
A = d.add(logic.DOT, xy=S.in1)
d.add(logic.LINE, d='left', l=d.unit*2, lftlabel='$A$')
d.add(logic.LINE, d='left', xy=S.in2)
B = d.add(logic.DOT)
d.add(logic.LINE, d='left', lftlabel='$B$')

d.add(logic.LINE, d='down', xy=A.start, l=d.unit*3)
C = d.add(logic.AND2, d='right', anchor='in1', rgtlabel='$C$')
d.add(logic.LINE, d='down', xy=B.start, toy=C.in2)
d.add(logic.LINE, to=C.in2)
d.draw()<jupyter_output><empty_output><jupyter_text>Quantum VersionXOR = 2 CX gatesAND = 1 CCX gate<jupyter_code>from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister

def build_curcuit(input1, input2):

    qc = QuantumCircuit(
        QuantumRegister(1, name="input1"),
        QuantumRegister(1, name="input2"),
        QuantumRegister(1, name="xor"),
        QuantumRegister(1, name="and"),
        ClassicalRegister(1, name="sum"),
        ClassicalRegister(1, name="carry")
    )

    # init values, default 1+1
    if input1:
        qc.x(0)
    if input2:
        qc.x(1)
    qc.barrier()

    # xor gate
    qc.cx(0,2)
    qc.cx(1,2)
    qc.barrier()

    # and gate
    qc.ccx(0,1,3)
    qc.barrier()

    # measure
    qc.measure([2,3], [0,1])
    return qc
# Draw circuit
qc = build_curcuit(0, 0)
qc.draw()
from qiskit import execute, Aer
from qiskit.visualization import plot_histogram
from itertools import product
# Execute experiment

backend = Aer.get_backend('qasm_simulator')

legend = []
counts = []
for input1, input2 in product(range(2), range(2)):
    name = f"{input1} + {input2}"
    legend.append(name)
    qc = build_curcuit(input1, input2)
    result = execute(qc, backend).result()
    counts.append(result.get_counts())

plot_histogram(counts, legend=legend, figsize=(12, 5))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16142131979695432, 'fraction_numerical': 0.027411167512690356, 'mean_word_length': 4.106217616580311, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '583784', 'license': 'Apache-2.0', 'n_tokens_mistral': 830, 'n_tokens_neox': 774, 'n_words': 153, 'path': 'arithmetic/halfadder.ipynb', 'repo_name': 'dhorbach/quantum-sandbox', 'size': '1970'}