In the "Superposition" Microsoft quantum katas (https://github.com/microsoft/QuantumKatas/blob/master/Superposition/ReferenceImplementation.qs) the solution for Task 7 looks like this:
// ------------------------------------------------------
// Task 7. All Bell states
// Inputs:
// 1) two qubits in |00⟩ state (stored in an array of length 2)
// 2) an integer index
// Goal: create one of the Bell states based on the value of index:
// 0: |Φ⁺⟩ = (|00⟩ + |11⟩) / sqrt(2)
// 1: |Φ⁻⟩ = (|00⟩ - |11⟩) / sqrt(2)
// 2: |Ψ⁺⟩ = (|01⟩ + |10⟩) / sqrt(2)
// 3: |Ψ⁻⟩ = (|01⟩ - |10⟩) / sqrt(2)
operation AllBellStates_Reference (qs : Qubit[], index : Int) : Unit is Adj {
H(qs[0]);
CNOT(qs[0], qs[1]);
// now we have |00⟩ + |11⟩ - modify it based on index arg
if (index % 2 == 1) {
// negative phase
Z(qs[1]);
}
if (index / 2 == 1) {
X(qs[1]);
}
}
And my alternative solution looks like this:
// Task 7. All Bell states
// Inputs:
// 1) two qubits in |00⟩ state (stored in an array of length 2)
// 2) an integer index
// Goal: create one of the Bell states based on the value of index:
// 0: |Φ⁺⟩ = (|00⟩ + |11⟩) / sqrt(2)
// 1: |Φ⁻⟩ = (|00⟩ - |11⟩) / sqrt(2)
// 2: |Ψ⁺⟩ = (|01⟩ + |10⟩) / sqrt(2)
// 3: |Ψ⁻⟩ = (|01⟩ - |10⟩) / sqrt(2)
operation AllBellStates (qs : Qubit[], index : Int) : Unit
{
H(qs[0]);
CNOT(qs[0], qs[1]);
if (index == 0){
} elif(index == 1) {
Z(qs[0]);
} elif(index == 2){
X(qs[0]);
} elif(index == 3){
X(qs[0]);
Z(qs[1]);
}
}
Yet BOTH solutions pass the unit tests. How is that possible, since the X-gate and Z-gate operators are being applied to the other qubit in the pair? Could the unit test logic be incorrect?