microsoft / QuantumLibraries

Q# libraries for the Quantum Development Kit

Home Page:https://docs.microsoft.com/quantum

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FixedPoint conversion functions

msoeken opened this issue · comments

FixedPoint conversion functions

Conceptual overview

This adds two functions to convert fixed-point representations to and from Bool[]. This extracts the underlying logic for PrepareFxP and MeasureFxP as functions.

Current status

This functions are only implicitly available and would require qubit allocation in order to access them.

Proposal

New and modified functions, operations, and UDTs

namespace Microsoft.Quantum.Convert
{

/// # Summary
/// Computes fixed-point approximation for a double and returns it as `Bool` array.
///
/// # Input
/// ## integerBits
/// Assumed number of integerBits (including the sign big)
/// ## fractionalBits
/// Assumed number of fractionalBits
/// ## value
/// Value to be approximated
function FixedPointAsBoolArray(integerBits : Int, fractionalBits : Int, value : Double) : Bool[] {}

/// # Summary
/// Returns the double value of a fixed-point approximation from of a `Bool` array.
///
/// # Input
/// ## integerBits
/// Assumed number of integerBits (including the sign big)
/// ## bits
/// Bit-string representation of approximated number
function BoolArrayAsFixedPoint(integerBits : Int, bits : Bool[]) : Double {}

/// # Summary
/// Discretizes a double value as a double and returns its approximated representation as a double.
///
/// # Input
/// ## integerBits
/// Assumed number of integerBits (including the sign big)
/// ## fractionalBits
/// Assumed number of fractionalBits
/// ## value
/// Value to be approximated
function DoubleAsFixedPoint(integerBits : Int, fractionalBits : Int, value : Double) : Double {
    return BoolArrayAsFixedPoint(integerBits, fractionalBits, FixedPointAsBoolArray(integerBits, fractionalBits, value));
}

}

Examples

Current status

TODO.

Using proposed changes

TODO.

Open design questions and considerations

These functions should be used in the implementation of PrepareFxP and MeasureFxP.

I missed this when I was reviewing #575, but these functions will need examples in the API docs. They're classical so examples should be simple, giving usage example and expected results for them.