Oracles

Bit Oracle to Phase Oracle

Difficulty: Easy ★

Your library only has bit-flip oracles, but your algorithm wants phase oracles. Convert one to the other with a single helper qubit, and hand that helper back clean.

Objective

phase_from_bit_oracle(oracle, num_inputs) receives a Gate on num_inputs + 1 qubits acting as |x>|y> -> |x>|y XOR f(x)>. Return an (n + 1)-qubit circuit mapping |x>|0> -> (-1)^f(x) |x>|0>.

Constraints

  • The helper qubit (index num_inputs) must end in |0>.
  • Do not inspect the oracle: every non-oracle gate must be identical for every oracle.

Entry Point

phase_from_bit_oracle

Checks

  • Exports phase_from_bit_oracle(oracle, num_inputs).
  • Applies (-1)^f(x) on a full superposition and restores the helper qubit.
  • The circuit is identical apart from the oracle box.

Your Code

Outputpending

Execution results will appear here.