This repository has been archived by the owner on Nov 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDistance_oracles.qs
57 lines (47 loc) · 1.52 KB
/
Distance_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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
namespace Final_Project {
open Microsoft.Quantum.Primitive;
open Microsoft.Quantum.Canon;
operation distance_add(i : Qubit[], j : Qubit[], target : Qubit[], distances : Int[]) : Unit {
body (...) {
index_to_distance(i + j, target, distances);
}
adjoint auto;
controlled auto;
controlled adjoint auto;
}
operation distance_cmp(d1 : Qubit[], d2 : Qubit[], target : Qubit) : Unit {
body (...) {
efficient_TC_comparator(d1, d2, target);
}
adjoint auto;
controlled auto;
controlled adjoint auto;
}
operation index_to_distance(index : Qubit[], target : Qubit[], distances: Int[]) : Unit {
body (...) {
for(i in 0.. Length(distances) - 1) {
let bool_i = int_to_boolsBE(i, Length(index));
(ControlledOnBitString(bool_i, IIBE_wrap(i, _, distances)))(index, target);
}
}
adjoint auto;
controlled auto;
controlled adjoint auto;
}
operation IIBE_wrap(i: Int, qs: Qubit[], distances: Int[]) : Unit{
body (...) {
IntegerIncrementBE(distances[i], qs);
}
adjoint auto;
controlled auto;
controlled adjoint auto;
}
operation IntegerIncrementBE(i: Int, qs: Qubit[]) : Unit {
body (...) {
IntegerIncrementLE(i, BigEndianToLittleEndian(BigEndian(qs)));
}
adjoint auto;
controlled auto;
controlled adjoint auto;
}
}