I have a qubit |ψ⟩ and I want it to measure in bell states. My procedure is now

to calculate the transformation matrix U=Σ|i⟩⟨b_i| where |i⟩ is the computation basis and ⟨b_i| are the bell states. It works so far. The code in Yao.jl

```
function getFreq(r, shots, state_nr)
statistics = zeros(Int64, state_nr)
for i in eachindex(r) statistics[r[i].buf + 1] += 1 end
statistics/shots
end
# we define Σ|i⟩⟨b_i| where b_i is bell state
function defOperator()
ϕ⁺ = Array(1/sqrt(2)*[1.0+0.0im,0,0,1])
ϕ⁻ = Array(1/sqrt(2)*[1.0+0.0im,0,0,-1])
Ψ⁺ = Array(1/sqrt(2)*[0,1.0+0.0im,1,0])
Ψ⁻ = Array(1/sqrt(2)*[0,1.0+0.0im,-1,0])
return reshape([ϕ⁺;ϕ⁻;Ψ⁺;Ψ⁻],(4,4))'
end
op = defOperator()
ψ=ComplexF64[4.0, 2.0im,1.0,-2.0im]
Yao.normalize!(ψ)
qubit = Yao.ArrayReg(ψ)
block=GeneralMatrixBlock(op)
circuit = chain(2, block)
results = measure(apply(qubit, circuit), nshots=1000)
# |⟨Φ⁺,ψ⟩|^2=0.4 |⟨Φ⁻,ψ⟩|^2=0.4 |⟨Ψ⁺,ψ⟩|^2=0.1 |⟨Ψ⁻,ψ⟩|^2=0.1
getFreq(results,1000,4)
```

output:

```
0.392
0.401
0.098
0.109
```

How can I achieve the same goal with quantum gates CNOT and other gates(X,Y,Z,H,…)?

Is there no simple way to decompose the unitary matrix in quantum gates?