Safe Haskell | None |
---|---|

Language | Haskell2010 |

This module contains QIO unitaries that represent various Arithmetic functions. These are exactly the Arithmetic functions required to implement Shor's algorithm.

- swapQInt :: QInt -> QInt -> U
- ifElseQ :: Qbit -> U -> U -> U
- ifQ :: Qbit -> U -> U
- cnot :: Qbit -> Qbit -> U
- addBit :: Qbit -> Qbit -> Qbit -> U
- carry :: Qbit -> Qbit -> Qbit -> Qbit -> U
- addBits :: [Qbit] -> [Qbit] -> Qbit -> U
- addBits' :: [Qbit] -> [Qbit] -> [Qbit] -> Qbit -> U
- adder :: QInt -> QInt -> Qbit -> U
- tadder :: (Int, (Int, Bool)) -> QIO (Int, (Int, Bool))
- tRadder :: (Int, (Int, Bool)) -> QIO (Int, (Int, Bool))
- tBiAdder :: (Int, (Int, Bool)) -> QIO (Int, (Int, Bool))
- adderMod :: Int -> QInt -> QInt -> U
- tadderMod :: Int -> (Int, Int) -> QIO (Int, Int)
- multMod :: Int -> Int -> QInt -> QInt -> U
- tmultMod :: Int -> Int -> Int -> QIO (Int, Int)
- condMultMod :: Qbit -> Int -> Int -> QInt -> QInt -> U
- inverseMod :: Int -> Int -> Int
- modExpStep :: Qbit -> Int -> Int -> QInt -> Int -> U
- modExpStept :: Int -> Int -> Int -> Int -> QIO Int
- modExp :: Int -> Int -> QInt -> QInt -> U
- modExpt :: Int -> (Int, Int) -> QIO Int

# Documentation

swapQInt :: QInt -> QInt -> U Source #

A swap operation can be applied to two QInts, by mapping qubit swap operations over the underlying qubits that make up a QInt.

ifElseQ :: Qbit -> U -> U -> U Source #

ifElseQ defines a quantum If statement, whereby depending on the state of the given (control) qubit, one of two unitaries are applied.

ifQ :: Qbit -> U -> U Source #

ifQ defines a special case of ifElseQ, where the Else part of the computation is simply the identity.

cnot :: Qbit -> Qbit -> U Source #

A controlled-not operations, that applies a Not to the second qubit, depending on the state of the first qubit.

adder :: QInt -> QInt -> Qbit -> U Source #

Defines the QIO unitary that adds two QInts, with an overflow qubit

tadder :: (Int, (Int, Bool)) -> QIO (Int, (Int, Bool)) Source #

A small function to test the adder unitary

tRadder :: (Int, (Int, Bool)) -> QIO (Int, (Int, Bool)) Source #

A small function to test applying the adder unitary in reverse, ie. this defines subtraction.

tBiAdder :: (Int, (Int, Bool)) -> QIO (Int, (Int, Bool)) Source #

A small function to test applying the adder unitary, and then applying the reverse of the adder unitary, which should give the identity function.

adderMod :: Int -> QInt -> QInt -> U Source #

This unitary is for modular addition, and is done modulo some fixed classical modulus, given as the first Int argument.

tadderMod :: Int -> (Int, Int) -> QIO (Int, Int) Source #

A small function to test the modular addition unitary.

multMod :: Int -> Int -> QInt -> QInt -> U Source #

This unitary defines modular multiplication, whereby the integer `n`

is the
the modulus, and the integer `a`

is the scalar by which to multiply the quantum
integer `x`

. The result is added to the quantum integer `y`

, ie. if `y`

is in
state 0 before the operation, then it is left in the sate a*x mod n.

tmultMod :: Int -> Int -> Int -> QIO (Int, Int) Source #

A small function for testing the modular multiplication unitary. This function
initialises `y`

as zero, so the output is as expected.

condMultMod :: Qbit -> Int -> Int -> QInt -> QInt -> U Source #

A unitary that adds a single qubit control to modular multiplication

inverseMod :: Int -> Int -> Int Source #

A classical Haskell function that returns the smalles positive inverse
of a `mod n (if one exists). That is, the smallest positive integer
x, such that x*a `mod`

n equals 1.

modExpStep :: Qbit -> Int -> Int -> QInt -> Int -> U Source #

The unitary that represents modular exponentiation is constructed in terms of multiple "steps". This function defines those steps.

modExpStept :: Int -> Int -> Int -> Int -> QIO Int Source #

A QIO computation that forms a test of the `modExpStep`

unitary

modExp :: Int -> Int -> QInt -> QInt -> U Source #

This function defines a unitary that implements modular exponentiation, as required in Shor's algorithm. Given classical arguments n and a, a quantum register containg x, and a quantum register o in state 1, this unitary will leave the quantum register o in the state a^x mod n.