úÎ’(‹ûx      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVW X Y Z [ \ ] ^ _ ` a b c d e f g h i j k lmnopqrstuvwNone!"(*234=BHKM fA representation that uses native 64-bit ints and 64-bit doubles. Really, this should be 32-bit ints.iAn assignment from variables to values. Maps integer variables to integers, and real variables to reals./The Representation class. Requires its members Z c and R c to be Num, Ord and Eq.AFor some reason, for type inference to work, the members must be data instead of type=. This gives some minor annoyances when unpacking them. See   below.Integers Real numbersLConvert an integer to a real. This should not lose any precision. (whereas fromIntegral 1000 :: Word8 would lose precision) @Retrieve value of integer variable - or 0, if there is no value. =Retrieve value of real variable - or 0, if there is no value. URetrieve value of an integer or real variable, with result cast to a real regardless. 4Convert a wrapped (R IntDouble) to an actual Double..Define show manually, so we can strip out the Z and R prefixes.     None!"(*234=BHKM CMaybe a lower bound, the variable's name, and maybe an upper bound.„Define upper and lower bounds of program variables. Bounds may be specified multiple times: the intersection of all bounds is used.7Create a lower and upper bound for an integer variable.3Create only a lower bound for an integer variable. 4Create only an upper bound for an integer variable. 'A binary integer variable: can only be 0 or 1.3Create a lower and upper bound for a real variable./Create only a lower bound for a real variable. 0Create only an upper bound for a real variable.    None!"(*234=BHKM Convert a K to its actual representation (Z or R). ŸFind the result type of merging, or adding, two linear functions: adding two integers produces an integer, while adding a real on either side produces a real.!|Representation of either integral of real linear functions: a list of variables with coefficients, plus a constant summand.$IClassify the result type of a linear function to either integral or real:%Real or mixed R& Integral Z !"#$%& !"#$%&$&%!#"  !#"$&%None!"(*234=BHKM'AAny linear function can be converted into a real linear function.(Integral variable)$Integral variable with coefficient 1* Real variable+ Real variable with coefficient 1,An integral constant summand-An integral constant summand. Constant 0/ Constant 10A real constantx7Helper for applying function to second element of tuple1=Negate a linear function. Negation does not change the kind.2,Multiply a linear function by some constant.uNote that you cannot multiply a linear function by another linear function, as the result would likely be non-linear!3,Multiply a linear function by some constant.4HAdd two linear functions together. They can have different result types.5PSubtract one linear function from another. They can have different result types.'()*+,-./0x12345!"#'()*+,-./012345!#"'()*+,-0./12345'()*+,-./0x123452345None!"(*234=BHKM6Different kind of constraints.iThese are not all necessary, but I have a hunch that keeping some structure may be helpful in the future. Constructors: :==Equality constraint:<=Less than or equal:<EStrictly less than: this is only allowed for purely integer functions:>=Greater than or equal:>HStrictly greater than: this is only allowed for purely integer functionsBetween Between a b c is equivalent to a :<= b :&& b :<= c:&&Conjunction of two constraints:!"name" :! constr@ Annotate a constraint with a name, or other useless informationCTrueTrivially true constraint 6789:;<=>?@ 6789:;<=>? 6?>=<;:987@6 ?>=<;:987@89;<=>?None!"(*234=BHKMA Whole program, parameterised by: ztype of integer variablesrtype of real variablesc*representation of integers and reals (see )COptimisation directionDThe objective functionE All constraints bundled up with :&&.F–Upper and lower bounds of variables. Not all variables need to be mentioned, and if variables are mentioned multiple times, the intersection is used.G7Direction to optimise program in: minimise or maximise. ABCDEFGHIJKL ABCDEFGHIJKL GIHABCDEFJKLABCDEFGIHJKLNone!"(*234=BHKMM`Evaluate a linear function with given assignment. If the linear function is purely integral, a Z will be returned; otherwise, R.NGEvaluate a linear function with given assignment, returning real value.O.Check whether assignment satisfies constraint.PJCheck whether an assignment satisfies the program's constraints and boundsMNOPQMNOPQMNOPQMNOPQNone!"(*234=BHKM= !"#$%&'()*+,-./0123456789:;<=>?ABCDEFGHIJKLMNOPQNone!"(*234=BHKMRsLinear function is represented as a map from either a integral variable or an real variable, to a real coefficient.T>Create linear function from list of variables and coefficientsU.Evaluate linear function with given assignmentV/Find set of all variables mentioned in functionRSTUVRSTUVRSTUVRSTUV None!"(*234=BHKMWA simple constraintXAMaybe a lower bound, a linear function, and maybe an upper bound.JIn order to be meaningful, at least one of lower or upper bound should be Just.Y!Conjunction of simple constraints[4Check whether an assignment satisfies the constraint\"Get set of variables in constraintWXYZ[\WXYZ[\YZWX[\WXYZ[\ None!"(*234=BHKM]‹A program represented by objective, constraints and bounds. There is no need for an optimisation direction; the objective is just negated.b.Find set of all variables mentioned in programc!Merge some lower and upper boundsdJCheck whether an assignment satisfies the program's constraints and bounds ]^_`abcde ]^_`abcde ]^_`abcde]^_`abcde None!"(*234=BHKMfConvert a Frontend ! into a Canon RK. Returns the constant summand as well, as Canon Linear do not have these.Should satisfy that Fforall a l. P.evalR a l == evalR a (fst $ linear l) + (snd $ linear l)gConvert a Frontend 6 into a Canon Y.Should satisfy that 1forall a c. P.check a c == check a (constraint c)hConvert a Frontend A into a Canon ].LIf we had a solve function that worked on either, it would ideally satisfy (forall p. P.solve p == solve (program p)…However, due to potential non-determinism in solving functions, it could be possible to get a different, but still optimal, solution: Óforall p. let aP = P.solve p p' = program p a = solve p' in P.eval aP (P._objective p) == eval a (_objective p') && check a (P._constraints p) && check ...fghfghfghfghNone!"(*234=BHKMRSTUVWXYZ[\]^_`abcdefgh None!"(*234=BHKMijijiij None!"(*234=BHKMkRFind the constants in a program, only by looking at the bounds with lo==up. (See "Numeric.Limp.Canon.Simplify.Stride" to convert constraints to bounds)kkkkNone!"(*234=BHKMm6Convert a single constraint into a bound, if possible. Abounder $ Constraint (5 <= y <= 10) == Bound (Just 5) y (Just 10) Cbounder $ Constraint (5 <= 2y <= 10) == Bound (Just 2.5) y (Just 5)lmnolmnolmnolmnoNone!"(*234=BHKMp&Crunch the constraints in some programqICrunch some constraints. Constraints with the same function, for example J 2x + y < 5 && 0 < 2x + y && 2x + y < 10becomes  0 < 2x + y < 5This should satisfy: hforall a c. check a c == check a (crunchConstraint c) forall a. length (checkConstraint c) <= length cpqpqpqpqNone!"(*234=BHKMr6Substitute assignment into linear function. However, R} isn't quite a linear function! That is, it doesn't have a constant summand. So we must return the constant summand we lose. Satisfies: Rforall a b f. let (f', c') = substLinear a f in eval (a <> b) f == eval b f' + c'  subst (x := 5) in 2x + y (y, 10)s<Substitute assignment into a single linear constraint. See t. 15 <= 2x + y <= 10 subst (y := 3) 2 <= 2x <= 7tCSubstitute assignment into a set of linear constraints. Satisfies: Mforall a b f. let c' = substConstraint a c in check (a <> b) c == check b c' 1subst (x := 5) in 15 <= 2x + y <= 20 5 <= y <= 10uBSubstitute assignment into a program. What does this satisfy? Hm.rsturstursturstuNone!"(*234=BHKMvwvwvwvwy !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRRSTUVWXYZ[\]^_`a22b^c d e G G _ f R R T U V g h ` a i j Z k l mnopqrstuvwxyz{ limp-0.3.1.0Numeric.Limp.RepNumeric.Limp.Program.BoundsNumeric.Limp.Program.ResultKindNumeric.Limp.Program.LinearNumeric.Limp.Program.ConstraintNumeric.Limp.Program.ProgramNumeric.Limp.Program.EvalNumeric.Limp.Canon.LinearNumeric.Limp.Canon.ConstraintNumeric.Limp.Canon.ProgramNumeric.Limp.Canon.ConvertNumeric.Limp.Canon.Pretty$Numeric.Limp.Canon.Analyse.Constants#Numeric.Limp.Canon.Simplify.Bounder"Numeric.Limp.Canon.Simplify.Crunch!Numeric.Limp.Canon.Simplify.SubstNumeric.Limp.Canon.SimplifyNumeric.Limp.ProgramNumeric.Limp.Canon IntDouble AssignmentRepZRfromZzOfrOfzrOfassSizeunwrapR$fShowR$fShowZTFCo:R:ZIntDoubleTFCo:R:RIntDouble$fRepIntDouble$fMonoidAssignmentBBoundsBoundRBoundZ lowerUpperZlowerZupperZbinary lowerUpperRlowerRupperRKRepKMergeLinearLRLZKKRKZtoRzz1rr1conconZc0c1conRneg.**..+..-. ConstraintCTrue:!:&&Between:>:>=:<:<=:==$fMonoidConstraintProgram _direction _objective _constraints_bounds DirectionMaximiseMinimiseprogramminimisemaximiseevalevalRcheck checkProgram checkBoundsmkLinear varsOfLinear Constraint1C1varsOfConstraint varsOfProgram mergeBoundslinear constraintppr $fShowProgramconstantsProgramBoundbounderConstraint1bounderConstraintbounderProgram crunchProgramcrunchConstraint substLinearsubstConstraint1substConstraint substProgramsimplify simplify'on2