This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 175
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Comparison operations #593
Copy link
Copy link
Open
Labels
Area-APIIssue concerns the API design of a library, such as style guide or design principles adherence.Issue concerns the API design of a library, such as style guide or design principles adherence.Kind-EnhancementNew feature or requestNew feature or requestPkg-NumericsIssue relates to the Microsoft.Quantum.Numerics package.Issue relates to the Microsoft.Quantum.Numerics package.Pkg-StandardIssue relates to the Microsoft.Quantum.Standard package.Issue relates to the Microsoft.Quantum.Standard package.trackingThis label will trigger gh-sync to create or update a mirror internal ADO issue.This label will trigger gh-sync to create or update a mirror internal ADO issue.
Description
Comparison operations
Conceptual overview
Provides operations for <
, <=
, =>
, >
for
in Standard
:
- two
LittleEndian
registers withX
on target - two
LittleEndian
registers with arbitrary action on target - a
LittleEndian
register and a constant withX
on target - a
LittleEndian
register and a constant with arbitrary action on target
in Numerics
:
- two
FixedPoint
registers withX
on target - two
FixedPoint
registers with arbitrary action on target - a
FixedPoint
register and a constant (withX
on target)
Current status
Comparison operations are not readily available for all 4 cases and no specializations with constants exists. The constant variants are optimized and do not lead to additional qubit overhead.
User feedback
Useful for resource estimation.
Proposal
We describe all operations for the case LessThan
(<
), but analogously operations are introduced for LessThanOrEqual
(<=
), GreaterThanOrEqual
(>=
), and GreaterThan
(>
)
New and modified functions, operations, and UDTs
namespace Microsoft.Quantum.Arithmetic {
/// # Summary
/// Performs less-than comparison of two quantum registers.
///
/// # Description
/// Inverts classical state of output qubit `output` if and only if input register `x`
/// is less than input register `y`.
///
/// # Input
/// ## x
/// Quantum register.
/// ## y
/// Quantum register.
/// ## target
/// Target qubit for comparison result.
operation CompareLessThan(x : LittleEndian, y : LittleEndian, target : Qubit) : Unit is Adj+Ctl { ... }
/// # Summary
/// Conditional action based on less-than comparison of two quantum registers.
///
/// # Description
/// Applies `action` to `output` if and only if input register `x` is less than input register `y`.
///
/// # Input
/// ## action
/// Action to be applied to `target`
/// ## x
/// Quantum register.
/// ## y
/// Quantum register.
/// ## target
/// Target input for `action`.
operation ApplyControlledOnLessThan<'T>(action : 'T => Unit is Adj + Ctl, x : LittleEndian, y : LittleEndian, target : 'T) : Unit is Adj + Ctl { ... }
/// # Summary
/// Performs less-than comparison of a quantum register with a constant.
///
/// # Description
/// Inverts classical state of output qubit `output` if and only if input register `x`
/// is less than constant `c`.
///
/// # Input
/// ## c
/// Constant value.
/// ## x
/// Quantum register.
/// ## target
/// Target qubit for comparison result.
operation CompareLessThanConstant(c : BigInt, x : LittleEndian, target : Qubit) : Unit is Adj + Ctl { ... }
/// # Summary
/// Conditional action based on less-than comparison of two quantum registers.
///
/// # Description
/// Applies `action` to `output` if and only if input register `x` is less than constant `c`.
///
/// # Input
/// ## action
/// Action to be applied to `target`
/// ## c
/// Constant value.
/// ## x
/// Quantum register.
/// ## target
/// Target input for `action`.
operation ApplyControlledOnLessThanConstant<'T>(action : 'T => Unit is Adj + Ctl, c : BigInt, x : LittleEndian, target: 'T) { ... }
/// # Summary
/// Performs less-than comparison of two quantum registers in fixed-point representation.
///
/// # Description
/// Inverts classical state of output qubit `output` if and only if input register `x`
/// is less than to input register `y`.
///
/// # Input
/// ## x
/// Quantum register.
/// ## y
/// Quantum register.
/// ## target
/// Target qubit for comparison result.
operation CompareLessThanFxP(fp1 : FixedPoint, fp2 : FixedPoint, target : Qubit) : Unit is Adj + Ctl { ... }
/// # Summary
/// Conditional action based on less-than comparison of two quantum registers in fixed-point representation.
///
/// # Description
/// Applies `action` to `output` if and only if input register `x` is less than input register `y`.
///
/// # Input
/// ## action
/// Action to be applied to `target`
/// ## x
/// Quantum register.
/// ## y
/// Quantum register.
/// ## target
/// Target input for `action`.
operation ApplyControlledOnLessThanFxP<'T>(action : 'T => Unit is Adj + Ctl, fp1 : FixedPoint, fp2 : FixedPoint, target : 'T) : Unit is Adj + Ctl { ... }
/// # Summary
/// Performs less-than comparison of a quantum fixed-point register with a constant.
///
/// # Description
/// Inverts classical state of output qubit `output` if and only if input register `x`
/// is less than to constant `c`.
///
/// # Input
/// ## c
/// Constant value.
/// ## x
/// Quantum register.
/// ## target
/// Target qubit for comparison result.
operation CompareLessThanConstantFxP(c : Double, x : FixedPoint, target : Qubit) : Unit is Adj + Ctl { ... }
}
Relationship to other proposals
- Enhancements to UDTs for representing numeric data in quantum registers #337
- Simple and consistent arithmetic API #423
(see comments below)
Metadata
Metadata
Assignees
Labels
Area-APIIssue concerns the API design of a library, such as style guide or design principles adherence.Issue concerns the API design of a library, such as style guide or design principles adherence.Kind-EnhancementNew feature or requestNew feature or requestPkg-NumericsIssue relates to the Microsoft.Quantum.Numerics package.Issue relates to the Microsoft.Quantum.Numerics package.Pkg-StandardIssue relates to the Microsoft.Quantum.Standard package.Issue relates to the Microsoft.Quantum.Standard package.trackingThis label will trigger gh-sync to create or update a mirror internal ADO issue.This label will trigger gh-sync to create or update a mirror internal ADO issue.