Processing math: 96%
sbv-9.1: SMT Based Verification: Symbolic Haskell theorem prover using SMT solving.
Copyright(c) Levent Erkok
LicenseBSD3
Maintainererkokl@gmail.com
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

Documentation.SBV.Examples.Misc.SetAlgebra

Description

Proves various algebraic properties of sets using SBV. The properties we prove all come from http://en.wikipedia.org/wiki/Algebra_of_sets.

Synopsis

Documentation

>>> -- For doctest purposes only:
>>> import Data.SBV hiding (complement)
>>> import Data.SBV.Set
>>> :set -XScopedTypeVariables

type SI = SSet Integer Source #

Abbreviation for set of integers. For convenience only in monomorphising the properties.

Commutativity

 

AB=BA

>>> prove $ \(a :: SI) b -> a `union` b .== b `union` a
Q.E.D.

AB=BA

>>> prove $ \(a :: SI) b -> a `intersection` b .== b `intersection` a
Q.E.D.

Associativity

 

(AB)C=A(BC)

>>> prove $ \(a :: SI) b c -> a `union` (b `union` c) .== (a `union` b) `union` c
Q.E.D.

(AB)C=A(BC)

>>> prove $ \(a :: SI) b c -> a `intersection` (b `intersection` c) .== (a `intersection` b) `intersection` c
Q.E.D.

Distributivity

 

A(BC)=(AB)(AC)

>>> prove $ \(a :: SI) b c -> a `union` (b `intersection` c) .== (a `union` b) `intersection` (a `union` c)
Q.E.D.

A(BC)=(AB)(AC)

>>> prove $ \(a :: SI) b c -> a `intersection` (b `union` c) .== (a `intersection` b) `union` (a `intersection` c)
Q.E.D.

Identity properties

 

A=A

>>> prove $ \(a :: SI) -> a `union` empty .== a
Q.E.D.

AU=A

>>> prove $ \(a :: SI) -> a `intersection` full .== a
Q.E.D.

Complement properties

 

AAC=U

>>> prove $ \(a :: SI) -> a `union` complement a .== full
Q.E.D.

AAC=

>>> prove $ \(a :: SI) -> a `intersection` complement a .== empty
Q.E.D.

(AC)C=A

>>> prove $ \(a :: SI) -> complement (complement a) .== a
Q.E.D.

C=U

>>> prove $ complement (empty :: SI) .== full
Q.E.D.

UC=

>>> prove $ complement (full :: SI) .== empty
Q.E.D.

Uniqueness of the complement

 

The complement of a set is the only set that satisfies the first two complement properties above. That is complementation is characterized by those two laws, as we can formally establish:

AB=UAB=B=AC

>>> prove $ \(a :: SI) b -> a `union` b .== full .&& a `intersection` b .== empty .<=> b .== complement a
Q.E.D.

Idempotency

 

AA=A

>>> prove $ \(a :: SI) -> a `union` a .== a
Q.E.D.

AA=A

>>> prove $ \(a :: SI) -> a `intersection` a .== a
Q.E.D.

Domination properties

 

AU=U

>>> prove $ \(a :: SI) -> a `union` full .== full
Q.E.D.

A=

>>> prove $ \(a :: SI) -> a `intersection` empty .== empty
Q.E.D.

Absorption properties

 

A(AB)=A

>>> prove $ \(a :: SI) b -> a `union` (a `intersection` b) .== a
Q.E.D.

A(AB)=A

>>> prove $ \(a :: SI) b -> a `intersection` (a `union` b) .== a
Q.E.D.

Intersection and set difference

 

AB=A(AB)

>>> prove $ \(a :: SI) b -> a `intersection` b .== a `difference` (a `difference` b)
Q.E.D.

De Morgan's laws

 

(AB)C=ACBC

>>> prove $ \(a :: SI) b -> complement (a `union` b) .== complement a `intersection` complement b
Q.E.D.

(AB)C=ACBC

>>> prove $ \(a :: SI) b -> complement (a `intersection` b) .== complement a `union` complement b
Q.E.D.

Inclusion is a partial order

 

Subset inclusion is a partial order, i.e., it is reflexive, antisymmetric, and transitive:

AA

>>> prove $ \(a :: SI) -> a `isSubsetOf` a
Q.E.D.

ABBAA=B

>>> prove $ \(a :: SI) b -> a `isSubsetOf` b .&& b `isSubsetOf` a .<=> a .== b
Q.E.D.

ABBCAC

>>> prove $ \(a :: SI) b c -> a `isSubsetOf` b .&& b `isSubsetOf` c .=> a `isSubsetOf` c
Q.E.D.

Joins and meets

 

AAB

>>> prove $ \(a :: SI) b -> a `isSubsetOf` (a `union` b)
Q.E.D.

ACBC(AB)C

>>> prove $ \(a :: SI) b c -> a `isSubsetOf` c .&& b `isSubsetOf` c .=> (a `union` b) `isSubsetOf` c
Q.E.D.

ABA

>>> prove $ \(a :: SI) b -> (a `intersection` b) `isSubsetOf` a
Q.E.D.

ABB

>>> prove $ \(a :: SI) b -> (a `intersection` b) `isSubsetOf` b
Q.E.D.

CACBC(AB)

>>> prove $ \(a :: SI) b c -> c `isSubsetOf` a .&& c `isSubsetOf` b .=> c `isSubsetOf` (a `intersection` b)
Q.E.D.

Subset characterization

 

There are multiple equivalent ways of characterizing the subset relationship:

ABAB=A

>>> prove $ \(a :: SI) b -> a `isSubsetOf` b .<=> a `intersection` b .== a
Q.E.D.

ABAB=B

>>> prove $ \(a :: SI) b -> a `isSubsetOf` b .<=> a `union` b .== b
Q.E.D.

ABAB=

>>> prove $ \(a :: SI) b -> a `isSubsetOf` b .<=> a `difference` b .== empty
Q.E.D.

ABBCAC

>>> prove $ \(a :: SI) b -> a `isSubsetOf` b .<=> complement b `isSubsetOf` complement a
Q.E.D.

Relative complements

 

C(AB)=(CA)(CB)

>>> prove $ \(a :: SI) b c -> c \\ (a `intersection` b) .== (c \\ a) `union` (c \\ b)
Q.E.D.

C(AB)=(CA)(CB)

>>> prove $ \(a :: SI) b c -> c \\ (a `union` b) .== (c \\ a) `intersection` (c \\ b)
Q.E.D.

C(BA)=(AC)(CB)

>>> prove $ \(a :: SI) b c -> c \\ (b \\ a) .== (a `intersection` c) `union` (c \\ b)
Q.E.D.

(BA)C=(BC)A

>>> prove $ \(a :: SI) b c -> (b \\ a) `intersection` c .== (b `intersection` c) \\ a
Q.E.D.

(BA)C=B(CA)

>>> prove $ \(a :: SI) b c -> (b \\ a) `intersection` c .== b `intersection` (c \\ a)
Q.E.D.

(BA)C=(BC)(AC)

>>> prove $ \(a :: SI) b c -> (b \\ a) `union` c .== (b `union` c) \\ (a \\ c)
Q.E.D.

AA=

>>> prove $ \(a :: SI) -> a \\ a .== empty
Q.E.D.

A=

>>> prove $ \(a :: SI) -> empty \\ a .== empty
Q.E.D.

A=A

>>> prove $ \(a :: SI) -> a \\ empty .== a
Q.E.D.

BA=ACB

>>> prove $ \(a :: SI) b -> b \\ a .== complement a `intersection` b
Q.E.D.

(BA)C=ABC

>>> prove $ \(a :: SI) b -> complement (b \\ a) .== a `union` complement b
Q.E.D.

UA=AC

>>> prove $ \(a :: SI) -> full \\ a .== complement a
Q.E.D.

AU=

>>> prove $ \(a :: SI) -> a \\ full .== empty
Q.E.D.

Distributing subset relation

 

A common mistake newcomers to set theory make is to distribute the subset relationship over intersection and unions, which is only true as described above. Here, we use SBV to show two incorrect cases:

Subset relation does not distribute over union on the left:

A(BC)

>>> prove $ \(a :: SI) b c -> a `isSubsetOf` (b `union` c) .=> a `isSubsetOf` b .&& a `isSubsetOf` c
Falsifiable. Counter-example:
  s0 =     {2} :: {Integer}
  s1 =       U :: {Integer}
  s2 = U - {2} :: {Integer}

Similarly, subset relation does not distribute over intersection on the right:

(B \cap C) \subseteq A \nRightarrow B \subseteq A \land C \subseteq A

>>> prove $ \(a :: SI) b c -> (b `intersection` c) `isSubsetOf` a .=> b `isSubsetOf` a .&& c `isSubsetOf` a
Falsifiable. Counter-example:
  s0 = U - {2} :: {Integer}
  s1 =      {} :: {Integer}
  s2 =     {2} :: {Integer}