Function Repository Resource:

VennDiagram

Source Notebook

Generate the Venn diagram associated to a logical expression or collection of sets

Contributed by: Jack Heimrath

ResourceFunction["VennDiagram"][expr]

generates the Venn diagram associated to expr.

ResourceFunction["VennDiagram"][{s1,s2,}]

generates the Venn diagram associated to the sets s1,s2,.

Details

The input must be a valid logical expression containing between two and five variables or a list of between two and five sets.
The following Options can be used:
"DiagramLegends""SwatchLegend"specifies which legends to use
"EquationForm""AND"converts the legend expressions to the specified form
ImageSize185the absolute size at which to render the graphic
The "DiagramLegends" and "EquationForm" Options are only applicable to a Venn diagram of a list of lists.
The following settings for "DiagramLegends" can be given:
"SwatchLegend"generates a legend that associates colored swatches to appropriately colored regions of the diagram
"MouseOver"highlights the region under the cursor and displays the equation associated to it
The following settings for "EquationForm" can be given:
Noneno equation
"DNF","SOP"disjunctive normal form, sum of products
"CNF","POS"conjunctive normal form, product of sums
"ESOP"exclusive sum of products
"ANF"algebraic normal form
"NOR"two-level Nor and Not
"NAND"two-level Nand and Not
"AND"two-level And and Not
"OR"two-level Or and Not
"IMPLIES"Implies and Not
"ITE","IF"If and constants
"BFF"BooleanFunction form
"BDT"Boolean decision tree

Examples

Basic Examples (3) 

Generate a Venn diagram representing a logical expression:

In[1]:=
ResourceFunction["VennDiagram"][(a && b) || c]
Out[1]=
In[2]:=
ResourceFunction["VennDiagram"][a \[Xor] (b \[And] c \[Or] d)]
Out[2]=
In[3]:=
ResourceFunction["VennDiagram"][Xor[a, b, c, d, e]]
Out[3]=

VennDiagram accepts Boolean functions as input:

In[4]:=
ResourceFunction["VennDiagram"][BooleanFunction[2, 3][a, b, c]]
Out[4]=

Generate a Venn diagram for explicitly defined sets:

In[5]:=
ResourceFunction[
 "VennDiagram"][{{a, b, c}, {a, b, c, d}, {c, b, d, f}}]
Out[5]=

Options (3) 

EquationForm (1) 

Change the canonical normal form of equations used to describe particular sets:

In[6]:=
ResourceFunction[
 "VennDiagram"][{{a, b, c}, {a, b, c, d}, {c, b, d, f, k, l, m}, {b, c, f, g}}, "EquationForm" -> "NOR"]
Out[6]=

MouseOver (1) 

Only display the content and equation of the region beneath the cursor:

In[7]:=
ResourceFunction[
 "VennDiagram"][{{a, b, c}, {a, b, c, d}, {c, b, d, f, k, l, m}, {b, c, f, g}}, "DiagramLegends" -> "MouseOver", "EquationForm" -> "NOR"]
Out[7]=

ImageSize (1) 

Create Venn diagrams of various sizes:

In[8]:=
Table[ResourceFunction["VennDiagram"][Xor[a, b, c, d, e], ImageSize -> p], {p, {Tiny, Small, Medium}}]
Out[8]=

Possible Issues (1) 

VennDiagram requires at least 2, but no more than 5 variables or sets:

In[9]:=
ResourceFunction["VennDiagram"][a]
Out[9]=
In[10]:=
ResourceFunction["VennDiagram"][{}]
Out[10]=

Publisher

Jack Heimrath

Version History

  • 1.0.0 – 07 June 2021

Author Notes

Currently only works for expressions with 2 to 5 variables or for a list of 2 to 5 sets.

License Information