Last active
December 13, 2017 09:32
-
-
Save piyo7/b9fbb2f5ffc69783086d96cce7ee1ea2 to your computer and use it in GitHub Desktop.
吾輩は量子プログラミング言語である。名前はまだ無い。 Microsoftで生れ量子テレポーテーションした事だけは記憶している。 ref: https://qiita.com/piyo7/items/0c80181c567b3075c00f
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \newcommand{\ket}[1]{\left| #1 \right\rangle} | |
| \frac{1}{\sqrt{2}}\ket{00} + \frac{1}{\sqrt{2}}\ket{11} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \begin{align} | |
| \mathrm{X}\ket{0} &= \ket{1} \\ | |
| \mathrm{X}\ket{1} &= \ket{0} \\ | |
| \end{align} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CNOT (q1, q2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \frac{1}{\sqrt{2}}(\mathrm{CNOT} \ket{00}) + \frac{1}{\sqrt{2}}(\mathrm{CNOT} \ket{10}) = \frac{1}{\sqrt{2}}\ket{00} + \frac{1}{\sqrt{2}}\ket{11} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| operation() Teleport (Qubit msg, Qubit here, Qubit there) { | |
| Body { | |
| EPR (here, there) | |
| CNOT (msg, here) | |
| H (msg) | |
| let m_here = M (here) | |
| if (m_here == One) { | |
| X (there) | |
| } | |
| let m_msg = M (msg) | |
| if (m_msg == One) { | |
| Z (there) | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| operation() Teleport (Qubit msg, Qubit here, Qubit there) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| EPR (here, there) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \begin{align} | |
| &a\ket{0}(\mathrm{EPR} \ket{00}) + b\ket{1}(\mathrm{EPR} \ket{00}) \\ | |
| =\quad &\frac{a}{\sqrt{2}}\ket{000} + \frac{a}{\sqrt{2}}\ket{011} + \frac{b}{\sqrt{2}}\ket{100} + \frac{b}{\sqrt{2}}\ket{111} | |
| \end{align} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CNOT (msg, here) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \begin{align} | |
| &\frac{a}{\sqrt{2}}(\mathrm{CNOT} \ket{00})\ket{0} + \frac{a}{\sqrt{2}}(\mathrm{CNOT} \ket{01})\ket{1} \\ | |
| &+ \frac{b}{\sqrt{2}}(\mathrm{CNOT} \ket{10})\ket{0} + \frac{b}{\sqrt{2}}(\mathrm{CNOT} \ket{11})\ket{1} \\ | |
| =\quad &\frac{a}{\sqrt{2}}\ket{000} + \frac{a}{\sqrt{2}}\ket{011} + \frac{b}{\sqrt{2}}\ket{110} + \frac{b}{\sqrt{2}}\ket{101} | |
| \end{align} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| H (msg) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \begin{align} | |
| &\frac{a}{\sqrt{2}}(\mathrm{H}\ket{0})\ket{00} + \frac{a}{\sqrt{2}}(\mathrm{H}\ket{0})\ket{11} \\ | |
| &+ \frac{b}{\sqrt{2}}(\mathrm{H}\ket{1})\ket{10} + \frac{b}{\sqrt{2}}(\mathrm{H}\ket{1})\ket{01} \\ | |
| =\quad &\frac{a}{2}\ket{000} + \frac{a}{2}\ket{100} + \frac{a}{2}\ket{011} + \frac{a}{2}\ket{111} \\ | |
| &+ \frac{b}{2}\ket{010} - \frac{b}{2}\ket{110} + \frac{b}{2}\ket{001} - \frac{b}{2}\ket{101} | |
| \end{align} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \begin{align} | |
| \mathrm{Z}\ket{0} &= \ket{0} \\ | |
| \mathrm{Z}\ket{1} &= -\ket{1} \\ | |
| \end{align} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let m_here = M (here) | |
| if (m_here == One) { | |
| X (there) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \begin{align} | |
| &\sqrt{2}(\frac{a}{2}\ket{000} + \frac{a}{2}\ket{100} + \frac{b}{2}\ket{001} - \frac{b}{2}\ket{101}) \\ | |
| =\quad & \frac{a}{\sqrt{2}}\ket{000} + \frac{a}{\sqrt{2}}\ket{100} + \frac{b}{\sqrt{2}}\ket{001} - \frac{b}{\sqrt{2}}\ket{101} | |
| \end{align} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \begin{align} | |
| &\sqrt{2}(\frac{a}{2}\ket{01}(\mathrm{X} \ket{1}) + \frac{a}{2}\ket{11}(\mathrm{X} \ket{1}) + \frac{b}{2}\ket{01}(\mathrm{X} \ket{0}) - \frac{b}{2}\ket{11}(\mathrm{X} \ket{0})) \\ | |
| =\quad &\frac{a}{\sqrt{2}}\ket{010} + \frac{a}{\sqrt{2}}\ket{110} + \frac{b}{\sqrt{2}}\ket{011} - \frac{b}{\sqrt{2}}\ket{111} | |
| \end{align} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let m_msg = M (msg) | |
| if (m_msg == One) { | |
| Z (there) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \begin{align} | |
| &\sqrt{2}(\frac{a}{\sqrt{2}}\ket{000} + \frac{b}{\sqrt{2}}\ket{001}) \\ | |
| =\quad &a\ket{000} + b\ket{001} \\ | |
| =\quad &\ket{00}(a\ket{0} + b\ket{1}) | |
| \end{align} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \begin{align} | |
| &\sqrt{2}(\frac{a}{\sqrt{2}}\ket{10}(\mathrm{Z} \ket{0}) - \frac{b}{\sqrt{2}}\ket{10}(\mathrm{Z} \ket{1})) \\ | |
| =\quad &a\ket{100} + b\ket{101} \\ | |
| =\quad &\ket{10}(a\ket{0} + b\ket{1}) | |
| \end{align} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \begin{align} | |
| &\sqrt{2}(\frac{a}{\sqrt{2}}\ket{010} + \frac{b}{\sqrt{2}}\ket{011}) \\ | |
| =\quad &a\ket{010} + b\ket{011} \\ | |
| =\quad &\ket{01}(a\ket{0} + b\ket{1}) | |
| \end{align} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \begin{align} | |
| &\sqrt{2}(\frac{a}{\sqrt{2}}\ket{11}(\mathrm{Z} \ket{0}) - \frac{b}{\sqrt{2}}\ket{11}(\mathrm{Z} \ket{1})) \\ | |
| =\quad &a\ket{110} + b\ket{111} \\ | |
| =\quad &\ket{11}(a\ket{0} + b\ket{1}) | |
| \end{align} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| operation (Result) TeleportTest (Result msg) { | |
| Body { | |
| mutable res = Zero | |
| using (qubits = Qubit[3]) { | |
| let msgQ = qubits[0] | |
| // Set msgQ to message state | |
| SetQubit (msg, msgQ) | |
| Teleport (msgQ, qubits[1], qubits[2]) | |
| set res = M(qubits[2]) | |
| } | |
| return res | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| operation (Result) TeleportTest (Result msg) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \begin{align} | |
| \mathrm{H}\ket{0} &= \frac{1}{\sqrt{2}}\ket{0} + \frac{1}{\sqrt{2}}\ket{1} \\ | |
| \mathrm{H}\ket{1} &= \frac{1}{\sqrt{2}}\ket{0} - \frac{1}{\sqrt{2}}\ket{1} | |
| \end{align} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using (qubits = Qubit[3]) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let msgQ = qubits[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SetQubit (msg, msgQ) | |
| Teleport (msgQ, qubits[1], qubits[2]) | |
| set res = M(qubits[2]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| return res |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| OPENQASM 2.0; | |
| include "qelib1.inc"; | |
| qreg q[3]; | |
| creg c[1]; | |
| h q[1]; | |
| cx q[1],q[2]; | |
| cx q[0],q[1]; | |
| h q[0]; | |
| measure q[1] -> c[0]; | |
| if(c==1) x q[2]; | |
| measure q[0] -> c[0]; | |
| if(c==1) z q[2]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \begin{align} | |
| \mathrm{CNOT}\ket{00} &= \ket{00} \\ | |
| \mathrm{CNOT}\ket{01} &= \ket{01} \\ | |
| \mathrm{CNOT}\ket{10} &= \ket{11} \\ | |
| \mathrm{CNOT}\ket{11} &= \ket{10} | |
| \end{align} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| operation () EPR (Qubit q1, Qubit q2) { | |
| Body { | |
| H (q1) | |
| CNOT (q1, q2) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| operation () EPR (Qubit q1, Qubit q2) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| \ket{00} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| H (q1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (\mathrm{H}\ket{0})\ket{0} = \frac{1}{\sqrt{2}}\ket{00} + \frac{1}{\sqrt{2}}\ket{10} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment