h$gb,      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~*Implementation of Allen's interval algebra(c) NoviSci, Inc 2020BSD3bsaul@novisci.comSafe 8>(interval-algebra5Defines a predicate of two object of different types.interval-algebra+Defines a predicate of two objects of type a.interval-algebraThe 9 typeclass provides methods for (possibly) combining two i a s to form a  i a, or in case of ><, a possibly different  Intervallic type.interval-algebraMaybe form a new i a by the union of two i as that #.interval-algebraIf x is % y, then form a new Just Interval a, from the interval in the "gap" between x and y from the " of x to the ! of y . Otherwise, .interval-algebraIf x is % y , return f x appended to f y. Otherwise, return N of x and y (wrapped in f). This is useful for (left) folding over an *ordered* container of Interval#s and combining intervals when x is *not* % y.interval-algebraThe : typeclass provides functions to determine the size of an $ type and to resize an 'Interval a'.interval-algebra*The smallest duration for an 'Interval a'.interval-algebra Gives back a  based on the input's type. interval-algebraDetermine the duration of an 'i a'. interval-algebra Shifts an a. Most often, the b will be the same type as a. But for example, if a is  then b could be . interval-algebra!Takes the difference between two a to return a b. interval-algebraThe   type and the associated predicate functions enumerate the thirteen possible ways that two  objects may ? according to Allen's interval algebra. Constructors are shown with their corresponding predicate function. interval-algebra%interval-algebra#interval-algebra)interval-algebra.interval-algebra0interval-algebra+interval-algebra1interval-algebra,interval-algebra/interval-algebra-interval-algebra*interval-algebra$interval-algebra&interval-algebraThe * typeclass defines how to get and set the  content of a data structure. It also includes functions for getting the endpoints of the  via ! and ". getInterval (Interval (0, 10))(0, 10)begin (Interval (0, 10))0end (Interval (0, 10))10interval-algebraGet the interval from an i a.interval-algebraSet the interval in an i a.interval-algebra+A type identifying interval parsing errors.interval-algebraAn  a is a pair  (x, y) \text{ such that } x < y. To create intervals use the  , H, or I functions. interval-algebraSafely parse a pair of as to create an  a.parseInterval 0 1 Right (0, 1)parseInterval 1 0 Left "0<1"!interval-algebraAccess the endpoints of an i a ."interval-algebraAccess the endpoints of an i a .#interval-algebraDoes x # y? Is x metBy y?$interval-algebraDoes x # y? Is x metBy y?%interval-algebraIs x before y? Is x after y?&interval-algebraIs x before y? Is x after y?'interval-algebraIs x before y? Is x after y?(interval-algebraIs x before y? Is x after y?)interval-algebra'Does x overlap y? Is x overlapped by y?*interval-algebra'Does x overlap y? Is x overlapped by y?+interval-algebra"Does x start y? Is x started by y?,interval-algebra"Does x start y? Is x started by y?-interval-algebra$Does x finish y? Is x finished by y?.interval-algebra$Does x finish y? Is x finished by y?/interval-algebra Is x during y? Does x contain y?0interval-algebra Is x during y? Does x contain y?1interval-algebraDoes x equal y?2interval-algebra2Operator for composing the union of two predicates3interval-algebra The set of IntervalRelation$ meaning two intervals are disjoint.4interval-algebra The set of IntervalRelation* meaning one interval is within the other.5interval-algebra The set of IntervalRelation5 meaning one interval is *strictly* within the other.6interval-algebraAre x and y disjoint (%, &, #, or $)?7interval-algebraAre x and y not disjoint (concur); i.e. do they share any support? This is the A of 6.8interval-algebraAre x and y not disjoint (concur); i.e. do they share any support? This is the A of 6.9interval-algebraIs x entirely *within* (enclosed by) the endpoints of y? That is, /, +, -, or 1?:interval-algebraIs x entirely *within* (enclosed by) the endpoints of y? That is, /, +, -, or 1?;interval-algebra Does x enclose y? That is, is y 9 x?<interval-algebraThe  of all  s.=interval-algebraCompose a list of interval relations with _or_ to create a new  i a. For example, unionPredicates [before, meets] creates a predicate function determining if one interval is either before or meets another interval.>interval-algebra6Forms a predicate function from the union of a set of  s.?interval-algebra Compare two i a to determine their  ./relate (Interval (0::Int, 1)) (Interval (1, 2))Meets/relate (Interval (1::Int, 2)) (Interval (0, 1))MetBy@interval-algebraCompose two interval relations according to the rules of the algebra. The rules are enumerated according to  https://thomasalspaugh.org/pub/fnd/allen.html#BasicCompositionsTable this table.Ainterval-algebraFinds the complement of a   .Binterval-algebraFind the intersection of two s of  s.Cinterval-algebraFind the union of two s of  s.Dinterval-algebraFind the converse of a   . Einterval-algebra Resize an i a to by expanding to "left" by l and to the "right" by r. In the case that l or r are less than a , the respective endpoints are unchanged. &expand 0 0 (Interval (0::Int, 2::Int))(0, 2)&expand 1 1 (Interval (0::Int, 2::Int))(-1, 3)Finterval-algebra Expands an i a to "left".%expandl 2 (Interval (0::Int, 2::Int))(-2, 2)Ginterval-algebra Expands an i a to "right".%expandr 2 (Interval (0::Int, 2::Int))(0, 4)Hinterval-algebra%Safely creates an 'Interval a' using x as the ! and adding max  dur to x as the ".beginerval (0::Int) (0::Int)(0, 1)beginerval (1::Int) (0::Int)(0, 1)beginerval (2::Int) (0::Int)(0, 2)Iinterval-algebra%Safely creates an 'Interval a' using x as the " and adding  negate max  dur to x as the !.enderval (0::Int) (0::Int)(-1, 0)enderval (1::Int) (0::Int)(-1, 0)enderval (2::Int) (0::Int)(-2, 0)Jinterval-algebra Creates a new Interval from the " of an i a.Kinterval-algebra Creates a new Interval from the ! of an i a.Linterval-algebraSafely creates a new Interval with  length with ! at xbeginervalMoment (10 :: Int)(10, 11)Minterval-algebraSafely creates a new Interval with  length with " at xendervalMoment (10 :: Int)(9, 10)Ninterval-algebraCreates a new Interval spanning the extent x and y.0extenterval (Interval (0, 1)) (Interval (9, 10))(0, 10)Ointerval-algebraModifies the endpoints of second argument's interval by taking the difference from the first's input's !. >>> diffFromBegin (Interval ((5::Int), 6)) (Interval (10, 15)) (5, 10)9diffFromBegin (Interval ((1::Int), 2)) (Interval (3, 15))(2, 14)Pinterval-algebraModifies the endpoints of second argument's interval by taking the difference from the first's input's ". >>> diffFromEnd (Interval ((5::Int), 6)) (Interval (10, 15)) (4, 9)7diffFromEnd (Interval ((1::Int), 2)) (Interval (3, 15))(1, 13)Qinterval-algebraChanges the duration of an ' value to a moment starting at the ! of the interval.momentize (Interval (6, 10))(6, 7)Rinterval-algebraImposes a total ordering on  a! based on first ordering the ! s then the "s.Zinterval-algebraNote that the moment of this instance is a Einterval-algebraduration to subtract from the !interval-algebraduration to add to the "Hinterval-algebraduration to add to the ! interval-algebrathe ! point of the Iinterval-algebraduration to subtract from the " interval-algebrathe " point of the Jinterval-algebraduration to add to the " interval-algebrathe i a from which to get the "Kinterval-algebraduration to subtract from the ! interval-algebrathe i a from which to get the !    !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQ!" HIEFG  #$%&)*.-0/+,1'(6789;:2>=345JKLMOPQ- finterval-algebra#Empty is used to trivially lift an  Interval a into a PairedInterval.hinterval-algebraAn  Interval a% paired with some other data of type b.iinterval-algebraMake a paired interval. jinterval-algebra,Gets the data (i.e. non-interval) part of a PairedInterval.kinterval-algebra$Tests for equality of the data in a PairedInterval.linterval-algebra3Gets the intervals from a list of paired intervals.minterval-algebra Lifts an  Interval a into a PairedInterval Empty a, where Empty, is a trivial type that contains no data.ninterval-algebraLifts a Functor containing  Interval a (s) into a Functor containing PairedInterval Empty a(s).qinterval-algebraDefines A total ordering on 'PairedInterval b a' based on the 'Interval a' part. fghijklmn hfgijlkmn3Functions for operating on containers of Intervals.(c) NoviSci, Inc 2020BSD3bsaul@novisci.com experimentalSafe>O#~interval-algebraReturns a list of the   between each consecutive pair of intervals. This is just a specialized  which returns a list.relationsL [iv 1 0, iv 1 1][Meets]interval-algebraA generic form of  which can output any  and  structure. >>> (relations [iv 1 0, iv 1 1]) :: [IntervalRelation (Interval Int)] [Meets]interval-algebraForms a  new interval from the intersection of two intervals, provided the intervals are not disjoint.intersect (iv 5 0) (iv 2 3) Just (3, 5)interval-algebra Returns a Maybe container of intervals consisting of the gaps between intervals in the input. *To work properly, the input should be sorted*. See * for a version that always returns a list.gaps [iv 4 1, iv 4 8, iv 3 11]interval-algebraReturns a (possibly empty) list of intervals consisting of the gaps between intervals in the input container. *To work properly, the input should be sorted*. This version outputs a list. See  for a version that lifts the result to same input structure f.interval-algebra Returns the  " of each 'Intervallic i a' in the  f.#durations [iv 9 1, iv 10 2, iv 1 5][9,10,1]interval-algebraIn the case that x y are not disjoint, clips y to the extent of x.clip (iv 5 0) (iv 3 3) Just (3, 5)clip (iv 3 0) (iv 2 4)Nothinginterval-algebraApplies & to all the non-disjoint intervals in x that are *not* disjoint from i. Intervals that ) or are * i are  ped to i , so that all the intervals are 9 i. If all of the input intervals are disjoint from the focal interval or if the input is empty, then  is returned. When there are no gaps among the concurring intervals, then `Just mempty` (e.g. `Just []`) is returned.-gapsWithin (iv 9 1) [iv 5 0, iv 2 7, iv 3 12]Just [(5, 7),(9, 10)]interval-algebraReturns a container of intervals where any intervals that meet or share support are combined into one interval. *To work properly, the input should be sorted*. See ( for a version that works only on lists.4combineIntervals [iv 10 0, iv 5 2, iv 2 10, iv 2 13][(0, 12),(13, 15)]interval-algebraReturns a list of intervals where any intervals that meet or share support are combined into one interval. *To work properly, the input list should be sorted*. 5combineIntervalsL [iv 10 0, iv 5 2, iv 2 10, iv 2 13][(0, 12),(13, 15)]interval-algebraGiven a predicate combinator, a predicate, and list of intervals, returns the input unchanged if the predicate combinator is True+. Otherwise, returns an empty list. See  and  for examples.interval-algebra Returns the  if *none* of the element of input satisfy the predicate condition.#For example, the following returns 2 because none of the intervals in the input list + (3, 5).0nothingIfNone (starts (iv 2 3)) [iv 1 3, iv 1 5]NothingIn the following, (3, 5) + (3, 6), so  the input is returned.0nothingIfNone (starts (iv 2 3)) [iv 3 3, iv 1 5]Just [(3, 6),(5, 6)]interval-algebraReturns  if *any* of the element of input satisfy the predicate condition./nothingIfAny (starts (iv 2 3)) [iv 3 3, iv 1 5]Just [(3, 6),(5, 6)]/nothingIfAny (starts (iv 2 3)) [iv 3 3, iv 1 5]Nothinginterval-algebraReturns  if *all* of the element of input satisfy the predicate condition. >>> nothingIfAll (starts (iv 2 3)) [iv 3 3, iv 4 3] Nothinginterval-algebraFilter  containers of one 7 type based by comparing to a (potentially different) : type using the corresponding interval predicate function.interval-algebraFilter  containers of one 7 type based by comparing to a (potentially different) : type using the corresponding interval predicate function.interval-algebraFilter  containers of one 7 type based by comparing to a (potentially different) : type using the corresponding interval predicate function.interval-algebraFilter  containers of one 7 type based by comparing to a (potentially different) : type using the corresponding interval predicate function.interval-algebraFilter  containers of one 7 type based by comparing to a (potentially different) : type using the corresponding interval predicate function.interval-algebraFilter  containers of one 7 type based by comparing to a (potentially different) : type using the corresponding interval predicate function.interval-algebraFilter  containers of one 7 type based by comparing to a (potentially different) : type using the corresponding interval predicate function.interval-algebraFilter  containers of one 7 type based by comparing to a (potentially different) : type using the corresponding interval predicate function.interval-algebraFilter  containers of one 7 type based by comparing to a (potentially different) : type using the corresponding interval predicate function.interval-algebraFilter  containers of one 7 type based by comparing to a (potentially different) : type using the corresponding interval predicate function.interval-algebraFilter  containers of one 7 type based by comparing to a (potentially different) : type using the corresponding interval predicate function.interval-algebraFilter  containers of one 7 type based by comparing to a (potentially different) : type using the corresponding interval predicate function.interval-algebraFilter  containers of one 7 type based by comparing to a (potentially different) : type using the corresponding interval predicate function.interval-algebraFilter  containers of one 7 type based by comparing to a (potentially different) : type using the corresponding interval predicate function.interval-algebraFilter  containers of one 7 type based by comparing to a (potentially different) : type using the corresponding interval predicate function.interval-algebraFilter  containers of one 7 type based by comparing to a (potentially different) : type using the corresponding interval predicate function.interval-algebraFilter  containers of one 7 type based by comparing to a (potentially different) : type using the corresponding interval predicate function.interval-algebraFilter  containers of one 7 type based by comparing to a (potentially different) : type using the corresponding interval predicate function.interval-algebraFilter  containers of one 7 type based by comparing to a (potentially different) : type using the corresponding interval predicate function.interval-algebra?Folds over a list of Paired Intervals and in the case that the j is equal between two sequential meeting intervals, these two intervals are combined into one. This function is "safe" in the sense that if the input is invalid and contains any sequential pairs of intervals with an IntervalRelation, other than +, then the function returns an empty list. interval-algebraConvert an ordered sequence of PairedInterval b a'. that may have any interval relation (%, +/, etc) into a sequence of sequentially meeting PairedInterval b a. That is, a sequence where one the end of one interval meets the beginning of the subsequent event. The j of the input PairedIntervals are combined using the Monoid * function, hence the pair data must be a  instance.interval-algebraiinterval-algebraxinterval-algebrae.g.  or interval-algebra0predicate to apply to each element of input listinterval-algebra0predicate to apply to each element of input listinterval-algebra0predicate to apply to each element of input listinterval-algebra0predicate to apply to each element of input listinterval-algebra;Be sure this only contains intervals that sequentially #.#~#~*Implementation of Allen's interval algebra(c) NoviSci, Inc 2020BSD3bsaul@novisci.comSafeP   !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQfghijklmn~,Functions for generating arbitrary intervals(c) NoviSci, Inc 2020BSD3bsaul@novisci.com experimentalSafe>?Uinterval-algebraConditional generation of intervals relative to a reference. If the reference iv is of moment duration, it is not possible to generate intervals from the strict enclose relations StartedBy, Contains, FinishedBy. If iv and rs are such that no possible relations can be generated, this function returns . Otherwise, it returns  an interval that satisfies at least one of the possible relations in rs relative to iv.generate $ arbitraryWithRelation (beginerval 10 (0::Int)) (fromList [Before]) Just (20, 22)generate $ arbitraryWithRelation (beginerval 1 (0::Int)) (fromList [StartedBy])Nothinggenerate $ arbitraryWithRelation (beginerval 1 (0::Int)) (fromList [StartedBy, Before]) Just (4, 13)interval-algebrareference intervalinterval-algebraset of  s, of which at least one will hold for the generated interval relative to the referenceProperties of Intervals(c) NoviSci, Inc 2020BSD3bsaul@novisci.com Safe-Inferred>^interval-algebra%"An Axiomatization of Interval Time".interval-algebraSmart constructor of .interval-algebraAxiom M1The first axiom of Allen and Hayes (1987) states that if "two periods both meet a third, thn any period met by one must also be met by the other." That is: \forall \text{ i,j,k,l } s.t. (i:j \text{ & } i:k \text{ & } l:j) \implies l:k  interval-algebraSmart constructor of .interval-algebraAxiom M2If period i meets period j and period k meets l, then exactly one of the following holds:1) i meets l; 2) there is an m such that i meets m and m meets l; 3) there is an n such that k meets n and n meets j.That is, \forall i,j,k,l s.t. (i:j \text { & } k:l) \implies i:l \oplus (\exists m s.t. i:m:l) \oplus (\exists m s.t. k:m:j)  interval-algebra Axiom ML1An interval cannot meet itself. \forall i \lnot i:i  interval-algebra Axiom ML2$If i meets j then j does not meet i., \forall i,j i:j \implies \lnot j:i  interval-algebraAxiom M3Time does not start or stop:* \forall i \exists j,k s.t. j:i:k  interval-algebraML3 says that For all i, there does not exist m such that i meets m and m meet i. Not testing that this axiom holds, as I'm not sure how I would test the lack of existence easily.Axiom M4If two meets are separated by intervals, then this sequence is a longer interval. \forall i,j i:j \implies (\exists k,m,n s.t m:i:j:n \text { & } m:k:n)  interval-algebraSmart constructor of .interval-algebraAxiom M5=There is only one time period between any two meeting places.? \forall i,j,k,l (i:j:l \text{ & } i:k:l) \equiv j = k  interval-algebra Axiom M4.1Ordered unions: \forall i,j i:j \implies (\exists m,n s.t. m:i:j:n \text{ & } m:(i+j):n)  interval-algebraA set used for testing M5.interval-algebraA set used for testing M2 defined so that the M2 condition is true.interval-algebraA set used for testing M1 defined so that the M1 condition is true.Properties of Intervals(c) NoviSci, Inc 2020BSD3bsaul@novisci.com Safe-Inferred>ainterval-algebraA collection of properties for the interval algebra. Some of these come from figure 2 in  2https://doi.org/10.1111/j.1467-8640.1989.tb00329.xAllen and Hayes (1987).interval-algebra*For any two pair of intervals exactly one   should holdinterval-algebraGiven a set of interval relations and predicate function, test that the predicate between two interval is equivalent to the relation of two intervals being in the set of relations. Safe-Inferredb      !"#$%&&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnnopqrstuvwxyz{|}~-interval-algebra-1.3.0-EmeKIfONKquHjnOZMXJQfLIntervalAlgebra.CoreIntervalAlgebra.PairedInterval!IntervalAlgebra.IntervalUtilitiesIntervalAlgebra.ArbitraryIntervalAlgebra.Axioms"IntervalAlgebra.RelationPropertiesIntervalAlgebraPaths_interval_algebraComparativePredicateOf2ComparativePredicateOf1IntervalCombinable.+.><<+>IntervalSizeablemomentmoment'durationadddiffIntervalRelationBeforeMeetsOverlaps FinishedByContainsStartsEquals StartedByDuringFinishes OverlappedByMetByAfter Intervallic getInterval setIntervalParseErrorIntervalInterval parseIntervalbeginendmeetsmetBybeforeafterprecedes precededByoverlaps overlappedBystarts startedByfinishes finishedByduringcontainsequals<|>disjointRelationswithinRelationsstrictWithinRelationsdisjoint notDisjointconcurwithin enclosedByencloseintervalRelationsunionPredicates predicaterelatecompose complement intersectionunionconverseexpandexpandlexpandr beginervalendervalbeginervalFromEndendervalFromBeginbeginervalMomentendervalMoment extenterval diffFromBegin diffFromEnd momentize $fOrdInterval$fNFDataInterval$fBinaryInterval$fShowInterval$fFunctorInterval$fIntervallicIntervala$fOrdIntervalRelation$fBoundedIntervalRelation($fIntervalSizeableUTCTimeNominalDiffTime$fIntervalSizeableDayInteger $fIntervalSizeableIntegerInteger$fIntervalSizeableIntInt$fIntervalCombinableIntervala$fEqIntervalRelation$fShowIntervalRelation$fEnumIntervalRelation$fEqParseErrorInterval$fShowParseErrorInterval $fEqInterval$fGenericIntervalEmptyPairedIntervalmakePairedInterval getPairData equalPairData intervals toTrivialPair trivialize#$fIntervalCombinablePairedIntervala$fShowPairedInterval$fOrdPairedInterval$fBinaryPairedInterval$fNFDataPairedInterval$fBifunctorPairedInterval$fFunctorPairedInterval$fIntervallicPairedIntervala $fMonoidEmpty$fSemigroupEmpty $fEqEmpty $fOrdEmpty $fShowEmpty$fEqPairedInterval$fGenericPairedInterval relationsL relations intersectgapsgapsL durationsclip gapsWithincombineIntervalscombineIntervalsL nothingIf nothingIfNone nothingIfAny nothingIfAllfilterOverlapsfilterOverlappedBy filterBefore filterAfter filterStartsfilterStartedByfilterFinishesfilterFinishedBy filterMeets filterMetBy filterDuringfilterContains filterEqualsfilterDisjointfilterNotDisjoint filterConcur filterWithin filterEnclosefilterEnclosedByfoldMeetingSafeformMeetingSequence$fSemigroupBox $fEqMeeting $fShowMeetingarbitraryWithRelation$fArbitraryPairedInterval$fArbitraryInterval$fArbitraryInterval0$fArbitraryUTCTime$fArbitraryDiffTime$fArbitraryNominalDiffTime$fArbitraryDay$fArbitraryInterval1IntervalAxiomsm1setprop_IAaxiomM1m2setprop_IAaxiomM2prop_IAaxiomML1prop_IAaxiomML2prop_IAaxiomM3prop_IAaxiomM4m5setprop_IAaxiomM5prop_IAaxiomM4_1M5setm51m52M2setm21m22m23m24M1setm11m12m13m14&$fIntervalAxiomsUTCTimeNominalDiffTime$fIntervalAxiomsDayInteger$fIntervalAxiomsIntInt$fArbitraryM5set$fArbitraryM5set0$fArbitraryM5set1$fArbitraryM2set$fArbitraryM2set0$fArbitraryM2set1$fArbitraryM1set$fArbitraryM1set0$fArbitraryM1set1 $fShowM5set $fShowM2set $fShowM1setIntervalRelationPropertiesprop_exclusiveRelationsprop_predicate_unions prop_IAbefore prop_IAstartsprop_IAfinishesprop_IAoverlaps prop_IAduringprop_disjoint_predicateprop_notdisjoint_predicateprop_concur_predicateprop_within_predicateprop_enclosedBy_predicateprop_enclose_predicate2$fIntervalRelationPropertiesUTCTimeNominalDiffTime&$fIntervalRelationPropertiesDayInteger"$fIntervalRelationPropertiesIntIntbase GHC.MaybeMaybeNothing time-1.9.3Data.Time.Calendar.DaysDayghc-prim GHC.TypesIntcontainers-0.6.2.1Data.Set.InternalSet Data.FixedPicoGHC.Base ApplicativeMonoidJustFunctor'witherable-0.4.2-BIaAXrIMODF3guZqYvNNdD Witherable Filterable<> Data.Foldableanyallversion getBinDir getLibDir getDynLibDir getDataDir getLibexecDir getSysconfDirgetDataFileName