import numpy as np

from qiskit import QuantumCircuit, QuantumRegister, execute, BasicAer
from qiskit.visualization import plot_bloch_multivector, plot_histogram

circ = QuantumCircuit(2)

circ.x(0)
circ.x(1)

circ.h(0)
circ.cx(0,1)
circ.measure_all()

circ.draw("mpl")

res_sim = BasicAer.get_backend("qasm_simulator")
counts = execute(circ,backend=res_sim,shots=1024).result().get_counts()
plot_histogram(counts)

def state_prepare(qc:QuantumCircuit, reg0, reg1):
    qc.x(reg0)
    qc.x(reg1)

    qc.h(reg0)
    qc.cx(reg0, reg1)
    return

def AB_gates(qc:QuantumCircuit, a, b):
    qc.z(a)
    qc.h(b)
    return 

qc = QuantumCircuit(2)
state_prepare(qc,0,1)
qc.barrier()
AB_gates(qc,0,1)
qc.measure_all()

qc.draw("mpl")

from qiskit.aqua.operators import Z, X, H, One, Zero
operator = - Z ^ H
psi = 1 / np.sqrt(2) * ((Zero ^ One) - (One ^ Zero))
mu = (~psi @ operator @ psi).eval()
print(mu.real)

operator = - Z ^ (X@H@X)
psi = 1 / np.sqrt(2) * ((Zero ^ One) - (One ^ Zero))
mu = (~psi @ operator @ psi).eval()
print(mu.real)

operator = X
psi = Zero
mu = (~psi @ operator @ psi).eval()
print(mu.real)

