You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
There is a close connection between the iteration over classical values, and generalizing "circuit"-like patterns into high-level code. In Q#, we use exploit this connection with the Microsoft.Quantum.Arrays namespace to make it easier express high-level patterns. We have noted from user feedback, however, that some common patterns are difficult to express using existing array functions, or that users may not be able to discover needed functionality.
The improvements proposed here empower users to make better use of high-level quantum development in Q# by making it easier to iterate over collections of values, such as Qubit[], and to use them to write out complex algorithmic patterns efficiently.
Proposed deprecations and renamings
namespace Microsoft.Quantum.Arrays
function Exclude<'T>(remove : Int[], array : 'T[]) : 'T[]; function Excluding<'T>(remove : Int[], array : 'T[]) : 'T[];
function Zip<'T, 'U>(left : 'T[], right : 'U[]) : ('T, 'U)[]; function Zipped<'T, 'U>(left : 'T[], right : 'U[]) : ('T, 'U)[];
Future considerations and language feature dependencies
Functions like Transposed or ColumnAt may need to be redesigned to work well with 𝑛-d arrays.
Other comments
@guenp has suggested that Fold is a reasonable name if there's a way to find it in docs from searching for "reduce." The input name "folder" is dubious, though, regardless; duplicate meaning that can be confused.
Abstract
There is a close connection between the iteration over classical values, and generalizing "circuit"-like patterns into high-level code. In Q#, we use exploit this connection with the Microsoft.Quantum.Arrays namespace to make it easier express high-level patterns. We have noted from user feedback, however, that some common patterns are difficult to express using existing array functions, or that users may not be able to discover needed functionality.
The improvements proposed here empower users to make better use of high-level quantum development in Q# by making it easier to iterate over collections of values, such as Qubit[], and to use them to write out complex algorithmic patterns efficiently.
Proposed deprecations and renamings
function Exclude<'T>(remove : Int[], array : 'T[]) : 'T[];function Excluding<'T>(remove : Int[], array : 'T[]) : 'T[];function Zip<'T, 'U>(left : 'T[], right : 'U[]) : ('T, 'U)[];function Zipped<'T, 'U>(left : 'T[], right : 'U[]) : ('T, 'U)[];Proposed additions
function ElementAt<'T>(index : Int, array : 'T[]) : 'T;function ElementsAt<'T>(range : Range, array : 'T[]) : 'T[];function CumulativeFolded<'State, 'TInput>(fn : ('State, 'TInput -> 'State), initialState : 'State, arr : 'TInput[]) : 'State[];function FlatMapped<'TInput, 'TOutput>(mapper : 'TInput -> 'TOutput[], arr : 'TInput[]) : 'TOutput[];Returns (mapper(arr[0]) + mapper(arr[1]) + ... + mapper(arr[n - 1])).
function MappedOverRange<'T>(fn : Int -> 'T, range : Range) : 'T[];Returns the value of
fnat each element ofrange.function Flattened<'T>(arr : 'T[][]) : 'T[];Returns the sum over array concatenation of
arr; i.e.:arr[0] + arr[1] + ... + arr[Length(arr) - 1]. See comment by @msoeken below.function ColumnAt<'T>(index : Int, array : 'T[][]) : 'T[];function Diagonal<'T>(array : 'T[][]) : 'T[];function Transposed<'T>(array : 'T[][]) : 'T[][];function RectangularArrayFact<'T>(array : 'T[][], msg : String) : Unitfunction SquareArrayFact<'T>(array : 'T[][], msg : String)function HeadAndRest<'T>(arr : 'T[]) : ('T, 'T[]);function MostAndTail<'T>(arr : 'T[]) : ('T[], T);function Count<'T>(predicate : ('T -> Bool), array : 'T[]) : Intfunction EmptyArray<'T>() : 'T[];(see Default values for qubits and callables in uninitialized arrays cause runtime errors qsharp-compiler#589)function Interleaved<'T>(first : 'T[], second : 'T[]) : 'T[];Given two arrays, returns a new array
[first[0], second[0], first[1], second[1], ...]function Prefixes<'T>(arr : 'T[]) : 'T[][];Given an array, returns a new array of all prefixes; i.e.:
[[arr[0]], [arr[0], arr[1]], ... arr].function Windows<'T>(size : Int, arr : 'T[]) : 'T[][];Returns
[[arr[0], arr[1], ..., arr[size - 1]], [arr[1], arr[2], ..., arr[size]], ..., [arr[n - size + 1], arr[n - size + 2], ..., arr[n - 1]]].function Unique<'T>(arr : 'T[]) : 'T[];function Unzipped<'T, 'U>(arr : ('T, 'U)[]) : ('T[], 'U[]);operation ApplyTo{Head, Tail, Most, Rest}{,A,C,CA}Future considerations and language feature dependencies
Other comments