Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System.Numerics
- open MathNet.Numerics
- open MathNet.Numerics.LinearAlgebra
- type Qregister = Qregister of Matrix<Complex>
- let qreg n =
- let ket = matrix [[Complex (1.0, 0.0)]
- [Complex (0.0, 0.0)]]
- let rec kronPow = function
- | 1 -> ket
- | n when n > 0 -> ket.KroneckerProduct (kronPow (n - 1))
- | _ -> failwith "degree must be greater than 0"
- Qregister (kronPow n)
- type Gate =
- Gate of Matrix<Complex>
- static member (*) (Gate a, Gate b) = Gate (a.KroneckerProduct b)
- static member (><) (Gate a, Qregister s) = Qregister (a * s)
- static member (+) (a, b) = Binding [a; b]
- and Binding =
- Binding of List<Gate>
- static member (+) (Binding a, Binding b) = Binding (List.append a b)
- static member (?-) (state, binding) =
- match binding with
- | Binding [] -> state
- | Binding (head::tail) -> (head >< state) ?- (Binding tail)
- // lol
- let I = matrix [[ Complex (1.0, 0.0); Complex (0.0, 0.0) ]
- [ Complex (0.0, 0.0); Complex (1.0, 0.0) ]] |> Gate
- let H = (Complex (1.0/sqrt 2.0, 0.0)) *
- matrix [[ Complex (1.0, 0.0); Complex (1.0, 0.0)]
- [ Complex (1.0, 0.0); Complex (-1.0, 0.0)]] |> Gate
- let PauliX = matrix [[Complex (0.0, 0.0); Complex (0.0, -1.0)]
- [Complex (0.0, 1.0); Complex (0.0, 0.0)]] |> Gate
- (qreg 2) ?- (I * H + H * I)
- |> printfn "%A"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement