| 1 | <h2>Full example</h2> |
| 2 | <pre><code>namespace Bell { |
| 3 | open Microsoft.Quantum.Canon; |
| 4 | open Microsoft.Quantum.Intrinsic; |
| 5 | |
| 6 | operation SetQubitState(desired : Result, target : Qubit) : Unit { |
| 7 | if desired != M(target) { |
| 8 | X(target); |
| 9 | } |
| 10 | } |
| 11 | |
| 12 | @EntryPoint() |
| 13 | operation TestBellState(count : Int, initial : Result) : (Int, Int) { |
| 14 | |
| 15 | mutable numOnes = 0; |
| 16 | use qubit = Qubit(); |
| 17 | for test in 1..count { |
| 18 | SetQubitState(initial, qubit); |
| 19 | let res = M(qubit); |
| 20 | |
| 21 | // Count the number of ones we saw: |
| 22 | if res == One { |
| 23 | set numOnes += 1; |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | SetQubitState(Zero, qubit); |
| 28 | |
| 29 | // Return number of times we saw a |0> and number of times we saw a |1> |
| 30 | Message("Test results (# of 0s, # of 1s): "); |
| 31 | return (count - numOnes, numOnes); |
| 32 | } |
| 33 | }</code></pre> |