MCPcopy Create free account
hub / github.com/OriginQ/QPanda-2 / QComplement

Function QComplement

QAlg/ArithmeticUnit/ArithmeticUnit.cpp:138–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136}
137
138QCircuit QComplement(QVec& a, QVec& k)
139{
140 if (k.size() < a.size() + 2)
141 {
142 QCERR_AND_THROW_ERRSTR(
143 run_fail,
144 "Auxiliary qubits is not big enough!");
145 }
146
147 int len = a.size();
148 auto t = k[len];
149 auto q1 = k[len + 1];
150
151 QCircuit circ, circ1;
152 for (int i = 0; i < len - 1; i++)
153 circ1 << X(a[i]);
154 QVec b(k.begin(), k.begin() + len);
155 circ1 << X(b[0]);
156 circ1 << QAdder(a, b, t);
157 circ1 << X(b[0]);
158
159 circ << CNOT(a[len - 1], q1);
160 circ << circ1.control(q1);
161 circ << CNOT(a[len - 1], q1);
162
163 return circ;
164}
165
166QCircuit QSub(QVec& a, QVec& b, QVec& k)
167{

Callers 3

QSubFunction · 0.70
test_QComplementFunction · 0.50
checkQComplementFunction · 0.50

Calls 6

XClass · 0.85
CNOTClass · 0.85
QAdderFunction · 0.70
sizeMethod · 0.45
beginMethod · 0.45
controlMethod · 0.45

Tested by 2

test_QComplementFunction · 0.40
checkQComplementFunction · 0.40