IterateThroughCartesianProduct operation
Warning
This documentation refers to the Classic QDK, which has been replaced by the Modern QDK.
Please see https://aka.ms/qdk.api for the API documentation for the Modern QDK.
Namespace: Microsoft.Quantum.Canon
Package: Microsoft.Quantum.Standard
Applies an operation for each index in the Cartesian product of several ranges.
operation IterateThroughCartesianProduct (bounds : Int[], op : (Int[] => Unit)) : Unit
Description
Iteratively applies an operation for each element of the Cartesian product
of 0..(bounds[0] - 1)
, 0..(bounds[1] - 1)
, ..., 0..(bounds[Length(bounds) - 1] - 1)
Input
bounds : Int[]
An array specifying the ranges to be iterated over, with each range being specified as an integer length.
op : Int[] => Unit
An operation to be called for each element of the given Cartesian product.
Output : Unit
Example
Given an operation op
, the following two snippets are equivalent:
IterateThroughCartesianProduct([3, 4, 5], op);
op([0, 0, 0]);
op([1, 0, 0]);
op([2, 0, 0]);
op([0, 1, 0]);
// ...
op([0, 3, 0]);
op([0, 0, 1]);
//
op([2, 3, 4]);
See Also
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for