If we don't know the number of solutions, then we can test in pairs and tally up the number of times we detect one. This tally will have the same parity (i.e., odd or even) as the total number of solutions since we can only miss solutions in pairs of two. Thus, we can learn a global property about the function that we didn't know beforehand! Let us now use the same circuit as before to test for many solutions and learn the parity of the number of solutions.
Implement the circuit above, but now for how_many
solutions instead of one. You will first need to implement the multi-solution version of the oracle matrix, multisol_oracle_matrix(combos)
, which takes a list of bit strings (representing different solutions) and returns the associated oracle in matrix form.
To interact with codercises, please switch to a larger screen size.
Learning Objectives: