2

Is there a higher order H-gate in Q# language? For example, if I want to apply Hadamard gate to an array(combined state) of 3 qubits. Is there a way to generate a tensor product version of H-gate or other gates?

2 Answers2

3

One way to think of it is to think of the unitary operator H = |+⟩⟨0| + |−⟩⟨1| and the quantum operation H separately. Taking this view, the unitary H is how we simulate the effect of applying the operation H on an ideal quantum processor. The quantum operation ApplyToEach(H, _) is then represented by the unitary operator HH ⊗ ⋯ ⊗ H in precisely the same way that H is represented by H.

One consequence of this mental model is that the tensor product is defined between unitary operators and not between quantum operations. Rather, the ideal action of quantum operations acting on distinct qubits is represented by the tensor product of the unitary representations of each individual operation.

Chris Granade
  • 913
  • 7
  • 21
0

Q# does not allow you to pass more qubits than the basic gate allows. So you have to run each of the qubits through the H() gate manually like this

let n = Length(qs);
for(index in 0 .. (n-1)) {
H(qs[index]);
}

Or use the convenient standard library function

ForEach(H,qs);

The basic reason why you can't apply a higher order H gate is it will increase the function signature to more qubits which creates complication. Also you may want to pass only some of the qubits of the same array to the gate, in that case you can't pass the entire array either and have to do it manually.