c.imaginary = sin(phi) * sin(theta/2.0);
d.real = cos(phi + lambda) * cos(theta/2.0);
d.imaginary = sin(phi + lambda) * cos(theta/2.0);
+ //remember it must be transposed!!!
cpx_mtx_init(&m, 2, 2);
cpx_mtx_set(&m, 0, 0, &a);
- cpx_mtx_set(&m, 0, 1, &b);
- cpx_mtx_set(&m, 1, 0, &c);
+ cpx_mtx_set(&m, 0, 1, &c);
+ cpx_mtx_set(&m, 1, 0, &b);
cpx_mtx_set(&m, 1, 1, &d);
return m.ptr;
}
/*
IMPORTANT NOTE
-
- (AB)^T = (A^T)(B^T)
In quantum mechanics, if the relative state is S, then evolving
- the relative state by a logic gate A requires computing AS.
+ the relative state by a logic gate G requires computing GS. The
+ relative state S is a column vector.
+
+ Traditionally, a one-dimensional array is treated as a single
+ row. While it could be treated as a single column, I find this
+ to be unintuitive. Thus, I opt to store the relative state of
+ the system as a row vector. This means the simulator only ever
+ stores S^T and not S.
+
+ This means that we cannot apply a logic gate by multiplying G
+ by the state vector S as it will give the wrong answer.
+ Rather, we can make use of the equality below.
+
+ (AB)^T = (A^T)(B^T)
- This is inefficient as S is a column vector and it is more
- efficient in terms of caching to use a row vector. Hence, the
- simulator does not store S but only S^T. To apply the logic
- gate A, it is not AS that needs to be computed but instead
- (S^T)(A^T).
+ This tells us that we have to instead compute (S^T)(G^T). The
+ important takeaway here is that all the logic gates represented
+ here are their transposed equivalents. For most logic gates,
+ they are equal to their transpose, but the Y gate is a clear
+ exception here. Y is not equal to Y^T.
- This means all the logic gates stored below are represented
- as their transposed equivalents.
+ Keep this in mind if more logic gates are added in the future.
+ They all must be first transposed before being hardcoded on
+ this page.
*/
static float Identity[] =