From e3e04eef809b83943194a6c62bff8cd0482d67cc Mon Sep 17 00:00:00 2001 From: Alex Hansen Date: Wed, 21 Aug 2024 19:14:35 -0700 Subject: [PATCH] Update library/signed/src/Comparison.qs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: César Zaragoza Cortés --- library/signed/src/Comparison.qs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/library/signed/src/Comparison.qs b/library/signed/src/Comparison.qs index be5b8f9721..9931e76cc9 100644 --- a/library/signed/src/Comparison.qs +++ b/library/signed/src/Comparison.qs @@ -16,14 +16,15 @@ import Utils.ApplyCCNOTChain; /// Will be flipped if $xs > ys$ operation CompareGTSI(xs : Qubit[], ys : Qubit[], result : Qubit) : Unit is Adj + Ctl { use tmp = Qubit(); - CNOT(Tail(xs), tmp); - CNOT(Tail(ys), tmp); - X(tmp); - Controlled CompareGTI([tmp], (xs, ys, result)); - X(tmp); - CCNOT(tmp, Tail(ys), result); - CNOT(Tail(xs), tmp); - CNOT(Tail(ys), tmp); + within { + CNOT(Tail(xs), tmp); + CNOT(Tail(ys), tmp); + } apply { + X(tmp); + Controlled CompareGTI([tmp], (xs, ys, result)); + X(tmp); + CCNOT(tmp, Tail(ys), result); + } }