Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Fixed point truncation #598

Open
msoeken opened this issue Jun 24, 2022 · 1 comment
Open

Fixed point truncation #598

msoeken opened this issue Jun 24, 2022 · 1 comment
Labels
Area-API Issue concerns the API design of a library, such as style guide or design principles adherence. Kind-Enhancement New feature or request Pkg-Numerics Issue relates to the Microsoft.Quantum.Numerics package. Status-NeedsApiReview This PR requires an API review before merging in.

Comments

@msoeken
Copy link
Member

msoeken commented Jun 24, 2022

Fixed point truncation

Conceptual overview

Truncate fixed point register to lower precision.

Current status

Needs to be done manually and is very errorprone.

Proposal

New and modified functions, operations, and UDTs

Functions to be added to the Numerics package.

namespace Microsoft.Quantum.Arithmetic {

    /// # Summary
    /// Truncates a fixed point register to fewer precision
    ///
    /// # Input
    /// ## integerBits
    /// New number of integer bits, cannot be larger than current number of integer bits
    /// ## fractionalBits
    /// New number of fractional bits, cannot be larger than current number of fractional bits
    /// ## fp
    /// Input fixed point register
    ///
    /// # Output
    /// New fixed point register (based on qubits of input fixed point register) with adjusted
    /// precision.  The sign bit is preserved and counted as part of `integerBits`.
    ///
    /// # Example
    /// ```qsharp
    /// use qubits = Qubit[10];
    /// let fp = FixedPoint(7, qubits);
    /// let truncated = TruncateFxP(7, 1, fp);
    /// PrepareFxP(3.875, fp);
    /// NearEqualityFactD(MeasureFxP(truncated), 3.5);
    /// ```
    function TruncateFxP(integerBits : Int, fractionalBits : Int, fp : FixedPoint) : FixedPoint { ... }

}
@msoeken msoeken added Kind-Enhancement New feature or request Pkg-Numerics Issue relates to the Microsoft.Quantum.Numerics package. Status-NeedsApiReview This PR requires an API review before merging in. Area-API Issue concerns the API design of a library, such as style guide or design principles adherence. labels Jun 24, 2022
@msoeken msoeken added this to Ready to be reviewed in API Review Scheduling Jul 17, 2022
@tcNickolas
Copy link
Member

  • Fewer precision -> smaller precision
  • Let's add periods at the end of the summary and the input descriptions to match the rest of the APIs
  • Can you add a bit more detail on how the truncation happens in the # Output section? I can guess that for the fractional bits the least significant bits are truncated, but for the integer bits it's a little less obvious. Are the bits truncated the most significant bits, excluding the sign bit? It would also be good to expand the example to cover integer bit truncation as well.
  • I couldn't find in the API docs the limitations on the number of integer bits - do we require it to be >= 0 or => 1? Are there any limitations on the number of integer bits imposed by that here? For example, can we truncate the number to 0 integer bits, losing the sign bit in the process?

Other than that, looks good!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area-API Issue concerns the API design of a library, such as style guide or design principles adherence. Kind-Enhancement New feature or request Pkg-Numerics Issue relates to the Microsoft.Quantum.Numerics package. Status-NeedsApiReview This PR requires an API review before merging in.
Projects
API Review Scheduling
Ready to be reviewed
Development

No branches or pull requests

2 participants