quipper-0.8.1: An embedded, scalable functional programming language for quantum computing.

Safe HaskellNone
LanguageHaskell2010

Quipper.QClasses

Contents

Description

This module defines quantum analogues of some Haskell type classes. For instance, Haskell’s Eq a has one method

(==) :: a -> a -> Bool.  

Correspondingly, our QEq a qa ca has a method

q_is_equal :: qa -> qa -> Circ (qa,qa,Qubit).  

All quantum type classes assume that their instance types are QData (or sometimes QCData).

Quantum type classes are designed to play nicely with the translation of Quipper.CircLifting.

Synopsis

The type class QEq

class QCData qc => QEq qc where Source #

This is a quantum analogue of Haskell’s Eq type class. Default implementations are provided; by default, equality is bitwise equality of the underlying data structure. However, specific instances can provide custom implementations. In this case, q_is_equal is a minimal complete definition.

Methods

q_is_equal :: qc -> qc -> Circ (qc, qc, Qubit) Source #

Test for equality.

q_is_not_equal :: qc -> qc -> Circ (qc, qc, Qubit) Source #

Test for inequality.

Instances

QCData qc => QEq qc Source # 

Methods

q_is_equal :: qc -> qc -> Circ (qc, qc, Qubit) Source #

q_is_not_equal :: qc -> qc -> Circ (qc, qc, Qubit) Source #

The type class QOrd

class (QEq qa, QData qa) => QOrd qa where Source #

This is a quantum analogue of Haskell's Ord type class. Its purpose is to define a total ordering on each of its instances. The functions in this class are assumed dirty in the sense that they do not uncompute ancillas, and some of the inputs may be returned as outputs. The functions are also assumed to be non-linear safe, i.e., they apply no gates to their inputs except as control sources. Minimal complete definition: q_less or q_greater. The default implementations of q_max and q_min assume that both arguments are of the same shape (for example, numbers of the same length).

Methods

q_less :: qa -> qa -> Circ Qubit Source #

Test for less than.

q_greater :: qa -> qa -> Circ Qubit Source #

Test for greater than.

q_leq :: qa -> qa -> Circ Qubit Source #

Test for less than or equal.

q_geq :: qa -> qa -> Circ Qubit Source #

Test for greater than or equal.

q_max :: qa -> qa -> Circ qa Source #

Compute the maximum of two values.

q_min :: qa -> qa -> Circ qa Source #

Compute the minimum of two values.

Functionally-typed wrappers for QOrd methods

q_lt :: QOrd qa => qa -> qa -> Circ (qa, qa, Qubit) Source #

q_lt qx qy: test whether qx < qy. A functionally typed wrapper for q_less.

q_gt :: QOrd qa => qa -> qa -> Circ (qa, qa, Qubit) Source #

q_gt qx qy: test whether qx > qy. A functionally typed wrapper for q_greater.

q_le :: QOrd qa => qa -> qa -> Circ (qa, qa, Qubit) Source #

q_le qx qy: test whether qxqy. A functionally typed wrapper for q_leq.

q_ge :: QOrd qa => qa -> qa -> Circ (qa, qa, Qubit) Source #

q_ge qx qy: test whether qxqy. A functionally typed wrapper for q_geq.