Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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
- newtype VennDiagram a = VennDiagram {}
- vennDiagramNumberOfSets :: VennDiagram a -> Int
- vennDiagramNumberOfZones :: VennDiagram a -> Int
- vennDiagramNumberOfNonemptyZones :: VennDiagram Int -> Int
- unsafeMakeVennDiagram :: [([Bool], a)] -> VennDiagram a
- isTrivialVennDiagram :: VennDiagram Int -> Bool
- printVennDiagram :: Show a => VennDiagram a -> IO ()
- prettyVennDiagram :: Show a => VennDiagram a -> String
- asciiVennDiagram :: Show a => VennDiagram a -> ASCII
- vennDiagramSetCardinalities :: VennDiagram Int -> [Int]
- enumerateVennDiagrams :: [Int] -> [VennDiagram Int]
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)
Instances
Show a => Show (VennDiagram a) Source # | |
Defined in Math.Combinat.Sets.VennDiagrams showsPrec :: Int -> VennDiagram a -> ShowS # show :: VennDiagram a -> String # showList :: [VennDiagram a] -> ShowS # | |
Show a => DrawASCII (VennDiagram a) Source # | |
Defined in Math.Combinat.Sets.VennDiagrams ascii :: VennDiagram a -> ASCII Source # | |
Eq a => Eq (VennDiagram a) Source # | |
Defined in Math.Combinat.Sets.VennDiagrams (==) :: VennDiagram a -> VennDiagram a -> Bool # (/=) :: VennDiagram a -> VennDiagram a -> Bool # | |
Ord a => Ord (VennDiagram a) Source # | |
Defined in Math.Combinat.Sets.VennDiagrams compare :: 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 # |
vennDiagramNumberOfSets :: VennDiagram a -> Int Source #
How many sets are in the Venn diagram
vennDiagramNumberOfZones :: VennDiagram a -> Int Source #
How many zones are in the Venn diagram
vennDiagramNumberOfZones v == 2 ^ (vennDiagramNumberOfSets v)
vennDiagramNumberOfNonemptyZones :: VennDiagram Int -> Int Source #
How many nonempty zones are in the Venn diagram
unsafeMakeVennDiagram :: [([Bool], a)] -> VennDiagram a Source #
isTrivialVennDiagram :: VennDiagram Int -> Bool Source #
We call venn diagram trivial if all the intersection zones has zero cardinality (that is, the original sets are all disjoint)
printVennDiagram :: Show a => VennDiagram a -> IO () Source #
prettyVennDiagram :: Show a => VennDiagram a -> String Source #
asciiVennDiagram :: Show a => VennDiagram a -> ASCII Source #
vennDiagramSetCardinalities :: VennDiagram Int -> [Int] Source #
Given a Venn diagram of cardinalities, we compute the cardinalities of the original sets (note: this is slow!)
enumerateVennDiagrams :: [Int] -> [VennDiagram Int] Source #
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]