|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +namespace Microsoft.Quantum.Canon { |
| 5 | + |
| 6 | + /// # Summary |
| 7 | + /// Given a controllable operation, returns a controlled version of that operation |
| 8 | + /// accepting exactly one control qubit. |
| 9 | + /// |
| 10 | + /// # Input |
| 11 | + /// ## op |
| 12 | + /// The operation to be controlled. |
| 13 | + /// |
| 14 | + /// # Output |
| 15 | + /// A controlled variant of `op` accepting exactly one control qubit. |
| 16 | + /// |
| 17 | + /// # Example |
| 18 | + /// To add the weight (number of "1" bits) of a control register to |
| 19 | + /// a target register: |
| 20 | + /// ```qsharp |
| 21 | + /// ApplyToEachCA( |
| 22 | + /// SinglyControlled(IncrementByInteger)(_, (1, target)), |
| 23 | + /// controls) |
| 24 | + /// ); |
| 25 | + /// ``` |
| 26 | + /// |
| 27 | + /// # See Also |
| 28 | + /// - Microsoft.Quantum.Canon.SinglyControlledA |
| 29 | + function SinglyControlled<'T>(op : 'T => Unit is Ctl) : (Qubit, 'T) => Unit is Ctl { |
| 30 | + return (ctrl, originalInput) => Controlled op([ctrl], originalInput); |
| 31 | + } |
| 32 | + |
| 33 | + /// # Summary |
| 34 | + /// Given a controllable operation, returns a controlled version of that operation |
| 35 | + /// accepting exactly one control qubit. |
| 36 | + /// |
| 37 | + /// # Input |
| 38 | + /// ## op |
| 39 | + /// The operation to be controlled. |
| 40 | + /// |
| 41 | + /// # Output |
| 42 | + /// A controlled variant of `op` accepting exactly one control qubit. |
| 43 | + /// |
| 44 | + /// # Example |
| 45 | + /// To add the weight (number of "1" bits) of a control register to |
| 46 | + /// a target register: |
| 47 | + /// ```qsharp |
| 48 | + /// ApplyToEachCA( |
| 49 | + /// SinglyControlledA(IncrementByInteger)(_, (1, target)), |
| 50 | + /// controls) |
| 51 | + /// ); |
| 52 | + /// ``` |
| 53 | + /// |
| 54 | + /// # See Also |
| 55 | + /// - Microsoft.Quantum.Canon.SinglyControlled |
| 56 | + function SinglyControlledA<'T>(op : 'T => Unit is Adj + Ctl) : (Qubit, 'T) => Unit is Adj + Ctl { |
| 57 | + return (ctrl, originalInput) => Controlled op([ctrl], originalInput); |
| 58 | + } |
| 59 | + |
| 60 | +} |
0 commit comments