/
ch05_03_add_squared.qasm
64 lines (58 loc) · 1.7 KB
/
ch05_03_add_squared.qasm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Programming Quantum Computers
// by Eric Johnston, Nic Harrigan and Mercedes Gimeno-Segovia
// O'Reilly Media
//
// More samples like this can be found at http://oreilly-qc.github.io
//
// A complete set of all OpenQASM samples (including this one) can be found at
// https://github.com/oreilly-qc/oreilly-qc.github.io/tree/master/samples/OpenQASM
//
// OpenQASM code was generated with the help of Qiskit (http://qiskit.org)
// A complete set of all Qiskit samples (including this one) can be found at
// https://github.com/oreilly-qc/oreilly-qc.github.io/tree/master/samples/Qiskit
// Run this sample in the IBM Q Experience Circuit Composer
// at https://quantum-computing.ibm.com
// Example 5-3: Add squared value of one qint to another
OPENQASM 2.0;
include "qelib1.inc";
qreg a[4];
qreg b[2];
qreg scratch[2];
x a[0];
h a[2];
rz(0.785398163397448) a[2];
x b[0];
h b[1];
rz(1.57079632679490) b[1];
// a += b * b
barrier a[0],a[1],a[2],a[3],b[0],b[1],scratch[0],scratch[1];
ccx b[0],a[0],scratch[0];
ccx a[1],a[2],scratch[1];
ccx scratch[0],scratch[1],a[3];
ccx a[1],a[2],scratch[1];
ccx b[0],a[0],scratch[0];
ccx b[0],a[0],scratch[0];
ccx scratch[0],a[1],a[2];
ccx b[0],a[0],scratch[0];
ccx b[0],a[0],a[1];
cx b[0],a[0];
ccx b[0],b[1],scratch[0];
ccx a[1],a[2],scratch[1];
ccx scratch[0],scratch[1],a[3];
ccx a[1],a[2],scratch[1];
ccx b[0],b[1],scratch[0];
ccx b[0],b[1],scratch[0];
ccx scratch[0],a[1],a[2];
ccx b[0],b[1],scratch[0];
ccx b[0],b[1],a[1];
ccx b[0],b[1],scratch[0];
ccx a[1],a[2],scratch[1];
ccx scratch[0],scratch[1],a[3];
ccx a[1],a[2],scratch[1];
ccx b[0],b[1],scratch[0];
ccx b[0],b[1],scratch[0];
ccx scratch[0],a[1],a[2];
ccx b[0],b[1],scratch[0];
ccx b[0],b[1],a[1];
ccx b[1],a[2],a[3];
cx b[1],a[2];