The Quipper System

Safe HaskellNone

Quipper.Algorithms.QLS.QDouble

Contents

Description

This modules implements a library for fixed-points real numbers.

Synopsis

Signed fixed point type

data XDouble x Source #

Data type for fixed point arithmetic.

XDouble k n represents the number n⋅2-k, where n is a signed integer and k is an integer parameter.

We refer to k as the exponent of the fixed point number. When we speak of the length, we mean the total number of digits (excluding the sign), i.e., the length, in binary digits, of the underlying n.

Constructors

XDouble Int (SignedInt x) 
Instances
Eq QDouble # 
Instance details

Defined in Quipper.Algorithms.QLS.QDouble

Methods

(==) :: QDouble -> QDouble -> Bool #

(/=) :: QDouble -> QDouble -> Bool #

Eq FDouble # 
Instance details

Defined in Quipper.Algorithms.QLS.QDouble

Methods

(==) :: FDouble -> FDouble -> Bool #

(/=) :: FDouble -> FDouble -> Bool #

Floating FDouble # 
Instance details

Defined in Quipper.Algorithms.QLS.RealFunc

Fractional FDouble # 
Instance details

Defined in Quipper.Algorithms.QLS.QDouble

Num FDouble # 
Instance details

Defined in Quipper.Algorithms.QLS.QDouble

Ord FDouble # 
Instance details

Defined in Quipper.Algorithms.QLS.QDouble

Real FDouble # 
Instance details

Defined in Quipper.Algorithms.QLS.QDouble

RealFloat FDouble # 
Instance details

Defined in Quipper.Algorithms.QLS.RealFunc

RealFrac FDouble # 
Instance details

Defined in Quipper.Algorithms.QLS.QDouble

Methods

properFraction :: Integral b => FDouble -> (b, FDouble) #

truncate :: Integral b => FDouble -> b #

round :: Integral b => FDouble -> b #

ceiling :: Integral b => FDouble -> b #

floor :: Integral b => FDouble -> b #

QOrd QDouble # 
Instance details

Defined in Quipper.Algorithms.QLS.QDouble

QNum QDouble # 
Instance details

Defined in Quipper.Algorithms.QLS.QDouble

QFloating QDouble # 
Instance details

Defined in Quipper.Algorithms.QLS.RealFunc

Show x => Show (XDouble x) # 
Instance details

Defined in Quipper.Algorithms.QLS.QDouble

Methods

showsPrec :: Int -> XDouble x -> ShowS #

show :: XDouble x -> String #

showList :: [XDouble x] -> ShowS #

QCLeaf x => QCData (XDouble x) # 
Instance details

Defined in Quipper.Algorithms.QLS.QDouble

Methods

qcdata_mapM :: Monad m => XDouble x -> (q -> m q') -> (c -> m c') -> QCType q c (XDouble x) -> m (QCType q' c' (XDouble x)) Source #

qcdata_zip :: XDouble x -> q -> c -> q' -> c' -> QCType q c (XDouble x) -> QCType q' c' (XDouble x) -> ErrMsg -> QCType (q, q') (c, c') (XDouble x) Source #

qcdata_promote :: BType (XDouble x) -> XDouble x -> ErrMsg -> BType (XDouble x) Source #

QCLeaf x => Labelable (XDouble x) String # 
Instance details

Defined in Quipper.Algorithms.QLS.QDouble

Methods

label_rec :: XDouble x -> String -> LabelMonad () Source #

CircLiftingUnpack (Circ QDouble) (Circ QDouble) # 
Instance details

Defined in Quipper.Algorithms.QLS.QDouble

Num (FDouble, FDouble) # 
Instance details

Defined in Quipper.Algorithms.QLS.QDouble

QNum (QDouble, QDouble) # 
Instance details

Defined in Quipper.Algorithms.QLS.QDouble

type QTypeB FDouble # 
Instance details

Defined in Quipper.Algorithms.QLS.QDouble

type QCType x y (XDouble z) # 
Instance details

Defined in Quipper.Algorithms.QLS.QDouble

type QCType x y (XDouble z) = XDouble (QCType x y z)

type FDouble = XDouble Bool Source #

The parameter type of fixed-point numbers.

type QDouble = XDouble Qubit Source #

The quantum type of fixed-point numbers.

type CDouble = XDouble Bit Source #

The classical type of fixed-point numbers.

Auxiliary definitions

integer_power :: Int -> Int -> Integer Source #

Compute the power of an integer by a non-negative integer.

double_power :: Int -> Int -> Double Source #

Compute the power of an integer by another, possibly negative one.

div_round :: Integer -> Integer -> Integer Source #

Divide one integer by another, and round the result to the closest integer. If the result is half way between two integers, round to the even one (this is the same behavior as Haskell's round function). This function has unlimited precision.

Operation for length and exponent

Generic functions for XDouble

xdouble_exponent :: XDouble x -> Int Source #

Return the exponent k of an XDouble.

xdouble_length :: XDouble x -> Int Source #

Return the length m of an XDouble.

xdouble_extent :: XDouble x -> (Int, Int) Source #

Return the "extent" of an XDouble. The extent of a fixed-point number x is, by definition, the pair (hi,lo) of integers such that the most significant bit of x has positional index hi-1 (in other words, the value of this bit is 2hi-1), and the least significant bit of x has positional index lo (in other words, the value of this bit is 2lo. Typically, but not necessarily, hi ≥ 0 and lo ≤ 0. In this case, one can also think of hi as "the number of digits before the radix point" and −lo as "the number of digits after the radix point".

The exponent k, length m, and extent (hi,lo) are related by k=-lo and m=hilo.

Examples:

  • a number represented in the form xxxx.yyy has extent (4,-3), exponent 3, and length 7.
  • a number represented in the form xxxx000. has extent (7,3), exponent -3, and length 4.
  • a number represented in the form .000xxxx has extent (-3,-7), exponent 7, and length 4.

If we regard extents as intervals, ordered by inclusion, then it is always possible to losslessly cast a fixed-point number from a smaller to a larger extent.

xdouble_pad_left :: Monad m => m x -> Int -> XDouble x -> m (XDouble x) Source #

Add n zeros to the high bits of the XDouble. This sends xxx.yyy to 000xxx.yyy. This increases the length without changing the exponent or value.

xdouble_pad_right :: Monad m => m x -> Int -> XDouble x -> m (XDouble x) Source #

Add n zeros to the low bits of the XDouble. This sends xxx.yyy to xxx.yyy000. This increases the length and the exponent without changing the value.

xdouble_pad_to_extent :: Monad m => m x -> (Int, Int) -> XDouble x -> m (XDouble x) Source #

Pad an XDouble on both sides to reach the desired extent. This increases the length and exponent without changing the value (it is a lossless operation). It is an error to call this function if the selected extent does not contain the extent of the input XDouble.

xdouble_truncate_right :: Int -> QDouble -> QDouble Source #

Remove the n low bits of an XDouble. This sends xxx.yyyzzz to xxx.yyy. It is an error to call this function when the XDouble has fewer than n digits.

xdouble_of_sint :: SignedInt x -> XDouble x Source #

Convert a SignedInt to an XDouble with exponent 0.

Special cases for QDouble

qdouble_pad_left :: Int -> QDouble -> Circ QDouble Source #

Add n zeros to the high bits of the QDouble. This sends xxx.yyy to 000xxx.yyy. This increases the length without changing the exponent or value. This function does not return a fresh copy; it reuses part of its input.

qdouble_pad_right :: Int -> QDouble -> Circ QDouble Source #

Add n zeros to the low bits of the QDouble. This sends xxx.yyy to xxx.yyy000. This increases the length and the exponent without changing the value. This function does not return a fresh copy; it reuses part of its input.

qdouble_pad_to_extent :: (Int, Int) -> QDouble -> Circ QDouble Source #

Pad a QDouble on both sides to reach the desired extent. This increases the length and exponent without changing the value (it is a lossless operation). It is an error to call this function if the selected extent does not contain the extent of the input QDouble. This function does not return a fresh copy; it reuses part of its input.

qdouble_truncate_right :: Int -> QDouble -> QDouble Source #

Remove the n low bits of a QDouble. This sends xxx.yyyzzz to xxx.yyy. Note that the n low qubits are not terminated and become garbage. It is an error to call this function when the QDouble has fewer than n digits.

Special cases for FDouble

fdouble_pad_right :: Int -> FDouble -> FDouble Source #

Add n zeros to the low bits of the FDouble. This sends xxx.yyy to xxx.yyy000. This increases the length and the exponent without changing the value.

fdouble_pad_to_extent :: (Int, Int) -> FDouble -> FDouble Source #

Pad a FDouble on both sides to reach the desired extent. This increases the length and exponent without changing the value (it is a lossless operation). It is an error to call this function if the selected extent does not contain the extent of the input FDouble.

Operations for FDouble

Casts

fdouble_of_double :: Int -> Int -> Double -> FDouble Source #

fdouble_of_double k m x: Convert x to an FDouble of exponent k and length m ≥ 0. Note that the exponent does not need to be between 0 and m; it can even be negative.

fdouble_of_fsint :: FSignedInt -> FDouble Source #

Convert an FSignedInt to an FDouble with exponent 0.

fdouble_of_integer :: Int -> Int -> Integer -> FDouble Source #

Make an FDouble value of exponent k, length m, and value a2-k.

fdouble :: Double -> FDouble Source #

Construct a Double from an FDouble, using some arbitrary method to guess the length and exponent.

show_fdouble :: FDouble -> String Source #

Convert an FDouble to a string in human-readable form.

Type class instances

We make FDouble an instance of Eq, Ord, Real, Num, Fractional, and RealFrac. See the source code for details.

fdouble_align :: FDouble -> FDouble -> (Int, FSignedInt, FSignedInt) Source #

Express a pair of FDouble values as a pair of FSignedInts with a common exponent.

Casts

qdouble_of_qsint :: QSignedInt -> Circ QDouble Source #

Convert a QSignedInt to a QDouble with exponent 0. This function does not return a fresh copy; instead, it uses the input qubits.

Type class instances

We make QDouble an instance of QOrd.

qdouble_align :: QDouble -> QDouble -> Circ (Int, QSignedInt, QSignedInt) Source #

Express a pair of QDouble values as a pair of QSignedInts with a common exponent.

Other functions

q_ceiling :: QDouble -> Circ QSignedInt Source #

QDouble of ceiling: coercion from QDouble to QSignedInt.

q_div_real :: QDouble -> QDouble -> Circ QDouble Source #

Real division with QDouble.

Orphan instances

Eq QSignedInt # 
Instance details