Skip to content

Instantly share code, notes, and snippets.

@billchenxi
Created May 15, 2020 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billchenxi/caa8b2132b8e412beedd4a3bd258b8c3 to your computer and use it in GitHub Desktop.
Save billchenxi/caa8b2132b8e412beedd4a3bd258b8c3 to your computer and use it in GitHub Desktop.
operation Teleportation(sentMessage : Bool) : Bool {
mutable receivedMessage = false;
using (register = Qubit[3]) {
let message = register[0];
if (sentMessage) {
X(message); // flip the message to "true"
}
let person_1 = register[1];
let person_2 = register[2];
// entanglement
H(person_1);
CNOT(person_1, person_2);
// teleportation: this order CNOT->H transfer the state of the message QuBit onto Alice.
CNOT(message, person_1);
H(message);
// Find the bell state was used
let messageState = M(message);
let person_1_state = M(person_1);
if (messageState == One) {
Z(person_2);
}
if (person_1_state == One) {
X(person_2);
}
if (M(person_2) == One) {
set receivedMessage = true;
}
ResetAll(register);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment