Skip to content

Commit

Permalink
Merge pull request #4 from ardeleanasm/qubits
Browse files Browse the repository at this point in the history
#3 added qubit and utils modules
  • Loading branch information
ardeleanasm committed Jul 23, 2017
2 parents f67f459 + a57f8ba commit 4a9357e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions qchas.cabal
Expand Up @@ -15,6 +15,8 @@ cabal-version: >=1.10
library
hs-source-dirs: src
exposed-modules: Lib
, Utils
, Qubits
build-depends: base >= 4.7 && < 5
default-language: Haskell2010

Expand Down
24 changes: 24 additions & 0 deletions src/Qubits.hs
@@ -0,0 +1,24 @@
module Qubits
(
qOne
,qZero
,qPlus
,qMinus
) where


import Data.Complex
import Data.List(transpose)
import Utils

qZero::Vector(Complex Double)
qZero=complexVector[1,0]

qOne::Vector(Complex Double)
qOne=complexVector[0,1]

qPlus::Vector(Complex Double)
qPlus=complexVector[1/sqrt 2, 1/sqrt 2]

qMinus::Vector(Complex Double)
qMinus=complexVector[1/sqrt 2, -1/sqrt 2]
25 changes: 25 additions & 0 deletions src/Utils.hs
@@ -0,0 +1,25 @@
module Utils
(
Vector,
Matrix,
complexVector,
complexMatrix
) where

import Data.Complex
import Data.List(transpose)

-- Basic new types needed for defining qubits
type Vector a=[a]
type Matrix a=[Vector a]

complexVector::Real a=>Vector a->Vector(Complex Double)
complexVector=map(\i->realToFrac i:+0.0)

complexMatrix::Real a=>Matrix a->Matrix(Complex Double)
complexMatrix=map complexVector





0 comments on commit 4a9357e

Please sign in to comment.