microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
library/signed/src/Utils.qs
17lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | // Util functions for internal use by the signed integer library. |
| 5 | |
| 6 | import Std.Math.Min; |
| 7 | import Std.Diagnostics.Fact; |
| 8 | import Std.Arrays.Head, Std.Arrays.Tail, Std.Arrays.Most, Std.Arrays.Rest; |
| 9 | |
| 10 | operation AndLadder(controls : Qubit[], targets : Qubit[]) : Unit is Adj { |
| 11 | Fact(Length(controls) == Length(targets), "The number of control qubits must match the number of target qubits."); |
| 12 | let controls1 = [Head(controls)] + Most(targets); |
| 13 | let controls2 = Rest(controls); |
| 14 | for i in 0..Length(controls1) - 1 { |
| 15 | AND(controls1[i], controls2[i], targets[i]); |
| 16 | } |
| 17 | } |