From: server Date: Mon, 18 Sep 2023 23:13:58 +0000 (-0400) Subject: Mon Sep 18 07:13:56 PM EDT 2023 X-Git-Url: http://www.foleosoft.com/?a=commitdiff_plain;h=28a1c710c76b699f8df8fd83d1e2bebc8694cdbe;p=QAnsel.git Mon Sep 18 07:13:56 PM EDT 2023 --- diff --git a/bin/QAnsel b/bin/QAnsel index 82b3bc7..6cb6c5a 100755 Binary files a/bin/QAnsel and b/bin/QAnsel differ diff --git a/examples/belltest.sh b/examples/belltest.sh new file mode 100644 index 0000000..788d048 --- /dev/null +++ b/examples/belltest.sh @@ -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 index 2b72f35..0000000 --- a/examples/belltest/classic.sh +++ /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"