microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
brlackey/ising-model-sample

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

library/signed/src/Comparison.qs

31lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4import Std.Arrays.Tail, Std.Arrays.Zipped, Std.Arrays.Most, Std.Arrays.Rest;
5import Std.Diagnostics.Fact;
6import Std.Arithmetic.ApplyIfGreaterLE;
7
8/// # Summary
9/// Wrapper for signed integer comparison: `result = xs > ys`.
10///
11/// # Input
12/// ## xs
13/// First $n$-bit number
14/// ## ys
15/// Second $n$-bit number
16/// ## result
17/// Will be flipped if $xs > ys$
18operation CompareGTSI(xs : Qubit[], ys : Qubit[], result : Qubit) : Unit is Adj + Ctl {
19 use tmp = Qubit();
20 within {
21 CNOT(Tail(xs), tmp);
22 CNOT(Tail(ys), tmp);
23 } apply {
24 X(tmp);
25 Controlled ApplyIfGreaterLE([tmp], (X, xs, ys, result));
26 X(tmp);
27 CCNOT(tmp, Tail(ys), result);
28 }
29}
30
31export CompareGTSI;