úÎ%y6      !"#$%&'()*+,-./012345(c) Justin Le 2016BSD3 justin@jle.im experimental non-portableSafe-./6789:;<=>?@ABCDEFGHI6789:;<=>?@ABCDEFGHI6789:;<=>?@ABCDEFGHI(c) Justin Le 2016BSD3 justin@jle.im experimental non-portableNone  +04INUZwRepresents an independent experimental value centered around a mean value with "inherent" and independent uncertainty.?Mostly useful due to its instances of numeric typeclasses like J, KÙ, etc., which allows you to add and multiply and apply arbitrary numerical functions to them and have the uncertainty propagate appropriately. You can also lift arbitrary (sufficiently polymorphic) functions with , ,  and family. ghci> let x = 1.52 9 0.07 ghci> let y = 781.4 +/- 0.3 ghci> let z = 1.53e-1 `withPrecision'l 3 ghci> cosh x 2.4 +/- 0.2 ghci> exp x / z * sin (y ** z) 10.9 +/- 0.9 ghci> pi + 3 * logBase x y 52 +/- 5 ÿUncertaintly is properly propagated according to the second-degree taylor series approximations of the applied functions. However, if the higher-degree terms are large with respect to to the means and variances of the uncertain values, these approximations may be inaccurate.Can be created with ; to represent an "exact" measurement with no uncertainty,  and . to specify a standard deviation as a range,  , to specify through decimal precision, and P to specify with a variance. Can also be inferred from a list of samples with  7.13  0.05 91800 +/- 100 12.5 `withVar' 0.36  7.9512 81.42 `withPrecision'5 4 7 :: Uncertain Double 9.18 :: Uncertain Double  [12.5, 12.7, 12.6, 12.6, 12.5] Can be deconstructed with â, the pattern synonym/pseudo-constructor which matches on the mean and a standard deviation (supported on GHC 7.8+, with bidirectional constructor functionality supported on GHC 7.10+). You can also access properties with , , ,  ,  ,  , etc.^It's important to remember that each "occurrence" represents a unique independent sample, so: ghci> let x = 15 = 2 in x + x 30 +/- 3 ghci> let x = 15 +/- 2 in x*2 30 +/- 4 x + xK does not represent adding the same sample to itself twice, it represents  independently& sampling two values within the range 15 +/- 2} and adding them together. In general, errors and deviations will cancel each-other out, leading to a smaller uncertainty. However, x*2 represents taking onet sample and multiplying it by two. This yields a greater uncertainty, because errors and deviations are amplified.Also be aware that the L˜ instance "normalizes" the result, and won't show any mean/central point to a decimal precision smaller than the uncertainty, rounding off the excess.Mmaintained to be positive!Pattern match on an 9 with its central value and its standard deviation (see  for clarification).Can also be used to  construct an , identically as .Note:Š Only supported on GHC 7.8 and above. Bidirectional functionality (to allow use as a constructor) only supported on GHC 7.10 and above. Get the mean central valueexpected value of an .Get the variance of the uncertainty of an O, proportional to the square of "how uncertain" a value is. Is the square of .Get the standard deviation of the uncertainty of an ., proportional to "how uncertain" a value is.ÙVery informally, it can be thought of as the interval above and below the mean that about 68% of sampled values will fall under after repeated sampling, or as the range that one is 68% sure the true value is within.Is the square root of . Create an ' with an exact value and 0 uncertainty. Create an ° around a central value and a given "range" of uncertainty. The range is interpreted as the standard deviation of the underlying random variable. Might be preferrable over 0 because it is more general (doesn't require a N$ constraint) and looks a bit nicer.See  for more details. Create an B around a central value, specifying its uncertainty with a given variance]. The variance is taken to be proportional to the square of the range of uncertainty. See  for more details.-"Negative variances" are treated as positive. Infer an " from a given list of independent samples4 of an underlying uncertain or random distribution. JRetrieve both the mean (central) value and the underlying variance of an  together.  uMeanVar "a  &&&  SRetreve both the mean (central) value and the underlying standard deviation of an  together. (See  for more details)  uMeanStd "a  &&&  :Retrieve the "range" of the underlying distribution of an ¥, derived from the standard deviation, where which approximly 68% of sampled values are expected to occur (or within which you are 68% certain the true value is). $uRange (x +/- dx) "a (x - dx, x + dx) Like  }, except takes a number of "digits" of precision in the desired numeric base. For example, in base 2, takes the number of bits of precision.   "a withPrecisionAtBase 10  Create an D about a given approximate central value, with the given number of digits of precision (in decimal notation). 5.21   3 "a 5.21  0.01Like 7, but takes a numerical base to round with respect to.  "a uNormalizeAtBase 10Attempts to "normalize" an Š. Rounds the uncertainty (the standard deviation) to one digit of precision, and rounds the central moment up to the implied precision.,For example, it makes no real sense to have 542.185433 +/- 83.584, because the extra digits of  542.185433m past the tens place has no meaning because of the overpowering uncertainty. Normalizing this results in  540 +/- 80.Note that the L instance for ( normalizes values before showing them.Like O for ), but does not normalize the value (see )) before showing. See documentation for O7 for more information on how this is meant to be used.Like P for ), but does not normalize the value (see ) before showing. P "a uShow . BLifts a multivariate numeric function on a container (given as an  f a -> a) to work on a container of ÿs. Correctly propagates the uncertainty according to the second-order (multivariate) taylor expansion of the function. Note that if the higher-degree taylor series terms are large with respect to the means and variances, this approximation may be inaccurate.bShould take any function sufficiently polymorphic over numeric types, so you can use things like Q, R, S, etc. 'ghci> liftUF ([x,y,z] -> x*y+z) [12.2 + - 0.5, 56 +- 2, 0.12 +/- 0.08] 680 +/- 40 !Lifts a numeric function over an ÿ. Correctly propagates the uncertainty according to the second-order taylor expansion expansion of the function. Note that if the higher-degree taylor series terms are large with respect to the mean and variance, this approximation may be inaccurate.bShould take any function sufficiently polymorphic over numeric types, so you can use things like R, T, U, etc. 8ghci> liftU (x -> log x ^ 2) (12.2 +/- 0.5) 6.3 +/- 0.2 1Lifts a two-argument (curried) function over two ÿs. Correctly propagates the uncertainty according to the second-order (multivariate) taylor expansion expansion of the function. Note that if the higher-degree taylor series terms are large with respect to the mean and variance, this approximation may be inaccurate.bShould take any function sufficiently polymorphic over numeric types, so you can use things like Q, S, V, etc. "ghci> liftU2 (x y -> x**y) (13.5 +- 0.1) (1.64 +- 0.08) 70 +/- 10 5Lifts a three-argument (curried) function over three  s. See  and  for more details.3Lifts a four-argument (curried) function over four  s. See  and  for more details.3Lifts a five-argument (curried) function over five  s. See  and  for more details.$WXMThe exact valueThe mean or central value4The standard deviation of the underlying uncertaintyThe mean or central value*The variance of the underlying uncertainty /The base to determine precision with respect toThe approximate value of the +The number of "digits" of precision to take The approximate value of the +The number of "digits" of precision to take%The base to normalize with respect to'Function on container of values to lift Container of s to apply the function toFunction on values to lift to apply the function toYZ[\]^_`a   !WXM YZ[\]^_`a(c) Justin Le 2016BSD3 justin@jle.im experimental non-portableNone !"*-7>CINU The n monad allows us to keep track of correlated and non-independent samples. It fixes a basic "failure" of the 0 type, which can't describe correlated samples.-For example, consider the difference between: ghci> sum $ replicate 10 (12.5 4 0.8) 125 +/- 3 ghci> 10 * (12.5 +/- 0.8) 125 +/- 8 ñThe first one represents the addition of ten independent samples, whose errors will in general cancel eachother out. The second one represents sampling once and multiplying it by ten, which will amplify any error by a full factor of 10. See how the ( monad expresses the above computations: ghci> evalCorr $ do x <-  sampleUncert $ 12.5  0.8 y1 <-  resolveUncert[ $ sum (replicate 10 x) y2 <- resolveUncert $ 10 * x return (y1, y2) (125 + - 8, 125 + - 8) ghci> evalCorr# $ do xs <- replicateM 10 ( sampleUncert (12.5 +/- 0.8))  resolveUncert $ sum xs 125 +/- 3 xThe first example samples once and describes operations on the single sample; the second example samples 10 times with  replicateM and sums all of the results.?Things are more interesting when you sample multiple variables: ghci> evalCorr $ do x <-  sampleUncert $ 12.5 w 0.8 y <- sampleUncert $ 15.9 +/- 0.5 z <- sampleUncert $ 1.52 +/- 0.07 let k = y ** x  resolveUncert$ $ (x+z) * logBase z k 1200 +/- 200 AThe first parameter is a dummy phantom parameter used to prevent ,s from leaking out of the computation (see evalCorr§). The second parameter is the numeric type of all samples within the description (for example, if you ever sample an 'Uncert Double', the second parameter wil be bP). The third parameter is the result type of the computation -- the value the  is describing.LRepresents a single sample (or a value calculated from samples) within the # monad. These can be created with  sampleUncert,  sampleExact, and L, or made by combinining others with its numeric typeclass instances (like J>) or its functions lifting arbitrary numeric functions (like Y). These keep track of inter-correlations between sources, and if you add together two 8s that are correlated, their results will reflect this.ACan be "resolved" into the uncertain value they represent using  resolveUncert.?Note that these are parameterized by a dummy phantom parameter s/ so that they can't be "evaluated" out of the  they live in with evalCorr. Note that a  s a) can only ever meaningfully "exist" in a  s a+, meaning that the all samples within that  are of the same type.cKUnsafe function to bypass the universal qualification guard for returning s from s.BLifts a multivariate numeric function on a container (given as an  f a -> a) to work on a container of Ñs. Correctly propagates the uncertainty according to the second-order (multivariate) taylor expansion of the function, and properly takes into account and keeps track of all inter-correlations between the ˜ samples. Note that if the higher-degree taylor series terms are large with respect to the means and variances, this approximation may be inaccurate.bShould take any function sufficiently polymorphic over numeric types, so you can use things like Q, R, S, etc. èghci> evalCorr $ do x <- sampleUncert $ 12.5 +/- 0.8 y <- sampleUncert $ 15.9 +/- 0.5 z <- sampleUncert $ 1.52 +/- 0.07 resolveUncert $ liftCF ([a,b,c] -> (a+c) * logBase c (b**a)) x y z 1200 +/- 200  Creates a > representing a completely independent sample from all other #s containing the exact value given.:Lifts a numeric function over the sample represented by a ÿÿ. Correctly propagates the uncertainty according to the second-order taylor expansion expansion of the function. Note that if the higher-degree taylor series terms are large with respect to the mean and variance, this approximation may be inaccurate.bShould take any function sufficiently polymorphic over numeric types, so you can use things like R, T, U, etc. ªghci> evalCorr $ do x <- sampleUncert $ 12.5 +/- 0.8 y <- sampleUncert $ 15.9 +/- 0.5 resolveUncert $ liftC (z -> log z ^ 2) (x + y) 11.2 +/- 0.2 MLifts a two-argument (curried) function over the samples represented by two Ûs. Correctly propagates the uncertainty according to the second-order (multivariate) taylor expansion expansion of the function, and properly takes into account and keeps track of all inter-correlations between the – samples. Note that if the higher-degree taylor series terms are large with respect to the mean and variance, this approximation may be inaccurate.bShould take any function sufficiently polymorphic over numeric types, so you can use things like Q, S, V, etc. ¯ghci> evalCorr $ do x <- sampleUncert $ 12.5 +/- 0.8 y <- sampleUncert $ 15.9 +/- 0.5 resolveUncert $ liftC2 (a b -> log (a + b) ^ 2) x y 11.2 +/- 0.2 QLifts a three-argument (curried) function over the samples represented by three s. See  and  for more details.OLifts a four-argument (curried) function over the samples represented by four s. See  and  for more details. OLifts a five-argument (curried) function over the samples represented by five s. See  and  for more details.defghijklcm'Function on container of values to lift Container of ! samples to apply the function toFunction on values to lift sample to apply the function to nopqfghicm defghijklcm nopq(c) Justin Le 2016BSD3 justin@jle.im experimental non-portableNoneIN!#Evaluates the value described by a @ monad, taking into account inter-correlations between samples.Takes a universally qualified L, which should not affect usage. See the examples in the documentation for l. The univeral qualification is mostly a type system trick to ensure that you aren't allowed to ever use ! to evaluate a ."Generate a sample in  from an . value, independently from all other samples.Note that you can only sample  a s within a  s a4, meaning that all other "sampled" values are also as.#Generate an exact sample in > with zero uncertainty, independently from all other samples.=Not super useful, since you can do something equivalent with  or the numeric instances: sampleExact x "a return ( x) sampleExact 10 "a return 10 +But is provided for completeness alongside ".$Note that you can exactly sample an a within a  s a4, meaning that all other "sampled" values are also as.$Resolve an  from a k using its potential multiple samples and sample sources, taking into account inter-correlations between s and samples.Note that if you use "‘ on the result, the new sample will be treated as something completely independent. Usually this should only be used as the "exit point" of a  description.!"#$  !"#$ !"#$ !"#$(c) Justin Le 2016BSD3 justin@jle.im experimental non-portableNone%A 5 specialized to work in an "interactive" context, in ghci or r.&Generate a sample in r from an  b. value, independently from all other samples.'Generate an exact sample in r> with zero uncertainty, independently from all other samples.=Not super useful, since you can do something equivalent with  or the numeric instances: sampleExact x "a return ( x) sampleExact 10 "a return 10 +But is provided for completeness alongside &.(Resolve an  from a %k using its potential multiple samples and sample sources, taking into account inter-correlations between %s and samples.Note that if you use &° on the result, the new sample will be treated as something completely independent. Usually this should only be used as the "final value" of your computation or exploration.%st&'(  %&'( %&'( %st&'((c) Justin Le 2016BSD3 justin@jle.im experimental non-portableNone 345 )Sample a random b( from the distribution specified by an  b. x +/- dxa is treated as a random variable whose probability density is the normal distribution with mean x and standard deviation dx.*!Lifts a numeric function over an 3 using a Monte Carlo simulation with 1000 samples.  ghci> g <- u> ghci> MC.liftU (x -> log x ^ 2) (12.2 +/- 0.5) g 6.3 +/- 0.2 +BLifts a multivariate numeric function on a container (given as an  f a -> a) to work on a container of 4s using a Monte Carlo simulation with 1000 samples.  ghci> g <- u* ghci> M.liftUF ([x,y,z] -> x*y+z) [12.2 + - 0.5, 56 +!- 2, 0.12 +/- 0.08] g 680 +/- 40 ,1Lifts a two-argument (curried) function over two 4s using a Monte Carlo simulation with 1000 samples.  ghci> g <- u& ghci> MC.liftU2 (x y -> x**y) (13.5 +- 0.1) (1.64 +- 0.08) 70 +/- 20 -5Lifts a three-argument (curried) function over three  s. See , and + for more details..3Lifts a four-argument (curried) function over four  s. See , and + for more details./3Lifts a five-argument (curried) function over five  s. See , and + for more details.0Like *Z, but allows you to specify the number of samples to run the Monte Carlo simulation with.1Like +Z, but allows you to specify the number of samples to run the Monte Carlo simulation with.2Like ,Z, but allows you to specify the number of samples to run the Monte Carlo simulation with.3Like -Z, but allows you to specify the number of samples to run the Monte Carlo simulation with.4Like .Z, but allows you to specify the number of samples to run the Monte Carlo simulation with.5Like /Z, but allows you to specify the number of samples to run the Monte Carlo simulation with. )*+,-./012345 )*+,-./012345 )*,-./+023451 )*+,-./012345v      !"#$%&'()*+,)*+)-./012334455667789:;<=>?@ABCDBEFBGHIBJKBGLBGMBCNBJOBJPBJQBCRBJSTUVWXYZ[\]^_`abcdefghijklmno_`pqrstuvuncer_JxPjzvROvzQDwhxcwIemBCNumeric.UncertainNumeric.Uncertain.Correlated(Numeric.Uncertain.Correlated.InteractiveNumeric.Uncertain.MonteCarlo Data.Hople%Numeric.Uncertain.Correlated.InternalUncert:+/-uMeanuVaruStdexact+/-withVar fromSamplesuMeanVaruMeanStduRangewithPrecisionAtBase withPrecisionuNormalizeAtBase uNormalize uShowsPrecuShowliftUFliftUliftU2liftU3liftU4liftU5CorrCVarliftCFconstCliftCliftC2liftC3liftC4liftC5evalCorr sampleUncert sampleExact resolveUncertCVarIOliftU'liftUF'liftU2'liftU3'liftU4'liftU5'H5H4H3H2H1curryH1curryH2curryH3curryH4curryH5 uncurryH1 uncurryH2 uncurryH3 uncurryH4 uncurryH5baseGHC.NumNumGHC.Real FractionalGHC.ShowShow_uVar GHC.FloatFloating showsPrecshow*sqrtatan2sinnegate**Un_uMean$fRealFloatUncert$fRealFracUncert $fRealUncert $fOrdUncert $fEqUncert$fFloatingUncert$fFractionalUncert $fNumUncert $fShowUncertghc-prim GHC.TypesDouble dephantomcorrFreeCorrFGenFunReiCKCVCF corrToState$fFloatingCVar$fFractionalCVar $fNumCVar$fFunctorCorrFIO globalCorrMap runCorrIOmwcra_0lrQ1SkkNA85sa8eZ98xQkSystem.Random.MWCcreate