]> foleosoft.com Git - QAnsel.git/commitdiff
Wed Aug 14 08:58:50 PM EDT 2024
authormiha-q <>
Thu, 15 Aug 2024 00:58:50 +0000 (20:58 -0400)
committermiha-q <>
Thu, 15 Aug 2024 00:58:50 +0000 (20:58 -0400)
examples/test.txt [new file with mode: 0644]
src/bytecode.c
src/bytecode.h

diff --git a/examples/test.txt b/examples/test.txt
new file mode 100644 (file)
index 0000000..32e85ca
--- /dev/null
@@ -0,0 +1,3 @@
+qreg q[1];
+ry(pi/2) q[0];
+print q;
index e892ccb9e23d64666ee70b9882d103bb990a2808..9a73886ff89f3a43385171eb395fd1d7f1d6081f 100644 (file)
@@ -178,10 +178,11 @@ float* qansel_unitary(float theta, float phi, float lambda)
        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;
 }
index 50b0ee7bb443b4d82477cdaef26e9470f64616b2..5e97d87fad4a7eaaa964cff35a432b93c163eba3 100644 (file)
@@ -28,20 +28,32 @@ typedef struct
 
 /*
        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[] =