| 75 | // ---------------------------------------------------------------------------------------- |
| 76 | |
| 77 | void shor_decode ( |
| 78 | quantum_register& reg |
| 79 | ) |
| 80 | /*! |
| 81 | requires |
| 82 | - reg.num_bits() == 9 |
| 83 | ensures |
| 84 | - #reg.num_bits() == 1 |
| 85 | - #reg == the decoded qubit that was in the given input register |
| 86 | !*/ |
| 87 | { |
| 88 | DLIB_CASSERT(reg.num_bits() == 9,""); |
| 89 | |
| 90 | using namespace dlib::quantum_gates; |
| 91 | const gate<1> h = hadamard(); |
| 92 | const gate<1> i = noop(); |
| 93 | |
| 94 | // Now apply the gates that constitute Shor's decoding to the input register |
| 95 | |
| 96 | (cnot<2,0>(),cnot<2,0>(),cnot<2,0>()).apply_gate_to(reg); |
| 97 | (cnot<1,0>(),i,cnot<1,0>(),i,cnot<1,0>(),i).apply_gate_to(reg); |
| 98 | |
| 99 | (toffoli<0,1,2>(),toffoli<0,1,2>(),toffoli<0,1,2>()).apply_gate_to(reg); |
| 100 | |
| 101 | (h,i,i,h,i,i,h,i,i).apply_gate_to(reg); |
| 102 | |
| 103 | (cnot<6,0>(),i,i).apply_gate_to(reg); |
| 104 | (cnot<3,0>(),i,i,i,i,i).apply_gate_to(reg); |
| 105 | (toffoli<0,3,6>(),i,i).apply_gate_to(reg); |
| 106 | |
| 107 | // Now that we have decoded the value we don't need the extra 8 bits any more so |
| 108 | // remove them from the register. |
| 109 | for (int i = 0; i < 8; ++i) |
| 110 | reg.measure_and_remove_bit(0,rnd); |
| 111 | } |
| 112 | |
| 113 | // ---------------------------------------------------------------------------------------- |
| 114 | // ---------------------------------------------------------------------------------------- |
no test coverage detected