connections-0.3.2: Orders, Galois connections, and lattices.

Safe HaskellSafe
LanguageHaskell2010

Data.Lattice

Contents

Description

Lattices & algebras

Synopsis

Semilattice

type Lattice a = (Join a, Meet a) Source #

class Order a => Semilattice k a where Source #

Bounded lattices.

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 bound lattice adds unique elements top and bottom, which serve as identities to \/ and /\, respectively.

Neutrality:

x \/ bottom = x
x /\ top = x
glb bottom x top = x
lub bottom x top = 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 Absorption.

Note that distributivity is _not_ a requirement for a complete. However when a is distributive we have:

glb x y z = lub x y z

See https://en.wikipedia.org/wiki/Lattice_(order).

Methods

bound :: Cast k () a Source #

The defining connection of a bound semilattice.

bottom and top are defined by the left and right adjoints to a -> ().

semilattice :: Cast k (a, a) a Source #

The defining connection of a semilattice.

\/ and /\ are defined by the left and right adjoints to a -> (a, a).

Instances
Semilattice k IntSet Source # 
Instance details

Defined in Data.Lattice

Semilattice k Int Source # 
Instance details

Defined in Data.Lattice

Semilattice k Int64 Source # 
Instance details

Defined in Data.Lattice

Semilattice k Int32 Source # 
Instance details

Defined in Data.Lattice

Semilattice k Int16 Source # 
Instance details

Defined in Data.Lattice

Semilattice k Int8 Source # 
Instance details

Defined in Data.Lattice

Semilattice k Word Source # 
Instance details

Defined in Data.Lattice

Semilattice k Word64 Source # 
Instance details

Defined in Data.Lattice

Semilattice k Word32 Source # 
Instance details

Defined in Data.Lattice

Semilattice k Word16 Source # 
Instance details

Defined in Data.Lattice

Semilattice k Word8 Source # 
Instance details

Defined in Data.Lattice

Semilattice k Ordering Source # 
Instance details

Defined in Data.Lattice

Semilattice k Bool Source # 
Instance details

Defined in Data.Lattice

Semilattice k () Source # 
Instance details

Defined in Data.Lattice

Methods

bound :: Cast k () () Source #

semilattice :: Cast k ((), ()) () Source #

Join a => Semilattice L (Maybe a) Source # 
Instance details

Defined in Data.Lattice

Methods

bound :: Cast L () (Maybe a) Source #

semilattice :: Cast L (Maybe a, Maybe a) (Maybe a) Source #

Join a => Semilattice L (IntMap a) Source # 
Instance details

Defined in Data.Lattice

Methods

bound :: Cast L () (IntMap a) Source #

semilattice :: Cast L (IntMap a, IntMap a) (IntMap a) Source #

Total a => Semilattice L (Set a) Source # 
Instance details

Defined in Data.Lattice

Methods

bound :: Cast L () (Set a) Source #

semilattice :: Cast L (Set a, Set a) (Set a) Source #

Join a => Semilattice L (Extended a) Source # 
Instance details

Defined in Data.Lattice

Meet a => Semilattice R (Maybe a) Source # 
Instance details

Defined in Data.Lattice

Methods

bound :: Cast R () (Maybe a) Source #

semilattice :: Cast R (Maybe a, Maybe a) (Maybe a) Source #

Meet a => Semilattice R (Extended a) Source # 
Instance details

Defined in Data.Lattice

(Lattice a, Lattice b) => Semilattice k (a, b) Source # 
Instance details

Defined in Data.Lattice

Methods

bound :: Cast k () (a, b) Source #

semilattice :: Cast k ((a, b), (a, b)) (a, b) Source #

(Join a, Join b) => Semilattice L (Either a b) Source #

All minimal elements of the upper lattice cover all maximal elements of the lower lattice.

Instance details

Defined in Data.Lattice

Methods

bound :: Cast L () (Either a b) Source #

semilattice :: Cast L (Either a b, Either a b) (Either a b) Source #

(Total k, Join a) => Semilattice L (Map k a) Source # 
Instance details

Defined in Data.Lattice

Methods

bound :: Cast L () (Map k a) Source #

semilattice :: Cast L (Map k a, Map k a) (Map k a) Source #

(Meet a, Meet b) => Semilattice R (Either a b) Source # 
Instance details

Defined in Data.Lattice

Methods

bound :: Cast R () (Either a b) Source #

semilattice :: Cast R (Either a b, Either a b) (Either a b) Source #

Meet

type Meet = Semilattice R Source #

A convenience alias for a meet semilattice

(/\) :: Meet a => a -> a -> a infixr 6 Source #

Lattice meet.

(/\) = curry $ floor semilattice

glb :: Lattice a => a -> a -> a -> a Source #

Greatest lower bound operator.

glb 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.0
7.0
>>> glb 1.0 9.0 (0.0 / 0.0)
9.0
>>> glb (fromList [1..3]) (fromList [3..5]) (fromList [5..7]) :: IntSet
fromList [3,5]

top :: Meet a => a Source #

The unique top element of a bound lattice

x /\ top = x
x \/ top = top

Join

type Join = Semilattice L Source #

A convenience alias for a join semilattice

(\/) :: Join a => a -> a -> a infixr 5 Source #

Lattice join.

(\/) = curry $ lower semilattice

lub :: Lattice a => a -> a -> a -> a Source #

Least upper bound operator.

The order dual of glb.

>>> lub 1.0 9.0 7.0
7.0
>>> lub 1.0 9.0 (0.0 / 0.0)
1.0

bottom :: Join a => a Source #

The unique bottom element of a bound lattice

x /\ bottom = bottom
x \/ bottom = x

Algebra

type Biheyting a = (Coheyting a, Heyting a) Source #

A bi-Heyting algebra.

Laws:

neg x <= non x

with equality occurring iff a is a Boolean algebra.

class Semilattice k a => Algebra k a where Source #

Heyting and co-Heyting algebras

A Heyting algebra is a bound, distributive lattice equipped with an implication operation.

  • The complete of closed subsets of a topological space is the primordial example of a Coheyting (co-Algebra) algebra.
  • The 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 \/ a

Note that co-Heyting algebras needn't obey the law of non-contradiction:

EQ /\ non EQ = EQ /\ GT \\ EQ = EQ /\ GT = EQ /= LT

See https://ncatlab.org/nlab/show/co-Heyting+algebra

Heyting:

Implication from a is the upper adjoint of conjunction with a:

x <= a // y <=> a /\ x <= y

Similarly, Heyting algebras needn't obey the law of the excluded middle:

EQ \/ neg EQ = EQ \/ EQ // LT = EQ \/ LT = EQ /= GT

See https://ncatlab.org/nlab/show/Heyting+algebra

Methods

algebra :: a -> Cast k a a Source #

The defining connection of a (co-)Heyting algebra.

algebra @'L x = CastL (\\ x) (\/ x)
algebra @'R x = CastR (x /\) (x //)
Instances
Algebra L Bool Source # 
Instance details

Defined in Data.Lattice

Algebra L Int Source # 
Instance details

Defined in Data.Lattice

Methods

algebra :: Int -> Cast L Int Int Source #

Algebra L Int8 Source # 
Instance details

Defined in Data.Lattice

Algebra L Int16 Source # 
Instance details

Defined in Data.Lattice

Algebra L Int32 Source # 
Instance details

Defined in Data.Lattice

Algebra L Int64 Source # 
Instance details

Defined in Data.Lattice

Algebra L Ordering Source # 
Instance details

Defined in Data.Lattice

Algebra L Word Source # 
Instance details

Defined in Data.Lattice

Algebra L Word8 Source # 
Instance details

Defined in Data.Lattice

Algebra L Word16 Source # 
Instance details

Defined in Data.Lattice

Algebra L Word32 Source # 
Instance details

Defined in Data.Lattice

Algebra L Word64 Source # 
Instance details

Defined in Data.Lattice

Algebra L () Source # 
Instance details

Defined in Data.Lattice

Methods

algebra :: () -> Cast L () () Source #

Algebra L IntSet Source # 
Instance details

Defined in Data.Lattice

Algebra R Bool Source # 
Instance details

Defined in Data.Lattice

Algebra R Int Source # 
Instance details

Defined in Data.Lattice

Methods

algebra :: Int -> Cast R Int Int Source #

Algebra R Int8 Source # 
Instance details

Defined in Data.Lattice

Algebra R Int16 Source # 
Instance details

Defined in Data.Lattice

Algebra R Int32 Source # 
Instance details

Defined in Data.Lattice

Algebra R Int64 Source # 
Instance details

Defined in Data.Lattice

Algebra R Ordering Source # 
Instance details

Defined in Data.Lattice

Algebra R Word Source # 
Instance details

Defined in Data.Lattice

Algebra R Word8 Source # 
Instance details

Defined in Data.Lattice

Algebra R Word16 Source # 
Instance details

Defined in Data.Lattice

Algebra R Word32 Source # 
Instance details

Defined in Data.Lattice

Algebra R Word64 Source # 
Instance details

Defined in Data.Lattice

Algebra R () Source # 
Instance details

Defined in Data.Lattice

Methods

algebra :: () -> Cast R () () Source #

Algebra R IntSet Source # 
Instance details

Defined in Data.Lattice

Join a => Algebra L (IntMap a) Source # 
Instance details

Defined in Data.Lattice

Methods

algebra :: IntMap a -> Cast L (IntMap a) (IntMap a) Source #

Total a => Algebra L (Set a) Source # 
Instance details

Defined in Data.Lattice

Methods

algebra :: Set a -> Cast L (Set a) (Set a) Source #

Heyting a => Algebra R (Maybe a) Source # 
Instance details

Defined in Data.Lattice

Methods

algebra :: Maybe a -> Cast R (Maybe a) (Maybe a) Source #

Heyting a => Algebra R (Extended a) Source # 
Instance details

Defined in Data.Lattice

Methods

algebra :: Extended a -> Cast R (Extended a) (Extended a) Source #

(Coheyting a, Coheyting b) => Algebra L (a, b) Source # 
Instance details

Defined in Data.Lattice

Methods

algebra :: (a, b) -> Cast L (a, b) (a, b) Source #

(Total k, Join a) => Algebra L (Map k a) Source # 
Instance details

Defined in Data.Lattice

Methods

algebra :: Map k a -> Cast L (Map k a) (Map k a) Source #

Heyting a => Algebra R (Either () a) Source # 
Instance details

Defined in Data.Lattice

Methods

algebra :: Either () a -> Cast R (Either () a) (Either () a) Source #

Heyting a => Algebra R (Either a ()) Source #

Subdirectly irreducible Algebra algebra.

Instance details

Defined in Data.Lattice

Methods

algebra :: Either a () -> Cast R (Either a ()) (Either a ()) Source #

(Heyting a, Heyting b) => Algebra R (a, b) Source # 
Instance details

Defined in Data.Lattice

Methods

algebra :: (a, b) -> Cast R (a, b) (a, b) Source #

Heyting

type Heyting a = (Lattice a, Algebra R a) Source #

A convenience alias for a Heyting algebra.

(//) :: Algebra R a => a -> a -> a infixr 8 Source #

Logical implication:

\( 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 /\ y
>>> False // False
True
>>> False // True
True
>>> True // False
False
>>> True // True
True

iff :: Algebra R a => a -> a -> a Source #

Intuitionistic equivalence.

When a is Bool this is 'if-and-only-if'.

neg :: Heyting a => a -> a Source #

Logical negation.

 neg x = x // bottom

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 De Morgan conditions.

middle :: Heyting a => a -> a Source #

The Algebra (not necessarily excluded) middle operator.

heyting :: Meet a => (a -> a -> a) -> a -> Cast R a a Source #

Default constructor for a Algebra algebra.

booleanR :: Heyting a => Cast R a a Source #

An adjunction between a Algebra algebra and its Boolean sub-algebra.

Double negation is a meet-preserving monad.

Coheyting

type Coheyting a = (Lattice a, Algebra L a) Source #

A convenience alias for a co-Heyting algebra.

(\\) :: Algebra L a => a -> a -> a infixl 8 Source #

Logical co-implication:

\( 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 \/ y
>>> False \\ False
False
>>> False \\ True
False
>>> True \\ False
True
>>> True \\ True
False

For many collections (e.g. Set) \\ coincides with the native \\ operator.

>>> :set -XOverloadedLists
>>> [GT,EQ] Set.\\ [LT]
fromList [EQ,GT]
>>> [GT,EQ] \\ [LT]
fromList [EQ,GT]

equiv :: Algebra L a => a -> a -> a Source #

Intuitionistic co-equivalence.

non :: Coheyting a => a -> a Source #

Logical co-negation.

 non x = top \\ x

Laws:

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)) = bottom

boundary :: Coheyting a => a -> a Source #

The co-Heyting boundary 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 y

coheyting :: Join a => (a -> a -> a) -> a -> Cast L a a Source #

Default constructor for a co-Heyting algebra.

booleanL :: Coheyting a => Cast L a a Source #

An adjunction between a co-Heyting algebra and its Boolean sub-algebra.

Double negation is a join-preserving comonad.

Symmetric

class Biheyting a => Symmetric a where Source #

Symmetric Heyting algebras

A symmetric Heyting algebra is a De Morgan 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 x

with equality occurring iff a is a Boolean algebra.

Minimal complete definition

not

Methods

not :: a -> a Source #

Symmetric 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)

xor :: a -> a -> a infixl 4 Source #

Exclusive or.

xor x y = (x \/ y) /\ (not x \/ not y)
Instances
Symmetric Bool Source # 
Instance details

Defined in Data.Lattice

Methods

not :: Bool -> Bool Source #

xor :: Bool -> Bool -> Bool Source #

Symmetric Ordering Source # 
Instance details

Defined in Data.Lattice

Symmetric () Source # 
Instance details

Defined in Data.Lattice

Methods

not :: () -> () Source #

xor :: () -> () -> () Source #

Symmetric IntSet Source # 
Instance details

Defined in Data.Lattice

(Symmetric a, Symmetric b) => Symmetric (a, b) Source # 
Instance details

Defined in Data.Lattice

Methods

not :: (a, b) -> (a, b) Source #

xor :: (a, b) -> (a, b) -> (a, b) Source #

converseL :: Symmetric a => a -> a Source #

Left converse operator.

converseR :: Symmetric a => a -> a Source #

Right converse operator.

symmetricL :: Symmetric a => a -> Cast L a a Source #

Default constructor for a co-Heyting algebra.

symmetricR :: Symmetric a => a -> Cast R a a Source #

Default constructor for a Heyting algebra.

Boolean

class Symmetric a => Boolean a where Source #

Boolean algebras.

Boolean algebras 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 = bottom

If a is Boolean we also have:

non = not = neg

Minimal complete definition

Nothing

Methods

boolean :: Cast k a a Source #

A witness to the lawfulness of a boolean algebra.

Instances
Boolean Bool Source # 
Instance details

Defined in Data.Lattice

Boolean () Source # 
Instance details

Defined in Data.Lattice

Methods

boolean :: Cast k () () Source #

(Boolean a, Boolean b) => Boolean (a, b) Source # 
Instance details

Defined in Data.Lattice

Methods

boolean :: Cast k (a, b) (a, b) Source #