def _H(i, s, o):
    if o.skip:
        return s
    n = s.nbits
    c = 1.0 / 2.0**0.5
    return state(n,
                 c * (s.v[o.sbmask0[i]] + o.hmask[i] * s.v[o.sbmask1[i]]),
                 basis=s.basis)
def _CNOT(i, j, s, o):  # i is control, j is target
    if o.skip:
        return s
    n = s.nbits
    return state(n, s.v[o.cnotmask[i][j]], basis=s.basis)
def _Rz(i, phi, s, o):
    if o.skip:
        return s
    n = s.nbits
    return state(n, (o.onemask[i] * np.exp(1j * phi) + o.zeromask[i]) * s.v,
                 basis=s.basis)
def _X(i, s, o):
    if o.skip:
        return s
    n = s.nbits
    return state(n, s.v[o.notmask[i]], basis=s.basis)