-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcVector.java
More file actions
100 lines (72 loc) · 1.78 KB
/
cVector.java
File metadata and controls
100 lines (72 loc) · 1.78 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
public class cVector {
private ZOmega [] col = new ZOmega[2];
private long k;
public cVector(ZOmega x, ZOmega y, long k) {
col[0] = x;
col[1] = y;
this.k = k;
}
private static ZOmega negative(ZOmega z){
long[] c = z.getCoeffs();
return new ZOmega(-c[0], -c[1], -c[2], -c[3]);
}
public void applyHGate() {
ZOmega new0 = col[0].add(col[1]);
ZOmega new1 = col[0].add(negative(col[1]));
col[0] = new0;
col[1] = new1;
ZOmega tempX = col[0];
ZOmega tempY = col[1];
long [] x = tempX.factorOutAllDeltas();
long [] y = tempY.factorOutAllDeltas();
col[0] = new ZOmega(x[0], x[1], x[2], x[3]);
col[1] = new ZOmega(y[0], y[1], y[2], y[3]);
long sdeDrop = 0;
if (x[4] > y[4]) {
sdeDrop = x[4];
} else {
sdeDrop = y[4];
}
this.k = this.k + (2 - sdeDrop);
}
public void applyTGate(int power) {
ZOmega w;
switch (power) {
case 0: w = new ZOmega(1, 0, 0, 0); break;
case 1: w = new ZOmega(0, 1, 0, 0); break;
case 2: w = new ZOmega(0, 0, 1, 0); break;
case 3: w = new ZOmega(0, 0, 0, 1); break;
case 4: w = new ZOmega(-1, 0, 0, 0); break;
case 5: w = new ZOmega(0, -1, 0, 0); break;
case 6: w = new ZOmega(0, 0, -1, 0); break;
case 7: w = new ZOmega(0, 0, 0, -1); break;
default: w = new ZOmega(1, 0, 0, 0);
}
ZOmega temp = new ZOmega(col[1]);
col[1] = temp.multiplication(w);
}
public void incrementK(long n) {
k += n;
}
public long getK() {
return k;
}
public ZOmega[] getCol() {
return col;
}
public ZOmega getX() {
return col[0];
}
public ZOmega getY() {
return col[1];
}
public void setX(ZOmega x) {
col[0] = x;
}
public void setY(ZOmega y) {
col[1] = y;
}
public void printCVector() {
System.out.println(col[0] + " " + col[1] + " sde = " + k);
}
}