{      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                                  ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~            *create a singleton list, you can also use  for the list  apply a function to the nth element of a list t9Simulation means to repeat a random chage many times and :to accumulate all results into a distribution. Therefore, @simulation can be regarded as an approximation of distributions through randomization. AThe Sim class allows the overloading of simulation for different <kinds of generators, namely transitions and random changes:  (Trans a = a -> Dist a ==> c = Dist *RChange a = a -> R a ==> c = R = IO (returns the final randomized transition returns the whole trace Naming convention:  * takes n :: Int4 and a generator and iterates the generator n times  . produces a single result  .. produces a trace  ~ takes k :: Int [and n :: Int] and a generator and simulates & the [n-fold repetition of the] generator k times #There are the following functions:  n *. t* iterates t and produces a distribution  n *.. t# iterates t and produces a trace   k ~. t+ simulates t and produces a distribution   (k,n) ~*. tD simulates the n-fold repetition of t and produces a distribution   (k,n) ~.. t= simulates the n-fold repetition of t and produces a trace /Iteration captures three iteration strategies: ?iter builds an n-fold composition of a (randomized) transition 2while and until implement conditional repetitions DThe class Iterate allows the overloading of iteration for different <kinds of generators, namely transitions and random changes:  )Trans a = a -> Dist a ==> c = Dist +RChange a = a -> R a ==> c = R = IO random transition random change =functions to convert a list of transitions into a transition 9functions to convert a list of changes into a transition probabilistic generator deterministic generator Randomized distributions Random values filtering distributions !"distribution generators #probability disribution $%&'()*+,-./01binary composition 2+composition of a list of monadic functions 3456789:;<=>3product of independent distributions, identical to  Monad.liftM2 ?@ABCDEFGHIJKL4extracting and mapping the domain of a distribution MN=unfold a distribution of distributions into one distribution Oconditional distribution PQconditional probability RSTUselecting from distributions VWXstatistical analyses YZ[\]^_`abcdefghijklmm3 converts a list of randomly generated values into 6a distribution by taking equal weights for all values n(>>:)2 composes the result of a transition with a space %(transition is composed on the left) (a -> m a) -> (a -> [m a]) -> (a -> [m a])o=walk is a bounded version of the predefined function iterate p(*..) is identical to (*.), 7but returns the list of all intermediate distributions qrr1 computes a list of values by randomly selecting ,one value from a distribution in each step. ss converts a list of s 2into a list of randomized distributions, i.e., an , Oby creating a randomized distribution for each list position across all traces t  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrst)*+'(&,-./012#$%3456789:;<=>?"@ABCDEFGHIJKLMNOPQ! RSTUVWXYZ[\]^_`abcdefghijklm  nopqrst   ! !"#$%$%&'(()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrst&calculate the full joint distribution uvwxyz{|}prior burglary 1% ~prior earthquake 0.1% ?conditional probability of alarm given burglary and earthquake 4conditional probability of john calling given alarm 4conditional probability of mary calling given alarm ?what is the probability that mary calls given that john calls? tuvwxyz{|}~{|}~tuvwxyztuvwxyzuvwxyz{|}~2(customers waiting,validity period of that queue) -customers and their individual serving times (servingTime, nextArrival) multiple servers =decrease served customers remaining time by specified amount time until next completion avg barber idle time /avg customer waiting time (unserved customers) #Two possible causes for one effect  &mini-blackjack: =draw 2 cards, and if value is less than 14, continue drawing 9until value equals or exceeds 14. if values exceeds 21, you lose, otherwise you win. &&&  sixes p n% computes the probability of getting  p sixes (>1, ==2, ...) when rolling n dice     )initial configuration of the game status  Steps of the game:  hide the prize  choose a door / open a non-open door, not revealing the prize  apply strategy: switch or stay                    !"  !"  !"  !" =#Visualization output $settings for individual plots %&'()*+,-./0123456789:;<=>?@ABCDglobal settings for one figure EFGHIJ(default settings for figure environment Kdefault plotting environment LMNO"create a plot from a distribution PQcreate a plot from a function Rcreate a plot from a list STUVWHwe want to increase the bounds absolutely, account for negative numbers XYZ[\]^_=#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_=DEFGHIJ4CBA@?>=<;:98765-3210/.,$%&'()*+KLMNOPQRSTUWV#XYZ[\]^_=#$%&'()*+%&'()*+,-3210/../01234CBA@?>=<;:9876556789:;<=>?@ABCDEFGHIEFGHIJKLMNOPQRSTUVWXYZ[\]^_ `abcdefghijkl `abcdefghijkl abc`defghijkl `abcdefghijkl mnopqrstuvtree growth simulation: + start with seed and run for n generations wtree n) : tree distribution after n generations xhist n3 : history of tree distributions for n generations ySince '(*.)'& is overloaded for Trans and RChange, )we can run the simulation ~. directly to  n *. live. z{|}~mnopqrstuvwxyz{|}~qmponrstuvwxyz{|}~mponnopqrstuvwxyz{|}~ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~9)                 R                    ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~   probability-0.1 ProbabilityAlarmQueuingBarberBayesianBoys CollectionDice MontyHallNBoys VisualizePredator TreeGrowth PrintList ListUtilsShowRExpandRWalkRSpaceRTraceExpandWalkSpaceTraceSim~.~..~*.Iterate*.whileuntil ApproxDistRTransRChangeSpreadTSpreadCTransChangeRDistRExpectedexpected FromFloat fromFloatToFloattoFloatSelectOtherCaseSpreadDistDunDProbRepPEventoneOfjust precisionshowPfixroundRelshowP errorMargin>@>sequisZeroonDsizeDcheckDmkDsumPsortPnormByaccumBynormnorm'joinWithprod certainly impossiblechooseenumenumPCrelativeshapelinearuniformnegexpnormal normalCurveextractmapDunfoldDcondtruth|||abovescalefilterDselectPscanP??variancestddevprintRpickrAboveidTmapTunfoldT certainlyTmaybeTliftCuniformTnormalTlinearTenumTliftT uniformTTnormalTTlinearTTenumTTrandomrDist>>:walk*.. composelRrWalk mergeTracesBurglaryBburglary earthquakealarmjohnmaryPBoolflpbeajmbJointpmjREventsREventRProfileEventsSystemStateQueueProfileTimeeventsystemmEventmServe mTimeStepmSystemrSystem rBuildEventsrmSystem evalSystemunitmaxQueue allWaiting countWaitingwaitinginSystemtotalserveridleidleAvgPCategory MoreThanTen FourToTen ThreeOrLesscustServnextCustbarbers customersruns barberEvent barberEvents barberSystemcatperc barberIdle customerWaitNodesEASPredSTransPStatehappensnetworksourcebingaEbEFamilyChildGirlBoybirthfamilyboys existsBoy familyWithBoytwoBoys countBoysnumBoysCardRankAceKingQueenJackPlainSuitDiamondHeartSpadeClubMarbleG selectOneselect1select2 selectManyselectbucketjarpRGBpRGplainsfacesisFaceisPlainrankssuitsdeckvaluedrawdrawTo16win chanceWinDiedietwoDicedicetwoSixessixesdrollg3addTwoOutcomeLoseWinStrategyDoorsprizechosenopenedDoorCdoorsstarthideopenswitchstaygameresultevalsimEval firstChoiceswitch'nBoys onlyBoys1VisPlotysxscolor lineStyle lineWidthlabelPlotFun LineStyleTwoDashLongDashDotDashDottedDashedSolidColorCustomWhiteYellowOrangeMagenta LightGreenCyanDarkGrayPurpleGrayBrownRedGreenBlueBlack FigureEnvFEfileNametitlexLabelyLabelfigureplotcolorssetColor autoColorplotDplotRDplotFplotLplotRLyls metaTupleincrdecrfigfigP showParamslegenddrawyvecout0out1dsv0p0dvdpdvpvpvspsfig1TreeFallenHitAliveHeightgrowhitfallevolveseedtreehistsimTreesimHistt2h2st2sh2heightp1p2p3p4 heightAtTimep5 heightCurvep6doneev5LinesasLinesshowNQindent printListasTupleasSeqasListasSetasLispasPlainasPlain'asStringasCasesasDefs asParagraphs singletonbaseGHC.BasereturnMonadonNthshowLshowRrep