Can you send a subarray of qubits as a parameter in Q#?

59 Views Asked by At

Is it possible to send array slices of qubits as parameters? Something like this:

using(q : Qubit[5]){
    myOp(q[2:3]);
}
1

There are 1 best solutions below

0
Mariia Mykhailova On BEST ANSWER

Yes, Q# supports array slicing: https://learn.microsoft.com/en-us/quantum/quantum-qr-expressions#array-expressions. You can use Range data type as an index to create a subarray of elements of the array indexed by elements of the range.

Your example will look like this:

using (q = Qubit[5]) {
    myOp(q[2..3]);
}