9/2      !"#$%&'()*+,-./01 (c) Levent ErkokBSD3erkokl@gmail.com experimentalSafe0,Importable type as an annotation alternativeThe actual annotation.Plugin options. Note that we allow picking multiple solvers, which will all be run in parallel. You can pick and choose any number of them, or if you want to run all available solvers, then use the option v. The default behavior is to error-out on failure, using the default-SMT solver picked by SBV, which is currently Z3.Continue even if proof failsVSkip the proof. Can be handy for properties that we currently do not want to focus on.*Produce verbose output, good for debuggingDProduce really verbose output, use only when things go really wrong! Perform quickCheck +Uninterpret this binding for proof purposes 9Use these names for the arguments; need not be exhaustive NIf a list-input is found, use this length. If not specified, we will complain! Use Z3 Use Yices Use BoolectorUse CVC4 Use MathSATUse ABCURun all installed solvers in parallel, and report the result from the first to finish-A property annotation, using default options.)Synonym for sbv really, just looks cooler      (c) Levent ErkokBSD3erkokl@gmail.com experimentalNone#9;OT2+The values kept track of by the interpreter3The kinds used by the plugin4'Configuration info as we run the plugin5The interpreter monad6Interpreter environment72Certain "very-polymorphic" things are just special88Given the user options, determine which solver(s) to use9:Structural lifting of a boolean function (eq/neq) over Val:Symbolic equality over values;"Symbolic if-then-else over values.<MCompute the span given a Tick. Returns the old-span if the tick span useless.=Compute the span for a binding.>Pick the first "good" span, hopefully corresponding to the closest location to where we are in the code when we issue an error message.?%Show a GHC span in user-friendly form@@This comes mighty handy! Wonder why GHC doesn't have it already:AOutputable instance for ValBOutputable instance for S.KindCOutputable instance for SKind32DEFGH3IJKL4MNOPQ56RSTUVWXYZ[\]^_`7abcd89:;<=>?@ABC/2DEFGH3IJKL4MNOPQ56RTSUVWXYZ[\]^_`7abcd89:;<=>?2DEFGH3IJKL4MNOPQ56RSTUVWXYZ[\]^_`7abcd89:;<=>?@ABC(c) Levent ErkokBSD3erkokl@gmail.com experimentalNone#BeTWhat tuple-sizes we support? We go upto 15, but would be easy to change if necessaryf.Build the initial environment containing typesg2Build the initial environment containing functionsh#Basic conversions, only on one kindi?Symbolic functions supported by the plugin; those from a class.j DestructorsklThese types show up during uninterpretation, but are not really "interesting" as they are singly inhabited.lTCertain things are just too special, as they uniformly apply to uninterpreted types.m$Lift a binary type, with result boolnLift a unary typeoLift a binary typep0Lift a binary type, where second argument is Intq(Construct the type for a split operationr'Construct the type for a join operationsType of enumFromTo: [x .. y]t Type of enumFromThenTo: [x .. y]u/Lift a unary SBV function that via kind/integerv3Lift a unary SBV function to the plugin value spacew>Lift a two argument SBV function to our the plugin value spacexLifting splitsyDLifting an equality is special; since it acts uniformly over tuples.zLifting enumFromTo: [x .. y]{$Lifting sEnumFromThenTo: [x, y .. z]|CImplement [x .. y] or [x, y .. z]; provided the inputs are concreteefghijklmnopqrstuvwxyz{|}~fgjklefghijklmnopqrstuvwxyz{|}~(c) Levent ErkokBSD3erkokl@gmail.com experimentalNone##Dispatch the analyzer over bindingsProve an SBVTheoremgSafely execute an action, catching the exceptions, printing and returning False if something goes wrongReturns True if proof went thruIs this really a dictionary in disguise? This is a terrible hack, and the ice is thin here. But it seems to work. TODO: Figure out if there's a better way of doing this. Note that this function really does get applications, when those dictionaries are parameterized by others. Think of the case where "Eq [a]" dictionary depends on "Eq a", for instance. In these cases, GHC to produces applications.Uninterpret an expressionBConvert a Core type to an SBV Type, retaining functions and tuples   (c) Levent ErkokBSD3erkokl@gmail.com experimentalNone#Entry point to the plugin(c) Levent ErkokBSD3erkokl@gmail.com experimentalNone    (c) Levent ErkokBSD3erkokl@gmail.com experimentalNone GSBVPlugin can only see definitions in the current module. So we define  ourselves.Returns 1 if bool is True Formalizes Dhttps://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax Formalizes Dhttps://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax  Formalizes Hhttps://graphics.stanford.edu/~seander/bithacks.html#DetectOppositeSigns! Formalizes ^https://graphics.stanford.edu/~seander/bithacks.html#ConditionalSetOrClearBitsWithoutBranching" Formalizes Hhttps://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2# Formalizes @https://graphics.stanford.edu/~seander/bithacks.html#MaskedMerge$ Formalizes Dhttps://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2% Formalizes ?https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord  !"#$%  !"#$%  !"#$%  !"#$%(c) Levent ErkokBSD3erkokl@gmail.com experimentalNone&5Merging two given sorted lists, preserving the order.'!Simple merge-sort implementation.(1Check whether a given sequence is non-decreasing.)Check whether two given sequences are permutations. We simply check that each sequence is a subset of the other, when considered as a set. The check is slightly complicated for the need to account for possibly duplicated elements.*Asserting correctness of merge-sort for a list of the given size. Note that we can only check correctness for fixed-size lists. Also, the proof will get more and more complicated for the backend SMT solver as n" increases. Here we try it with 4.We have: R [SBV] tests/T48.hs:100:1-16 Proving "mergeSortCorrect", using Z3. [Z3] Q.E.D. &'()*&'()*&'()*&'()*(c) Levent ErkokBSD3erkokl@gmail.com experimentalNone+GThe range detector must output if the range is larger than this amount.,NThe range detector must have sent an output before this many cycles have past.-+Given a last-signal-time calculator, named  calculate^, check that it satisfies the following three requirements: We must've just sent a signal if:minRate9: The last-time we sent is strictly less than the , amountminRange=: We must've just sent a signal if the range is beyond +manualOverrideC: We must've just sent a signal if the manual-override is specified.mA "bad" implementation, see if you can spot the problem with it, before looking at the failed theorem below!/Using SBV, prove that the .K is indeed a bad implementation. Here's the output we get from the plugin:  [SBV] MicroController.hs:85:1-8 Proving "checkBad", using Z3. [Z3] Falsifiable. Counter-example: range = 200 :: Int64 manual = False :: Bool timeSince = 9 :: Int64 We're being told that if the range is 200, and manual override is off, and time-since last is 9, then our "calculator" returns 10. But that violates the minRate) requirement, since we never want to go ,! cycles without sending a signal!0PA "good" implementation, properly handling the off-by-one error of the original.1=We now verify that the good variant is indeed good. We have: P [SBV] MicroController.hs:108:1-9 Proving "checkGood", using Z3. [Z3] Q.E.D. +,-./01+,-./01+,-./01+,-./01 (c) Nickolas FotopoulosBSD3nickolas.fotopoulos@gmail.com experimentalNonegA top-level binding with its type wrapped in Proved causes sbvPlugin to run a proof on the expression.)Simple booleans can be made theorems too.    !"#$% &'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVW?XYZ[A\]^_`abcdefghiBjklmnopqrstuvwxyz{|}~ $sbvPlugin-0.8-DpjGlB16h0eECTgfdfAwtyData.SBV.Plugin.DataData.SBV.Plugin"Data.SBV.Plugin.Examples.BitTricks"Data.SBV.Plugin.Examples.MergeSort(Data.SBV.Plugin.Examples.MicroControllerData.SBV.Plugin.CommonData.SBV.Plugin.EnvData.SBV.Plugin.AnalyzeData.SBV.Plugin.PluginData.SBV.Plugin.Examples.ProvedProved SBVAnnotationSBVoptions SBVOption IgnoreFailureSkipVerboseDebug QuickCheck UninterpretNamesListSizeZ3Yices BoolectorCVC4MathSATABC AnySolversbvtheorem$fShowSBVOption $fEqSBVOption$fDataSBVOption$fEqSBVAnnotation$fDataSBVAnnotationpluginelemoneIffastMinCorrectfastMaxCorrectoppositeSignsCorrectconditionalSetClearCorrectpowerOfTwoCorrectmaskedMergeCorrectroundPowerOfTwoCorrect zeroInWordmerge mergeSort nonDecreasingisPermutationOfmergeSortCorrectsafetyDistance maxTimeSince checkSpeccomputeLastBadcheckBadcomputeLastGood checkGoodValSKindConfigEvalEnvSpecials pickSolvers liftEqValeqValiteValtickSpanvarSpanpickSpanshowSpan $fShowExpr$fOutputableVal$fOutputableKind$fOutputableSKindBaseTypTupLstFuncKBaseKTupKLstKFunisGHCiopts sbvAnnotationcfgEnvcurLocflags machWordSize mbListSize uninterestingrUninterpreted rUsedNamesrUITypesspecialstcMapenvMapdestMapcoreMapbailOut isEqualityisTupleisListsupportTupleSizes buildTCEnv buildFunEnv basicFuncssymFuncs buildDestsuninterestingTypes buildSpecials tlift2Booltlift1tlift2 tlift2ShRottSplittJoin tEnumFromTotEnumFromThenTolift1Intlift1lift2 liftSplitliftEq sEnumFromTosEnumFromThenToenumListthToGHCgrabTH analyzeBindprovesafelyproveItisReallyADictionary uninterpretgetTypemkSym mkValidNameintegerAssociativeisTrue