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


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



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


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




1 Answer
1



Yes, Q# supports array slicing: https://docs.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.


Range



Your example will look like this:


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






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

JMeter fails on beanshell imports

Why in node-red my HTTP POST no receive payload from inject?

PHP contact form sending but not receiving emails