import numpy as np

from common import show

ket0 = np.array([1, 0])
ket1 = np.array([0, 1])
plus = np.array([1, 1]) / np.sqrt(2)
minus = np.array([1, -1]) / np.sqrt(2)


def ket_bra(phi, chi):
    """|φ⟩⟨χ|"""
    return np.outer(phi, chi.conj())


Z = ket_bra(ket0, ket0) - ket_bra(ket1, ket1)
H = ket_bra(plus, ket0) + ket_bra(minus, ket1)
print("|0⟩⟨0| − |1⟩⟨1| =", show(Z))
print("|+⟩⟨0| + |−⟩⟨1| =", show(H))
