Родитель
8e8bf59b36
Коммит
d759353409
|
@ -7,6 +7,18 @@ namespace Microsoft.Quantum.Canon {
|
|||
return op(arg1, _);
|
||||
}
|
||||
|
||||
internal function WithFirstInputAppliedA<'T, 'U> (op : (('T, 'U) => Unit is Adj), arg1 : 'T) : ('U => Unit is Adj) {
|
||||
return op(arg1, _);
|
||||
}
|
||||
|
||||
internal function WithFirstInputAppliedC<'T, 'U> (op : (('T, 'U) => Unit is Ctl), arg1 : 'T) : ('U => Unit is Ctl) {
|
||||
return op(arg1, _);
|
||||
}
|
||||
|
||||
internal function WithFirstInputAppliedCA<'T, 'U> (op : (('T, 'U) => Unit is Adj + Ctl), arg1 : 'T) : ('U => Unit is Adj + Ctl) {
|
||||
return op(arg1, _);
|
||||
}
|
||||
|
||||
|
||||
/// # Summary
|
||||
/// Returns a curried version of an operation on two inputs.
|
||||
|
@ -39,10 +51,135 @@ namespace Microsoft.Quantum.Canon {
|
|||
/// let partial = curried(x);
|
||||
/// partial(y);
|
||||
/// ```
|
||||
///
|
||||
/// # See Also
|
||||
/// - Microsoft.Quantum.Canon.CurriedOpC
|
||||
/// - Microsoft.Quantum.Canon.CurriedOpA
|
||||
/// - Microsoft.Quantum.Canon.CurriedOpCA
|
||||
function CurriedOp<'T, 'U> (op : (('T, 'U) => Unit)) : ('T -> ('U => Unit)) {
|
||||
return WithFirstInputApplied(op, _);
|
||||
}
|
||||
|
||||
/// # Summary
|
||||
/// Returns a curried version of an operation on two inputs.
|
||||
///
|
||||
/// That is, given an operation with two inputs, this function applies Curry's isomorphism
|
||||
/// $f(x, y) \equiv f(x)(y)$ to return an operation of one input which
|
||||
/// returns an operation of one input.
|
||||
///
|
||||
/// # Input
|
||||
/// ## op
|
||||
/// An operation whose input is a pair.
|
||||
///
|
||||
/// # Output
|
||||
/// An operation which accepts the first element of a pair and returns
|
||||
/// an operation which accepts as its input the second element of the
|
||||
/// original operation's input.
|
||||
///
|
||||
/// # Type Parameters
|
||||
/// ## 'T
|
||||
/// The type of the first component of a function defined on pairs.
|
||||
/// ## 'U
|
||||
/// The type of the second component of a function defined on pairs.
|
||||
///
|
||||
/// # Remarks
|
||||
/// The following are equivalent:
|
||||
/// ```qsharp
|
||||
/// op(x, y);
|
||||
///
|
||||
/// let curried = CurriedOp(op);
|
||||
/// let partial = curried(x);
|
||||
/// partial(y);
|
||||
/// ```
|
||||
///
|
||||
/// # See Also
|
||||
/// - Microsoft.Quantum.Canon.CurriedOp
|
||||
/// - Microsoft.Quantum.Canon.CurriedOpC
|
||||
/// - Microsoft.Quantum.Canon.CurriedOpCA
|
||||
function CurriedOpA<'T, 'U> (op : (('T, 'U) => Unit is Adj)) : ('T -> ('U => Unit is Adj)) {
|
||||
return WithFirstInputAppliedA(op, _);
|
||||
}
|
||||
|
||||
/// # Summary
|
||||
/// Returns a curried version of an operation on two inputs.
|
||||
///
|
||||
/// That is, given an operation with two inputs, this function applies Curry's isomorphism
|
||||
/// $f(x, y) \equiv f(x)(y)$ to return an operation of one input which
|
||||
/// returns an operation of one input.
|
||||
///
|
||||
/// # Input
|
||||
/// ## op
|
||||
/// An operation whose input is a pair.
|
||||
///
|
||||
/// # Output
|
||||
/// An operation which accepts the first element of a pair and returns
|
||||
/// an operation which accepts as its input the second element of the
|
||||
/// original operation's input.
|
||||
///
|
||||
/// # Type Parameters
|
||||
/// ## 'T
|
||||
/// The type of the first component of a function defined on pairs.
|
||||
/// ## 'U
|
||||
/// The type of the second component of a function defined on pairs.
|
||||
///
|
||||
/// # Remarks
|
||||
/// The following are equivalent:
|
||||
/// ```qsharp
|
||||
/// op(x, y);
|
||||
///
|
||||
/// let curried = CurriedOp(op);
|
||||
/// let partial = curried(x);
|
||||
/// partial(y);
|
||||
/// ```
|
||||
///
|
||||
/// # See Also
|
||||
/// - Microsoft.Quantum.Canon.CurriedOp
|
||||
/// - Microsoft.Quantum.Canon.CurriedOpA
|
||||
/// - Microsoft.Quantum.Canon.CurriedOpCA
|
||||
function CurriedOpC<'T, 'U> (op : (('T, 'U) => Unit is Ctl)) : ('T -> ('U => Unit is Ctl)) {
|
||||
return WithFirstInputAppliedC(op, _);
|
||||
}
|
||||
|
||||
/// # Summary
|
||||
/// Returns a curried version of an operation on two inputs.
|
||||
///
|
||||
/// That is, given an operation with two inputs, this function applies Curry's isomorphism
|
||||
/// $f(x, y) \equiv f(x)(y)$ to return an operation of one input which
|
||||
/// returns an operation of one input.
|
||||
///
|
||||
/// # Input
|
||||
/// ## op
|
||||
/// An operation whose input is a pair.
|
||||
///
|
||||
/// # Output
|
||||
/// An operation which accepts the first element of a pair and returns
|
||||
/// an operation which accepts as its input the second element of the
|
||||
/// original operation's input.
|
||||
///
|
||||
/// # Type Parameters
|
||||
/// ## 'T
|
||||
/// The type of the first component of a function defined on pairs.
|
||||
/// ## 'U
|
||||
/// The type of the second component of a function defined on pairs.
|
||||
///
|
||||
/// # Remarks
|
||||
/// The following are equivalent:
|
||||
/// ```qsharp
|
||||
/// op(x, y);
|
||||
///
|
||||
/// let curried = CurriedOp(op);
|
||||
/// let partial = curried(x);
|
||||
/// partial(y);
|
||||
/// ```
|
||||
///
|
||||
/// # See Also
|
||||
/// - Microsoft.Quantum.Canon.CurriedOp
|
||||
/// - Microsoft.Quantum.Canon.CurriedOpC
|
||||
/// - Microsoft.Quantum.Canon.CurriedOpA
|
||||
function CurriedOpCA<'T, 'U> (op : (('T, 'U) => Unit is Adj + Ctl)) : ('T -> ('U => Unit is Adj + Ctl)) {
|
||||
return WithFirstInputAppliedCA(op, _);
|
||||
}
|
||||
|
||||
internal operation ApplyCurriedOp<'T, 'U> (curriedOp : ('T -> ('U => Unit)), first : 'T, second : 'U) : Unit {
|
||||
let innerOp = curriedOp(first);
|
||||
innerOp(second);
|
||||
|
|
|
@ -34,12 +34,32 @@ namespace Microsoft.Quantum.Tests {
|
|||
|
||||
@Test("QuantumSimulator")
|
||||
operation TestCurried() : Unit {
|
||||
|
||||
let curried = CurriedOp(Exp([PauliZ], _, _));
|
||||
AssertOperationsEqualInPlace(1, curried(1.7), Exp([PauliZ], 1.7, _));
|
||||
AssertOperationsEqualReferenced(1, curried(1.7), Exp([PauliZ], 1.7, _));
|
||||
}
|
||||
|
||||
@Test("QuantumSimulator")
|
||||
operation TestCurriedA() : Unit {
|
||||
let curried = CurriedOpA(Exp([PauliZ], _, _));
|
||||
AssertOperationsEqualInPlace(1, curried(1.7), Exp([PauliZ], 1.7, _));
|
||||
AssertOperationsEqualReferenced(1, curried(1.7), Exp([PauliZ], 1.7, _));
|
||||
}
|
||||
|
||||
@Test("QuantumSimulator")
|
||||
operation TestCurriedC() : Unit {
|
||||
let curried = CurriedOpC(Exp([PauliZ], _, _));
|
||||
AssertOperationsEqualInPlace(1, curried(1.7), Exp([PauliZ], 1.7, _));
|
||||
AssertOperationsEqualReferenced(1, curried(1.7), Exp([PauliZ], 1.7, _));
|
||||
}
|
||||
|
||||
@Test("QuantumSimulator")
|
||||
operation TestCurriedCA() : Unit {
|
||||
let curried = CurriedOpCA(Exp([PauliZ], _, _));
|
||||
AssertOperationsEqualInPlace(1, curried(1.7), Exp([PauliZ], 1.7, _));
|
||||
AssertOperationsEqualReferenced(1, curried(1.7), Exp([PauliZ], 1.7, _));
|
||||
}
|
||||
|
||||
@Test("QuantumSimulator")
|
||||
operation TestBind() : Unit {
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче