!]3      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                      !"#$%&'()*+,-./0123456789:; < = > ? @ 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 { | } ~                                                                                                                                                                   ! " # $ % & ' ( ) * + , - . / 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 { | } ~                             Safe,-.1478;<=>?HUVmb connections4Positive rationals, extended with an absorbing zero. is the canonical  0https://en.wikipedia.org/wiki/Semifield#Examples semifield. connectionsAn  6https://en.wikipedia.org/wiki/Modular_lattice#Examples/N5/ lattice.$A non-modular lattice formed by the  7https://en.wikipedia.org/wiki/Extended_real_number_lineaffine extended reals along with a NaN7 value that is incomparable to any finite number, i.e.: =pcompare (N5 NaN) (N5 x) = pcompare (N5 x) (N5 NaN) = Nothingfor any finite x. JN5 NaN == N5 NaN = True N5 NaN < N5 (1/0) = True N5 NaN > N5 (-1/0) = True connectionsA  &https://en.wikipedia.org/wiki/Preorderpreorder on a.A preorder relation  ' must satisfy the following two axioms: \forall x: x \leq x  (reflexivity)H \forall a, b, c: ((a \leq b) \wedge (b \leq c)) \Rightarrow (a \leq c)  (transitivity)Given a preorder on a( one may define an equivalence relation # such that a ~~ b if and only if a <~ b and b <~ a.If no partion induced by #+ contains more than a single element, then a* is a partial order and we may define an ) instance such that the following holds: x  y = x # y x <= y = x < y  x # y $Minimal complete definition: either * or  . Using ** can be more efficient for complex types.  connections(A non-strict preorder order relation on a.Is x less than or equal to y? . is reflexive, anti-symmetric, and transitive. Dx <~ y = x < y || x ~~ y x <~ y = maybe False (<~ EQ) (pcompare x y)for all x, y in a.! connections+A converse non-strict preorder relation on a.Is x greater than or equal to y?!. is reflexive, anti-symmetric, and transitive. Dx >~ y = x > y || x ~~ y x >~ y = maybe False (>~ EQ) (pcompare x y)for all x, y in a." connectionsAn equivalence relation on a.Are x and y comparable?") is reflexive, symmetric, and transitive.If a implements Ord then we should have  x ?~ y = True.# connectionsAn equivalence relation on a.Are x and y equivalent?#) is reflexive, symmetric, and transitive. Ex ~~ y = x <~ y && y <~ x x ~~ y = maybe False (~~ EQ) (pcompare x y)$Use this as a lawful substitute for / when comparing floats, doubles, or rationals.$ connections Negation of #.Are x and y not equivalent?% connectionsA strict preorder relation on a.Is x less than y?%, is irreflexive, asymmetric, and transitive. Px `plt` y = x <~ y && not (y <~ x) x `plt` y = maybe False (< EQ) (pcompare x y)When   is antisymmetric then a! is a partial order and we have: x `plt` y = x <~ y && x /~ yfor all x, y in a.& connections'A converse strict preorder relation on a.Is x greater than y?&, is irreflexive, asymmetric, and transitive. Px `pgt` y = x >~ y && not (y >~ x) x `pgt` y = maybe False (> EQ) (pcompare x y)When   is antisymmetric then a! is a partial order and we have: x `pgt` y = x >~ y && x /~ yfor all x, y in a.' connectionsA similarity relation on a.Are x and y# either equivalent or incomparable?'< is reflexive and symmetric, but not necessarily transitive. Note this is only equivalent to  in a total order: similar (0/0 :: Float) 5 = TrueIf a implements Ord then we should have (#) = ' = ().( connectionsA partial version of .7Returns the left-hand argument in the case of equality.) connectionsA partial version of .7Returns the left-hand argument in the case of equality.* connectionsA partial version of . <x < y = maybe False (< EQ) $ pcompare x y x > y = maybe False (> EQ) $ pcompare x y x <~ y = maybe False (<~ EQ) $ pcompare x y x >~ y = maybe False (>~ EQ) $ pcompare x y x ~~ y = maybe False (~~ EQ) $ pcompare x y x ?~ y = maybe False (const True) $ pcompare x y similar x y = maybe True (~~ EQ) $ pcompare x yIf a implements Ord then we should have * x y =   compare x y.+ connectionsA  )https://en.wikipedia.org/wiki/Total_order total order on a.*Note: ideally this would be a subclass of Order, without instances for Float, Double, Rational, etc.`We instead use a constraint kind in order to retain compatibility with the downstream users of Ord., connectionsAn  Ahttps://en.wikipedia.org/wiki/Order_theory#Partially_ordered_setsorder on a.*Note: ideally this would be a subclass of Preorder.`We instead use a constraint kind in order to retain compatibility with the downstream users of Eq.- connectionsA partial version of . 'pcomparing p x y = pcompare (p x) (p y)The partial application  pcomparing f3 induces a lawful preorder for any total function f.# *!"$%&()'+,-,+# *!"$%&()'- 4!4"4#4$4%4&4(4)4*4Safe%,.47HSVXgk(e connections A (chain of) Galois connections.A  /https://en.wikipedia.org/wiki/Galois_connectionGalois connectiona between preorders P and Q is a pair of monotone maps `f :: p -> q` and `g :: q -> p` such that: f x <= y iff x <= g y We say that f# is the left or right adjoint, and g0 is the right or left adjoint of the connection.?Connections have many nice properties wrt numerical conversion:Yrange (conn @_ @Rational @Float) (1 :% 8) -- eighths are exactly representable in a float (0.125,0.125)=range (conn @_ @Rational @Float) (1 :% 7) -- sevenths are not(0.14285713,0.14285715)See the README0 file for a slightly more in-depth introduction.f connectionsEA data kind distinguishing the directionality of a Galois connection:L)-tagged types are low / increasing (e.g.  ,  ,  )R*-tagged types are high / decreasing (e.g.  ,  ,  )i connectionsAn  ,https://ncatlab.org/nlab/show/adjoint+tripleadjoint triple of Galois connections.8An adjoint triple is a chain of connections of length 3:f \dashv g \dashv h When applied to a d or c, the two functions of type a -> b returned will be identical.Caution:  Conn f g h must obey f \dashv g \dashv h . This condition is not checked.For detailed properties see .j connections3A Galois connection between two monotone functions.c is the mirror image of d: connR :: ConnL a b -> ConnR b aIf you only require one connection there is no particular reason to use one version over the other. However some use cases (e.g. rounding) require an adjoint triple of connections that can lower into a standard connection in either of two ways.Caution:  ConnR f g must obey  f \dashv g  . This condition is not checked.For further information see .k connectionsA  /https://ncatlab.org/nlab/show/Galois+connectionGalois connection between two monotone functions.A Galois connection between f and g , written  f \dashv g 0 is an adjunction in the category of preorders.AEach side of the connection may be defined in terms of the other:+ g(x) = \sup \{y \in E \mid f(y) \leq x \} + f(x) = \inf \{y \in E \mid g(y) \geq x \} Caution:  ConnL f g must obey  f \dashv g  . This condition is not checked.For further information see .l connections Retrieve the upper adjoint of a d, or lower adjoint of a c.m connections8Retrieve the left and/or right adjoints of a connection. range c = floor c &&& ceiling crange f64f32 pi(3.1415925,3.1415927)range f64f32 (0/0) (NaN,NaN)n connections The identity e.o connectionsLift a e into a functor.Cautionh: This function will result in an invalid connection if the functor alters the internal preorder (i.e. ).p connections Lift two e s into a e on the Hhttps://en.wikibooks.org/wiki/Category_Theory/Categories_of_ordered_setscoproduct order (choice id) (ab >>> cd) = (choice id) ab >>> (choice id) cd (flip choice id) (ab >>> cd) = (flip choice id) ab >>> (flip choice id) cdq connections Lift two e s into a e on the Yhttps://en.wikibooks.org/wiki/Order_Theory/Preordered_classes_and_poclasses#product_order product order (strong id) (ab >>> cd) = (strong id) ab >>> (strong id) cd (flip strong id) (ab >>> cd) = (flip strong id) ab >>> (flip strong id) cdr connections Witness to the symmetry between d and c. %connL . connR = id connR . connL = ids connectionsObtain the upper adjoint of a d, or lower adjoint of a c.t connections Map over a d from the right.(This is the unit of the resulting monad: x <~ upper1 c id x compare pi $ upper1 f64f32 id piLTu connections Zip over a d from the right.v connections*Semigroup operation on a join-semilattice.w connectionsExtract the lower half of a d. Eceiling identity = id ceiling c (x \/ y) = ceiling c x \/ ceiling c y<The latter law is the adjoint functor theorem for preorders.'Data.Connection.ceiling ratf32 (0 :% 0)NaN'Data.Connection.ceiling ratf32 (1 :% 0)Infinity)Data.Connection.ceiling ratf32 (13 :% 10) 1.3000001!Data.Connection.ceiling f64f32 pi 3.1415927x connections Map over a d from the left.,This is the counit of the resulting comonad: x >~ ceiling1 c id x&ceiling1 (conn @_ @() @Ordering) id LTLT&ceiling1 (conn @_ @() @Ordering) id GTLTy connections Zip over a d from the left.z connections Witness to the symmetry between d and c. %connL . connR = id connR . connL = id{ connectionsObtain the lower adjoint of a c.| connections Map over a c from the left.,This is the counit of the resulting comonad: x >~ lower1 c id x compare pi $ lower1 f64f32 id piGT} connections Zip over a c from the left.~ connections*Semigroup operation on a meet-semilattice. connectionsExtract the upper half of a c =floor identity = id floor c (x /\ y) = floor c x /\ floor c y<The latter law is the adjoint functor theorem for preorders.%Data.Connection.floor ratf32 (0 :% 0)NaN%Data.Connection.floor ratf32 (1 :% 0)Infinity'Data.Connection.floor ratf32 (13 :% 10)1.3Data.Connection.floor f64f32 pi 3.1415925 connections Map over a c from the right.(This is the unit of the resulting monad: x <~ floor1 c id x$floor1 (conn @_ @() @Ordering) id LTGT$floor1 (conn @_ @() @Ordering) id GTGT connections Zip over a c from the right. connectionsBDetermine which half of the interval between 2 representations of a a particular value lies.   c x = * (x - | c  x) (t c  x - x)6maybe False (== EQ) $ half f64f32 (midpoint f64f32 pi)True connections1Return the midpoint of the interval containing x.pi - midpoint f64f32 pi3.1786509424591713e-8 connectionsReturn the nearest value to x. round identity = idIf x lies halfway between two finite values, then return the value with the larger absolute value (i.e. round away from zero).See  &https://en.wikipedia.org/wiki/Rounding. connectionsLift a unary function over a Trip.?Results are rounded to the nearest value with ties away from 0. connectionsLift a binary function over a Trip.?Results are rounded to the nearest value with ties away from 0.#Example avoiding loss-of-precision:f x y = (x + y) - xmaxOdd32 = 1.6777215e7f maxOdd32 2.0 :: Float1.0round2 ratf32 f maxOdd32 2.02.0 connectionsTruncate towards zero. truncate identity = id connectionsLift a unary function over a Trip.#Results are truncated towards zero. truncate1 identity = id connectionsConvert an inverted d to a d. upL . downL = downL . upL = id connectionsConvert an inverted c to a c. upR . downR = downR . upR = id connections Convert a d to an inverted d.6let counit = upper1 (downL $ conn @_ @() @Ordering) idcounit (Down LT)Down LTcounit (Down GT)Down LT connections Convert a c to an inverted c.4let unit = lower1 (downR $ conn @_ @() @Ordering) idunit (Down LT)Down GTunit (Down GT)Down GT connectionsObtain the principal filter in B generated by an element of A. A subset B of a lattice is an filter if and only if it is an upper set that is closed under finite meets, i.e., it is nonempty and for all x, y in B, the element  meet c x y is also in b.filterL and filterR commute with Down: +filterL c a b <=> ideal c (Down a) (Down b) +filterL c (Down a) (Down b) <=> ideal c a b filterL c a is upward-closed for all a: ^a <= b1 && b1 <= b2 => a <= b2 a1 <= b && a2 <= b => meet c (ceiling c a1) (ceiling c a2) <= bSee 2https://en.wikipedia.org/wiki/Filter_(mathematics) connectionsObtain the principal ideal in B generated by an element of A. A subset B of a lattice is an ideal if and only if it is a lower set that is closed under finite joins, i.e., it is nonempty and for all x, y in B, the element  join c x y is also in B. filterR c a is downward-closed for all a: a >= b1 && b1 >= b2 => a >= b2 ;a1 >= b && a2 >= b => join c (floor c a1) (floor c a2) >= bSee 2https://en.wikipedia.org/wiki/Ideal_(order_theory)1cdefhgijklmnopqrstuvwxyz{|}~1fhgelmnopqdkrstuvwxycjz{|}~iv5~6Safe connectionsCaution: This assumes that  on your system is 64 bits.%%Safe,.Xk! connectionsCaution: This assumes that  on your system is 64 bits.Safe,  connectionsA strict preorder relation on a.Is x less than y?, is irreflexive, asymmetric, and transitive. Hx < y = x <~ y && not (y <~ x) x < y = maybe False (< EQ) (pcompare x y)When   is antisymmetric then a! is a partial order and we have: x < y = x <~ y && x /~ yfor all x, y in a. connections'A converse strict preorder relation on a.Is x greater than y?, is irreflexive, asymmetric, and transitive. Hx > y = x >~ y && not (y >~ x) x > y = maybe False (> EQ) (pcompare x y)When   is antisymmetric then a! is a partial order and we have: x > y = x >~ y && x /~ yfor all x, y in a. connectionsA wrapper around == that forces  NaN == NaN. connectionsFind the minimum of two values. )min x y == if x <= y then x else y = TrueNote: this function will throw a ArithExceptionM on floats and rationals if one of the arguments is finite and the other is NaN. connectionsFind the minimum of two values. )max x y == if x >= y then x else y = TrueNote: this function will throw a ArithExceptionM on floats and rationals if one of the arguments is finite and the other is NaN. connections$Compare two values in a total order. Nx < y = compare x y == LT x > y = compare x y == GT x == y = compare x y == EQcompare (1/0 :: Double) 0GTcompare (-1/0 :: Double) 0LTcompare (1/0 :: Double) (0/0)GTcompare (-1/0 :: Double) (0/0)LTNote: this function will throw a ArithExceptionM on floats and rationals if one of the arguments is finite and the other is NaN:compare (0/0 :: Double) 0*** Exception: divide by zero connections#Compare on the range of a function. %comparing p x y = compare (p x) (p y)+,,+ 4444444444Safe4H connectionsAn interval in a poset P.An interval in a poset P is a subset I of P with the following property:B \forall x, y \in I, z \in P: x \leq z \leq y \Rightarrow z \in I  connectionsMap over an interval.Notej this is not a functor, as a non-monotonic map may cause the interval to collapse to the iempty interval. connections,Construct an interval from a pair of points.Note$: Endpoints are preorder-sorted. If pcompare x y = Nothing, then the resulting interval will be empty. connectionsThe iempty interval.iemptyEmpty connections0Construct an interval containing a single point. singleton 11 ... 1 connections$Obtain the endpoints of an interval. connectionsA /https://en.wikipedia.org/wiki/Containment_ordercontainment order3 Safe47 connections"Add a bottom and top to a lattice.eThe top is the absorbing element for the join, and the bottom is the absorbing element for the meet. connections Eliminate an . Safe%,.SXk; connectionsA NaN-handling min32 function. min32 x NaN = x min32 NaN y = y connectionsA NaN-handling max32 function. max32 x NaN = x max32 NaN y = y connectionsECompute the difference between a float and its next largest neighbor.See  -https://en.wikipedia.org/wiki/Machine_epsilon. connectionsKCompute the signed distance between two floats in units of least precision.ulp32 1.0 (shift32 1 1.0) Just (LT,1)ulp32 (0.0/0.0) 1.0Nothing connections,Compare two floats for approximate equality.;Required accuracy is specified in units of least precision.See  [https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/. connectionsShift a float by n units of least precision. shift32 1 01.0e-45shift32 1 1 - 1 1.1920929e-7shift32 1 $ 0/0Infinityshift32 (-1) $ 0/0 -Infinityshift32 1 $ 1/0Infinity connectionsAll  ' values are exactly representable in a . connectionsAll ' values are exactly representable in a .+Data.Connection.Conn.ceiling f32i16 32767.0Extended 32767+Data.Connection.Conn.ceiling f32i16 32767.1Top connectionsA NaN-handling min function. min64 x NaN = x min64 NaN y = y connectionsA NaN-handling max function. max64 x NaN = x max64 NaN y = y connectionsFCompute the difference between a double and its next largest neighbor.See  -https://en.wikipedia.org/wiki/Machine_epsilon.  connectionsLCompute the signed distance between two doubles in units of least precision.ulp64 1.0 (shift64 1 1.0) Just (LT,1)ulp64 (0.0/0.0) 1.0Nothing  connections=Compare two double-precision floats for approximate equality.;Required accuracy is specified in units of least precision. See also  [https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/.  connections Shift by n units of least precision. shift64 1 05.0e-324shift64 1 1 - 12.220446049250313e-16shift64 1 $ 0/0Infinityshift64 (-1) $ 0/0 -Infinityshift64 1 $ 1/0Infinity  connectionsAll  ' values are exactly representable in a .  connectionsAll ' values are exactly representable in a . connectionsAll ' values are exactly representable in a .          Safe,Xk? connectionsSShift by n 'units of least precision' where the ULP is determined by the precision.This is an analog of  ! for fixed point numbers."  !"#$%&'()"   !"#$%&'() Safe%,XkC+* connectionsA total version of "#.+ connectionsTShift by n 'units of least precision' where the ULP is determined by the denominatorThis is an analog of  ! for rationals.*+,-./0123456789:*+,-./0123456789: Safe%,.=>?@AHSXgkd; connectionsAn  ,https://ncatlab.org/nlab/show/adjoint+stringadjoint string( of Galois connections of length 2 or 3.< connections*range (conn @_ @Rational @Float) (22 :% 7)(3.142857,3.1428573)!range (conn @_ @Double @Float) pi(3.1415925,3.1415927)= connectionsA constraint kind for  conversions.Usable in conjunction with RebindableSyntax: <fromRational = round conn :: ConnRational a => Rational -> a> connectionsA constraint kind for  conversions.Usable in conjunction with RebindableSyntax: @fromInteger = upper conn . Just :: ConnInteger a => Integer -> a? connections"A constraint kind representing an  ,https://ncatlab.org/nlab/show/adjoint+tripleadjoint triple of Galois connections.B connectionsA specialization of conn to left-side connections.C connectionsA specialization of conn to right-side connections.D connections Lattice join.  (\/) = curry $ lower semilatticeE connections Lattice meet.  (/\) = curry $ floor semilatticeF connectionsLeast upper bound operator.The order dual of G.lub 1.0 9.0 7.07.0lub 1.0 9.0 (0.0 / 0.0)1.0G connectionsGreatest lower bound operator. cglb x x y = x glb x y z = glb z x y glb x y z = glb x z y glb (glb x w y) w z = glb x w (glb y w z)glb 1.0 9.0 7.07.0glb 1.0 9.0 (0.0 / 0.0)9.0Dglb (fromList [1..3]) (fromList [3..5]) (fromList [5..7]) :: Set IntfromList [3,5]H connectionsA preorder variant of $%.I connectionsA preorder variant of $&.J connections A minimal element of a preorder. 'x /\ minimal = minimal x \/ minimal = xJ% needn't be unique, but it must obey: x <~ minimal => x ~~ minimalK connections A maximal element of a preorder. 'x /\ maximal = x x \/ maximal = maximalK% needn't be unique, but it must obey: x >~ maximal => x ~~ maximalL connections The canonical connection with a .[ connectionsAll ' values are exactly representable in a .\ connectionsAll ' values are exactly representable in a .] connectionsAll ' values are exactly representable in a .i connectionsAll ' values are exactly representable in a .j connectionsAll ' values are exactly representable in a .;<=>?@ABCDEFGHIJKLAB@C?DEFGHIJKL;<>=D5E6H3I4 Safe ,.8=>?@AHXk% connectionsBoolean algebras. -https://ncatlab.org/nlab/show/Boolean+algebraBoolean algebrasw are symmetric Algebra algebras that satisfy both the law of excluded middle and the law of law of non-contradiction: $x \/ neg x = top x /\ non x = bottomIf a is Boolean we also have: non = not = neg connections1A witness to the lawfulness of a boolean algebra. connectionsSymmetric Heyting algebras!A symmetric Heyting algebra is a  7https://ncatlab.org/nlab/show/De+Morgan+Algebra+algebra De MorganD bi-Algebra algebra with an idempotent, antitone negation operator.Laws: x <= y => not y <= not x -- antitone not . not = id -- idempotence x \\ y = not (not y // not x) x // y = not (not y \\ not x)and: converseR x <= converseL xwith equality occurring iff a is a  algebra. connectionsSymmetric negation. not . not = id neg . neg = converseR . converseL non . non = converseL . converseR neg . non = converseR . converseR non . neg = converseL . converseL neg = converseR . not = not . converseL non = not . converseR = converseL . not x \\ y = not (not y // not x) x // y = not (not y \\ not x) connections Exclusive or. &xor x y = (x \/ y) /\ (not x \/ not y) connectionsHeyting and co-Heyting algebras]A Heyting algebra is a bounded, distributive lattice equipped with an implication operation.VThe complete of closed subsets of a topological space is the primordial example of a  Coheyting (co-Algebra) algebra.bThe dual complete of open subsets of a topological space is likewise the primordial example of a Heyting algebra. Coheyting:Co-implication to a* is the lower adjoint of disjunction with a: x \\ a <= y <=> x <= y \/ aHNote that co-Heyting algebras needn't obey the law of non-contradiction: 3EQ /\ non EQ = EQ /\ GT \\ EQ = EQ /\ GT = EQ /= LTSee 0https://ncatlab.org/nlab/show/co-Algebra+algebraHeyting:Implication from a* is the upper adjoint of conjunction with a: x <= a // y <=> a /\ x <= yHSimilarly, Heyting algebras needn't obey the law of the excluded middle: 3EQ \/ neg EQ = EQ \/ EQ // LT = EQ \/ LT = EQ /= GTSee -https://ncatlab.org/nlab/show/Heyting+algebra connections2The defining connection of a (co-)Heyting algebra. Galgebra @'L x = ConnL (\\ x) (\/ x) algebra @'R x = ConnR (x /\) (x //) connectionsA  0https://ncatlab.org/nlab/show/co-Heyting+algebrabi-Heyting algebra.Laws: neg x <= non xwith equality occurring iff a is a  algebra. connectionsA convenience alias for a  0https://ncatlab.org/nlab/show/co-Heyting+algebraco-Heyting algebra. connections*A convenience alias for a Heyting algebra. connectionsBounded  %https://ncatlab.org/nlab/show/latticelattices.A lattice is a partially ordered set in which every two elements have a unique join (least upper bound or supremum) and a unique meet (greatest lower bound or infimum).'A bounded lattice adds unique elements $ and & , which serve as identities to % and #, respectively. Neutrality: x % & = x x # $ = x G & x $ = x F & x $ = x  Associativity x % (y % z) = (x % y) % z x # (y # z) = (x # y) # z  Commutativity x % y = y % x x # y = y # x  Idempotency x % x = x x # x = x  Absorption (x % y) # y = y (x # y) % y = y See  ,https://en.wikipedia.org/wiki/Absorption_law Absorption.NNote that distributivity is _not_ a requirement for a complete. However when a is distributive we have: G x y z = F x y z See  -https://en.wikipedia.org/wiki/Lattice_(order). connections1The defining connection of a bounded semilattice.& and $/ are defined by the left and right adjoints to a -> (). connections)The defining connection of a semilattice.% and #/ are defined by the left and right adjoints to  a -> (a, a).  connections*A convenience alias for a meet semilattice! connections*A convenience alias for a join semilattice# connections Lattice meet.  (/\) = curry $ floor semilattice$ connections+The unique top element of a bounded lattice x /\ top = x x \/ top = top% connections Lattice join.  (\/) = curry $ lower semilattice& connections.The unique bottom element of a bounded lattice $x /\ bottom = bottom x \/ bottom = x' connectionsLogical implication:6 a \Rightarrow b = \vee \{x \mid x \wedge a \leq b \} Laws: x /\ y <= z <=> x <= y // z x // y <= x // (y \/ z) x <= y => z // x <= z // y y <= x // (x /\ y) x <= y <=> x // y = top (x \/ z) // y <= x // y (x /\ y) // z = x // y // z x // (y /\ z) = x // y /\ x // z x /\ x // y = x /\ yFalse // FalseTrue False // TrueTrue True // FalseFalse True // TrueTrue( connectionsIntuitionistic equivalence.When a is Bool this is 'if-and-only-if'.) connectionsLogical negation.  ) x = x ' &Laws: neg bottom = top neg top = bottom x <= neg (neg x) neg (x \/ y) <= neg x neg (x // y) = neg (neg x) /\ neg y neg (x \/ y) = neg x /\ neg y x /\ neg x = bottom neg (neg (neg x)) = neg x neg (neg (x \/ neg x)) = top!Some logics may in addition obey  7https://ncatlab.org/nlab/show/De+Morgan+Algebra+algebraDe Morgan conditions.* connections The Algebra ( -https://ncatlab.org/nlab/show/excluded+middlenot necessarily excluded) middle operator.+ connections*Default constructor for a Algebra algebra., connectionsDAn adjunction between a Algebra algebra and its Boolean sub-algebra.+Double negation is a meet-preserving monad.- connectionsLogical co-implication:6 a \Rightarrow b = \wedge \{x \mid a \leq b \vee x \} Laws: x \\ y <= z <=> x <= y \/ z x \\ y >= (x /\ z) \\ y x >= y => x \\ z >= y \\ z x >= x \\ y x >= y <=> y \\ x = bottom x \\ (y /\ z) >= x \\ y z \\ (x \/ y) = z \\ x \\ y (y \/ z) \\ x = y \\ x \/ z \\ x x \/ y \\ x = x \/ yFalse \\ FalseFalse False \\ TrueFalse True \\ FalseTrue True \\ TrueFalseFor many collections (e.g. '() - coincides with the native ') operator.:set -XOverloadedLists[GT,EQ] Set.\\ [LT]fromList [EQ,GT][GT,EQ] \\ [LT]fromList [EQ,GT]. connectionsIntuitionistic co-equivalence./ connectionsLogical  1https://ncatlab.org/nlab/show/co-Heyting+negation co-negation.  / x = $ - xLaws: non bottom = top non top = bottom x >= non (non x) non (x /\ y) >= non x non (y \\ x) = non (non x) \/ non y non (x /\ y) = non x \/ non y x \/ non x = top non (non (non x)) = non x non (non (x /\ non x)) = bottom0 connectionsThe co-Heyting  1https://ncatlab.org/nlab/show/co-Heyting+boundaryboundary operator. x = boundary x \/ (non . non) x boundary (x /\ y) = (boundary x /\ y) \/ (x /\ boundary y) -- (Leibniz rule) boundary (x \/ y) \/ boundary (x /\ y) = boundary x \/ boundary y1 connections-Default constructor for a co-Heyting algebra.2 connectionsGAn adjunction between a co-Heyting algebra and its Boolean sub-algebra.-Double negation is a join-preserving comonad.3 connectionsLeft converse operator.4 connectionsRight converse operator.5 connections*Default constructor for a Heyting algebra.6 connections-Default constructor for a co-Heyting algebra.K connectionsZAll minimal elements of the upper lattice cover all maximal elements of the lower lattice.o connections(Subdirectly irreducible Algebra algebra.$ !"#$%&'()*+,-./0123456$" #$!%&'()*+,-./01234654#6%5'8-8 Safe.z connectionsSee  8https://en.wikipedia.org/wiki/Binary_relation#Properties.CNote that these properties do not exhaust all of the possibilities.5As an example over the natural numbers, the relation a \# b  defined by  a > 2 > is neither symmetric nor antisymmetric, let alone asymmetric.~ connectionsCheck a  is internally consistent.This is a required property. connectionsCheck that an , is internally consistent.This is a required property. connections> \forall a, b: (a \leq b) \wedge (b \leq a) \Rightarrow a = b   is an antisymmetric relation.This is a required property. connections \forall a: (a \leq a)   is a reflexive relation.This is a required property. connectionsH \forall a, b, c: ((a \leq b) \wedge (b \leq c)) \Rightarrow (a \leq c)   is an transitive relation.This is a required property. connections, \forall a, b: ((a \leq b) \vee (b \leq a))   is a connex relation. connections4 \forall a, b: (a \lt b) \Rightarrow \neg (b \lt a) lt is an asymmetric relation.This is a required property. connections \forall a: \neg (a \lt a) lt is an irreflexive relation.This is a required property. connectionsE \forall a, b, c: ((a \lt b) \wedge (b \lt c)) \Rightarrow (a \lt c) lt is a transitive relation.This is a required property. connectionsC \forall a, b: \neg (a = b) \Rightarrow ((a \lt b) \vee (b \lt a)) lt is a semiconnex relation. connectionsr \forall a, b, c: ((a \lt b) \vee (a = b) \vee (b \lt a)) \wedge \neg ((a \lt b) \wedge (a = b) \wedge (b \lt a)) In other words, exactly one of a \lt b, a = b, or b \lt a holds.If lt< is a trichotomous relation then the set is totally ordered. connectionsP \forall x, y, z, w: x \lt y \wedge y \sim z \wedge z \lt w \Rightarrow x \lt w A  'https://en.wikipedia.org/wiki/Semiorder semiorder does not allow 2-2 chains. connections/ \forall a, b: (a = b) \Leftrightarrow (b = a) # is a symmetric relation.This is a required property. connections \forall a: (a = a) # is a reflexive relation.This is a required property connections? \forall a, b, c: ((a = b) \wedge (b = c)) \Rightarrow (a = c) # is a transitive relation.This is a required property. connections \forall a: (a \# a) 4For example, "e is a reflexive relation but > is not. connections \forall a: \neg (a \# a) 8For example, > is an irreflexive relation, but "e is not. connectionsC \forall a, b: ((a \# b) \wedge (b \# a)) \Rightarrow (a \equiv b) For example, the relation over the integers in which each odd number is related to itself is a coreflexive relation. The equality relation is the only example of a relation that is both reflexive and coreflexive, and any coreflexive relation is a subset of the equality relation. connections? \forall a, b: (a \# b) \Rightarrow ((a \# a) \wedge (b \# b))  connectionsB \forall a, b, c: ((a \# b) \wedge (a \# c)) \Rightarrow (b \# c)  For example, =* is a right Euclidean relation because if x = y and x = z then y = z. connectionsB \forall a, b, c: ((b \# a) \wedge (c \# a)) \Rightarrow (b \# c)  For example, =) is a left Euclidean relation because if x = y and x = z then y = z. connectionsB \forall a, b, c: ((a \# b) \wedge (b \# c)) \Rightarrow (a \# c) TFor example, "is ancestor of" is a transitive relation, while "is parent of" is not. connections( \forall a, b: ((a \# b) \vee (b \# a)) CFor example, "e is a connex relation, while 'divides evenly' is not.IA connex relation cannot be symmetric, except for the universal relation. connectionsF \forall a, b: \neg (a \equiv b) \Rightarrow ((a \# b) \vee (b \# a)) [A binary relation is semiconnex if it relates all pairs of _distinct_ elements in some way.CA relation is connex if and only if it is semiconnex and reflexive. connectionsx \forall a, b, c: ((a \# b) \vee (a \doteq b) \vee (b \# a)) \wedge \neg ((a \# b) \wedge (a \doteq b) \wedge (b \# a)) In other words, exactly one of a \# b,  a \doteq b, or b \# a holds.:For example, > is a trichotomous relation, while "e is not. Note that  trichotomous (>)  should hold for any  instance. connections1 \forall a, b: (a \# b) \Leftrightarrow (b \# a) For example, "is a blood relative of" is a symmetric relation, because A is a blood relative of B if and only if B is a blood relative of A. connections2 \forall a, b: (a \# b) \Rightarrow \neg (b \# a) 7For example, > is an asymmetric relation, but "e is not.QA relation is asymmetric if and only if it is both antisymmetric and irreflexive. connections? \forall a, b: (a \# b) \wedge (b \# a) \Rightarrow a \equiv b wFor example, "e is an antisymmetric relation; so is >, but vacuously (the condition in the definition is always false)."z{|}~"z{|}~{1|0Safe=>?Xk ;;Safe"*Ccdefhgijklmnopqrstuvwxyz{|}~;<=>?@ABCDEFGHIJKLSafe ,.HSVXk3X  connectionsQ \forall x, y : f \dashv g \Rightarrow f (x) \leq y \Leftrightarrow x \leq g (y) OA Galois connection is an adjunction of preorders. This is a required property. connections2 \forall a: f a \leq b \Leftrightarrow a \leq g b +A monotone Galois connection is defined by adjunction (<~) (<~)5, while an antitone Galois connection is defined by adjunction (>~) (<~). connections9 \forall x : f \dashv g \Rightarrow x \leq g \circ f (x) This is a required property. connections9 \forall x : f \dashv g \Rightarrow x \leq g \circ f (x) This is a required property. connections \forall a: f (g a) \sim a  connections6 \forall x, y : x \leq y \Rightarrow f (x) \leq f (y) This is a required property. connections3 \forall a, b: a \leq b \Rightarrow f(a) \leq f(b)  connectionsd \forall x: f \dashv g \Rightarrow counit \circ f (x) \sim f (x) \wedge unit \circ g (x) \sim g (x) See 3https://ncatlab.org/nlab/show/idempotent+adjunction connections% \forall a: g \circ f (a) \sim f (a) *+,*+-*./0"10"2*.3*.4*.506706806906:06;06<06=06>06?06@06A06B000CD0CEFGGHIIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                        !   ! " # $ % & ' ( ) * + , - . / 0 1 23456789:;<=>?@ABCDEFGH#IJKLMNOPQRSTUVWX 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 { | } ~                                                                                                                                                                   ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > c ? b @ 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 { | } ~                                                     *+*+000*.*. *. 0  *. 0 0"*.0 (connections-0.3.0-5hc3AsDPSlgLdQXx9bRK5sData.Order.Syntax Data.OrderData.Connection.RatioData.Connection.FixedData.Connection.ConnData.Connection.WordData.Connection.IntData.Order.IntervalData.Order.ExtendedData.Connection.FloatData.Connection.Class Data.LatticeData.Order.PropertyData.Lattice.PropertyData.Connection.PropertyData.OrdmaxmincompareData.Order.Total comparingminimalceilingjoinmaximalfloormeetData.ConnectionPropertyDownData.IntInt08shift32GHC.Realreduce Control.Arrow|||&&&Data.SetSet\\ghc-prim GHC.ClassesEqOrd GHC.TypesOrderingbaseRatio:%LTEQGT Data.Fixed showFixedMkFixedFixed resolution HasResolutionUniDeciCentiMilliMicroNanoPicoControl.Category>>><<<PositiveN5getN5BasegetBasePreorder<~>~?~~~/~pltpgtsimilarpmaxpminpcompareTotalOrder pcomparing$fPreorderIntSet$fPreorderIntMap $fPreorderSet $fPreorderMap$fPreorder(,,,,)$fPreorder(,,,)$fPreorder(,,) $fPreorder(,)$fPreorderEither$fPreorderNonEmpty $fPreorder[]$fPreorderMaybe$fPreorderIdentity $fPreorderAll $fPreorderAny $fPreorderMin $fPreorderMax$fPreorderDual$fPreorderDown$fPreorderComplex$fPreorderRatio$fPreorderBase $fPreorderN5$fPreorderRatio0$fEqBase $fOrdBase $fShowBase $fFunctorBase$fApplicativeBase$fEqN5$fShowN5 $fFunctorN5$fApplicativeN5$fPreorderDouble$fPreorderFloat$fPreorderFixed$fPreorderInteger$fPreorderInt64$fPreorderInt32$fPreorderInt16$fPreorderInt8 $fPreorderInt$fPreorderNatural$fPreorderWord64$fPreorderWord32$fPreorderWord16$fPreorderWord8$fPreorderWord$fPreorderChar$fPreorderOrdering$fPreorderBool $fPreorder()$fPreorderVoidConnRConnLConnKanLRembedrangeidentitymappedchoicestrongconnLupperupper1upper2ceiling1ceiling2connRlowerlower1lower2floor1floor2halfmidpointroundround1round2truncate truncate1 truncate2upLupRdownLdownRfilterLfilterR$fCategoryTYPEConni08w08w08w16i08w16i16w16w08w32w16w32i08w32i16w32i32w32w08w64w16w64w32w64i08w64i16w64i32w64i64w64ixxw64w08wxxw16wxxw32wxxw64wxxi08wxxi16wxxi32wxxi64wxxixxwxxw08natw16natw32natw64natwxxnati08nati16nati32nati64natixxnatintnatw08i16i08i16w08i32w16i32i08i32i16i32w08i64w16i64w32i64i08i64i16i64i32i64w08ixxw16ixxw32ixxi08ixxi16ixxi32ixxi64ixxw08intw16intw32intw64intwxxintnatinti08inti16inti32inti64intixxint<>==/=<=>=Intervalimap...iempty singletonendptscontains$fPreorderInterval $fEqInterval$fShowIntervalExtendedBottomTopLoweredLiftedextended liftMaybe liftEitherL liftEitherR liftExtended$fPreorderExtended $fEqExtended $fOrdExtended$fShowExtended$fGenericExtended$fFunctorExtended$fGeneric1Extendedmin32max32eps32ulp32near32f32i08f32i16f32i32f32i64f32ixxf32intmin64max64eps64ulp64near64shift64f64i08f64i16f64i32f64i64f64ixxf64intf64f32untilshiftff01f00f02f00f02f01f03f00f03f01f03f02f06f00f06f01f06f02f06f03f09f00f09f01f09f02f09f03f09f06f12f00f12f01f12f02f12f03f12f06f12f09shiftrrati08rati16rati32rati64ratixxratintratfixratf32ratf64posw08posw16posw32posw64poswxxposnat Connectionconn ConnRational ConnIntegerTripleRightLeftleftright\//\lubglbchoosedivideextremal$fConnectionL()IntMap$fConnectionL()Map$fConnectionk(,)IntSet$fConnectionL()IntSet$fConnectionk(,)Set$fConnectionL()Set$fConnectionk()Extended$fConnectionL()Maybe$fConnectionkaIdentity$fConnectionkIdentityb$fConnectionLDoubleExtended$fConnectionLDoubleExtended0$fConnectionLDoubleExtended1$fConnectionLDoubleExtended2$fConnectionkDoubleExtended$fConnectionkDoubleExtended0$fConnectionkDoubleExtended1$fConnectionLDoubleExtended3$fConnectionLDoubleExtended4$fConnectionLDoubleExtended5$fConnectionLDoubleExtended6$fConnectionLDoubleExtended7$fConnectionLDoubleExtended8$fConnectionLFloatExtended$fConnectionLFloatExtended0$fConnectionLFloatExtended1$fConnectionLFloatExtended2$fConnectionLFloatExtended3$fConnectionkFloatExtended$fConnectionkFloatExtended0$fConnectionLFloatExtended4$fConnectionLFloatExtended5$fConnectionLFloatExtended6$fConnectionLFloatExtended7$fConnectionLFloatExtended8$fConnectionLFloatExtended9$fConnectionkRatioExtended$fConnectionkRatioExtended0$fConnectionkRatioExtended1$fConnectionkRatioExtended2$fConnectionkRatioExtended3$fConnectionkRatioExtended4$fConnectionkRatioExtended5$fConnectionLIntegerMaybe$fConnectionLIntMaybe$fConnectionLInt64Maybe$fConnectionLInt32Maybe$fConnectionLInt16Maybe$fConnectionLInt8Maybe$fConnectionLNaturalMaybe$fConnectionLWordMaybe$fConnectionLWord64Maybe$fConnectionLWord32Maybe$fConnectionLWord16Maybe$fConnectionLWord8Maybe$fConnectionkInt64Int$fConnectionLInt32Maybe0$fConnectionLInt16Maybe0$fConnectionLInt8Maybe0$fConnectionLWord32Maybe0$fConnectionLWord16Maybe0$fConnectionLWord8Maybe0$fConnectionLInt32Maybe1$fConnectionLInt16Maybe1$fConnectionLInt8Maybe1$fConnectionLWord32Maybe1$fConnectionLWord16Maybe1$fConnectionLWord8Maybe1$fConnectionLInt16Maybe2$fConnectionLInt8Maybe2$fConnectionLWord16Maybe2$fConnectionLWord8Maybe2$fConnectionLInt8Maybe3$fConnectionLWord8Maybe3$fConnectionk(,)Double$fConnectionkRatioDouble$fConnectionk()Double$fConnectionk(,)Float$fConnectionkRatioFloat$fConnectionkDoubleFloat$fConnectionk()Float$fConnectionk(,)Fixed$fConnectionkFixedFixed$fConnectionkFixedFixed0$fConnectionkFixedFixed1$fConnectionkFixedFixed2$fConnectionkFixedFixed3$fConnectionkFixedFixed4$fConnectionkFixedFixed5$fConnectionkFixedFixed6$fConnectionkFixedFixed7$fConnectionkFixedFixed8$fConnectionkFixedFixed9$fConnectionkFixedFixed10$fConnectionkFixedFixed11$fConnectionkFixedFixed12$fConnectionkFixedFixed13$fConnectionkFixedFixed14$fConnectionkFixedFixed15$fConnectionkFixedFixed16$fConnectionkFixedFixed17$fConnectionkFixedFixed18$fConnectionkFixedFixed19$fConnectionk(,)Ratio$fConnectionk()Ratio$fConnectionk(,)Integer$fConnectionk(,)Int$fConnectionk()Int$fConnectionk(,)Int64$fConnectionk()Int64$fConnectionk(,)Int32$fConnectionk()Int32$fConnectionk(,)Int16$fConnectionk()Int16$fConnectionk(,)Int8$fConnectionk()Int8$fConnectionk(,)Ratio0$fConnectionk()Ratio0$fConnectionk(,)Natural$fConnectionLIntegerNatural$fConnectionLIntNatural$fConnectionLInt64Natural$fConnectionLInt32Natural$fConnectionLInt16Natural$fConnectionLInt8Natural$fConnectionLWordNatural$fConnectionLWord64Natural$fConnectionLWord32Natural$fConnectionLWord16Natural$fConnectionLWord8Natural$fConnectionL()Natural$fConnectionk(,)Word$fConnectionLIntWord$fConnectionLInt64Word$fConnectionLInt32Word$fConnectionLInt16Word$fConnectionLInt8Word$fConnectionkWord64Word$fConnectionLWord32Word$fConnectionLWord16Word$fConnectionLWord8Word$fConnectionk()Word$fConnectionk(,)Word64$fConnectionLIntWord64$fConnectionLInt64Word64$fConnectionLInt32Word64$fConnectionLInt16Word64$fConnectionLInt8Word64$fConnectionLWord32Word64$fConnectionLWord16Word64$fConnectionLWord8Word64$fConnectionk()Word64$fConnectionk(,)Word32$fConnectionLInt32Word32$fConnectionLInt16Word32$fConnectionLInt8Word32$fConnectionLWord16Word32$fConnectionLWord8Word32$fConnectionk()Word32$fConnectionk(,)Word16$fConnectionLInt16Word16$fConnectionLInt8Word16$fConnectionLWord8Word16$fConnectionk()Word16$fConnectionk(,)Word8$fConnectionLInt8Word8$fConnectionk()Word8$fConnectionk(,)Ordering$fConnectionk()Ordering$fConnectionk(,)Bool$fConnectionkDoubleBool$fConnectionkFloatBool$fConnectionkRatioBool$fConnectionkIntBool$fConnectionkInt64Bool$fConnectionkInt32Bool$fConnectionkInt16Bool$fConnectionkInt8Bool$fConnectionkRatioBool0$fConnectionkWordBool$fConnectionkWord64Bool$fConnectionkWord32Bool$fConnectionkWord16Bool$fConnectionkWord8Bool$fConnectionkOrderingBool$fConnectionk()Bool$fConnectionk(,)()$fConnectionkaa$fConnectionR(,)IntMap$fConnectionR(,)Map$fConnectionR()Either$fConnectionR()Maybe$fConnectionL(,)IntMap$fConnectionL(,)Map$fConnectionL()Either$fConnectionkMaybeEither$fConnectionkMaybeEither0$fConnectionk()(,)Booleanboolean SymmetricnotxorAlgebraalgebra Biheyting CoheytingHeyting Semilatticebounded semilatticeMeetJoinLatticetopbottom//iffnegmiddleheytingbooleanRequivnonboundary coheytingbooleanL converseL converseR symmetricR symmetricL$fSemilatticeLIntSet$fSemilatticeLSet$fSemilatticekInt$fSemilatticekInt64$fSemilatticekInt32$fSemilatticekInt16$fSemilatticekInt8$fSemilatticekWord$fSemilatticekWord64$fSemilatticekWord32$fSemilatticekWord16$fSemilatticekWord8$fSemilatticekOrdering$fSemilatticekBool$fSemilatticek()$fSemilatticeREither$fSemilatticeRExtended$fSemilatticeRMaybe$fSemilatticeLIntMap$fSemilatticeLMap$fSemilatticeLEither$fSemilatticeLExtended$fSemilatticeLMaybe$fSemilatticek(,)$fAlgebraLIntMap $fAlgebraLMap$fAlgebraLIntSet $fAlgebraLSet $fAlgebraRInt $fAlgebraLInt$fAlgebraRInt64$fAlgebraLInt64$fAlgebraRInt32$fAlgebraLInt32$fAlgebraRInt16$fAlgebraLInt16$fAlgebraRInt8$fAlgebraLInt8$fAlgebraRWord$fAlgebraLWord$fAlgebraRWord64$fAlgebraLWord64$fAlgebraRWord32$fAlgebraLWord32$fAlgebraRWord16$fAlgebraLWord16$fAlgebraRWord8$fAlgebraLWord8$fAlgebraROrdering$fAlgebraLOrdering$fAlgebraRBool$fAlgebraLBool $fAlgebraR() $fAlgebraL() $fAlgebraL(,)$fAlgebraREither$fAlgebraREither0$fAlgebraRExtended$fAlgebraRMaybe $fAlgebraR(,)$fSymmetric(,)$fSymmetricOrdering$fSymmetricBool $fSymmetric() $fBoolean(,) $fBooleanBool $fBoolean()Rel==><=>xor3preorderorderantisymmetric_le reflexive_le transitive_le connex_le asymmetric_ltirreflexive_lt transitive_lt semiconnex_lttrichotomous_ltchain_22chain_31 symmetric_eq reflexive_eq transitive_eq reflexive irreflexive coreflexivequasireflexive euclideanR euclideanL transitiveconnex semiconnex trichotomous symmetric asymmetric antisymmetric coheyting0 coheyting1 coheyting2 coheyting3 coheyting4 coheyting5 coheyting6 coheyting7 coheyting8 coheyting9 coheyting10 coheyting11 coheyting12 coheyting13 coheyting14 coheyting15 coheyting16 coheyting17 coheyting18 coheyting19 coheyting20heyting0heyting1heyting2heyting3heyting4heyting5heyting6heyting7heyting8heyting9 heyting10 heyting11 heyting12 heyting13 heyting14 heyting15 heyting16 heyting17 symmetric1 symmetric2 symmetric3 symmetric4 symmetric5 symmetric6 symmetric7 symmetric8 symmetric9 symmetric10 symmetric11 symmetric12 symmetric13boolean0boolean1boolean2boolean3boolean4boolean5boolean6adjointLadjointRadjoint adjunctionclosedLclosedRclosedkernelLkernelRkernel invertible monotonicR monotonicL monotonicmonotone idempotentL idempotentR idempotent projective|| GHC.MaybeJustGHC.Base$idWordIntFloatGHC.IntInt16DoubleInt32Rational integer-gmpGHC.Integer.TypeIntegerBoolInt8