The Quipper System

QuipperLib.Qureg

Description

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

Synopsis

# Quantum registers

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 ith 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.

Convert a Qulist to a Qureg. The conversion is tail-endian, i.e., r.!(0) holds the tail of the list.

Convert a Qureg to a Qulist. The conversion is tail-endian, i.e., r.!(0) holds the tail of the list.

Return the length of a Qureg.

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.

Measure a quantum register, yielding a list of Bits.

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.

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

The type of Bit registers. The syntax a .!(i) is used to access the ith element of the register a.

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

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

Return the length of a Bitreg.

# Boolean registers

The type of boolean registers.

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

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

Return the length of a Boolreg.

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 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

data Register x Source #

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.

Instances

 # Methodsqcdata_mapM :: Monad m => Bitreg -> (q -> m q') -> (c -> m c') -> QCType q c Bitreg -> m (QCType q' c' Bitreg) Source #qcdata_zip :: Bitreg -> q -> c -> q' -> c' -> QCType q c Bitreg -> QCType q' c' Bitreg -> ErrMsg -> QCType (q, q') (c, c') Bitreg Source # # Methodsqcdata_mapM :: Monad m => Qureg -> (q -> m q') -> (c -> m c') -> QCType q c Qureg -> m (QCType q' c' Qureg) Source #qcdata_zip :: Qureg -> q -> c -> q' -> c' -> QCType q c Qureg -> QCType q' c' Qureg -> ErrMsg -> QCType (q, q') (c, c') Qureg Source # # Methods # Methods Show x => Show (Register x) # MethodsshowsPrec :: Int -> Register x -> ShowS #show :: Register x -> String #showList :: [Register x] -> ShowS # type QTypeB Boolreg # type QTypeB Boolreg = Qureg type QCType x y Bitreg # type QCType x y Bitreg = Register y type QCType x y Qureg # type QCType x y Qureg = Register x

(.!) :: Register x -> Int -> x infixl 9 Source #

r !.(i): Return the ith element of a register r.