oreilly-qc / oreilly-qc.github.io

Code samples for Programming Quantum Computers, from O'Reilly Media
130 stars 59 forks source link

Possible typo on page 96? #41

Open joshuaguerin opened 3 years ago

joshuaguerin commented 3 years ago

In the explanation of Fig 5-11 on page 96, we have:

Note that for some values of a, subtracting 3 from a will cause its lowest-weight qubit to be set. We can use this top bit as a condition for our increment operation.

Emphasis mine.

I'm reading this as referring to the nots in the if (a<0) then b++ block being conditioned over 0x4 (for a). Should this be the most significant qubit?

dyordan1 commented 2 years ago

Agreed. Further, the result of the program (and the QCEngine implementation) agree with the most significant interpretation - note the 0x4 line being conditioned in the CNOTs below. image

This may just be a terminology clarification since the exact wording used is "lowest-weight" not "least significant".

It is also not very clear that the net result is if(a >= -1 && a < 3) b++. It took me quite a long time to understand that -1-3 = -4 (duh). Perhaps a-4 would be more clear? Or maybe even just, don't modify a for this example and setup "negative" a states from the beginning and skip the a-3 / a+3. I felt like a bit too much was thrown into it at once and made it pretty dense to work through.