combinat-0.2.10.0: Generate and manipulate various combinatorial objects.

Math.Combinat.Sets.VennDiagrams

Description

Venn diagrams. See https://en.wikipedia.org/wiki/Venn_diagram

TODO: write a more efficient implementation (for example an array of size 2^n)

Synopsis

# Documentation

newtype VennDiagram a Source #

Venn diagrams of n sets. Each possible zone is annotated with a value of type a. A typical use case is to annotate with the cardinality of the given zone.

Internally this is representated by a map from [Bool], where True means element of the set, False means not.

TODO: write a more efficient implementation (for example an array of size 2^n)

Constructors

 VennDiagram FieldsvennTable :: Map [Bool] a

#### Instances

Instances details
 Eq a => Eq (VennDiagram a) Source # Instance detailsDefined in Math.Combinat.Sets.VennDiagrams Methods(==) :: VennDiagram a -> VennDiagram a -> Bool #(/=) :: VennDiagram a -> VennDiagram a -> Bool # Ord a => Ord (VennDiagram a) Source # Instance detailsDefined in Math.Combinat.Sets.VennDiagrams Methodscompare :: VennDiagram a -> VennDiagram a -> Ordering #(<) :: VennDiagram a -> VennDiagram a -> Bool #(<=) :: VennDiagram a -> VennDiagram a -> Bool #(>) :: VennDiagram a -> VennDiagram a -> Bool #(>=) :: VennDiagram a -> VennDiagram a -> Bool #max :: VennDiagram a -> VennDiagram a -> VennDiagram a #min :: VennDiagram a -> VennDiagram a -> VennDiagram a # Show a => Show (VennDiagram a) Source # Instance detailsDefined in Math.Combinat.Sets.VennDiagrams MethodsshowsPrec :: Int -> VennDiagram a -> ShowS #show :: VennDiagram a -> String #showList :: [VennDiagram a] -> ShowS # Show a => DrawASCII (VennDiagram a) Source # Instance detailsDefined in Math.Combinat.Sets.VennDiagrams Methods

How many sets are in the Venn diagram

How many zones are in the Venn diagram

vennDiagramNumberOfZones v == 2 ^ (vennDiagramNumberOfSets v)

How many nonempty zones are in the Venn diagram

We call venn diagram trivial if all the intersection zones has zero cardinality (that is, the original sets are all disjoint)

Given a Venn diagram of cardinalities, we compute the cardinalities of the original sets (note: this is slow!)

Given the cardinalities of some finite sets, we list all possible Venn diagrams.

Note: we don't include the empty zone in the tables, because it's always empty.

Remark: if each sets is a singleton set, we get back set partitions:

> [ length $enumerateVennDiagrams$ replicate k 1 | k<-[1..8] ]
[1,2,5,15,52,203,877,4140]

> [ countSetPartitions k | k<-[1..8] ]
[1,2,5,15,52,203,877,4140]

Maybe this could be called multiset-partitions?

Example:

autoTabulate RowMajor (Right 6) $map ascii$ enumerateVennDiagrams [2,3,3]