Safe Haskell | None |
---|
QuipperLib.ClassicalOptim.QuickCheckArith
Contents
Description
This module contains small examples of arithmetic functions, coded in Template Haskell, for use with QuipperLib.ClassicalOptim.QuickCheck.
- int_of_boollist :: [Bool] -> Integer
- boollist_of_int :: Int -> Integer -> [Bool]
- template_map :: Circ ((a -> Circ a) -> Circ ([a] -> Circ [a]))
- template_zip :: Circ ([a] -> Circ ([b] -> Circ [(a, b)]))
- template_tail :: Circ ([a] -> Circ [a])
- template_symb_obracket_symb_cbracket_ :: Circ [a]
- template_symb_dollar_ :: Circ ((a -> Circ b) -> Circ (a -> Circ b))
- mapAccumLM :: (acc -> x -> Circ (acc, y)) -> acc -> [x] -> Circ (acc, [y])
- template_mapAccumL :: Circ ((acc -> Circ (x -> Circ (acc, y))) -> Circ (acc -> Circ ([x] -> Circ (acc, [y]))))
- majority :: Bool -> Bool -> Bool -> Bool
- bit_adder :: Bool -> (Bool, Bool, Bool) -> (Bool, Bool)
- adder :: [Bool] -> [Bool] -> [Bool]
- test_adder' :: Property
- test_adder :: IO ()
- subtract :: [Bool] -> [Bool] -> [Bool]
- test_subtract' :: Property
- test_subtract :: IO ()
- pad_right :: [Bool] -> [Bool] -> [Bool]
- shift :: [Bool] -> [Bool]
- takeOnly :: [Bool] -> [Bool] -> [Bool]
- multiplier' :: [Bool] -> [Bool] -> [Bool]
- multiplier :: [Bool] -> [Bool] -> [Bool]
- test_multiplier' :: Property
- test_multiplier :: IO ()
Binary representation of integers
int_of_boollist :: [Bool] -> IntegerSource
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_tail :: Circ ([a] -> Circ [a])Source
Template Haskell version of tail
.
template_symb_obracket_symb_cbracket_ :: Circ [a]Source
Template Haskell version of []
.
template_symb_dollar_ :: Circ ((a -> Circ b) -> Circ (a -> Circ b))Source
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
Addition
adder :: [Bool] -> [Bool] -> [Bool]Source
Multi-bit adder. Add two n-bit integers, represented as little-tailian bit lists.
test_adder' :: PropertySource
Test the validity of the functional implementation of adder
.
test_adder :: IO ()Source
Wrapper around test_adder'
.
Subtraction
test_subtract' :: PropertySource
Test the validity of the functional implementation of subtract
.
test_subtract :: IO ()Source
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.
multiplier' :: [Bool] -> [Bool] -> [Bool]Source
Reversible multiplier stripping high bits.
multiplier :: [Bool] -> [Bool] -> [Bool]Source
Reversible multiplier keeping high bits.
test_multiplier' :: PropertySource
Test the validity of the functional implementation of multiplier
.
test_multiplier :: IO ()Source
Wrapper around test_multiplier'
.