]> foleosoft.com Git - QAnsel.git/commitdiff
Mon Sep 18 07:13:56 PM EDT 2023
authorserver <[email protected]>
Mon, 18 Sep 2023 23:13:58 +0000 (19:13 -0400)
committerserver <[email protected]>
Mon, 18 Sep 2023 23:13:58 +0000 (19:13 -0400)
bin/QAnsel
examples/belltest.sh [new file with mode: 0644]
examples/belltest/classic.sh [deleted file]

index 82b3bc701b1fa4a1e7bbc00dd5f60f6d1ce7c826..6cb6c5ab54df475b764f4681ba075e05ef3398fc 100755 (executable)
Binary files a/bin/QAnsel and b/bin/QAnsel differ
diff --git a/examples/belltest.sh b/examples/belltest.sh
new file mode 100644 (file)
index 0000000..788d048
--- /dev/null
@@ -0,0 +1,111 @@
+#!/bin/bash
+
+function classic {
+../bin/QAnsel << HERE
+qreg q[2];
+creg c[2];
+
+h q[0];
+h q[1];
+measure q[0] -> c[0];
+measure q[1] -> c[1];
+x q[0];
+if(c[1]==1) x q[1];
+print c;
+
+//Player X rules
+if(c[0]==1) x q[0];
+
+//Player Y rules
+x q[1];
+
+//Results
+measure q[0] -> c[0];
+measure q[1] -> c[1];
+print c;
+
+HERE
+}
+
+function quantum {
+../bin/QAnsel << HERE
+qreg q[2];
+creg c[2];
+
+h q[0];
+h q[1];
+measure q[0] -> c[0];
+measure q[1] -> c[1];
+print c;
+reset q[0];
+reset q[1];
+
+h q[0];
+cx q[0], q[1];
+
+//Player X rules
+if(c[0]==1) ry(pi/2) q[0];
+
+//Player Y rules
+if(c[1]==0) ry(pi/4) q[1];
+if(c[1]==1) ry(-pi/4) q[1];
+
+measure q[0] -> c[0];
+measure q[1] -> c[1];
+print c;
+
+HERE
+}
+
+function test
+{
+    if [ "$1" == "00 00" ]
+    then
+        echo 1
+    elif [ "$1" == "00 11" ]
+    then
+        echo 1
+    elif [ "$1" == "01 00" ]
+    then
+        echo 1
+    elif [ "$1" == "01 11" ]
+    then
+        echo 1
+    elif [ "$1" == "10 00" ]
+    then
+        echo 1
+    elif [ "$1" == "10 11" ]
+    then
+        echo 1
+    elif [ "$1" == "11 10" ]
+    then
+        echo 1
+    elif [ "$1" == "11 01" ]
+    then
+        echo 1
+    else
+        echo 0
+    fi
+}
+
+trials=1000
+cwins=0
+qwins=0
+for i in $(seq 1 $trials)
+do
+    clear
+    echo "$(( (100 * i) / trials ))%"
+
+    trial=$(classic | xargs)
+    results=$(test "$trial")
+    cwins=$((cwins+results))
+
+    trial=$(quantum | xargs)
+    results=$(test "$trial")
+    qwins=$((qwins+results))
+
+done
+clear
+
+echo "Classical Strategy: $cwins points"
+echo "Quantum Strategy: $qwins points"
diff --git a/examples/belltest/classic.sh b/examples/belltest/classic.sh
deleted file mode 100644 (file)
index 2b72f35..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-#!/bin/bash
-
-function classic {
-../../bin/QAnsel << HERE
-qreg q[2];
-creg c[2];
-
-h q[0];
-h q[1];
-measure q[0] -> c[0];
-measure q[1] -> c[1];
-x q[0];
-if(c[1]==1) x q[1];
-print c;
-
-//Player X rules
-if(c[0]==1) x q[0];
-
-//Player Y rules
-x q[1];
-
-//Results
-measure q[0] -> c[0];
-measure q[1] -> c[1];
-print c;
-
-HERE
-}
-
-function quantum {
-../../bin/QAnsel << HERE
-qreg q[2];
-creg c[2];
-
-h q[0];
-h q[1];
-measure q[0] -> c[0];
-measure q[1] -> c[1];
-print c;
-reset q[0];
-reset q[1];
-
-h q[0];
-cx q[0], q[1];
-
-if(c[0]==1) ry(pi/2) q[0];
-if(c[0]==1) rz(pi) q[0];
-
-if(c[1]==0) ry(pi/4) q[1];
-if(c[1]==0) rz(pi) q[1];
-
-if(c[1]==1) ry(-pi/4) q[1];
-if(c[1]==1) rz(pi) q[1];
-
-measure q[0] -> c[0];
-measure q[1] -> c[1];
-print c;
-
-HERE
-}
-
-function test
-{
-    if [ "$1" == "00 00" ]
-    then
-        echo 1
-    elif [ "$1" == "00 11" ]
-    then
-        echo 1
-    elif [ "$1" == "01 00" ]
-    then
-        echo 1
-    elif [ "$1" == "01 11" ]
-    then
-        echo 1
-    elif [ "$1" == "10 00" ]
-    then
-        echo 1
-    elif [ "$1" == "10 11" ]
-    then
-        echo 1
-    elif [ "$1" == "11 10" ]
-    then
-        echo 1
-    elif [ "$1" == "11 01" ]
-    then
-        echo 1
-    else
-        echo 0
-    fi
-}
-
-trials=1000
-cwins=0
-qwins=0
-for i in $(seq 1 $trials)
-do
-    clear
-    echo "$(( (100 * i) / trials ))%"
-
-    trial=$(classic | xargs)
-    results=$(test "$trial")
-    cwins=$((cwins+results))
-
-    trial=$(quantum | xargs)
-    results=$(test "$trial")
-    qwins=$((qwins+results))
-
-done
-clear
-
-echo "Classical Strategy: $cwins points"
-echo "Quantum Strategy: $qwins points"