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

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 where Source #

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

Minimal complete definition

Methods

vzero :: v x a Source #

An empty instance of the vector

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

Two Vectors can be combined

(<.>) :: (Num x, Eq x) => x -> v x a -> v x a Source #

A Vector can be multiplied by a scalar

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

The amplitude of a given element can be accessed

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

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

 Source # VecEqL is an instance of the VecEq class Methodsvzero :: VecEqL x a Source #(<+>) :: (Eq a, Num x) => VecEqL x a -> VecEqL x a -> VecEqL x a Source #(<.>) :: (Num x, Eq x) => x -> VecEqL x a -> VecEqL x a Source #(<@>) :: (Eq a, Num x) => a -> VecEqL x a -> x Source #fromList :: [(a, x)] -> VecEqL x a Source #toList :: VecEqL x a -> [(a, x)] Source #

newtype VecEqL x a Source #

This type is a wrapper around a list of pairs.

Constructors

 VecEqL FieldsunVecEqL :: [(a, x)]

Instances

 Source # VecEqL is an instance of the VecEq class Methodsvzero :: VecEqL x a Source #(<+>) :: (Eq a, Num x) => VecEqL x a -> VecEqL x a -> VecEqL x a Source #(<.>) :: (Num x, Eq x) => x -> VecEqL x a -> VecEqL x a Source #(<@>) :: (Eq a, Num x) => a -> VecEqL x a -> x Source #fromList :: [(a, x)] -> VecEqL x a Source #toList :: VecEqL x a -> [(a, x)] Source # (Show x, Show a) => Show (VecEqL x a) Source # MethodsshowsPrec :: Int -> VecEqL x a -> ShowS #show :: VecEqL x a -> String #showList :: [VecEqL x a] -> ShowS #

vEqZero :: VecEqL x a Source #

An empty VecEqL is a wrapper around the empty list

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

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 a Source #

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 a Source #

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 -> x Source #

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

class EqMonad m where Source #

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

Minimal complete definition

Methods

eqReturn :: Eq a => a -> m a Source #

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

Instances

 (VecEq v, Num x, Eq x) => EqMonad (v x) Source # Any VecEq over v, along with a Numeric tpye x is an EqMonad. MethodseqReturn :: Eq a => a -> v x a Source #eqBind :: (Eq a, Eq b) => v x a -> (a -> v x b) -> v x b Source #

data AsMonad m a where Source #

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

Constructors