The Quipper System

QuipperLib.ClassicalOptim.QuickCheckArith

Description

This module contains small examples of arithmetic functions, coded in Template Haskell, for use with QuipperLib.ClassicalOptim.QuickCheck.

Synopsis

# Binary representation of integers

Compute an unsigned integer from its binary representation. The input is a big-headian list of booleans. This means that the head of the list is the most significant digit.

boollist_of_int :: Int -> Integer -> [Bool] Source #

Compute the binary representation of an unsigned integer, using the given number of digits. The output is the binary representation as a big-headian list of booleans.

# Circuit templates for common functions

template_map :: Circ ((a -> Circ a) -> Circ ([a] -> Circ [a])) Source #

Template Haskell version of map.

template_zip :: Circ ([a] -> Circ ([b] -> Circ [(a, b)])) Source #

Template Haskell version of zip.

template_tail :: Circ ([a] -> Circ [a]) Source #

Template Haskell version of tail.

Template Haskell version of [].

mapAccumLM :: (acc -> x -> Circ (acc, y)) -> acc -> [x] -> Circ (acc, [y]) Source #

Monadic version of mapAccumL.

template_mapAccumL :: Circ ((acc -> Circ (x -> Circ (acc, y))) -> Circ (acc -> Circ ([x] -> Circ (acc, [y])))) Source #

Template Haskell version of mapAccumL.

# Tests

majority :: Bool -> Bool -> Bool -> Bool Source #

Return the majority of three booleans.

bit_adder :: Bool -> (Bool, Bool, Bool) -> (Bool, Bool) Source #

Bit adder. The first input is False for adding, and True for subtracting. The second input is a triple consisting of a carry, and two bits to be added. The output consists of the new carry and the sum.

adder :: [Bool] -> [Bool] -> [Bool] Source #

Test the validity of the functional implementation of adder.

Wrapper around test_adder'.

## Subtraction

subtract :: [Bool] -> [Bool] -> [Bool] Source #

Reversible subtraction.

test_subtract' :: Property Source #

Test the validity of the functional implementation of subtract.

Wrapper around test_subtract'.

## Multiplication

pad_right :: [Bool] -> [Bool] -> [Bool] Source #

Pad the second list on the right, to the length of (and using the corresponding elements of) the first list.

template_pad_right :: Circ ([a] -> Circ ([a] -> Circ [a])) Source #

shift :: [Bool] -> [Bool] Source #

Shift a bit list to the right by one.

takeOnly :: [Bool] -> [Bool] -> [Bool] Source #

takeOnly shape l: take the first (length shape) elements out of l.

template_takeOnly :: Circ ([t1] -> Circ ([t] -> Circ [t])) Source #

multiplier' :: [Bool] -> [Bool] -> [Bool] Source #

Reversible multiplier stripping high bits.

multiplier :: [Bool] -> [Bool] -> [Bool] Source #

Reversible multiplier keeping high bits.

test_multiplier' :: Property Source #

Test the validity of the functional implementation of multiplier.

Wrapper around test_multiplier'.