QIO-1.2: The Quantum IO Monad is a library for defining quantum computations in Haskell

Safe HaskellSafe-Infered

QIO.VecEq

Description

This module defines a class of Vectors over types with Equality, along with an instance of this class using lists of pairs. In the context of QIO, these Vectors are used to hold the amplitudes of various basis-states within a superposition.

Synopsis

Documentation

class VecEq v whereSource

Any type that fulfills this type class is a Vector over types with equality

Methods

vzero :: v x aSource

An empty instance of the vector

(<+>) :: (Eq a, Num x) => v x a -> v x a -> v x aSource

Two Vectors can be combined

(<*>) :: (Num x, Eq x) => x -> v x a -> v x aSource

A Vector can be multiplied by a scalar

(<@>) :: (Eq a, Num x) => a -> v x a -> xSource

The amplitude of a given element can be accessed

fromList :: [(a, x)] -> v x aSource

The vector can be created from a list of pairs

toList :: v x a -> [(a, x)]Source

The cevtor can be converted into a list of pairs

Instances

VecEq VecEqL

VecEqL is an instance of the VecEq class

newtype VecEqL x a Source

This type is a wrapper around a list of pairs.

Constructors

VecEqL 

Fields

unVecEqL :: [(a, x)]
 

Instances

VecEq VecEqL

VecEqL is an instance of the VecEq class

(Show x, Show a) => Show (VecEqL x a) 

vEqZero :: VecEqL x aSource

An empty VecEqL is a wrapper around the empty list

add :: (Eq a, Num x) => (a, x) -> VecEqL x a -> VecEqL x aSource

A basis state with the given amplitude can be added to a VecEqL by adding the amplitudes if the state is already in the vector, or by inserting the base state if it isn't already in the vector.

vEqPlus :: (Eq a, Num x) => VecEqL x a -> VecEqL x a -> VecEqL x aSource

Combining two vectors is achieved by folding the add operation over the second vector

vEqTimes :: (Num x, Eq x) => x -> VecEqL x a -> VecEqL x aSource

Scalar multiplcation is achieved by mapping the multiplication over each pair in the vector. Multiplication by 0 is a special case, and will remove all the basis states from the vector.

vEqAt :: (Eq a, Num x) => a -> VecEqL x a -> xSource

The amplitude of an element can be found by looking through each element until the matchinf one is found.

class EqMonad m whereSource

An EqMonad is a monad that has Return and Bind operations that depend on the type in the monad being a member of the Eq class

Methods

eqReturn :: Eq a => a -> m aSource

eqBind :: (Eq a, Eq b) => m a -> (a -> m b) -> m bSource

Instances

(VecEq v, Num x, Eq x) => EqMonad (v x)

Any VecEq over v, along with a Numeric tpye x is an EqMonad.

data AsMonad m a whereSource

We can define a datatype that holds EqMonad operations, so that it can be defined as a Monad.

Constructors

Embed :: (EqMonad m, Eq a) => m a -> AsMonad m a 
Return :: EqMonad m => a -> AsMonad m a 
Bind :: EqMonad m => AsMonad m a -> (a -> AsMonad m b) -> AsMonad m b 

Instances

EqMonad m => Monad (AsMonad m)

We can define an AsMonad over an EqMonad, as a Monad

unEmbed :: Eq a => AsMonad m a -> m aSource

Given Equality, we can unembed the EqMonad operations from an AsMonad