qfunc-0.1.0.0
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

FunQ

Description

Exports the language and simulator

Synopsis

Core operations

new :: Bit -> QM QBit Source #

Create new QBit from a bit. maps \(0 \mapsto |0>\) and \(1 \mapsto |1>\)

measure :: QBit -> QM Bit Source #

Performs a measurement operation, collapsing a QBit to a Bit. The qubit will still exist in the quantum state, but be collapsed.

Finds qubit probability to collapse to a zero and one. Uses random number generator to "measure it" to a zero or one. Updates quantum state to remove impossible states, and normalizes it so probabilites sum to one.

ndist :: Int -> QM Bit -> IO () Source #

Run a quantum program producing a single bit reps times and print the results

dist :: QM Bit -> IO () Source #

Print results from a 100 runs of a program

controlbit :: QM a -> Bit -> QM () Source #

Sets a classical bit as the controlbit for a quantum gate. Making it run only when the classical bit is equal to one.

Core types

data QBit Source #

Pointer to a qubit in QState. Represents the linking function in QLambda

Instances

Instances details
Show QBit Source # 
Instance details

Defined in Lib.QM

Methods

showsPrec :: Int -> QBit -> ShowS #

show :: QBit -> String #

showList :: [QBit] -> ShowS #

data Bit #

Instances

Instances details
Bounded Bit 
Instance details

Defined in Data.Bit.Internal

Methods

minBound :: Bit #

maxBound :: Bit #

Enum Bit 
Instance details

Defined in Data.Bit.Internal

Methods

succ :: Bit -> Bit #

pred :: Bit -> Bit #

toEnum :: Int -> Bit #

fromEnum :: Bit -> Int #

enumFrom :: Bit -> [Bit] #

enumFromThen :: Bit -> Bit -> [Bit] #

enumFromTo :: Bit -> Bit -> [Bit] #

enumFromThenTo :: Bit -> Bit -> Bit -> [Bit] #

Eq Bit 
Instance details

Defined in Data.Bit.Internal

Methods

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

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

Fractional Bit 
Instance details

Defined in Data.Bit.Internal

Methods

(/) :: Bit -> Bit -> Bit #

recip :: Bit -> Bit #

fromRational :: Rational -> Bit #

Integral Bit 
Instance details

Defined in Data.Bit.Internal

Methods

quot :: Bit -> Bit -> Bit #

rem :: Bit -> Bit -> Bit #

div :: Bit -> Bit -> Bit #

mod :: Bit -> Bit -> Bit #

quotRem :: Bit -> Bit -> (Bit, Bit) #

divMod :: Bit -> Bit -> (Bit, Bit) #

toInteger :: Bit -> Integer #

Num Bit 
Instance details

Defined in Data.Bit.Internal

Methods

(+) :: Bit -> Bit -> Bit #

(-) :: Bit -> Bit -> Bit #

(*) :: Bit -> Bit -> Bit #

negate :: Bit -> Bit #

abs :: Bit -> Bit #

signum :: Bit -> Bit #

fromInteger :: Integer -> Bit #

Ord Bit 
Instance details

Defined in Data.Bit.Internal

Methods

compare :: Bit -> Bit -> Ordering #

(<) :: Bit -> Bit -> Bool #

(<=) :: Bit -> Bit -> Bool #

(>) :: Bit -> Bit -> Bool #

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

max :: Bit -> Bit -> Bit #

min :: Bit -> Bit -> Bit #

Read Bit 
Instance details

Defined in Data.Bit.Internal

Real Bit 
Instance details

Defined in Data.Bit.Internal

Methods

toRational :: Bit -> Rational #

Show Bit 
Instance details

Defined in Data.Bit.Internal

Methods

showsPrec :: Int -> Bit -> ShowS #

show :: Bit -> String #

showList :: [Bit] -> ShowS #

Generic Bit 
Instance details

Defined in Data.Bit.Internal

Associated Types

type Rep Bit :: Type -> Type #

Methods

from :: Bit -> Rep Bit x #

to :: Rep Bit x -> Bit #

Bits Bit 
Instance details

Defined in Data.Bit.Internal

Methods

(.&.) :: Bit -> Bit -> Bit #

(.|.) :: Bit -> Bit -> Bit #

xor :: Bit -> Bit -> Bit #

complement :: Bit -> Bit #

shift :: Bit -> Int -> Bit #

rotate :: Bit -> Int -> Bit #

zeroBits :: Bit #

bit :: Int -> Bit #

setBit :: Bit -> Int -> Bit #

clearBit :: Bit -> Int -> Bit #

complementBit :: Bit -> Int -> Bit #

testBit :: Bit -> Int -> Bool #

bitSizeMaybe :: Bit -> Maybe Int #

bitSize :: Bit -> Int #

isSigned :: Bit -> Bool #

shiftL :: Bit -> Int -> Bit #

unsafeShiftL :: Bit -> Int -> Bit #

shiftR :: Bit -> Int -> Bit #

unsafeShiftR :: Bit -> Int -> Bit #

rotateL :: Bit -> Int -> Bit #

rotateR :: Bit -> Int -> Bit #

popCount :: Bit -> Int #

FiniteBits Bit 
Instance details

Defined in Data.Bit.Internal

NFData Bit 
Instance details

Defined in Data.Bit.Internal

Methods

rnf :: Bit -> () #

Unbox Bit 
Instance details

Defined in Data.Bit.Internal

MVector MVector Bit 
Instance details

Defined in Data.Bit.Internal

Methods

basicLength :: MVector s Bit -> Int

basicUnsafeSlice :: Int -> Int -> MVector s Bit -> MVector s Bit

basicOverlaps :: MVector s Bit -> MVector s Bit -> Bool

basicUnsafeNew :: PrimMonad m => Int -> m (MVector (PrimState m) Bit)

basicInitialize :: PrimMonad m => MVector (PrimState m) Bit -> m ()

basicUnsafeReplicate :: PrimMonad m => Int -> Bit -> m (MVector (PrimState m) Bit)

basicUnsafeRead :: PrimMonad m => MVector (PrimState m) Bit -> Int -> m Bit

basicUnsafeWrite :: PrimMonad m => MVector (PrimState m) Bit -> Int -> Bit -> m ()

basicClear :: PrimMonad m => MVector (PrimState m) Bit -> m ()

basicSet :: PrimMonad m => MVector (PrimState m) Bit -> Bit -> m ()

basicUnsafeCopy :: PrimMonad m => MVector (PrimState m) Bit -> MVector (PrimState m) Bit -> m ()

basicUnsafeMove :: PrimMonad m => MVector (PrimState m) Bit -> MVector (PrimState m) Bit -> m ()

basicUnsafeGrow :: PrimMonad m => MVector (PrimState m) Bit -> Int -> m (MVector (PrimState m) Bit)

Vector Vector Bit 
Instance details

Defined in Data.Bit.Internal

Methods

basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) Bit -> m (Vector Bit)

basicUnsafeThaw :: PrimMonad m => Vector Bit -> m (Mutable Vector (PrimState m) Bit)

basicLength :: Vector Bit -> Int

basicUnsafeSlice :: Int -> Int -> Vector Bit -> Vector Bit

basicUnsafeIndexM :: Monad m => Vector Bit -> Int -> m Bit

basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) Bit -> Vector Bit -> m ()

elemseq :: Vector Bit -> Bit -> b -> b

type Rep Bit 
Instance details

Defined in Data.Bit.Internal

type Rep Bit = D1 ('MetaData "Bit" "Data.Bit.Internal" "bitvec-1.0.3.0-1bYctJlKC6eAXJO2rehjXD" 'True) (C1 ('MetaCons "Bit" 'PrefixI 'True) (S1 ('MetaSel ('Just "unBit") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Bool)))
data Vector Bit 
Instance details

Defined in Data.Bit.Internal

data Vector Bit = BitVec !Int !Int !ByteArray
data MVector s Bit 
Instance details

Defined in Data.Bit.Internal

data MVector s Bit = BitMVec !Int !Int !(MutableByteArray s)

data QM a Source #

The Quantum Monad Keeps a state of the complex vector representation while allowing pseudo-random number generation

Instances

Instances details
Monad QM Source # 
Instance details

Defined in Lib.QM

Methods

(>>=) :: QM a -> (a -> QM b) -> QM b #

(>>) :: QM a -> QM b -> QM b #

return :: a -> QM a #

Functor QM Source # 
Instance details

Defined in Lib.QM

Methods

fmap :: (a -> b) -> QM a -> QM b #

(<$) :: a -> QM b -> QM a #

Applicative QM Source # 
Instance details

Defined in Lib.QM

Methods

pure :: a -> QM a #

(<*>) :: QM (a -> b) -> QM a -> QM b #

liftA2 :: (a -> b -> c) -> QM a -> QM b -> QM c #

(*>) :: QM a -> QM b -> QM b #

(<*) :: QM a -> QM b -> QM a #

Show (QM a) Source # 
Instance details

Defined in Lib.QM

Methods

showsPrec :: Int -> QM a -> ShowS #

show :: QM a -> String #

showList :: [QM a] -> ShowS #

Gates

pauliX :: QBit -> QM QBit Source #

Pauli-X gate

\[ \text{X} = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix} \]

pauliY :: QBit -> QM QBit Source #

Pauli-Y gate

\[ \text{Y} = \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix} \]

pauliZ :: QBit -> QM QBit Source #

Pauli-Z gate

\[ \text{Z} = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} \]

hadamard :: QBit -> QM QBit Source #

Hadamard gate

\[ \text{X} = \frac1{\sqrt2} \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix} \]

phase :: QBit -> QM QBit Source #

Phase gate

\[ \text{S} = \begin{bmatrix} 1 & 0 \\ 0 & i \end{bmatrix} \]

phasePi8 :: QBit -> QM QBit Source #

Pi/8 gate (T gate)

\[ \text{T} = \begin{bmatrix} 1 & 0 \\ 0 & e^{i\pi/4} \end{bmatrix} \]

cnot :: (QBit, QBit) -> QM (QBit, QBit) Source #

CNOT gate

\[ \text{CNOT} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{bmatrix} \]

identity :: QBit -> QM QBit Source #

Identity gate

\[ \text{I} = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \]

swap :: (QBit, QBit) -> QM (QBit, QBit) Source #

SWAP gate

\[ \text{SWAP} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \]

tdagger :: QBit -> QM QBit Source #

Hermetian adjoint of T gate (phasePi8)

fredkin :: (QBit, QBit, QBit) -> QM (QBit, QBit, QBit) Source #

Fredkin gate

toffoli :: (QBit, QBit, QBit) -> QM (QBit, QBit, QBit) Source #

Toffoli gate

\[ \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \end{bmatrix} \]

urot :: Int -> QBit -> QM QBit Source #

UROT gate

crot :: Int -> (QBit, QBit) -> QM (QBit, QBit) Source #

Controlled UROT

qft :: [QBit] -> QM [QBit] Source #

Quantum fourier transform

Simulators

run :: QM a -> IO a Source #

Run quantum program, discarding it's final state

runDebug :: QM a -> IO a Source #

Run quantum program, prints the final quantum state and returns the result

Utils

bell :: (Bit, Bit) -> QM (QBit, QBit) Source #

Prepares bell state

bellMeasure :: (QBit, QBit) -> QM (Bit, Bit) Source #

Performs bell measurement