In [ ]:
%autosave 0
%matplotlib inline
Please install matplotlib-venn package in Anaconda before executing Python scripts in this notebook.
$ conda install -c conda-forge matplotlib-venn
Example:
All humans are mortal ($P_1$). Socrates is human ($P_2$). Therefore: Socrates is mortal ($C$).
This is a typical Syllogism.
In [ ]:
# Draw benn diaglam of Socrates
from matplotlib import pyplot as plt
from matplotlib_venn import venn3, venn3_circles
s = (
0, # Abc
0, # aBc
0, # ABc
4, # abC
0, # AbC
2, # aBC
0.2, # ABC
)
v = venn3(subsets=s, set_labels=('Socrates', '', ''))
# Subset labels
# v.get_label_by_id('100').set_text('')
# v.get_label_by_id('010').set_text('aBc')
#v.get_label_by_id('110').set_text('Human')
v.get_label_by_id('001').set_text('Mortal')
# v.get_label_by_id('101').set_text('aBc')
v.get_label_by_id('011').set_text('Human')
v.get_label_by_id('111').set_text('')
# Subset colors
# v.get_patch_by_id('100').set_color('c')
# v.get_patch_by_id('010').set_color('#993333')
# v.get_patch_by_id('110').set_color('blue')
# Subset alphas
# v.get_patch_by_id('101').set_alpha(0.4)
# v.get_patch_by_id('011').set_alpha(1.0)
# v.get_patch_by_id('111').set_alpha(0.7)
# Border styles
#c = venn3_circles(subsets=s, linestyle='solid')
#c[0].set_ls('dotted') # Line style
#c[1].set_ls('dashed')
#c[2].set_lw(1.0) # Line width
plt.show()
Natural language is not so strict and we need to take care of the meaning of the statement.
When we say A is B in natural language, it can be following meaning, but in Logic, it shall be treated as 1.
IF A then B and A is a sebset of B can be treated same as A is B.
In natural English, SOME means about 5, at least more than one. In Logic, SOME means 1 or more (Exist)
Also in natural English, Some of A is B implys Some of A is not B. But in Logic, no imply.
Some A is B is true even if All of A is B is true.
There is no intersection(overlap) between A and B. $$A \Rightarrow (\lnot B) \\ B \Rightarrow (\lnot A) \\ A \land B = False \\ A \cap B = \emptyset$$
means that $A \cap (\lnot B) \neq \emptyset$
In natural language, this may be understood as follows. In Logic is shall be 2.. It denys "All cave dwellers are intelligent".
http://www.harryhiker.com/lc/docs/pretest.pdf
Therefore:
In [ ]:
# Draw benn diaglam of Socrates
from matplotlib import pyplot as plt
from matplotlib_venn import venn3, venn3_circles
s = (
1, # Abc
0, # aBc
0, # ABc
2, # abC
0.5, # AbC
1, # aBC
0.5, # ABC
)
v = venn3(subsets=s, set_labels=('', '', ''))
# Subset labels
v.get_label_by_id('100').set_text('Dweller')
# v.get_label_by_id('010').set_text('aBc')
# v.get_label_by_id('110').set_text('')
v.get_label_by_id('001').set_text('Intelli')
v.get_label_by_id('101').set_text('')
v.get_label_by_id('011').set_text('Fire, P2')
v.get_label_by_id('111').set_text('P1')
# Subset colors
v.get_patch_by_id('100').set_color('c')
# v.get_patch_by_id('010').set_color('#993333')
v.get_patch_by_id('101').set_color('white')
# Subset alphas
# v.get_patch_by_id('101').set_alpha(0.4)
# v.get_patch_by_id('011').set_alpha(1.0)
v.get_patch_by_id('111').set_alpha(0.7)
plt.show()
In [ ]:
from matplotlib import pyplot as plt
from matplotlib_venn import venn3, venn3_circles
s = (
1, # Abc
0, # aBc
0, # ABc
2, # abC
0.5, # AbC
1, # aBC
0.5, # ABC
)
v = venn3(subsets=s, set_labels=('You', '', ''))
# Subset labels
v.get_label_by_id('100').set_text('P2')
# v.get_label_by_id('010').set_text('aBc')
# v.get_label_by_id('110').set_text('')
v.get_label_by_id('001').set_text('Late')
v.get_label_by_id('101').set_text('')
v.get_label_by_id('011').set_text('Sleep, P1')
v.get_label_by_id('111').set_text('P1')
# Subset colors
v.get_patch_by_id('100').set_color('c')
# v.get_patch_by_id('010').set_color('#993333')
v.get_patch_by_id('101').set_color('white')
# Subset alphas
# v.get_patch_by_id('101').set_alpha(0.4)
# v.get_patch_by_id('011').set_alpha(1.0)
# v.get_patch_by_id('111').set_alpha(0.7)
plt.show()
In [ ]:
from matplotlib import pyplot as plt
from matplotlib_venn import venn2
s = (
1, # Ab
1, # aB
0.00001 # AB
)
v = venn2(subsets=s, set_labels=('', '', ''))
# Subset labels
v.get_label_by_id('10').set_text('Murder')
v.get_label_by_id('01').set_text('Given Bail')
v.get_label_by_id('11').set_text('')
# v.get_label_by_id('111').set_text('')
plt.show()
In [ ]:
from matplotlib import pyplot as plt
from matplotlib_venn import venn3, venn3_circles
s = (
1, # Abc
0, # aBc
0, # ABc
2, # abC
0.5, # AbC
1, # aBC
0, # ABC
)
v = venn3(subsets=s, set_labels=('', 'No Bail', ''))
# Subset labels
v.get_label_by_id('100').set_text('Smith, P2')
# v.get_label_by_id('010').set_text('aBc')
# v.get_label_by_id('110').set_text('')
v.get_label_by_id('001').set_text('')
v.get_label_by_id('101').set_text('')
v.get_label_by_id('011').set_text('Murder, P1')
# v.get_label_by_id('111').set_text('')
# Subset colors
v.get_patch_by_id('100').set_color('c')
# v.get_patch_by_id('010').set_color('#993333')
v.get_patch_by_id('101').set_color('white')
# Subset alphas
# v.get_patch_by_id('101').set_alpha(0.4)
# v.get_patch_by_id('011').set_alpha(1.0)
# v.get_patch_by_id('111').set_alpha(0.7)
plt.show()
Therefore:
In [ ]:
from matplotlib import pyplot as plt
from matplotlib_venn import venn3, venn3_circles
s = (
1, # Abc
0, # aBc
0, # ABc
2, # abC
0.5, # AbC
1, # aBC
0.5, # ABC
)
v = venn3(subsets=s, set_labels=('', '', ''))
# Subset labels
v.get_label_by_id('100').set_text('some court')
# v.get_label_by_id('010').set_text('aBc')
# v.get_label_by_id('110').set_text('')
v.get_label_by_id('001').set_text('Not impartial')
v.get_label_by_id('101').set_text('')
v.get_label_by_id('011').set_text('evidence, P1')
v.get_label_by_id('111').set_text('P1, P2')
# Subset colors
v.get_patch_by_id('100').set_color('c')
# v.get_patch_by_id('010').set_color('#993333')
v.get_patch_by_id('101').set_color('white')
# Subset alphas
# v.get_patch_by_id('101').set_alpha(0.4)
# v.get_patch_by_id('011').set_alpha(1.0)
v.get_patch_by_id('111').set_alpha(0.7)
plt.show()
Therefore:
As for relation between Revolution and Financial Anxiety, there are 2 possible combinations. See below.
In [ ]:
from matplotlib import pyplot as plt
from matplotlib_venn import venn3, venn3_circles
s = (
1, # Abc
0, # aBc
0, # ABc
2, # abC
0.5, # AbC
1, # aBC
0.5, # ABC
)
v = venn3(subsets=s, set_labels=('', '', ''))
# Subset labels
v.get_label_by_id('100').set_text('Financial Anxiety')
# v.get_label_by_id('010').set_text('aBc')
# v.get_label_by_id('110').set_text('')
v.get_label_by_id('001').set_text('Trade disruption')
v.get_label_by_id('101').set_text('P2')
v.get_label_by_id('011').set_text('Revolution P1')
v.get_label_by_id('111').set_text('P1, P2')
# Subset colors
v.get_patch_by_id('100').set_color('c')
# v.get_patch_by_id('010').set_color('#993333')
v.get_patch_by_id('111').set_color('white')
# Subset alphas
# v.get_patch_by_id('101').set_alpha(0.4)
# v.get_patch_by_id('011').set_alpha(1.0)
v.get_patch_by_id('111').set_alpha(0.7)
plt.show()
In [ ]:
from matplotlib import pyplot as plt
from matplotlib_venn import venn3, venn3_circles
s = (
1, # Abc
0, # aBc
0, # ABc
2, # abC
0.5, # AbC
1, # aBC
0, # ABC
)
v = venn3(subsets=s, set_labels=('', '', 'Trade disruption'))
# Subset labels
v.get_label_by_id('100').set_text('Financial Anxiety')
# v.get_label_by_id('010').set_text('aBc')
# v.get_label_by_id('110').set_text('')
v.get_label_by_id('001').set_text('')
v.get_label_by_id('101').set_text('P2')
v.get_label_by_id('011').set_text('Revolution P1')
# v.get_label_by_id('111').set_text('')
# Subset colors
v.get_patch_by_id('100').set_color('c')
# v.get_patch_by_id('010').set_color('#993333')
# v.get_patch_by_id('110').set_color('blue')
# Subset alphas
# v.get_patch_by_id('101').set_alpha(0.4)
# v.get_patch_by_id('011').set_alpha(1.0)
# v.get_patch_by_id('111').set_alpha(0.7)
plt.show()
Therefore:
In [ ]:
from matplotlib import pyplot as plt
from matplotlib_venn import venn3, venn3_circles
s = (
1, # Abc
0, # aBc
0, # ABc
2, # abC
0, # AbC
1, # aBC
0, # ABC
)
v = venn3(subsets=s, set_labels=('P2', '', ''))
# Subset labels
v.get_label_by_id('100').set_text('Safe Pilot')
# v.get_label_by_id('010').set_text('aBc')
# v.get_label_by_id('110').set_text('')
v.get_label_by_id('001').set_text('Faint')
# v.get_label_by_id('101').set_text('')
v.get_label_by_id('011').set_text('Lost Blood, P1')
# v.get_label_by_id('111').set_text('')
# Subset colors
v.get_patch_by_id('100').set_color('c')
# v.get_patch_by_id('010').set_color('#993333')
# v.get_patch_by_id('110').set_color('blue')
# Subset alphas
# v.get_patch_by_id('101').set_alpha(0.4)
# v.get_patch_by_id('011').set_alpha(1.0)
# v.get_patch_by_id('111').set_alpha(0.7)
plt.show()
Therefore:
From Premise $P_1$ and $P_3$, we can make a new premise, and discard $P_1$ and $P_3$.
In [ ]:
from matplotlib import pyplot as plt
from matplotlib_venn import venn2
s = (
1, # Ab
0, # aB
0.3 # AB
)
v = venn2(subsets=s, set_labels=('', '', ''))
# Subset labels
v.get_label_by_id('10').set_text('with/wo Proof')
v.get_label_by_id('01').set_text('')
v.get_label_by_id('11').set_text('Knowledge, P1')
# v.get_label_by_id('111').set_text('')
plt.show()
In [ ]:
from matplotlib import pyplot as plt
from matplotlib_venn import venn3, venn3_circles
s = (
1, # Abc
1, # aBc
0.5, # ABc
1, # abC
0.5, # AbC
0, # aBC
0.0001, # ABC
)
v = venn3(subsets=s, set_labels=('', '', ''))
# Subset labels
v.get_label_by_id('100').set_text('')
v.get_label_by_id('010').set_text('Some: No proof')
v.get_label_by_id('110').set_text('P1,P3')
v.get_label_by_id('001').set_text('Every: with proof, P2')
v.get_label_by_id('101').set_text('P1,P2,P3')
#v.get_label_by_id('011').set_text('')
v.get_label_by_id('111').set_text('')
# Subset colors
v.get_patch_by_id('100').set_color('white')
# v.get_patch_by_id('010').set_color('#993333')
v.get_patch_by_id('001').set_color('red')
#v.get_patch_by_id('011').set_color('red')
#v.get_patch_by_id('111').set_color('red')
v.get_patch_by_id('101').set_color('red')
# Subset alphas
# v.get_patch_by_id('101').set_alpha(0.4)
# v.get_patch_by_id('011').set_alpha(1.0)
# v.get_patch_by_id('111').set_alpha(0.7)
plt.show()
Therefore:
In [ ]:
from matplotlib import pyplot as plt
from matplotlib_venn import venn3, venn3_circles
s = (
2, # Abc
2, # aBc
0, # ABc
1, # abC
0.5, # AbC
0.5, # aBC
0, # ABC
)
v = venn3(subsets=s, set_labels=('', '', ''))
# Subset labels
v.get_label_by_id('100').set_text('des-help, P1')
v.get_label_by_id('010').set_text('r-sacri, P1')
# v.get_label_by_id('110').set_text('')
v.get_label_by_id('001').set_text('Maso,P2')
v.get_label_by_id('101').set_text('')
v.get_label_by_id('011').set_text('')
#v.get_label_by_id('111').set_text('P1, P2')
# Subset colors
v.get_patch_by_id('100').set_color('c')
# v.get_patch_by_id('010').set_color('#993333')
v.get_patch_by_id('101').set_color('white')
# Subset alphas
# v.get_patch_by_id('101').set_alpha(0.4)
# v.get_patch_by_id('011').set_alpha(1.0)
# v.get_patch_by_id('111').set_alpha(0.7)
plt.show()
Therefore
In [ ]:
# Problem-10 P1 and P2
from matplotlib import pyplot as plt
from matplotlib_venn import venn3, venn3_circles
s = (
2, # Abc
2, # aBc
0, # ABc
0, # abC
0, # AbC
0.7, # aBC
0, # ABC
)
v = venn3(subsets=s, set_labels=('', '', ''))
# Subset labels
v.get_label_by_id('100').set_text('Animal, P2')
v.get_label_by_id('010').set_text('Lang user, P1,P2')
# v.get_label_by_id('110').set_text('')
#v.get_label_by_id('001').set_text('Maso,P2')
#v.get_label_by_id('101').set_text('')
v.get_label_by_id('011').set_text('Generalize P1')
#v.get_label_by_id('111').set_text('P1, P2')
# Subset colors
v.get_patch_by_id('100').set_color('c')
# v.get_patch_by_id('010').set_color('#993333')
#v.get_patch_by_id('101').set_color('white')
# Subset alphas
# v.get_patch_by_id('101').set_alpha(0.4)
# v.get_patch_by_id('011').set_alpha(1.0)
# v.get_patch_by_id('111').set_alpha(0.7)
plt.show()
In [ ]:
# Problem-10 (P1+P2) and P3
from matplotlib import pyplot as plt
from matplotlib_venn import venn3, venn3_circles
s = (
1, # Abc
2, # aBc
1, # ABc
2, # abC
1, # AbC
0, # aBC
0, # ABC
)
v = venn3(subsets=s, set_labels=('', '', ''))
# Subset labels
v.get_label_by_id('100').set_text('Reason')
v.get_label_by_id('010').set_text('Generalize')
v.get_label_by_id('110').set_text('')
v.get_label_by_id('001').set_text('Animal')
v.get_label_by_id('101').set_text('P3')
# v.get_label_by_id('011').set_text('')
#v.get_label_by_id('111').set_text('P1, P2')
# Subset colors
v.get_patch_by_id('100').set_color('c')
# v.get_patch_by_id('010').set_color('#993333')
v.get_patch_by_id('110').set_color('white')
# Subset alphas
# v.get_patch_by_id('101').set_alpha(0.4)
# v.get_patch_by_id('011').set_alpha(1.0)
# v.get_patch_by_id('111').set_alpha(0.7)
plt.show()
When thinkging about the relationship between 2 statements $A$ and $B$, using Benn Diagram, and logic fomula makes it clear.
In [ ]:
# A is B
from matplotlib import pyplot as plt
from matplotlib_venn import venn2
s = (
1, # Ab
0, # aB
0.3 # AB
)
v = venn2(subsets=s, set_labels=('(All)A is B; if A then B', '', ''))
# Subset labels
v.get_label_by_id('10').set_text('B')
v.get_label_by_id('01').set_text('')
v.get_label_by_id('11').set_text('A')
# v.get_label_by_id('111').set_text('')
plt.show()
In [ ]:
# A is equivalent to B
from matplotlib import pyplot as plt
from matplotlib_venn import venn2
s = (
0, # Ab
0, # aB
1 # AB
)
v = venn2(subsets=s, set_labels=('', '', 'A is equivalent to B'))
# Subset labels
v.get_label_by_id('10').set_text('')
v.get_label_by_id('01').set_text('')
v.get_label_by_id('11').set_text('A and B')
plt.show()
In [ ]:
# Some A is B
from matplotlib import pyplot as plt
from matplotlib_venn import venn2
s = (
1, # Ab
1, # aB
0.3 # AB
)
v = venn2(subsets=s, set_labels=('Some A is B', '', ''))
# Subset labels
v.get_label_by_id('10').set_text('A but Not B')
v.get_label_by_id('01').set_text('B')
v.get_label_by_id('11').set_text('A and B')
plt.show()
In [ ]:
# No A is B
from matplotlib import pyplot as plt
from matplotlib_venn import venn2
s = (
1, # Ab
1, # aB
0 # AB
)
v = venn2(subsets=s, set_labels=('No A is B', '', ''))
# Subset labels
v.get_label_by_id('10').set_text('A')
v.get_label_by_id('01').set_text('B')
#v.get_label_by_id('11').set_text('Some A')
plt.show()