I have an example with 6 qubits for names and 6 for telephones. I encoded their relation like this:

(ControlledOnInt(1, SetRegisterToInt(6, _)))(rnames, rtels);
(ControlledOnInt(3, SetRegisterToInt(2, _)))(rnames, rtels);

So there are only 2 registers states(tel->name) in a BD with 64 possible states.

When I ask the BD for a name from a telephone it works ok, 6 => 2 and 2 => 3 because only in these 2 values (6 and 2) the marked qbit entangled with telephones is One.

So the important part is the oracle made with ControlledOnInt, and I need to know how does it, because I have my own Grovers in c++ and I want to know the details to make it, and also to learn what gates it uses and how it multiply the matrices.


  • $\begingroup$ I mean what I need to know is which gates are used to transfrom telephone 6 in name 2 and T 2 in name 6 that are valid for both?. I supoposse there will be a comparation first to know if T is 2 or 6 and later convert their bits with CNOT? $\endgroup$ Jul 5, 2019 at 12:57
  • $\begingroup$ The questions seem very broad. Are you asking about your implementation of Grover's applied to a $6$-qubit database of names/telephone numbers? What is a BD? What do you mean by 6=>2 and 2=>3? "I have my own Grovers in c++ and I want to know the details to make it" - so did you implement Grover's algorithm, or not? "And also to learn what gate it uses" - gates for Grover's algorithm? Or your implementation? "how it multiple the matrices" - how what multiplies which matrices? $\endgroup$
    – Mark S
    Jul 5, 2019 at 13:51

1 Answer 1


ControlledOnInt is a library function which applies a specified operation (in this case SetRegisterToInt) to the target register only if the control register is in a state that encodes the given integer. Internally it does the following:

  • convert the given integer to an array of bits (in little-endian format I think);
  • applies X gate to each qubit that corresponds to a 0 bit in the notation of the integer;
  • applies normally controlled version of the operation (apply operation if all control qubits are in $|1\rangle$ state) to the control and target registers;
  • and applies X gate to each qubit that that corresponds to a 0 bit in the notation of the integer again to return control register to its starting state.
  • $\begingroup$ To quickly follow up on Mariia's answer, you can see the source code for ControlledOnInt at github.com/microsoft/QuantumLibraries/blob/…. Essentially, ControlledOnInt uses Q#'s partial application feature together with ControlledOnBitString to implement the steps that Mariia described above. $\endgroup$ Jul 5, 2019 at 17:44
  • $\begingroup$ Thanks, yes I made my own Grovers, but to be usefull needs to entangled 2 registers. What I dont know is which gates uses in the control register to know it is name 1 or 3 . I mean this is an if () with six &&. I saw this circuit i.stack.imgur.com/SiKmS.png with control and anticontrol dots. So which gates are these how to express this in quantum way? $\endgroup$ Jul 6, 2019 at 19:40
  • $\begingroup$ Anyway, because the entaglement that contains the BD looks like it have to be hardware encoded with gates in the circuit, this means that for each BD u need a specific hardware. So maybe the is a initial state (not Hadamard) that maps the searched number with a unique number(state), so this circuit could be used with any BD. Or at least that it could map a lot of numbers $\endgroup$ Jul 6, 2019 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.