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

Logic

Terminology

  • Statement: (Proposition). a sentence that is either True or False. (e.g. "A is B")
  • Premise: Precondition (Assumption). Statement that provide reason or support for conclution.
  • Conclution: a statement that the argument is trying to prove.
  • Argument: a group of statements that include one or more premises and 1 conclusion.

Example:

All humans are mortal ($P_1$). Socrates is human ($P_2$). Therefore: Socrates is mortal ($C$).

  • Argument: $P_1 \land P_2 \Rightarrow C$
  • Premise: $P_1$, $P_2$
  • Conclusion $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()

Logic and Natural Language

Natural language is not so strict and we need to take care of the meaning of the statement.

A is B

When we say A is B in natural language, it can be following meaning, but in Logic, it shall be treated as 1.

  1. All A is B, but some B may not be A. $A \Rightarrow B$
  2. All A is B, and All B is A. $A \Leftrightarrow B$
  3. Most of (Some) A is B

IF A then B and A is a sebset of B can be treated same as A is B.

Some

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.

No A is B

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$$

Not All A is B

means that $A \cap (\lnot B) \neq \emptyset$

  • Not all cave dwellers are intelligent

In natural language, this may be understood as follows. In Logic is shall be 2.. It denys "All cave dwellers are intelligent".

  1. There is no intelligent cave dweller
  2. There are 1 or more non-intelligent cave dwellers

Easy to mistake in Logic

  • The reverse is not always True. A is B, does not always mean, B is A.
  • True/False is just a symbol. Premise is a just assumption (IF ... is True). e.g. Apple is Red, forget about Green apple and assume that all apples are red.
  • If a statement is True, its contraposition is True. If a statement is False, its contraposition is False. And vise verse. ($A \Rightarrow B) \equiv (\lnot B \Rightarrow \lnot A$)

Logic Pretest

http://www.harryhiker.com/lc/docs/pretest.pdf

Problem 1

  • $P_1$: Some dwellers use fire
  • $P_2$: All who use fire have intelligence

Therefore:

  1. All cave dwellers have intelligence.
  2. All who have intelligence use fire.
  3. Some cave dwellers have intelligence.
  4. None of these validly follows.

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()

Problem 2

  • $P_1$: If you overslept, you'll be late
  • $P_2$: You aren't late

Therefore:

  1. You did oversleep
  2. You didn't oversleep
  3. You're late
  4. None of these validly follows

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()

Problem 3

  • $P_1$: No one held for murder is given bail
  • $P_2$: Smith isn't held for murder

Therefore:

  1. Smith is given bail
  2. Smith isn't given bail
  3. Smith is innocent
  4. None of these validly follows

M: (Held for murder), B: (is given bail) $$(M \cap B = \emptyset) \equiv (M \rightarrow \lnot B)$$


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()

Problem 4

  • $P_1$: No court that suppresses evidence is impartial
  • $P_2$: Some court subject to politicalpressure suppress evidence

Therefore:

  1. Some courts subject to political pressure aren't impartial
  2. No courts subject to political pressure are impartial
  3. Some courts subject to political pressure are impartial
  4. None of these validly follows

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()

Problem 5

If you overslept, you'll be late $P_1$. You didn't oversleep $P_2$. Therefore:

  1. You're late
  2. You aren't late
  3. You did oversleep
  4. None of these validly follows

(see the diagram of Problem 2)

Problem 6

  • $P_1$: Every revolution is a trade disruption
  • $P_2$: Some trade disruptions cause financial anxiety

Therefore:

  1. Some revolutions cause financial anxiety
  2. Some revolutions don't cause financial anxiety
  3. All trade disruptions cause financial anxiety
  4. Non of above validly follows

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()

Problem 7

  • $P_1$: Anyone who has just lost a lot of blood is likely to faint
  • $P_2$: No one who is likely to faint is a safe pilot

Therefore:

  1. Everyone who has just lost a lot of blood is a safe pilot
  2. No one who has just lost a lot of blood is a safe pilot
  3. All safe pilots have just lost a lot of blood
  4. None of these validly follows

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()

Problem 8

  • $P_1$: If there's knowledge, then either some things are known without proof or we can prove every premise by previous arguments infinitely
  • $P_2$: We can't prove every premise by previous arguments infinitely
  • $P_3$: There's knowledge

Therefore:

  1. Everything that's known is provable
  2. There's no knowledge
  3. Some things are known without proof
  4. None of these validly follows

From Premise $P_1$ and $P_3$, we can make a new premise, and discard $P_1$ and $P_3$.

  • $P_4$: Either some things are known without proof or we can prove every premise by previous arguments infinitely

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()

Problem 9

  • $P_1$: No person desiring to help others is reluctant to make scrifices
  • $P_2$: Some masochists aren't reluctant to make sacrifices

Therefore:

  1. Some masochists desire to help others
  2. Some masochists don't desire to help others
  3. All masochists desire to help others
  4. None of these validly follows

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()

Problem 10

  • $P_1$: Only language users employ generalizations
  • $P_2$: Not a single animal uses language
  • $P_3$: At least some animal reason

Therefore

  1. Not all reasoning beings employ generalizations
  2. Only reasoning beings employ generalizations
  3. No reasoning beings employ generalizations
  4. None of these validly follows

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()

All, Not All, Exist, Not Exist

When thinkging about the relationship between 2 statements $A$ and $B$, using Benn Diagram, and logic fomula makes it clear.

  • A is B, If A then B: $$\forall _x(A(_x) \Rightarrow B(_x)) \\ A \Rightarrow B$$
  • A is B and B is A: $$\forall _x(A(_x) \Leftrightarrow B(_x))$$
  • Some A is B: $$\exists _x(A(_x) \Rightarrow B(_x)) \\ \exists _x(A(_x) \land B(_x))$$
  • A is not B: $$\lnot \exists _x(A(_x) \Rightarrow B(_x)) \\ \lnot \exists _x(A(_x) \land B(_x))$$
  • Not all A is B: $$\lnot \forall _x(A(_x) \Rightarrow B(_x)) \\ \exists _x(A(_x) \Rightarrow \lnot B(_x)) \\ \exists _x(A(_x) \land \lnot B(_x))$$

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()