module Quipper103 where import System.Random import Quipper import Quipper.Libraries.Simulation c_r :: Int -> [Qubit] -> Qubit -> Circ ([Qubit], Qubit) c_r k [] q = return ([], q) c_r k (x:xs) q = do q <- rGate k q `controlled` x (xs, q) <- c_r (k+1) xs q return (x:xs, q) phi_a :: [Qubit] -> Qubit -> Circ ([Qubit], Qubit) phi_a qs q = do q <- hadamard q (qs, q) <- c_r 2 qs q return (qs, q) phiCirc = print_generic Preview phi_a [qubit, qubit, qubit, qubit, qubit, qubit, qubit] qubit qft :: [Qubit] -> Circ [Qubit] qft [] = return [] qft (x:xs) = do (xs, x) <- phi_a xs x xs <- qft xs return (x:xs) qftCirc = print_generic Preview qft $ replicate 5 qubit qftAdder :: [Qubit] -> [Qubit] -> Circ ([Qubit], [Qubit]) qftAdder as bs = with_computed qft' cbs where qft' = do as <- qft as return (as, bs) cbs ([], []) = return ([], []) cbs (a:as', b:bs') = do (b:bs', a) <- c_r 1 (b:bs') a (as', bs') <- cbs (as', bs') return (a:as', b:bs') qftAdderCirc = print_generic Preview qftAdder (replicate 5 qubit) (replicate 5 qubit) testQFTAdder :: IO () testQFTAdder = do g <- newStdGen let x = sim_generic (0.0 :: Double) qftAdder [False, True, True, True] [False, True, True, True] putStrLn $ show x