úÎ’¨ŽvH      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGSafe\!Distribution over values of type a.'Due to their internal representations,  Distribution can not have Functor or Monad instances. However,   is the equivalent of fmap for distributions and  and $ are respectively the equivalent of return and >>=.dConverts the distribution to a mapping from values to their probability. Values with probability 0. are not included in the resulting mapping.'Probability. Should be between 0 and 1.^Converts the distribution to a list of increasing values whose probability is greater than 0.. To each value is associated its probability.Q Returns the number of elements with non-zero probability in the distribution.5Values in the distribution with non-zero probability."Distribution that assigns to each value from the given (value, weight)( pairs a probability proportional to weight.'fromList [('A', 1), ('B', 2), ('C', 1)].fromList [('A',1 % 4),('B',1 % 2),('C',1 % 4)]¿Values may appear multiple times in the list. In this case, their total weight is the sum of the different associated weights. Values whose total weight is zero or negative are ignored.Distribution that assigns to x the probability of 1.always 0fromList [(0,1 % 1)] always 42fromList [(42,1 % 1)]„Uniform distribution over the values. The probability of each element is proportional to its number of appearance in the list.uniform [1 .. 6]FfromList [(1,1 % 6),(2,1 % 6),(3,1 % 6),(4,1 % 6),(5,1 % 6),(6,1 % 6)] True with given probability and False with complementary probability. 5Applies a function to the values in the distribution.select abs $ uniform [-1, 0, 1]fromList [(0,1 % 3),(1,2 % 3)] QReturns a new distribution conditioning on the predicate holding on the value.!assuming (> 2) $ uniform [1 .. 6]2fromList [(3,1 % 4),(4,1 % 4),(5,1 % 4),(6,1 % 4)]jNote that the resulting distribution will be empty if the predicate does not hold on any of the values.!assuming (> 7) $ uniform [1 .. 6] fromList [] DCombines multiple weighted distributions into a single distribution.jThe probability of each element is the weighted sum of the element's probability in every distribution.4combine [(always 2, 1 / 3), (uniform [1..6], 2 / 3)]FfromList [(1,1 % 9),(2,4 % 9),(3,1 % 9),(4,1 % 9),(5,1 % 9),(6,1 % 9)]/Note that the weights do not have to sum up to 1@. Distributions with negative or null weight will be ignored. NBinomial distribution. Assigns to each number of successes its probability. trials 2 $ uniform [True, False](fromList [(0,1 % 4),(1,1 % 2),(2,1 % 4)]Takes nL samples from the distribution and returns the distribution of their sum.times 2 $ uniform [1 .. 3]<fromList [(2,1 % 9),(3,2 % 9),(4,1 % 3),(5,2 % 9),(6,1 % 9)].This function makes use of the more efficient trials. functions for input distributions of size 2.$size $ times 10000 $ uniform [1, 10]10001—Computes for each value in the distribution a new distribution, and then combines those distributions, giving each the weight of the original value.4uniform [1 .. 3] `andThen` (\ n -> uniform [1 .. n])+fromList [(1,11 % 18),(2,5 % 18),(3,1 % 9)]See the 6 function for a convenient way to chain distributions.KUtility to partially apply a function on a distribution. A use case for " is to use it in conjunction with  to combine distributions.4uniform [1 .. 3] `andThen` (+) `on` uniform [1 .. 2]2fromList [(2,1 % 6),(3,1 % 3),(4,1 % 3),(5,1 % 6)]PLiterals are interpreted as distributions that always return the given value.42 == always 42TruefBinary operations on distributions are defined to be the binary operation on each pair of elements.For this reason, (+) and (*)C are not related in the same way as they are on natural numbers.1For instance, it is not always the case that: 3 * d == d + d + dlet d = uniform [0, 1]3 * dfromList [(0,1 % 2),(3,1 % 2)] d + d + d2fromList [(0,1 % 8),(1,3 % 8),(2,3 % 8),(3,1 % 8)]&For this particular behavior, see the  function.OLifts the bounds to the distributions that return them with probability one./Note that the degenerate distributions of size 0' will be less than the distribution minBound.FAppart from that, all other distributions d have the property that minBound <= d <= maxBound= if this property holds on the values of the distribution.A distribution d1& is less than some other distribution d2A if the smallest value that has a different probability in d1 and d2 is more probable in d1.QBy convention, empty distributions are less than everything except themselves.H   H 78Safe!Possible outcomes of a coin flip.&Distribution over the sides of a coin. Fair coin.Flips n5 times the given coin and counts the number of heads.HRerolls the coin once if the first outcome satifies the given predicate.Safe %)Distribution of the result of dice rolls.& Fair dice of n faces.' Fair dice of 4 faces.( Fair dice of 6 faces.) Fair dice of 8 faces.* Fair dice of 10 faces.I Fair dice of 12 faces.+ Fair dice of 20 faces.,Rolls n+ times the given dice and sums the results.-HRerolls the dice once if the first outcome satifies the given predicate. %&'()*I+,- %&'()*+,- %&'()*+,- %&'()*I+,-Safe .7Probability that a predicate holds on the distribution.8probability (\ x -> x == 1 || x == 6) $ uniform [1 .. 6]1 % 3Takes O(n) time. See / and 0; for a more efficient ways to query elements and ranges./Probability of a given value.Takes  O(log(n)) time.0Probability of a the inclusive  [low, high] range. When  low > high, the probability is 0.Takes  O(log(n) + m) time, where n( is the size of the distribution and m the size of the range.14Returns the expectation, or mean, of a distribution.expectation $ uniform [0, 1]0.5+Empty distributions have an expectation of 0.2'Returns the variance of a distribution.variance $ always 10.0variance $ uniform [0 .. 1]0.25variance $ uniform [1 .. 7]4.0'Empty distributions have a variance of 0.3Standard deviation.standardDeviation $ always 10.0$standardDeviation $ uniform [0 .. 1]0.5$standardDeviation $ uniform [1 .. 7]2.04PReturns the smallest value in the distribution such that at least a fraction p' of the values are less or equal to it. quantile 0.0 $ uniform [1, 2, 3]Just 1 quantile 0.5 $ uniform [1, 2, 3]Just 2 quantile 1.0 $ uniform [1, 2, 3]Just 3quantile 0.5 $ fromList []Nothing5†Returns the median of the values. The median is the smallest value such that at least 50% of the values are less or equal to it.&median $ fromList [(1, 0.6), (2, 0.4)]Just 1&median $ fromList [(1, 0.4), (2, 0.6)]Just 26 Synonym of 1.70Returns all values whose probability is maximal. ./01234567 ./01234567 ./01623574 ./01234567Safe:\ 8#Generator of random values of type a.QCan be created in linear time from distributions and sampled in constant time.JNumber of buckets.K"Probability to stay in the bucket.LValue in the bucket.M9Index of the "guest" value. Used when the bucket is left.9:Creates a generator from the given non-empty distribution.Runs in O(n) time where n! is the size of the distribution.:Safe version of 9 . Returns Nothing) when the given distribution is empty.;(Picks a random value from the generator.Runs in constant O(1) time.<(Picks a random value from the generator.Runs in constant O(1) time. 8NJKLM9:;<=89:;<89:<;8NJKLM9:;<=Safe >(Functions that can modify probabilities.?IApplies the aggregator and returns the modified list of probabilities.@v Applies an aggregator on a list of values tagged with their probability. The values themselves are left unchanged.Au Creates an aggregator from a function ignoring the values. The function should not modify the number of elements.B`Creates an aggregator from a function. The function should not modify the number of elements.CAAggregator that applies the first aggregator on values less than x* and the second on values greater than x. Potential probability at x is left untouched.DJAdds to each probability the sum of the probabilities earlier in the list.4aggregateWith cumulative $ toList $ uniform [1 .. 5]3[(1,1 % 5),(2,2 % 5),(3,3 % 5),(4,4 % 5),(5,1 % 1)]E,Replaces each probability by its complement.7aggregateWith complementary $ toList $ uniform [1 .. 5]3[(1,4 % 5),(2,4 % 5),(3,4 % 5),(4,4 % 5),(5,4 % 5)]FDAdds to each probability the sum of probabilities later in the list.5aggregateWith decreasing $ toList $ uniform [1 .. 5]3[(1,1 % 1),(2,4 % 5),(3,3 % 5),(4,2 % 5),(5,1 % 5)]GO? is the aggregator that leaves probabilities untouched, and P compose aggregators. >Q?@ABCDEFG >?@ABCDEF >?BAC?@DFE >Q?@ABCDEFGSafe) ./0123456789:;<>?@ABCDEFR      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRST@UVWUVXFY+distribution-1.0.1.0-4iRRIT32sxq9pZuciDhRZOData.Distribution.CoreData.Distribution.Domain.CoinData.Distribution.Domain.DiceData.Distribution.MeasureData.Distribution.SampleData.Distribution.AggregatorData.Distribution DistributiontoMap ProbabilitytoListsizesupportfromListalwaysuniformwithProbabilityselectassumingcombinetrialstimesandThenon$fMonoidDistribution$fFloatingDistribution$fFractionalDistribution$fNumDistribution$fBoundedDistribution$fOrdDistribution$fShowDistribution$fEqDistributionCoinSideHeadTailCoincoinflipsOfreflipOn $fEqCoinSide $fOrdCoinSide$fShowCoinSide$fReadCoinSide$fEnumCoinSideDicediced4d6d8d10d20rollsOfrerollOn probability probabilityAt probabilityIn expectationvariancestandardDeviationquantilemedianmeanmodes GeneratorfromDistributionsafeFromDistribution getSamplesample$fFunctorGenerator AggregatormodifyProbabilities aggregateWithmakePureAggregatormakeAggregator separated cumulative complementary decreasing$fMonoidAggregatord12capacity probabilitiesvaluesindexesbaseGHC.Basememptymappend