-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathU2Matrix.java
More file actions
89 lines (66 loc) · 2.22 KB
/
U2Matrix.java
File metadata and controls
89 lines (66 loc) · 2.22 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
public class U2Matrix {
private DOmega a;
private DOmega b;
private DOmega c;
private DOmega d;
public U2Matrix(DOmega a, DOmega c) {
// Store the first column (a, c)
this.a = a;
this.c = c;
// Compute the second column (b, d) = (-c*, a*)
this.b = (c.conjugate()).scalarMult(-1);
this.d = a.conjugate();
}
public U2Matrix(DOmega a, DOmega b, DOmega c, DOmega d) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
}
public boolean isUnitary() {
DOmega tempA = a;
DOmega tempB = b;
DOmega tempC = c;
DOmega tempD = d;
DOmega aConj = tempA.conjugate();
DOmega bConj = tempB.conjugate();
DOmega cConj = tempC.conjugate();
DOmega dConj = tempD.conjugate();
/*
System.out.println("printing dagger");
aConj.printDOmega();
cConj.printDOmega();
bConj.printDOmega();
dConj.printDOmega();
*/
U2Matrix dagger = new U2Matrix(aConj, cConj, bConj, dConj);
U2Matrix identity = matrixMultiplication(this, dagger);
if (identity.getA().equals(DOmega.ONE) && identity.getB().equals(DOmega.ZERO) && identity.getC().equals(DOmega.ZERO) && identity.getD().equals(DOmega.ONE)){
return true;
}
return false;
}
public U2Matrix matrixMultiplication(U2Matrix left, U2Matrix right){ //shld be correct (deepseek)
DOmega a = left.getA().multiplication(right.getA())
.add(left.getB().multiplication(right.getC()));
DOmega b = left.getA().multiplication(right.getB())
.add(left.getB().multiplication(right.getD()));
DOmega c = left.getC().multiplication(right.getA())
.add(left.getD().multiplication(right.getC()));
DOmega d = left.getC().multiplication(right.getB())
.add(left.getD().multiplication(right.getD()));
return new U2Matrix(a, b, c, d);
}
public DOmega getA() {
return a;
}
public DOmega getB() {
return b;
}
public DOmega getC() {
return c;
}
public DOmega getD() {
return d;
}
}