guppyalgos.primitives.subroutines.equality

Equality-check primitives.

Functions

equality_test(cnx_box, lhs, rhs, flag)

Flip flag when two same-sized registers encode the same basis state.

guppyalgos.primitives.subroutines.equality.equality_test(cnx_box, lhs, rhs, flag)

Flip flag when two same-sized registers encode the same basis state.

The routine computes the bitwise XOR of lhs and rhs into rhs, so the temporary rhs register is all-zero exactly when the original registers were equal. It then uses cnx_box to flip flag on that all-zero condition by surrounding the multi-controlled X with bit flips on the temporary register. Finally, it uncomputes the XOR so both input registers are restored to their original values.

Parameters:
  • cnx_box – Exact multi-controlled X implementation acting on the temporary comparison register and the flag qubit.

  • lhs – First input register.

  • rhs – Second input register, used as temporary workspace during the comparison and restored before returning.

  • flag – Target qubit flipped iff the original input registers were equal.