newsynth-0.3.0.5: Exact and approximate synthesis of quantum circuits

Safe HaskellSafe
LanguageHaskell98

Quantum.Synthesis.ToReal

Contents

Description

This module provides a type class of things that can be converted to arbitrary precision real numbers.

Synopsis

Conversion to real number types

class ToReal a where Source #

A type class for things that can be converted to a real number at arbitrary precision.

Minimal complete definition

to_real

Methods

to_real :: (Floating r, ArcTan2 r) => a -> r Source #

Instances

ToReal Double Source # 

Methods

to_real :: (Floating r, ArcTan2 r) => Double -> r Source #

ToReal Float Source # 

Methods

to_real :: (Floating r, ArcTan2 r) => Float -> r Source #

ToReal Int Source # 

Methods

to_real :: (Floating r, ArcTan2 r) => Int -> r Source #

ToReal Integer Source # 

Methods

to_real :: (Floating r, ArcTan2 r) => Integer -> r Source #

ToReal Rational Source # 

Methods

to_real :: (Floating r, ArcTan2 r) => Rational -> r Source #

Precision e => ToReal (FixedPrec e) Source # 

Methods

to_real :: (Floating r, ArcTan2 r) => FixedPrec e -> r Source #

Dynamic conversion to FixedPrec

dynamic_fixedprec :: forall a r. ToReal r => Integer -> (forall e. Precision e => FixedPrec e -> a) -> r -> a Source #

It would be useful to have a function for converting a symbolic real number to a fixed-precision real number with a chosen precision, such that the precision e depends on a parameter d:

to_fixedprec :: (ToReal r) => Integer -> r -> FixedPrec e
to_fixedprec d x = ...

However, since e is a type, d is a term, and Haskell is not dependently typed, this cannot be done directly.

The function dynamic_fixedprec is the closest thing we have to a workaround. The call dynamic_fixedprec d f x calls f(x'), where x' is the value x converted to d digits of precision. In other words, we have

dynamic_fixedprec d f x = f (to_fixedprec d x),

with the restriction that the precision e cannot occur freely in the result type of f.

dynamic_fixedprec2 :: forall a r s. (ToReal r, ToReal s) => Integer -> (forall e. Precision e => FixedPrec e -> FixedPrec e -> a) -> r -> s -> a Source #

Like dynamic_fixedprec, but take two real number arguments. In terms of the fictitious function to_fixedprec, we have:

dynamic_fixedprec2 d f x y = f (to_fixedprec d x) (to_fixedprec d y).