forked from microsoft/QuantumKatas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReferenceImplementation.qs
44 lines (37 loc) · 1.36 KB
/
ReferenceImplementation.qs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
//////////////////////////////////////////////////////////////////////
// This file contains reference solutions to all tasks.
// You should not modify anything in this file.
// We recommend that you try to solve the tasks yourself first,
// but feel free to look up the solution if you get stuck.
//////////////////////////////////////////////////////////////////////
namespace Quantum.Kata.SingleQubitSystemMeasurements {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Math;
// Exercise 2.
operation IsQubitZero_Reference (q : Qubit) : Bool {
return M(q) == Zero;
}
// Exercise 3.
operation IsQubitMinus_Reference (q : Qubit) : Bool {
return Measure([PauliX], [q]) == One;
}
// Exercise 5.
operation IsQubitPsiPlus_Reference (q : Qubit) : Bool {
Ry(-2.0 * ArcTan2(0.8, 0.6), q);
return M(q) == Zero;
}
// Exercise 6.
operation IsQubitA_Reference (alpha : Double, q : Qubit) : Bool {
Rx(-2.0 * alpha, q);
return M(q) == Zero;
}
// Exercise 7.
operation MeasureInABBasis_Reference (alpha : Double, q : Qubit) : Result {
Rx(-2.0 * alpha, q);
let measurementResult = M(q);
Rx(2.0 * alpha, q);
return measurementResult;
}
}