The Quipper System

Libraries.Sampling

Description

This module provides functions for generating lists of samples from a range of input values. This is primarily useful for generating test cases. Ranges can be specified for types that are members of the Interval class. Each sampling procedure generates a (finite or infinite) list of values from the range. We provide sampling procedures for

• generating the range in its entirety (sample_all)
• sampling every nth element from a range (sample_step)
• generating a random sample from the range (sample_random)

Synopsis

# Interval class

class Interval a where Source #

The Interval class contains types for which an interval of values can be specified by giving a lower bound and an upper bound. Intervals are specified as interval min max, for example:

interval (0,0) (1,2) = [(0,0),(0,1),(0,2),(1,0),(1,1),(1,2)].

Minimal complete definition

interval

Methods

interval :: a -> a -> [a] Source #

Takes a range (min,max) and returns a list of all values with lower bound min and upper bound max.

Instances

 # Methodsinterval :: Bool -> Bool -> [Bool] Source # # Methodsinterval :: Double -> Double -> [Double] Source # # Methodsinterval :: Int -> Int -> [Int] Source # # Methodsinterval :: Integer -> Integer -> [Integer] Source # Interval () # Methodsinterval :: () -> () -> [()] Source # # Methodsinterval :: IntM -> IntM -> [IntM] Source # Interval a => Interval [a] # Methodsinterval :: [a] -> [a] -> [[a]] Source # (Interval a, Interval b) => Interval (a, b) # Methodsinterval :: (a, b) -> (a, b) -> [(a, b)] Source # (Interval a, Interval b, Interval c) => Interval (a, b, c) # Methodsinterval :: (a, b, c) -> (a, b, c) -> [(a, b, c)] Source # (Interval a, Interval b, Interval c, Interval d) => Interval (a, b, c, d) # Methodsinterval :: (a, b, c, d) -> (a, b, c, d) -> [(a, b, c, d)] Source # (Interval a, Interval b, Interval c, Interval d, Interval e) => Interval (a, b, c, d, e) # Methodsinterval :: (a, b, c, d, e) -> (a, b, c, d, e) -> [(a, b, c, d, e)] Source # (Interval a, Interval b, Interval c, Interval d, Interval e, Interval f) => Interval (a, b, c, d, e, f) # Methodsinterval :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> [(a, b, c, d, e, f)] Source # (Interval a, Interval b, Interval c, Interval d, Interval e, Interval f, Interval g) => Interval (a, b, c, d, e, f, g) # Methodsinterval :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> [(a, b, c, d, e, f, g)] Source #

# Zero class

class Zero a where Source #

Types in the Zero class have an "origin", i.e., an element that can conveniently serve as the starting point for intervals.

Minimal complete definition

zero

Methods

zero :: a -> a Source #

Inputs any element of the type and outputs the corresponding "zero" element, for example:

zero ([1,2],3,True) = ([0,0],0,False)

Instances

 # Methods # Methods # Methods # Methods Zero () # Methodszero :: () -> () Source # # Methods Zero a => Zero [a] # Methodszero :: [a] -> [a] Source # (Zero a, Zero b) => Zero (a, b) # Methodszero :: (a, b) -> (a, b) Source # (Zero a, Zero b, Zero c) => Zero (a, b, c) # Methodszero :: (a, b, c) -> (a, b, c) Source # (Zero a, Zero b, Zero c, Zero d) => Zero (a, b, c, d) # Methodszero :: (a, b, c, d) -> (a, b, c, d) Source # (Zero a, Zero b, Zero c, Zero d, Zero e) => Zero (a, b, c, d, e) # Methodszero :: (a, b, c, d, e) -> (a, b, c, d, e) Source # (Zero a, Zero b, Zero c, Zero d, Zero e, Zero f) => Zero (a, b, c, d, e, f) # Methodszero :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) Source # (Zero a, Zero b, Zero c, Zero d, Zero e, Zero f, Zero g) => Zero (a, b, c, d, e, f, g) # Methodszero :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) Source #

# Random class

We extend the class Random with tuples and lists.

class Random a #

With a source of random number supply in hand, the Random class allows the programmer to extract random values of a variety of types.

Minimal complete definition: randomR and random.

Minimal complete definition

Instances

 MethodsrandomR :: RandomGen g => (Bool, Bool) -> g -> (Bool, g) #random :: RandomGen g => g -> (Bool, g) #randomRs :: RandomGen g => (Bool, Bool) -> g -> [Bool] #randoms :: RandomGen g => g -> [Bool] #randomRIO :: (Bool, Bool) -> IO Bool # MethodsrandomR :: RandomGen g => (Char, Char) -> g -> (Char, g) #random :: RandomGen g => g -> (Char, g) #randomRs :: RandomGen g => (Char, Char) -> g -> [Char] #randoms :: RandomGen g => g -> [Char] #randomRIO :: (Char, Char) -> IO Char # MethodsrandomR :: RandomGen g => (Double, Double) -> g -> (Double, g) #random :: RandomGen g => g -> (Double, g) #randomRs :: RandomGen g => (Double, Double) -> g -> [Double] #randoms :: RandomGen g => g -> [Double] #randomRIO :: (Double, Double) -> IO Double # MethodsrandomR :: RandomGen g => (Float, Float) -> g -> (Float, g) #random :: RandomGen g => g -> (Float, g) #randomRs :: RandomGen g => (Float, Float) -> g -> [Float] #randoms :: RandomGen g => g -> [Float] #randomRIO :: (Float, Float) -> IO Float # MethodsrandomR :: RandomGen g => (Int, Int) -> g -> (Int, g) #random :: RandomGen g => g -> (Int, g) #randomRs :: RandomGen g => (Int, Int) -> g -> [Int] #randoms :: RandomGen g => g -> [Int] #randomRIO :: (Int, Int) -> IO Int # MethodsrandomR :: RandomGen g => (Int8, Int8) -> g -> (Int8, g) #random :: RandomGen g => g -> (Int8, g) #randomRs :: RandomGen g => (Int8, Int8) -> g -> [Int8] #randoms :: RandomGen g => g -> [Int8] #randomRIO :: (Int8, Int8) -> IO Int8 # MethodsrandomR :: RandomGen g => (Int16, Int16) -> g -> (Int16, g) #random :: RandomGen g => g -> (Int16, g) #randomRs :: RandomGen g => (Int16, Int16) -> g -> [Int16] #randoms :: RandomGen g => g -> [Int16] #randomRIO :: (Int16, Int16) -> IO Int16 # MethodsrandomR :: RandomGen g => (Int32, Int32) -> g -> (Int32, g) #random :: RandomGen g => g -> (Int32, g) #randomRs :: RandomGen g => (Int32, Int32) -> g -> [Int32] #randoms :: RandomGen g => g -> [Int32] #randomRIO :: (Int32, Int32) -> IO Int32 # MethodsrandomR :: RandomGen g => (Int64, Int64) -> g -> (Int64, g) #random :: RandomGen g => g -> (Int64, g) #randomRs :: RandomGen g => (Int64, Int64) -> g -> [Int64] #randoms :: RandomGen g => g -> [Int64] #randomRIO :: (Int64, Int64) -> IO Int64 # MethodsrandomR :: RandomGen g => (Integer, Integer) -> g -> (Integer, g) #random :: RandomGen g => g -> (Integer, g) #randomRs :: RandomGen g => (Integer, Integer) -> g -> [Integer] #randoms :: RandomGen g => g -> [Integer] #randomRIO :: (Integer, Integer) -> IO Integer # MethodsrandomR :: RandomGen g => (Word, Word) -> g -> (Word, g) #random :: RandomGen g => g -> (Word, g) #randomRs :: RandomGen g => (Word, Word) -> g -> [Word] #randoms :: RandomGen g => g -> [Word] #randomRIO :: (Word, Word) -> IO Word # MethodsrandomR :: RandomGen g => (Word8, Word8) -> g -> (Word8, g) #random :: RandomGen g => g -> (Word8, g) #randomRs :: RandomGen g => (Word8, Word8) -> g -> [Word8] #randoms :: RandomGen g => g -> [Word8] #randomRIO :: (Word8, Word8) -> IO Word8 # MethodsrandomR :: RandomGen g => (Word16, Word16) -> g -> (Word16, g) #random :: RandomGen g => g -> (Word16, g) #randomRs :: RandomGen g => (Word16, Word16) -> g -> [Word16] #randoms :: RandomGen g => g -> [Word16] #randomRIO :: (Word16, Word16) -> IO Word16 # MethodsrandomR :: RandomGen g => (Word32, Word32) -> g -> (Word32, g) #random :: RandomGen g => g -> (Word32, g) #randomRs :: RandomGen g => (Word32, Word32) -> g -> [Word32] #randoms :: RandomGen g => g -> [Word32] #randomRIO :: (Word32, Word32) -> IO Word32 # MethodsrandomR :: RandomGen g => (Word64, Word64) -> g -> (Word64, g) #random :: RandomGen g => g -> (Word64, g) #randomRs :: RandomGen g => (Word64, Word64) -> g -> [Word64] #randoms :: RandomGen g => g -> [Word64] #randomRIO :: (Word64, Word64) -> IO Word64 # MethodsrandomR :: RandomGen g => (CChar, CChar) -> g -> (CChar, g) #random :: RandomGen g => g -> (CChar, g) #randomRs :: RandomGen g => (CChar, CChar) -> g -> [CChar] #randoms :: RandomGen g => g -> [CChar] #randomRIO :: (CChar, CChar) -> IO CChar # MethodsrandomR :: RandomGen g => (CSChar, CSChar) -> g -> (CSChar, g) #random :: RandomGen g => g -> (CSChar, g) #randomRs :: RandomGen g => (CSChar, CSChar) -> g -> [CSChar] #randoms :: RandomGen g => g -> [CSChar] #randomRIO :: (CSChar, CSChar) -> IO CSChar # MethodsrandomR :: RandomGen g => (CUChar, CUChar) -> g -> (CUChar, g) #random :: RandomGen g => g -> (CUChar, g) #randomRs :: RandomGen g => (CUChar, CUChar) -> g -> [CUChar] #randoms :: RandomGen g => g -> [CUChar] #randomRIO :: (CUChar, CUChar) -> IO CUChar # MethodsrandomR :: RandomGen g => (CShort, CShort) -> g -> (CShort, g) #random :: RandomGen g => g -> (CShort, g) #randomRs :: RandomGen g => (CShort, CShort) -> g -> [CShort] #randoms :: RandomGen g => g -> [CShort] #randomRIO :: (CShort, CShort) -> IO CShort # MethodsrandomR :: RandomGen g => (CUShort, CUShort) -> g -> (CUShort, g) #random :: RandomGen g => g -> (CUShort, g) #randomRs :: RandomGen g => (CUShort, CUShort) -> g -> [CUShort] #randoms :: RandomGen g => g -> [CUShort] #randomRIO :: (CUShort, CUShort) -> IO CUShort # MethodsrandomR :: RandomGen g => (CInt, CInt) -> g -> (CInt, g) #random :: RandomGen g => g -> (CInt, g) #randomRs :: RandomGen g => (CInt, CInt) -> g -> [CInt] #randoms :: RandomGen g => g -> [CInt] #randomRIO :: (CInt, CInt) -> IO CInt # MethodsrandomR :: RandomGen g => (CUInt, CUInt) -> g -> (CUInt, g) #random :: RandomGen g => g -> (CUInt, g) #randomRs :: RandomGen g => (CUInt, CUInt) -> g -> [CUInt] #randoms :: RandomGen g => g -> [CUInt] #randomRIO :: (CUInt, CUInt) -> IO CUInt # MethodsrandomR :: RandomGen g => (CLong, CLong) -> g -> (CLong, g) #random :: RandomGen g => g -> (CLong, g) #randomRs :: RandomGen g => (CLong, CLong) -> g -> [CLong] #randoms :: RandomGen g => g -> [CLong] #randomRIO :: (CLong, CLong) -> IO CLong # MethodsrandomR :: RandomGen g => (CULong, CULong) -> g -> (CULong, g) #random :: RandomGen g => g -> (CULong, g) #randomRs :: RandomGen g => (CULong, CULong) -> g -> [CULong] #randoms :: RandomGen g => g -> [CULong] #randomRIO :: (CULong, CULong) -> IO CULong # MethodsrandomR :: RandomGen g => (CLLong, CLLong) -> g -> (CLLong, g) #random :: RandomGen g => g -> (CLLong, g) #randomRs :: RandomGen g => (CLLong, CLLong) -> g -> [CLLong] #randoms :: RandomGen g => g -> [CLLong] #randomRIO :: (CLLong, CLLong) -> IO CLLong # MethodsrandomR :: RandomGen g => (CULLong, CULLong) -> g -> (CULLong, g) #random :: RandomGen g => g -> (CULLong, g) #randomRs :: RandomGen g => (CULLong, CULLong) -> g -> [CULLong] #randoms :: RandomGen g => g -> [CULLong] #randomRIO :: (CULLong, CULLong) -> IO CULLong # MethodsrandomR :: RandomGen g => (CFloat, CFloat) -> g -> (CFloat, g) #random :: RandomGen g => g -> (CFloat, g) #randomRs :: RandomGen g => (CFloat, CFloat) -> g -> [CFloat] #randoms :: RandomGen g => g -> [CFloat] #randomRIO :: (CFloat, CFloat) -> IO CFloat # MethodsrandomR :: RandomGen g => (CDouble, CDouble) -> g -> (CDouble, g) #random :: RandomGen g => g -> (CDouble, g) #randomRs :: RandomGen g => (CDouble, CDouble) -> g -> [CDouble] #randoms :: RandomGen g => g -> [CDouble] #randomRIO :: (CDouble, CDouble) -> IO CDouble # MethodsrandomR :: RandomGen g => (CPtrdiff, CPtrdiff) -> g -> (CPtrdiff, g) #random :: RandomGen g => g -> (CPtrdiff, g) #randomRs :: RandomGen g => (CPtrdiff, CPtrdiff) -> g -> [CPtrdiff] #randoms :: RandomGen g => g -> [CPtrdiff] #randomRIO :: (CPtrdiff, CPtrdiff) -> IO CPtrdiff # MethodsrandomR :: RandomGen g => (CSize, CSize) -> g -> (CSize, g) #random :: RandomGen g => g -> (CSize, g) #randomRs :: RandomGen g => (CSize, CSize) -> g -> [CSize] #randoms :: RandomGen g => g -> [CSize] #randomRIO :: (CSize, CSize) -> IO CSize # MethodsrandomR :: RandomGen g => (CWchar, CWchar) -> g -> (CWchar, g) #random :: RandomGen g => g -> (CWchar, g) #randomRs :: RandomGen g => (CWchar, CWchar) -> g -> [CWchar] #randoms :: RandomGen g => g -> [CWchar] #randomRIO :: (CWchar, CWchar) -> IO CWchar # MethodsrandomR :: RandomGen g => (CSigAtomic, CSigAtomic) -> g -> (CSigAtomic, g) #random :: RandomGen g => g -> (CSigAtomic, g) #randomRs :: RandomGen g => (CSigAtomic, CSigAtomic) -> g -> [CSigAtomic] #randoms :: RandomGen g => g -> [CSigAtomic] # MethodsrandomR :: RandomGen g => (CIntPtr, CIntPtr) -> g -> (CIntPtr, g) #random :: RandomGen g => g -> (CIntPtr, g) #randomRs :: RandomGen g => (CIntPtr, CIntPtr) -> g -> [CIntPtr] #randoms :: RandomGen g => g -> [CIntPtr] #randomRIO :: (CIntPtr, CIntPtr) -> IO CIntPtr # MethodsrandomR :: RandomGen g => (CUIntPtr, CUIntPtr) -> g -> (CUIntPtr, g) #random :: RandomGen g => g -> (CUIntPtr, g) #randomRs :: RandomGen g => (CUIntPtr, CUIntPtr) -> g -> [CUIntPtr] #randoms :: RandomGen g => g -> [CUIntPtr] #randomRIO :: (CUIntPtr, CUIntPtr) -> IO CUIntPtr # MethodsrandomR :: RandomGen g => (CIntMax, CIntMax) -> g -> (CIntMax, g) #random :: RandomGen g => g -> (CIntMax, g) #randomRs :: RandomGen g => (CIntMax, CIntMax) -> g -> [CIntMax] #randoms :: RandomGen g => g -> [CIntMax] #randomRIO :: (CIntMax, CIntMax) -> IO CIntMax # MethodsrandomR :: RandomGen g => (CUIntMax, CUIntMax) -> g -> (CUIntMax, g) #random :: RandomGen g => g -> (CUIntMax, g) #randomRs :: RandomGen g => (CUIntMax, CUIntMax) -> g -> [CUIntMax] #randoms :: RandomGen g => g -> [CUIntMax] #randomRIO :: (CUIntMax, CUIntMax) -> IO CUIntMax # Precision e => Random (FixedPrec e) MethodsrandomR :: RandomGen g => (FixedPrec e, FixedPrec e) -> g -> (FixedPrec e, g) #random :: RandomGen g => g -> (FixedPrec e, g) #randomRs :: RandomGen g => (FixedPrec e, FixedPrec e) -> g -> [FixedPrec e] #randoms :: RandomGen g => g -> [FixedPrec e] #randomRIO :: (FixedPrec e, FixedPrec e) -> IO (FixedPrec e) #randomIO :: IO (FixedPrec e) #

# Functions

sample_all :: Interval a => a -> a -> [a] Source #

sample_all min max: returns a list of all elements from the range (min,max). This is actually just a synonym of interval.

sample_step :: (Integral a, Integral b, Interval c) => a -> b -> c -> c -> [c] Source #

sample_step n k min max: returns every nth element from the range (min,max), starting with the kth element.

sample_random :: (Random a, RandomGen g) => g -> a -> a -> [a] Source #

sample_random g min max: returns an infinite list of random samples from the range (min,max), using the random number generator g.

sample_all0 :: (Zero a, Interval a) => a -> [a] Source #

A variant of sample_all that omits the min argument, and uses the zero element of the type instead.

sample_step0 :: (Integral a, Integral b, Zero c, Interval c) => a -> b -> c -> [c] Source #

A variant of sample_step that omits the min argument, and uses the zero element of the type instead.

sample_random0 :: (Random a, Zero a, RandomGen g) => g -> a -> [a] Source #

A variant of sample_random that omits the min argument, and uses the zero element of the type instead.

# Orphan instances

 Random () # 0-tuples MethodsrandomR :: RandomGen g => ((), ()) -> g -> ((), g) #random :: RandomGen g => g -> ((), g) #randomRs :: RandomGen g => ((), ()) -> g -> [()] #randoms :: RandomGen g => g -> [()] #randomRIO :: ((), ()) -> IO () #randomIO :: IO () # Random a => Random [a] # Lists MethodsrandomR :: RandomGen g => ([a], [a]) -> g -> ([a], g) #random :: RandomGen g => g -> ([a], g) #randomRs :: RandomGen g => ([a], [a]) -> g -> [[a]] #randoms :: RandomGen g => g -> [[a]] #randomRIO :: ([a], [a]) -> IO [a] #randomIO :: IO [a] # (Random a, Random b) => Random (a, b) # Pairs MethodsrandomR :: RandomGen g => ((a, b), (a, b)) -> g -> ((a, b), g) #random :: RandomGen g => g -> ((a, b), g) #randomRs :: RandomGen g => ((a, b), (a, b)) -> g -> [(a, b)] #randoms :: RandomGen g => g -> [(a, b)] #randomRIO :: ((a, b), (a, b)) -> IO (a, b) #randomIO :: IO (a, b) # (Random a, Random b, Random c) => Random (a, b, c) # Triples MethodsrandomR :: RandomGen g => ((a, b, c), (a, b, c)) -> g -> ((a, b, c), g) #random :: RandomGen g => g -> ((a, b, c), g) #randomRs :: RandomGen g => ((a, b, c), (a, b, c)) -> g -> [(a, b, c)] #randoms :: RandomGen g => g -> [(a, b, c)] #randomRIO :: ((a, b, c), (a, b, c)) -> IO (a, b, c) #randomIO :: IO (a, b, c) # (Random a, Random b, Random c, Random d) => Random (a, b, c, d) # 4-Tuples MethodsrandomR :: RandomGen g => ((a, b, c, d), (a, b, c, d)) -> g -> ((a, b, c, d), g) #random :: RandomGen g => g -> ((a, b, c, d), g) #randomRs :: RandomGen g => ((a, b, c, d), (a, b, c, d)) -> g -> [(a, b, c, d)] #randoms :: RandomGen g => g -> [(a, b, c, d)] #randomRIO :: ((a, b, c, d), (a, b, c, d)) -> IO (a, b, c, d) #randomIO :: IO (a, b, c, d) # (Random a, Random b, Random c, Random d, Random e) => Random (a, b, c, d, e) # 5-Tuples MethodsrandomR :: RandomGen g => ((a, b, c, d, e), (a, b, c, d, e)) -> g -> ((a, b, c, d, e), g) #random :: RandomGen g => g -> ((a, b, c, d, e), g) #randomRs :: RandomGen g => ((a, b, c, d, e), (a, b, c, d, e)) -> g -> [(a, b, c, d, e)] #randoms :: RandomGen g => g -> [(a, b, c, d, e)] #randomRIO :: ((a, b, c, d, e), (a, b, c, d, e)) -> IO (a, b, c, d, e) #randomIO :: IO (a, b, c, d, e) # (Random a, Random b, Random c, Random d, Random e, Random f) => Random (a, b, c, d, e, f) # 6-Tuples MethodsrandomR :: RandomGen g => ((a, b, c, d, e, f), (a, b, c, d, e, f)) -> g -> ((a, b, c, d, e, f), g) #random :: RandomGen g => g -> ((a, b, c, d, e, f), g) #randomRs :: RandomGen g => ((a, b, c, d, e, f), (a, b, c, d, e, f)) -> g -> [(a, b, c, d, e, f)] #randoms :: RandomGen g => g -> [(a, b, c, d, e, f)] #randomRIO :: ((a, b, c, d, e, f), (a, b, c, d, e, f)) -> IO (a, b, c, d, e, f) #randomIO :: IO (a, b, c, d, e, f) # (Random a, Random b, Random c, Random d, Random e, Random f, Random g) => Random (a, b, c, d, e, f, g) # 7-Tuples MethodsrandomR :: RandomGen g => ((a, b, c, d, e, f, g), (a, b, c, d, e, f, g)) -> g -> ((a, b, c, d, e, f, g), g) #random :: RandomGen g => g -> ((a, b, c, d, e, f, g), g) #randomRs :: RandomGen g => ((a, b, c, d, e, f, g), (a, b, c, d, e, f, g)) -> g -> [(a, b, c, d, e, f, g)] #randoms :: RandomGen g => g -> [(a, b, c, d, e, f, g)] #randomRIO :: ((a, b, c, d, e, f, g), (a, b, c, d, e, f, g)) -> IO (a, b, c, d, e, f, g) #randomIO :: IO (a, b, c, d, e, f, g) #