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

Safe HaskellSafe
LanguageHaskell2010

Data.Lattice

Contents

Description

Lattices & algebras

Synopsis

Types

type Lattice a = (Eq a, Semilattice L a, Extremal L a, Semilattice R a, Extremal R a) Source #

Bounded lattices.

Neutrality:

The least and greatest elements of a complete a are given by the unique upper and lower adjoints to the function a -> ().

x \/ false = x
x /\ true = x
glb false x true = x
lub false x true = x

type Semilattice k a = Connection k (a, a) a Source #

Semilattices.

A complete 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).

These operations may in turn be defined by the lower and upper adjoints to the unique function a -> (a, a).

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

HeytingL

type HeytingL = Heyting L Source #

A convenience alias for a co-Heyting algebra.

(\\) :: Heyting 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 = false
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]

non :: Heyting L a => a -> a Source #

Logical co-negation.

 non x = true \\ x

Laws:

non false = true
non true = false
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 = true
non (non (non x)) = non x
non (non (x /\ non x)) = false

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

Intuitionistic co-equivalence.

boundary :: Heyting L 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

booleanL :: Heyting L a => Conn L a a Source #

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

Double negation is a join-preserving comonad.

heytingL :: Lattice a => (a -> a -> a) -> a -> Conn L a a Source #

Default constructor for a co-Heyting algebra.

HeytingR

type HeytingR = Heyting R Source #

A convenience alias for a Heyting algebra.

(//) :: Heyting 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 = true
(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

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

Logical negation.

 neg x = x // false

Laws:

neg false = true
neg true = false
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 = false
neg (neg (neg x)) = neg x
neg (neg (x \/ neg x)) = true

Some logics may in addition obey De Morgan conditions.

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

Intuitionistic equivalence.

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

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

The Heyting (not necessarily excluded) middle operator.

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

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

Double negation is a meet-preserving monad.

heytingR :: Lattice a => (a -> a -> a) -> a -> Conn R a a Source #

Default constructor for a Heyting algebra.

Heyting

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

Semigroup operation on a join-semilattice.

(\/) = curry $ lowerL forked

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

Semigroup operation on a meet-semilattice.

(/\) = curry $ upperR forked

glb :: Triple (a, a) 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 x y = x
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]) :: Set Int
fromList [3,5]

lub :: Triple (a, a) 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

true :: Lattice a => a Source #

The unique top element of a bounded lattice

x /\ true = x
x \/ true = true

false :: Lattice a => a Source #

The unique bottom element of a bounded lattice

x /\ false = false
x \/ false = x

class Lattice a => Heyting k a where Source #

Heyting algebras

A Heyting algebra is a bounded, distributive complete equipped with an implication operation.

  • The complete of closed subsets of a trueological space is the primordial example of a HeytingL (co-Heyting) algebra.
  • The dual complete of open subsets of a trueological space is likewise the primordial example of a HeytingR algebra.

Heyting 'L:

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 'R:

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

heyting :: a -> Conn k a a Source #

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

heyting @'L x = ConnL (\\ x) (\/ x) 
heyting @'R x = ConnR (x /\) (x //)
Instances
Heyting L Bool Source # 
Instance details

Defined in Data.Lattice

Heyting L Int Source # 
Instance details

Defined in Data.Lattice

Methods

heyting :: Int -> Conn L Int Int Source #

Heyting L Int8 Source # 
Instance details

Defined in Data.Lattice

Heyting L Int16 Source # 
Instance details

Defined in Data.Lattice

Heyting L Int32 Source # 
Instance details

Defined in Data.Lattice

Heyting L Int64 Source # 
Instance details

Defined in Data.Lattice

Heyting L Ordering Source # 
Instance details

Defined in Data.Lattice

Heyting L Word Source # 
Instance details

Defined in Data.Lattice

Heyting L Word8 Source # 
Instance details

Defined in Data.Lattice

Heyting L Word16 Source # 
Instance details

Defined in Data.Lattice

Heyting L Word32 Source # 
Instance details

Defined in Data.Lattice

Heyting L Word64 Source # 
Instance details

Defined in Data.Lattice

Heyting L () Source # 
Instance details

Defined in Data.Lattice

Methods

heyting :: () -> Conn L () () Source #

Heyting L IntSet Source # 
Instance details

Defined in Data.Lattice

Heyting R Bool Source # 
Instance details

Defined in Data.Lattice

Heyting R Int Source # 
Instance details

Defined in Data.Lattice

Methods

heyting :: Int -> Conn R Int Int Source #

Heyting R Int8 Source # 
Instance details

Defined in Data.Lattice

Heyting R Int16 Source # 
Instance details

Defined in Data.Lattice

Heyting R Int32 Source # 
Instance details

Defined in Data.Lattice

Heyting R Int64 Source # 
Instance details

Defined in Data.Lattice

Heyting R Ordering Source # 
Instance details

Defined in Data.Lattice

Heyting R Word Source # 
Instance details

Defined in Data.Lattice

Heyting R Word8 Source # 
Instance details

Defined in Data.Lattice

Heyting R Word16 Source # 
Instance details

Defined in Data.Lattice

Heyting R Word32 Source # 
Instance details

Defined in Data.Lattice

Heyting R Word64 Source # 
Instance details

Defined in Data.Lattice

Heyting R () Source # 
Instance details

Defined in Data.Lattice

Methods

heyting :: () -> Conn R () () Source #

Heyting R IntSet Source # 
Instance details

Defined in Data.Lattice

Finite a => Heyting L (Predicate a) Source # 
Instance details

Defined in Data.Lattice

(Finite a, Biheyting a) => Heyting L (Endo a) Source # 
Instance details

Defined in Data.Lattice

Methods

heyting :: Endo a -> Conn L (Endo a) (Endo a) Source #

(Total a, Finite a) => Heyting L (Set a) Source # 
Instance details

Defined in Data.Lattice

Methods

heyting :: Set a -> Conn L (Set a) (Set a) Source #

KnownNat n => Heyting L (Finite n) Source # 
Instance details

Defined in Data.Lattice

Methods

heyting :: Finite n -> Conn L (Finite n) (Finite n) Source #

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

Defined in Data.Lattice

Methods

heyting :: Maybe a -> Conn R (Maybe a) (Maybe a) Source #

Finite a => Heyting R (Predicate a) Source # 
Instance details

Defined in Data.Lattice

(Finite a, Biheyting a) => Heyting R (Endo a) Source # 
Instance details

Defined in Data.Lattice

Methods

heyting :: Endo a -> Conn R (Endo a) (Endo a) Source #

(Total a, Finite a) => Heyting R (Set a) Source # 
Instance details

Defined in Data.Lattice

Methods

heyting :: Set a -> Conn R (Set a) (Set a) Source #

KnownNat n => Heyting R (Finite n) Source # 
Instance details

Defined in Data.Lattice

Methods

heyting :: Finite n -> Conn R (Finite n) (Finite n) Source #

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

Defined in Data.Lattice

Methods

heyting :: Extended a -> Conn R (Extended a) (Extended a) Source #

Heyting R a => Heyting R (Lowered a) Source #

Subdirectly irreducible Heyting algebra.

Instance details

Defined in Data.Lattice

Methods

heyting :: Lowered a -> Conn R (Lowered a) (Lowered a) Source #

Heyting R a => Heyting R (Lifted a) Source # 
Instance details

Defined in Data.Lattice

Methods

heyting :: Lifted a -> Conn R (Lifted a) (Lifted a) Source #

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

Defined in Data.Lattice

Methods

heyting :: (a, b) -> Conn k (a, b) (a, b) Source #

(Finite a, Biheyting b) => Heyting L (a -> b) Source # 
Instance details

Defined in Data.Lattice

Methods

heyting :: (a -> b) -> Conn L (a -> b) (a -> b) Source #

(Finite a, Biheyting b) => Heyting L (Op b a) Source # 
Instance details

Defined in Data.Lattice

Methods

heyting :: Op b a -> Conn L (Op b a) (Op b a) Source #

(Finite a, Biheyting b) => Heyting R (a -> b) Source # 
Instance details

Defined in Data.Lattice

Methods

heyting :: (a -> b) -> Conn R (a -> b) (a -> b) Source #

(Finite a, Biheyting b) => Heyting R (Op b a) Source # 
Instance details

Defined in Data.Lattice

Methods

heyting :: Op b a -> Conn R (Op b a) (Op b a) Source #

Symmetric

type Biheyting a = (HeytingL a, HeytingR a) Source #

A bi-Heyting algebra.

Laws:

neg x <= non x

with equality occurring iff a is a Boolean algebra.

class Biheyting a => Symmetric a where Source #

Symmetric Heyting algebras

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

converseL :: a -> a Source #

Left converse operator.

converseR :: a -> a Source #

Right converse operator.

Instances
Symmetric Bool Source # 
Instance details

Defined in Data.Lattice

Symmetric Ordering Source # 
Instance details

Defined in Data.Lattice

Symmetric () Source # 
Instance details

Defined in Data.Lattice

Methods

not :: () -> () Source #

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

converseL :: () -> () Source #

converseR :: () -> () Source #

Symmetric IntSet Source # 
Instance details

Defined in Data.Lattice

Finite a => Symmetric (Predicate a) Source # 
Instance details

Defined in Data.Lattice

(Finite a, Symmetric a) => Symmetric (Endo a) Source # 
Instance details

Defined in Data.Lattice

Methods

not :: Endo a -> Endo a Source #

xor :: Endo a -> Endo a -> Endo a Source #

converseL :: Endo a -> Endo a Source #

converseR :: Endo a -> Endo a Source #

(Total a, Finite a) => Symmetric (Set a) Source # 
Instance details

Defined in Data.Lattice

Methods

not :: Set a -> Set a Source #

xor :: Set a -> Set a -> Set a Source #

converseL :: Set a -> Set a Source #

converseR :: Set a -> Set a Source #

(Finite 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 :: (a -> b) -> a -> b Source #

converseR :: (a -> b) -> a -> b Source #

(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 :: (a, b) -> (a, b) Source #

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

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

Defined in Data.Lattice

Methods

not :: Op b a -> Op b a Source #

xor :: Op b a -> Op b a -> Op b a Source #

converseL :: Op b a -> Op b a Source #

converseR :: Op b a -> Op b a Source #

symmetricL :: Symmetric a => a -> ConnL a a Source #

Default constructor for a co-Heyting algebra.

symmetricR :: Symmetric a => a -> ConnR a a Source #

Default constructor for a Heyting algebra.

Boolean

class Symmetric a => Boolean a where Source #

Boolean algebras.

Boolean algebras are symmetric Heyting algebras that satisfy both the law of excluded middle and the law of law of non-contradiction:

x \/ neg x = true
x /\ non x = false

If a is Boolean we also have:

non = not = neg

Minimal complete definition

Nothing

Methods

boolean :: Trip 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 :: Trip () () Source #

Boolean IntSet Source # 
Instance details

Defined in Data.Lattice

Finite a => Boolean (Predicate a) Source # 
Instance details

Defined in Data.Lattice

(Finite a, Boolean a) => Boolean (Endo a) Source # 
Instance details

Defined in Data.Lattice

Methods

boolean :: Trip (Endo a) (Endo a) Source #

(Total a, Finite a) => Boolean (Set a) Source # 
Instance details

Defined in Data.Lattice

Methods

boolean :: Trip (Set a) (Set a) Source #

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

Defined in Data.Lattice

Methods

boolean :: Trip (a -> b) (a -> b) Source #

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

Defined in Data.Lattice

Methods

boolean :: Trip (a, b) (a, b) Source #

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

Defined in Data.Lattice

Methods

boolean :: Trip (Op b a) (Op b a) Source #