Safe Haskell | None |
---|---|
Language | Haskell98 |
This module introduces a simple way of defining boolean statements acting over qubits.
Synopsis
- data Boolean a
- data BooleanAnd a
- = AA a
- | NotA (BooleanAnd a)
- | AndA (BooleanAnd a) (BooleanAnd a)
- booleanToAnd' :: Boolean a -> BooleanAnd a
- stripDoubleNot :: BooleanAnd a -> BooleanAnd a
- booleanToAnd :: Boolean a -> BooleanAnd a
- booleanAnd' :: BooleanAnd Qubit -> Qubit -> Circ ()
- booleanAnd :: BooleanAnd Qubit -> Circ Qubit
- if_then_elseQinv :: Boolean Qubit -> Circ () -> Circ () -> Boolean Qubit -> Circ ()
- if_then_elseQ :: Boolean Qubit -> Circ () -> Circ () -> Circ ()
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".
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)
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).
AA a | |
NotA (BooleanAnd a) |
|
AndA (BooleanAnd a) (BooleanAnd a) |
|
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.