量子コンピューティング向け言語Q#の問題集 QuantumKatas Measurements Task 1.10 ベル状態の識別

Task 1.10は、4つのベル状態を識別する問題です。

解答1

    // Task 1.10. Distinguish four Bell states
    // Input: two qubits (stored in an array) which are guaranteed to be in one of the four Bell states:
    //         |Φ⁺⟩ = (|00⟩ + |11⟩) / sqrt(2)
    //         |Φ⁻⟩ = (|00⟩ - |11⟩) / sqrt(2)
    //         |Ψ⁺⟩ = (|01⟩ + |10⟩) / sqrt(2)
    //         |Ψ⁻⟩ = (|01⟩ - |10⟩) / sqrt(2)
    // Output: 0 if qubits were in |Φ⁺⟩ state,
    //         1 if they were in |Φ⁻⟩ state,
    //         2 if they were in |Ψ⁺⟩ state,
    //         3 if they were in |Ψ⁻⟩ state.
    // The state of the qubits at the end of the operation does not matter.
    operation BellState (qs : Qubit[]) : Int {
      CNOT(qs[0], qs[1]);
      H(qs[0]);

      let q0 = M(qs[0]);
      let q1 = M(qs[1]);

      if (q0 == Zero && q1 == Zero) {
        return 0;
      } elif (q0 == One && q1 == Zero) {
        return 1;
      } elif (q0 == Zero && q1 == One) {
        return 2;
      } else {
        return 3;
      }
    }

解答2

    // Task 1.10. Distinguish four Bell states
    // Input: two qubits (stored in an array) which are guaranteed to be in one of the four Bell states:
    //         |Φ⁺⟩ = (|00⟩ + |11⟩) / sqrt(2)
    //         |Φ⁻⟩ = (|00⟩ - |11⟩) / sqrt(2)
    //         |Ψ⁺⟩ = (|01⟩ + |10⟩) / sqrt(2)
    //         |Ψ⁻⟩ = (|01⟩ - |10⟩) / sqrt(2)
    // Output: 0 if qubits were in |Φ⁺⟩ state,
    //         1 if they were in |Φ⁻⟩ state,
    //         2 if they were in |Ψ⁺⟩ state,
    //         3 if they were in |Ψ⁻⟩ state.
    // The state of the qubits at the end of the operation does not matter.
    operation BellState (qs : Qubit[]) : Int {
      CNOT(qs[0], qs[1]);
      Ry(PI() / 2.0, qs[0]);

      let q0 = M(qs[0]);
      let q1 = M(qs[1]);

      if (q0 == Zero && q1 == Zero) {
        return 1;
      } elif (q0 == One && q1 == Zero) {
        return 0;
      } elif (q0 == Zero && q1 == One) {
        return 3;
      } else {
        return 2;
      }
    }

CNOT(qs[0], qs[1]);(Controlled X)([qs[0]], qs[1]);と同じ。