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

Language | Haskell98 |

This module provides a data type of quantum registers, as well as associated types of classical and boolean registers.

## Synopsis

- type Qureg = Register Qubit
- qureg_of_qulist_te :: Qulist -> Qureg
- qulist_of_qureg_te :: Qureg -> Qulist
- qureg_length :: Qureg -> Int
- qinit_register :: [Bool] -> Circ Qureg
- qterm_register :: [Bool] -> Qureg -> Circ ()
- qmeasure_register :: Qureg -> Circ [Bit]
- with_ancilla_reg :: Int -> (Qureg -> Circ a) -> Circ a
- with_ancilla_reg_init :: Boollist -> (Qureg -> Circ a) -> Circ a
- qureg_shape :: Int -> Qureg
- type Bitreg = Register Bit
- bitreg_of_bitlist_te :: Bitlist -> Bitreg
- bitlist_of_bitreg_te :: Bitreg -> Bitlist
- bitreg_length :: Bitreg -> Int
- type Boolreg = Register Bool
- boolreg_of_boollist_te :: Boollist -> Boolreg
- boollist_of_boolreg_te :: Boolreg -> Boollist
- boolreg_length :: Boolreg -> Int
- boolreg_of_int_le :: Integral a => Int -> a -> Boolreg
- int_of_boolreg_unsigned_le :: Integral a => Boolreg -> a
- data Register x
- (.!) :: Register x -> Int -> x

# Quantum registers

type Qureg = Register Qubit Source #

The type of quantum registers. A quantum register is an array of
qubits, indexed by natural numbers in the range from 0 to *n*-1,
where *n* is the length of the register. The syntax *a* .!(*i*) is
used to access the *i*th element of the register *a*.

The main advantage of a register over a list is constant-time access. The main disadvantage is that registers don't allow easy appending, pattern matching, or recursion.

qureg_of_qulist_te :: Qulist -> Qureg Source #

qulist_of_qureg_te :: Qureg -> Qulist Source #

qinit_register :: [Bool] -> Circ Qureg Source #

Creates a new quantum register, initialized from a list of
booleans. The conversion is tail-endian, i.e., *r*.!(0) holds the
tail of the list.

qterm_register :: [Bool] -> Qureg -> Circ () Source #

Terminates a quantum register, and assert that its state is as
specified by the list of booleans. The conversion is tail-endian,
i.e., *r*.!(0) holds the tail of the list.

qmeasure_register :: Qureg -> Circ [Bit] Source #

Measure a quantum register, yielding a list of `Bit`

s.

with_ancilla_reg :: Int -> (Qureg -> Circ a) -> Circ a Source #

Temporarily create a quantum register of size *n* for use as an
ancilla. This can be used to introduce an ancilla with a local scope, like this:

with_ancilla_reg n $ \r -> do { <<<code block using ancilla register r>>> }

with_ancilla_reg_init :: Boollist -> (Qureg -> Circ a) -> Circ a Source #

Like `with_ancilla_reg`

, except also initialize the register as
specified by a bit vector. In this case, the argument *n* is not
required, because it equals the length of the bit vector. When the
ancilla is terminated at the end of its scope, it is asserted to be
in the same state it was prepared in.

qureg_shape :: Int -> Qureg Source #

Return a piece of shape data to represent an *m*-qubit quantum
register. Please note that the data can only be used as shape; it
will be undefined at the leaves.

# Bit registers

type Bitreg = Register Bit Source #

The type of `Bit`

registers. The syntax *a* .!(*i*) is used to
access the *i*th element of the register *a*.

bitreg_of_bitlist_te :: Bitlist -> Bitreg Source #

Turn a bit vector into a bit register. The conversion is tail-endian,
i.e., *r*.!(0) holds the tail of the list.

bitlist_of_bitreg_te :: Bitreg -> Bitlist Source #

Turn a bit register into a bit vector. The conversion is tail-endian,
i.e., *r*.!(0) holds the tail of the list.

# Boolean registers

boolreg_of_boollist_te :: Boollist -> Boolreg Source #

Turn a bool vector into a bool register. The conversion is tail-endian,
i.e., *r*.!(0) holds the tail of the list.

boollist_of_boolreg_te :: Boolreg -> Boollist Source #

Turn a bool register into a bool vector. The conversion is tail-endian,
i.e., *r*.!(0) holds the tail of the list.

boolreg_of_int_le :: Integral a => Int -> a -> Boolreg Source #

`boolreg_of_int m x`

: Initialize a bool register directly from an
integer *x*, regarded as a binary string of length *m*. The
conversion is little-endian, i.e., the register holds the least
significant digit at index 0.

int_of_boolreg_unsigned_le :: Integral a => Boolreg -> a Source #

`int_of_boolreg_unsigned_le m r`

: Turn a bool register into an
integer, regarded as a binary string. The conversion is
little-endian, i.e., the register holds the least significant digit
at index 0. The integer is unsigned.

# General registers

A register is an array of elements of some type *x*, indexed by
natural numbers in the range from 0 to *n*-1, where *n* is the
length of the register.