{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
{-# LANGUAGE CPP #-}
module Physics.Learn.Ket
(
C
, i
, magnitude
, Ket
, Bra
, Operator
, xp
, xm
, yp
, ym
, zp
, zm
, np
, nm
, sx
, sy
, sz
, sn
, sn'
, timeEvOp
, timeEv
, Kron(..)
, possibleOutcomes
, outcomesProjectors
, outcomesProbabilities
, Mult(..)
, Dagger(..)
, HasNorm(..)
, Representable(..)
, OrthonormalBasis
, makeOB
, listBasis
, size
, xBasis
, yBasis
, zBasis
, nBasis
)
where
import qualified Data.Complex as C
import Data.Complex
( Complex(..)
, conjugate
)
import qualified Physics.Learn.QuantumMat as M
import Physics.Learn.QuantumMat
( C
, Vector
, Matrix
, (#>)
, (<#)
, conjugateTranspose
, scaleV
, scaleM
, conjV
, fromList
, toList
, fromLists
)
#if MIN_VERSION_base(4,11,0)
import Prelude hiding ((<>))
#endif
infixl 7 <>
data Ket = Ket (Vector C)
instance Show Ket where
show :: Ket -> String
show Ket
k =
let message :: String
message = String
"Use 'rep <basis name> <ket name>'."
in if forall a b. Representable a b => a -> Int
dim Ket
k forall a. Eq a => a -> a -> Bool
== Int
2
then String
"Representation in zBasis:\n" forall a. [a] -> [a] -> [a]
++
forall a. Show a => a -> String
show (forall a b. Representable a b => OrthonormalBasis -> a -> b
rep OrthonormalBasis
zBasis Ket
k) forall a. [a] -> [a] -> [a]
++ String
"\n" forall a. [a] -> [a] -> [a]
++ String
message
else String
message
data Operator = Operator (Matrix C)
instance Show Operator where
show :: Operator -> String
show Operator
op =
let message :: String
message = String
"Use 'rep <basis name> <operator name>'."
in if forall a b. Representable a b => a -> Int
dim Operator
op forall a. Eq a => a -> a -> Bool
== Int
2
then String
"Representation in zBasis:\n" forall a. [a] -> [a] -> [a]
++
forall a. Show a => a -> String
show (forall a b. Representable a b => OrthonormalBasis -> a -> b
rep OrthonormalBasis
zBasis Operator
op) forall a. [a] -> [a] -> [a]
++ String
"\n" forall a. [a] -> [a] -> [a]
++ String
message
else String
message
data Bra = Bra (Vector C)
instance Show Bra where
show :: Bra -> String
show Bra
_ = String
"<bra>\nTry 'rep zBasis <bra name>'"
magnitude :: C -> Double
magnitude :: Complex Double -> Double
magnitude = forall a. RealFloat a => Complex a -> a
C.magnitude
i :: C
i :: Complex Double
i = Double
0 forall a. a -> a -> Complex a
:+ Double
1
class Mult a b c | a b -> c where
(<>) :: a -> b -> c
instance Mult C C C where
Complex Double
z1 <> :: Complex Double -> Complex Double -> Complex Double
<> Complex Double
z2 = Complex Double
z1 forall a. Num a => a -> a -> a
* Complex Double
z2
instance Mult C Ket Ket where
Complex Double
c <> :: Complex Double -> Ket -> Ket
<> Ket Vector (Complex Double)
matrixKet = Vector (Complex Double) -> Ket
Ket (Complex Double
-> Vector (Complex Double) -> Vector (Complex Double)
scaleV Complex Double
c Vector (Complex Double)
matrixKet)
instance Mult C Bra Bra where
Complex Double
c <> :: Complex Double -> Bra -> Bra
<> Bra Vector (Complex Double)
matrixBra = Vector (Complex Double) -> Bra
Bra (Complex Double
-> Vector (Complex Double) -> Vector (Complex Double)
scaleV Complex Double
c Vector (Complex Double)
matrixBra)
instance Mult C Operator Operator where
Complex Double
c <> :: Complex Double -> Operator -> Operator
<> Operator Matrix (Complex Double)
m = Matrix (Complex Double) -> Operator
Operator (Complex Double
-> Matrix (Complex Double) -> Matrix (Complex Double)
scaleM Complex Double
c Matrix (Complex Double)
m)
instance Mult Ket C Ket where
Ket Vector (Complex Double)
matrixKet <> :: Ket -> Complex Double -> Ket
<> Complex Double
c = Vector (Complex Double) -> Ket
Ket (Complex Double
-> Vector (Complex Double) -> Vector (Complex Double)
scaleV Complex Double
c Vector (Complex Double)
matrixKet)
instance Mult Bra C Bra where
Bra Vector (Complex Double)
matrixBra <> :: Bra -> Complex Double -> Bra
<> Complex Double
c = Vector (Complex Double) -> Bra
Bra (Complex Double
-> Vector (Complex Double) -> Vector (Complex Double)
scaleV Complex Double
c Vector (Complex Double)
matrixBra)
instance Mult Operator C Operator where
Operator Matrix (Complex Double)
m <> :: Operator -> Complex Double -> Operator
<> Complex Double
c = Matrix (Complex Double) -> Operator
Operator (Complex Double
-> Matrix (Complex Double) -> Matrix (Complex Double)
scaleM Complex Double
c Matrix (Complex Double)
m)
instance Mult Bra Ket C where
Bra Vector (Complex Double)
matrixBra <> :: Bra -> Ket -> Complex Double
<> Ket Vector (Complex Double)
matrixKet
= forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall a. Num a => a -> a -> a
(*) (Vector (Complex Double) -> [Complex Double]
toList Vector (Complex Double)
matrixBra) (Vector (Complex Double) -> [Complex Double]
toList Vector (Complex Double)
matrixKet)
instance Mult Bra Operator Bra where
Bra Vector (Complex Double)
matrixBra <> :: Bra -> Operator -> Bra
<> Operator Matrix (Complex Double)
matrixOp
= Vector (Complex Double) -> Bra
Bra (Vector (Complex Double)
matrixBra Vector (Complex Double)
-> Matrix (Complex Double) -> Vector (Complex Double)
<# Matrix (Complex Double)
matrixOp)
instance Mult Operator Ket Ket where
Operator Matrix (Complex Double)
matrixOp <> :: Operator -> Ket -> Ket
<> Ket Vector (Complex Double)
matrixKet
= Vector (Complex Double) -> Ket
Ket (Matrix (Complex Double)
matrixOp Matrix (Complex Double)
-> Vector (Complex Double) -> Vector (Complex Double)
#> Vector (Complex Double)
matrixKet)
instance Mult Ket Bra Operator where
Ket Vector (Complex Double)
k <> :: Ket -> Bra -> Operator
<> Bra Vector (Complex Double)
b =
Matrix (Complex Double) -> Operator
Operator
([[Complex Double]] -> Matrix (Complex Double)
fromLists [[ Complex Double
xforall a. Num a => a -> a -> a
*Complex Double
y | Complex Double
y <- Vector (Complex Double) -> [Complex Double]
toList Vector (Complex Double)
b] | Complex Double
x <- Vector (Complex Double) -> [Complex Double]
toList Vector (Complex Double)
k])
instance Mult Operator Operator Operator where
Operator Matrix (Complex Double)
m1 <> :: Operator -> Operator -> Operator
<> Operator Matrix (Complex Double)
m2 = Matrix (Complex Double) -> Operator
Operator (Matrix (Complex Double)
m1 Matrix (Complex Double)
-> Matrix (Complex Double) -> Matrix (Complex Double)
M.<> Matrix (Complex Double)
m2)
instance Num Ket where
Ket Vector (Complex Double)
v1 + :: Ket -> Ket -> Ket
+ Ket Vector (Complex Double)
v2 = Vector (Complex Double) -> Ket
Ket (Vector (Complex Double)
v1 forall a. Num a => a -> a -> a
+ Vector (Complex Double)
v2)
Ket Vector (Complex Double)
v1 - :: Ket -> Ket -> Ket
- Ket Vector (Complex Double)
v2 = Vector (Complex Double) -> Ket
Ket (Vector (Complex Double)
v1 forall a. Num a => a -> a -> a
- Vector (Complex Double)
v2)
* :: Ket -> Ket -> Ket
(*) = forall a. HasCallStack => String -> a
error String
"Multiplication is not defined for kets"
negate :: Ket -> Ket
negate (Ket Vector (Complex Double)
v) = Vector (Complex Double) -> Ket
Ket (forall a. Num a => a -> a
negate Vector (Complex Double)
v)
abs :: Ket -> Ket
abs = forall a. HasCallStack => String -> a
error String
"abs is not defined for kets"
signum :: Ket -> Ket
signum = forall a. HasCallStack => String -> a
error String
"signum is not defined for kets"
fromInteger :: Integer -> Ket
fromInteger = forall a. HasCallStack => String -> a
error String
"fromInteger is not defined for kets"
instance Num Bra where
Bra Vector (Complex Double)
v1 + :: Bra -> Bra -> Bra
+ Bra Vector (Complex Double)
v2 = Vector (Complex Double) -> Bra
Bra (Vector (Complex Double)
v1 forall a. Num a => a -> a -> a
+ Vector (Complex Double)
v2)
Bra Vector (Complex Double)
v1 - :: Bra -> Bra -> Bra
- Bra Vector (Complex Double)
v2 = Vector (Complex Double) -> Bra
Bra (Vector (Complex Double)
v1 forall a. Num a => a -> a -> a
- Vector (Complex Double)
v2)
* :: Bra -> Bra -> Bra
(*) = forall a. HasCallStack => String -> a
error String
"Multiplication is not defined for bra vectors"
negate :: Bra -> Bra
negate (Bra Vector (Complex Double)
v) = Vector (Complex Double) -> Bra
Bra (forall a. Num a => a -> a
negate Vector (Complex Double)
v)
abs :: Bra -> Bra
abs = forall a. HasCallStack => String -> a
error String
"abs is not defined for bra vectors"
signum :: Bra -> Bra
signum = forall a. HasCallStack => String -> a
error String
"signum is not defined for bra vectors"
fromInteger :: Integer -> Bra
fromInteger = forall a. HasCallStack => String -> a
error String
"fromInteger is not defined for bra vectors"
instance Num Operator where
Operator Matrix (Complex Double)
v1 + :: Operator -> Operator -> Operator
+ Operator Matrix (Complex Double)
v2 = Matrix (Complex Double) -> Operator
Operator (Matrix (Complex Double)
v1 forall a. Num a => a -> a -> a
+ Matrix (Complex Double)
v2)
Operator Matrix (Complex Double)
v1 - :: Operator -> Operator -> Operator
- Operator Matrix (Complex Double)
v2 = Matrix (Complex Double) -> Operator
Operator (Matrix (Complex Double)
v1 forall a. Num a => a -> a -> a
- Matrix (Complex Double)
v2)
Operator Matrix (Complex Double)
v1 * :: Operator -> Operator -> Operator
* Operator Matrix (Complex Double)
v2 = Matrix (Complex Double) -> Operator
Operator (Matrix (Complex Double)
v1 Matrix (Complex Double)
-> Matrix (Complex Double) -> Matrix (Complex Double)
M.<> Matrix (Complex Double)
v2)
negate :: Operator -> Operator
negate (Operator Matrix (Complex Double)
v) = Matrix (Complex Double) -> Operator
Operator (forall a. Num a => a -> a
negate Matrix (Complex Double)
v)
abs :: Operator -> Operator
abs = forall a. HasCallStack => String -> a
error String
"abs is not defined for operators"
signum :: Operator -> Operator
signum = forall a. HasCallStack => String -> a
error String
"signum is not defined for operators"
fromInteger :: Integer -> Operator
fromInteger = forall a. HasCallStack => String -> a
error String
"fromInteger is not defined for operators"
class Dagger a b | a -> b where
dagger :: a -> b
instance Dagger Ket Bra where
dagger :: Ket -> Bra
dagger (Ket Vector (Complex Double)
v) = Vector (Complex Double) -> Bra
Bra (Vector (Complex Double) -> Vector (Complex Double)
conjV Vector (Complex Double)
v)
instance Dagger Bra Ket where
dagger :: Bra -> Ket
dagger (Bra Vector (Complex Double)
v) = Vector (Complex Double) -> Ket
Ket (Vector (Complex Double) -> Vector (Complex Double)
conjV Vector (Complex Double)
v)
instance Dagger Operator Operator where
dagger :: Operator -> Operator
dagger (Operator Matrix (Complex Double)
m) = Matrix (Complex Double) -> Operator
Operator (Matrix (Complex Double) -> Matrix (Complex Double)
conjugateTranspose Matrix (Complex Double)
m)
instance Dagger C C where
dagger :: Complex Double -> Complex Double
dagger Complex Double
c = forall a. Num a => Complex a -> Complex a
conjugate Complex Double
c
class HasNorm a where
norm :: a -> Double
normalize :: a -> a
instance HasNorm Ket where
norm :: Ket -> Double
norm (Ket Vector (Complex Double)
v) = Vector (Complex Double) -> Double
M.norm Vector (Complex Double)
v
normalize :: Ket -> Ket
normalize Ket
k = (Double
1 forall a. Fractional a => a -> a -> a
/ forall a. HasNorm a => a -> Double
norm Ket
k forall a. a -> a -> Complex a
:+ Double
0) forall a b c. Mult a b c => a -> b -> c
<> Ket
k
instance HasNorm Bra where
norm :: Bra -> Double
norm (Bra Vector (Complex Double)
v) = Vector (Complex Double) -> Double
M.norm Vector (Complex Double)
v
normalize :: Bra -> Bra
normalize Bra
b = (Double
1 forall a. Fractional a => a -> a -> a
/ forall a. HasNorm a => a -> Double
norm Bra
b forall a. a -> a -> Complex a
:+ Double
0) forall a b c. Mult a b c => a -> b -> c
<> Bra
b
newtype OrthonormalBasis = OB [Ket]
deriving (Int -> OrthonormalBasis -> ShowS
[OrthonormalBasis] -> ShowS
OrthonormalBasis -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OrthonormalBasis] -> ShowS
$cshowList :: [OrthonormalBasis] -> ShowS
show :: OrthonormalBasis -> String
$cshow :: OrthonormalBasis -> String
showsPrec :: Int -> OrthonormalBasis -> ShowS
$cshowsPrec :: Int -> OrthonormalBasis -> ShowS
Show)
makeOB :: [Ket] -> OrthonormalBasis
makeOB :: [Ket] -> OrthonormalBasis
makeOB = [Ket] -> OrthonormalBasis
OB forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Ket] -> [Ket]
gramSchmidt
size :: OrthonormalBasis -> Int
size :: OrthonormalBasis -> Int
size (OB [Ket]
ks) = forall (t :: * -> *) a. Foldable t => t a -> Int
length [Ket]
ks
listBasis :: OrthonormalBasis -> [Ket]
listBasis :: OrthonormalBasis -> [Ket]
listBasis (OB [Ket]
ks) = [Ket]
ks
class Representable a b | a -> b where
rep :: OrthonormalBasis -> a -> b
dim :: a -> Int
instance Representable Ket (Vector C) where
rep :: OrthonormalBasis -> Ket -> Vector (Complex Double)
rep (OB [Ket]
ks) Ket
k = [Complex Double] -> Vector (Complex Double)
fromList (forall a b. (a -> b) -> [a] -> [b]
map (\Ket
bk -> forall a b. Dagger a b => a -> b
dagger Ket
bk forall a b c. Mult a b c => a -> b -> c
<> Ket
k) [Ket]
ks)
dim :: Ket -> Int
dim (Ket Vector (Complex Double)
v) = Vector (Complex Double) -> Int
M.dim Vector (Complex Double)
v
instance Representable Bra (Vector C) where
rep :: OrthonormalBasis -> Bra -> Vector (Complex Double)
rep (OB [Ket]
ks) Bra
b = [Complex Double] -> Vector (Complex Double)
fromList (forall a b. (a -> b) -> [a] -> [b]
map (\Ket
bk -> Bra
b forall a b c. Mult a b c => a -> b -> c
<> Ket
bk) [Ket]
ks)
dim :: Bra -> Int
dim (Bra Vector (Complex Double)
v) = Vector (Complex Double) -> Int
M.dim Vector (Complex Double)
v
instance Representable Operator (Matrix C) where
rep :: OrthonormalBasis -> Operator -> Matrix (Complex Double)
rep (OB [Ket]
ks) Operator
op = [[Complex Double]] -> Matrix (Complex Double)
fromLists [[ forall a b. Dagger a b => a -> b
dagger Ket
k1 forall a b c. Mult a b c => a -> b -> c
<> Operator
op forall a b c. Mult a b c => a -> b -> c
<> Ket
k2 | Ket
k2 <- [Ket]
ks ] | Ket
k1 <- [Ket]
ks ]
dim :: Operator -> Int
dim (Operator Matrix (Complex Double)
m) = let (Int
p,Int
q) = Matrix (Complex Double) -> (Int, Int)
M.size Matrix (Complex Double)
m
in if Int
p forall a. Eq a => a -> a -> Bool
== Int
q then Int
p else forall a. HasCallStack => String -> a
error String
"dim: non-square operator"
xp :: Ket
xp :: Ket
xp = Vector (Complex Double) -> Ket
Ket Vector (Complex Double)
M.xp
xm :: Ket
xm :: Ket
xm = Vector (Complex Double) -> Ket
Ket Vector (Complex Double)
M.xm
yp :: Ket
yp :: Ket
yp = Vector (Complex Double) -> Ket
Ket Vector (Complex Double)
M.yp
ym :: Ket
ym :: Ket
ym = Vector (Complex Double) -> Ket
Ket Vector (Complex Double)
M.ym
zp :: Ket
zp :: Ket
zp = Vector (Complex Double) -> Ket
Ket Vector (Complex Double)
M.zp
zm :: Ket
zm :: Ket
zm = Vector (Complex Double) -> Ket
Ket Vector (Complex Double)
M.zm
np :: Double -> Double -> Ket
np :: Double -> Double -> Ket
np Double
theta Double
phi
= (forall a. Floating a => a -> a
cos (Double
theta forall a. Fractional a => a -> a -> a
/ Double
2) forall a. a -> a -> Complex a
:+ Double
0) forall a b c. Mult a b c => a -> b -> c
<> Ket
zp
forall a. Num a => a -> a -> a
+ (forall a. Floating a => a -> a
sin (Double
theta forall a. Fractional a => a -> a -> a
/ Double
2) forall a. a -> a -> Complex a
:+ Double
0) forall a. Num a => a -> a -> a
* (forall a. Floating a => a -> a
cos Double
phi forall a. a -> a -> Complex a
:+ forall a. Floating a => a -> a
sin Double
phi) forall a b c. Mult a b c => a -> b -> c
<> Ket
zm
nm :: Double -> Double -> Ket
nm :: Double -> Double -> Ket
nm Double
theta Double
phi
= (forall a. Floating a => a -> a
sin (Double
theta forall a. Fractional a => a -> a -> a
/ Double
2) forall a. a -> a -> Complex a
:+ Double
0) forall a b c. Mult a b c => a -> b -> c
<> Ket
zp
forall a. Num a => a -> a -> a
- (forall a. Floating a => a -> a
cos (Double
theta forall a. Fractional a => a -> a -> a
/ Double
2) forall a. a -> a -> Complex a
:+ Double
0) forall a. Num a => a -> a -> a
* (forall a. Floating a => a -> a
cos Double
phi forall a. a -> a -> Complex a
:+ forall a. Floating a => a -> a
sin Double
phi) forall a b c. Mult a b c => a -> b -> c
<> Ket
zm
xBasis :: OrthonormalBasis
xBasis :: OrthonormalBasis
xBasis = [Ket] -> OrthonormalBasis
makeOB [Ket
xp,Ket
xm]
yBasis :: OrthonormalBasis
yBasis :: OrthonormalBasis
yBasis = [Ket] -> OrthonormalBasis
makeOB [Ket
yp,Ket
ym]
zBasis :: OrthonormalBasis
zBasis :: OrthonormalBasis
zBasis = [Ket] -> OrthonormalBasis
makeOB [Ket
zp,Ket
zm]
nBasis :: Double -> Double -> OrthonormalBasis
nBasis :: Double -> Double -> OrthonormalBasis
nBasis Double
theta Double
phi = [Ket] -> OrthonormalBasis
makeOB [Double -> Double -> Ket
np Double
theta Double
phi,Double -> Double -> Ket
nm Double
theta Double
phi]
sx :: Operator
sx :: Operator
sx = Ket
xp forall a b c. Mult a b c => a -> b -> c
<> forall a b. Dagger a b => a -> b
dagger Ket
xp forall a. Num a => a -> a -> a
- Ket
xm forall a b c. Mult a b c => a -> b -> c
<> forall a b. Dagger a b => a -> b
dagger Ket
xm
sy :: Operator
sy :: Operator
sy = Ket
yp forall a b c. Mult a b c => a -> b -> c
<> forall a b. Dagger a b => a -> b
dagger Ket
yp forall a. Num a => a -> a -> a
- Ket
ym forall a b c. Mult a b c => a -> b -> c
<> forall a b. Dagger a b => a -> b
dagger Ket
ym
sz :: Operator
sz :: Operator
sz = Ket
zp forall a b c. Mult a b c => a -> b -> c
<> forall a b. Dagger a b => a -> b
dagger Ket
zp forall a. Num a => a -> a -> a
- Ket
zm forall a b c. Mult a b c => a -> b -> c
<> forall a b. Dagger a b => a -> b
dagger Ket
zm
sn :: Double -> Double -> Operator
sn :: Double -> Double -> Operator
sn Double
theta Double
phi
= (forall a. Floating a => a -> a
sin Double
theta forall a. Num a => a -> a -> a
* forall a. Floating a => a -> a
cos Double
phi forall a. a -> a -> Complex a
:+ Double
0) forall a b c. Mult a b c => a -> b -> c
<> Operator
sx forall a. Num a => a -> a -> a
+
(forall a. Floating a => a -> a
sin Double
theta forall a. Num a => a -> a -> a
* forall a. Floating a => a -> a
sin Double
phi forall a. a -> a -> Complex a
:+ Double
0) forall a b c. Mult a b c => a -> b -> c
<> Operator
sy forall a. Num a => a -> a -> a
+
(forall a. Floating a => a -> a
cos Double
theta forall a. a -> a -> Complex a
:+ Double
0) forall a b c. Mult a b c => a -> b -> c
<> Operator
sz
sn' :: Double -> Double -> Operator
sn' :: Double -> Double -> Operator
sn' Double
theta Double
phi
= Double -> Double -> Ket
np Double
theta Double
phi forall a b c. Mult a b c => a -> b -> c
<> forall a b. Dagger a b => a -> b
dagger (Double -> Double -> Ket
np Double
theta Double
phi) forall a. Num a => a -> a -> a
-
Double -> Double -> Ket
nm Double
theta Double
phi forall a b c. Mult a b c => a -> b -> c
<> forall a b. Dagger a b => a -> b
dagger (Double -> Double -> Ket
nm Double
theta Double
phi)
timeEvOp :: Double -> Operator -> Operator
timeEvOp :: Double -> Operator -> Operator
timeEvOp Double
dt (Operator Matrix (Complex Double)
m) = Matrix (Complex Double) -> Operator
Operator (Double -> Matrix (Complex Double) -> Matrix (Complex Double)
M.timeEvMat Double
dt Matrix (Complex Double)
m)
timeEv :: Double -> Operator -> Ket -> Ket
timeEv :: Double -> Operator -> Ket -> Ket
timeEv Double
dt (Operator Matrix (Complex Double)
m) (Ket Vector (Complex Double)
k) = Vector (Complex Double) -> Ket
Ket forall a b. (a -> b) -> a -> b
$ Double
-> Matrix (Complex Double)
-> Vector (Complex Double)
-> Vector (Complex Double)
M.timeEv Double
dt Matrix (Complex Double)
m Vector (Complex Double)
k
class Kron a where
kron :: a -> a -> a
instance Kron Ket where
kron :: Ket -> Ket -> Ket
kron (Ket Vector (Complex Double)
v1) (Ket Vector (Complex Double)
v2) = Vector (Complex Double) -> Ket
Ket (forall a. Kronecker a => a -> a -> a
M.kron Vector (Complex Double)
v1 Vector (Complex Double)
v2)
instance Kron Bra where
kron :: Bra -> Bra -> Bra
kron (Bra Vector (Complex Double)
v1) (Bra Vector (Complex Double)
v2) = Vector (Complex Double) -> Bra
Bra (forall a. Kronecker a => a -> a -> a
M.kron Vector (Complex Double)
v1 Vector (Complex Double)
v2)
instance Kron Operator where
kron :: Operator -> Operator -> Operator
kron (Operator Matrix (Complex Double)
m1) (Operator Matrix (Complex Double)
m2) = Matrix (Complex Double) -> Operator
Operator (forall a. Kronecker a => a -> a -> a
M.kron Matrix (Complex Double)
m1 Matrix (Complex Double)
m2)
possibleOutcomes :: Operator -> [Double]
possibleOutcomes :: Operator -> [Double]
possibleOutcomes (Operator Matrix (Complex Double)
observable) = Matrix (Complex Double) -> [Double]
M.possibleOutcomes Matrix (Complex Double)
observable
outcomesProjectors :: Operator -> [(Double,Operator)]
outcomesProjectors :: Operator -> [(Double, Operator)]
outcomesProjectors (Operator Matrix (Complex Double)
m)
= [(Double
val,Matrix (Complex Double) -> Operator
Operator Matrix (Complex Double)
p) | (Double
val,Matrix (Complex Double)
p) <- Matrix (Complex Double) -> [(Double, Matrix (Complex Double))]
M.outcomesProjectors Matrix (Complex Double)
m]
outcomesProbabilities :: Operator -> Ket -> [(Double,Double)]
outcomesProbabilities :: Operator -> Ket -> [(Double, Double)]
outcomesProbabilities (Operator Matrix (Complex Double)
m) (Ket Vector (Complex Double)
v)
= Matrix (Complex Double)
-> Vector (Complex Double) -> [(Double, Double)]
M.outcomesProbabilities Matrix (Complex Double)
m Vector (Complex Double)
v
gramSchmidt :: [Ket] -> [Ket]
gramSchmidt :: [Ket] -> [Ket]
gramSchmidt [] = []
gramSchmidt [Ket
k] = [forall a. HasNorm a => a -> a
normalize Ket
k]
gramSchmidt (Ket
k:[Ket]
ks) = let nks :: [Ket]
nks = [Ket] -> [Ket]
gramSchmidt [Ket]
ks
nk :: Ket
nk = forall a. HasNorm a => a -> a
normalize (forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl (-) Ket
k [Ket
w forall a b c. Mult a b c => a -> b -> c
<> forall a b. Dagger a b => a -> b
dagger Ket
w forall a b c. Mult a b c => a -> b -> c
<> Ket
k | Ket
w <- [Ket]
nks])
in Ket
nkforall a. a -> [a] -> [a]
:[Ket]
nks