-
Notifications
You must be signed in to change notification settings - Fork 0
/
Oracles.qs
32 lines (26 loc) · 1022 Bytes
/
Oracles.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
namespace QuantumSecretSanta {
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Intrinsic;
operation Oracle_And (queryRegister : Qubit[], target : Qubit) : Unit is Adj {
Controlled X(queryRegister, target);
}
operation Oracle_Or (queryRegister : Qubit[], target : Qubit) : Unit is Adj {
within {
// Flip input qubits to negate them
ApplyToEachA(X, queryRegister);
} apply {
// Use the AND oracle to get the AND of negated inputs
Oracle_And(queryRegister, target);
}
// Flip the target to get the final answer
X(target);
}
operation Oracle_Xor (queryRegister : Qubit[], target : Qubit) : Unit is Adj {
ApplyToEachA(CNOT(_, target), queryRegister);
}
operation Oracle_Exactly1One (queryRegister : Qubit[], target : Qubit) : Unit is Adj {
for (i in 0 .. Length(queryRegister) - 1) {
(ControlledOnInt(2^i, X))(queryRegister, target);
}
}
}