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

Function QAdder

QAlg/ArithmeticUnit/ArithmeticUnit.cpp:64–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62}
63
64QCircuit QAdder(
65 QVec &adder1,
66 QVec &adder2,
67 Qubit* c,
68 Qubit* is_carry)
69{
70 if ((adder1.size() == 0) || adder1.size() != adder2.size())
71 {
72 QCERR("adder1 and adder2 must be equal, but not equal to 0!");
73 throw run_fail("adder1 and adder2 must be equal, but not equal to 0!");
74 }
75
76 int nbit = adder1.size();
77
78 QCircuit circuit;
79 circuit << MAJ(c, adder1[0], adder2[0]);
80
81 for (auto i = 1; i < nbit; i++)
82 {
83 circuit << MAJ(adder2[i - 1], adder1[i], adder2[i]);
84 }
85
86 circuit << CNOT(adder2[adder2.size() - 1], is_carry);
87
88 for (auto i = nbit - 1; i > 0; i = i - 1)
89 {
90 circuit << UMA(adder2[i - 1], adder1[i], adder2[i]);
91 }
92
93 circuit << UMA(c, adder1[0], adder2[0]);
94
95 return circuit;
96
97}
98
99QCircuit QAdder(
100 QVec &adder1,

Callers 6

QComplementFunction · 0.70
QSubFunction · 0.70
QMultiplierFunction · 0.70
constModAddFunction · 0.70
test_QAdderFunction · 0.50
test_QAdderWithCarryFunction · 0.50

Calls 5

run_failClass · 0.85
CNOTClass · 0.85
MAJFunction · 0.70
UMAFunction · 0.70
sizeMethod · 0.45

Tested by 2

test_QAdderFunction · 0.40
test_QAdderWithCarryFunction · 0.40