The Quipper System

Safe HaskellNone

Quipper.Libraries.QuantumIf

Contents

Description

This module introduces a simple way of defining boolean statements acting over qubits.

Synopsis

Quantum "if then else" statements

This module introduces a simple way of defining boolean statements acting over qubits, which can then be used as the control in a quantum "if then else" statement. The idea is that an ancilla is initialized that is in the state represented by the boolean statement, and is then used to control the two branches of the "if then else", before being uncomputed. The boolean statements can contain "and", "or", and "not".

data Boolean a Source #

We can use (Boolean Qubit) to build up "boolean statements" over qubits and use the "boolean statement" in an if_then_elseQ construct.

Example (for qubits a, b, c, d):
(a and b) or !(c and !d) is written as:
(a `And` b) `Or` Not (c `And` Not d)

Constructors

A a

A q means if q == True.

Not (Boolean a)

Not b means the negation of the boolean statement b.

And (Boolean a) (Boolean a) infixr 3

And a b means the and of the boolean statements a and b.

Or (Boolean a) (Boolean a) infixr 2

Or a b means the or of the boolean statements a and b

Instances
Show a => Show (Boolean a) # 
Instance details

Defined in Quipper.Libraries.QuantumIf

Methods

showsPrec :: Int -> Boolean a -> ShowS #

show :: Boolean a -> String #

showList :: [Boolean a] -> ShowS #

data BooleanAnd a Source #

Allow And and Or to be used as infix operators, with the same precedences.

Internally, a "boolean statement" is converted into a statement that doesn't use or (e.g., using De Morgan's laws).

Constructors

AA a

AA q means if q == True.

NotA (BooleanAnd a)

NotA b means the negation of the boolean statement b.

AndA (BooleanAnd a) (BooleanAnd a)

AndA a b means the and of the boolean statements a and b.

booleanToAnd' :: Boolean a -> BooleanAnd a Source #

Convert any boolean formula to a formula using just and and not. This conversion function uses De Morgan's law, i.e.,

A or B = !( !A and !B ),

but does not remove double negations. For a version that also removes double negations, see booleanToAnd.

stripDoubleNot :: BooleanAnd a -> BooleanAnd a Source #

Strip any redundant double negations, i.e., in this context !!A = A.

booleanToAnd :: Boolean a -> BooleanAnd a Source #

Convert any boolean formula to a formula using just and and not, removing double negations.

booleanAnd' :: BooleanAnd Qubit -> Qubit -> Circ () Source #

Create a circuit from the "boolean statement".

booleanAnd :: BooleanAnd Qubit -> Circ Qubit Source #

Create a circuit from the "boolean statement", passing in an ancilla.

if_then_elseQinv :: Boolean Qubit -> Circ () -> Circ () -> Boolean Qubit -> Circ () Source #

The definition of a quantum if_then_else structure uses a "boolean statement" to create a single ancilla in the state defined by the boolean statement, and uses this as a control for the two branches of the if statement. The ancilla then needs to be uncomputed, this is achieved using the other given "boolean statement", i.e., a new boolean statement that would produce the state of the control ancilla, from the output state of the two branches.This allows the branches to update the state of qubits used in the original "boolean statement" as long as it is done in a (reversible) known-manner. This is useful for the WALK algorithm, where TOPARENT and TOCHILD are controlled by the state of the direction register, but also change the state of the direction register.

if_then_elseQ :: Boolean Qubit -> Circ () -> Circ () -> Circ () Source #

Like if_then_elseQinv, but where the original "boolean statement" still holds after the branches have taken place.