{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
{-# LINE 1 "Quipper/Algorithms/CL/RegulatorTemplate.hs" #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
module Quipper.Algorithms.CL.RegulatorTemplate where
import Quipper
import Text.Printf
import Quipper.Libraries.FPReal
import Quipper.Algorithms.CL.Types
import Quipper.Libraries.Arith
import Control.Monad
d_of_ideal :: Ideal -> Integer
d_of_ideal (Ideal bigD m l a b) = d_of_bigD bigD
d_of_idealQ :: IdealQ -> Integer
d_of_idealQ (Ideal bigD m l a b) = d_of_bigD bigD
equal_d_of_ideals :: Ideal -> Ideal -> BoolParam
equal_d_of_ideals i j = if ((d_of_ideal i) == (d_of_ideal j)) then PTrue else PFalse
equal_d_of_idealQs :: IdealQ -> IdealQ -> BoolParam
equal_d_of_idealQs i j = if ((d_of_idealQ i) == (d_of_idealQ j)) then PTrue else PFalse
template_equal_d_of_ideals :: Circ (IdealQ -> Circ (IdealQ -> Circ BoolParam))
template_equal_d_of_ideals = return $ \i -> return $ \j -> return (equal_d_of_idealQs i j)
template_and :: Circ ([Qubit] -> Circ Qubit)
template_and = return $ \qs -> do
result_qubit <- qinit False
qnot result_qubit `controlled` qs
m_of_ideal :: Ideal -> IntM
m_of_ideal (Ideal bigD m l a b) = m
l_of_ideal :: Ideal -> IntM
l_of_ideal (Ideal bigD m l a b) = l
a_of_ideal :: Ideal -> IntM
a_of_ideal (Ideal bigD m l a b) = a
b_of_ideal :: Ideal -> IntM
b_of_ideal (Ideal bigD m l a b) = b
template_m_of_ideal :: Circ (IdealQ -> Circ QDInt)
template_m_of_ideal = return $ \(Ideal bigD m l a b) -> return m
template_l_of_ideal :: Circ (IdealQ -> Circ QDInt)
template_l_of_ideal = return $ \(Ideal bigD m l a b) -> return l
template_a_of_ideal :: Circ (IdealQ -> Circ QDInt)
template_a_of_ideal = return $ \(Ideal bigD m l a b) -> return a
template_b_of_ideal :: Circ (IdealQ -> Circ QDInt)
template_b_of_ideal = return $ \(Ideal bigD m l a b) -> return b
one_of_size :: IntM -> IntM
one_of_size n =
case intm_length n of
Just m -> intm m 1
Nothing -> error "one_of_size: indeterminate size"
template_one_of_size :: Circ (QDInt -> Circ QDInt)
template_one_of_size = return (\qx -> qinit $ one_of_size $ qc_false qx)
isReduced :: Ideal -> Bool
isReduced i = (m_of_ideal i == (one_of_size (m_of_ideal i)) && (l_of_ideal i == a_of_ideal i))
{-# LINE 83 "Quipper/Algorithms/CL/RegulatorTemplate.hs" #-}
$( decToCircMonad [d| isReduced :: Ideal -> Bool
isReduced i = (m_of_ideal i == (one_of_size (m_of_ideal i)) && (l_of_ideal i == a_of_ideal i))
|] )
{-# LINE 84 "Quipper/Algorithms/CL/RegulatorTemplate.hs" #-}
assert :: Bool -> a -> a
assert True a = a
assert False _ = error "False Assertion"
template_assert :: Circ (Qubit -> Circ (a -> Circ a))
template_assert = return $ \assertion -> return $ \a -> do
qterm True assertion
return a
assertReduced :: Ideal -> a -> a
assertReduced i rest =
let assertion = isReduced i in
assert assertion rest
{-# LINE 107 "Quipper/Algorithms/CL/RegulatorTemplate.hs" #-}
$( decToCircMonad [d| assertReduced :: Ideal -> a -> a
assertReduced i rest =
let assertion = isReduced i in
assert assertion rest
|] )
{-# LINE 108 "Quipper/Algorithms/CL/RegulatorTemplate.hs" #-}
idealEquals :: Ideal -> Ideal -> Bool
idealEquals i j = case equal_d_of_ideals i j of
PFalse -> error "Comparing two ideals of different d"
PTrue -> and [(m_of_ideal i == m_of_ideal j),
(l_of_ideal i == l_of_ideal j),
(a_of_ideal i == a_of_ideal j),
(b_of_ideal i == b_of_ideal j)]
{-# LINE 117 "Quipper/Algorithms/CL/RegulatorTemplate.hs" #-}
$( decToCircMonad [d| idealEquals :: Ideal -> Ideal -> Bool
idealEquals i j = case equal_d_of_ideals i j of
PFalse -> error "Comparing two ideals of different d"
PTrue -> and [(m_of_ideal i == m_of_ideal j),
(l_of_ideal i == l_of_ideal j),
(a_of_ideal i == a_of_ideal j),
(b_of_ideal i == b_of_ideal j)]
|] )
{-# LINE 118 "Quipper/Algorithms/CL/RegulatorTemplate.hs" #-}
data BoolPair = BoolPair Bool Bool
data QubitPair = QubitPair Qubit Qubit
boolPair = BoolPair
template_boolPair = return $ \x -> return $ \y -> return $ QubitPair x y
template_BoolPair = QubitPair
truePair :: BoolPair
truePair = boolPair True True
{-# LINE 133 "Quipper/Algorithms/CL/RegulatorTemplate.hs" #-}
$( decToCircMonad [d| truePair :: BoolPair
truePair = boolPair True True
|] )
{-# LINE 134 "Quipper/Algorithms/CL/RegulatorTemplate.hs" #-}
myPlus :: Int -> Int -> Int
myPlus x y = x + y
{-# LINE 143 "Quipper/Algorithms/CL/RegulatorTemplate.hs" #-}
$( decToCircMonad [d| myPlus :: Int -> Int -> Int
myPlus x y = x + y
|] )
{-# LINE 144 "Quipper/Algorithms/CL/RegulatorTemplate.hs" #-}
test_is_reduced :: IO ()
test_is_reduced = let zero = qdint_shape 4
ideal = Ideal 17 zero zero zero zero
in print_generic ASCII (unpack template_isReduced) ideal
main :: IO ()
main = test_is_reduced