Logic
A method of making a conclusion from
given premises using the concept of Truth
Slide 3
Slide 3 text
! NSSpain is iOS Conference
iOS Conference is Awesome
Therefore,
! NSSpain is Awesome
Slide 4
Slide 4 text
If A then B
If B then C
Therefore, if A then C
Slide 5
Slide 5 text
Q. Is this always true?
Slide 6
Slide 6 text
I am Gorilla
Gorilla is Handsome
Therefore,
I am Handsome
Slide 7
Slide 7 text
No content
Slide 8
Slide 8 text
What is True?
How should we define
“correctness” more precisely?
Slide 9
Slide 9 text
Separate the definition of “correctness”
1. Form (Syntax)
2. Meaning (Semantics)
Slide 10
Slide 10 text
Syntax
Using symbolic formulas and inference rules
to systematically deduce a new formula
Slide 11
Slide 11 text
Patterns of Formula
If A then B
A and B
A or B
not A
A → B
A ∧ B
A ∨ B
¬A
Slide 12
Slide 12 text
Symbols in Formula
Operators
Variables
Constants
∧ , ∨ , ¬, →
A, B, C, ⋯
⊤ , ⊥
Slide 13
Slide 13 text
Examples of Formula
A ∧ (B → C)
(A ∨ B) ∧ (C → D)
(¬A → ⊥ ) ∨ (¬B ∧ ⊤ )
Slide 14
Slide 14 text
Example of Inference Rule: Modus Ponens
A → B A
B Inference Rules
as a part of
axiomatic system
Premise 1: If A then B
Premise 2: A
Conclusion: B
Slide 15
Slide 15 text
Example of Proof Tree
Slide 16
Slide 16 text
Semantics
Interpreting the meaning of formula
by assigning truth value (true or false)
Slide 17
Slide 17 text
Truth Table (Interpretation of the formula)
A B ¬A A∧B A∨B A→B
1 1 0 1 1 1
1 0 0 0 1 0
0 1 1 0 1 1
0 0 1 0 0 1
Valuation
A → B
A ∧ B
A ∨ B
¬A
Slide 18
Slide 18 text
Example of Truth Table
A B ¬A ¬A∨B A→B (¬A∨B) → (A→B) (A→B) → (¬A∨B)
1 1 0 1 1 1 1
1 0 0 0 0 1 1
0 1 1 1 1 1 1
0 0 1 1 1 1 1
Some formulas
are always 1 (true)
Slide 19
Slide 19 text
(A → B) ↔ (¬A ∨ B)
Tautology:
Formulas that are always true
in every possible interpretation
P ↔ Q := (P → Q) ∧ (Q → P)
Slide 20
Slide 20 text
Examples of Tautology
A → A
Law of Identity
A ∨ ¬A
Law of
Excluded Middle
Slide 21
Slide 21 text
Examples of Tautology
(A → B) → ((B → C) → (A → C))
((((A → B) → (¬C → ¬D)) → C) → E) → ((E → A) → (D → A))
¬(A ∧ ¬A) (A ∧ ¬A) → B
((A → B) → A) → A
¬¬A → A
(A → B) ↔ (¬B → ¬A)
¬(A ∧ B) ↔ (¬A ∨ ¬B) ¬(A ∨ B) ↔ (¬A ∧ ¬B)
Slide 22
Slide 22 text
(A → B) → ((B → C) → (A → C))
((((A → B) → (¬C → ¬D)) → C) → E) → ((E → A) → (D → A))
¬(A ∧ ¬A) (A ∧ ¬A) → B
((A → B) → A) → A
¬¬A → A
(A → B) ↔ (¬B → ¬A)
¬(A ∧ B) ↔ (¬A ∨ ¬B) ¬(A ∨ B) ↔ (¬A ∧ ¬B)
Examples of Tautology
Law of
Contradiction
Principle of
Explosion
Double Negation
Elimination
Peirce’s Law
Law of
Contraposition
De Morgan’s Laws
Transitive Law
Meredith’s Axiom
Slide 23
Slide 23 text
Examples of Tautology
There are infinite number of tautologies…
Can we abstract into a finite subset as a basis?
A → ¬¬A
A → ¬¬¬¬A
A → ¬¬¬¬¬¬A ⋯
Slide 24
Slide 24 text
Building
Formal System
Slide 25
Slide 25 text
Formal System
Axiom l Base premises (part of tautologies)
Inference Rules l Deduces new formula
from existing ones
Using Axioms and Inference Rules to
deduce Theorem (all possible tautologiesʣ
Slide 26
Slide 26 text
Styles of Formal System
•Gentzen Style l Many inference rules
•Natural Deduction l + No axioms
•Sequent Calculus l + 1 axiom (identity)
•Hilbert Style
•Many axioms + 1 inference rule (modus ponens)
Slide 27
Slide 27 text
Gentzen Natural Deduction
A B
A ∧ B
A ∧ B
A
A ∧ B
B
A
A ∨ B
B
A ∨ B
A ∨ B C C
C
A → B A
B
B
A → B
⊥
¬A
A ¬A
⊥
⊥
A
⋮
[A]
¬¬A
A
⋮
[A]
⋮
[B]
⋮
[A]
Slide 28
Slide 28 text
Hilbert Style A → B A
B
B → (A → B)
(A → (B → C)) → ((A → B) → (A → C))
¬¬A → A
A → A ∨ B ⊥ → A
B → A ∨ B
(A → C) → ((B → C) → ((A ∨ B) → C))
A ∧ B → A
A ∧ B → B
A → (B → (A ∧ B))
(A → ¬A) → ¬A
¬A → (A → B)
Modus ponens
is the only available
inference rule
Hilbert Style
B → (A → B)
(A → (B → C)) → ((A → B) → (A → C))
A → A ∨ B
B → A ∨ B
(A → C) → ((B → C) → ((A ∨ B) → C))
A ∧ B → A
A ∧ B → B
A → (B → (A ∧ B))
A → B A
B
Modus ponens
is the only available
inference rule
¬¬A → A
⊥ → A
(A → ¬A) → ¬A
¬A → (A → B)
Slide 38
Slide 38 text
(A → C) → ((B → C) → ((A ∨ B) → C))
A → A ∨ B
B → A ∨ B
A ∧ B → A
A ∧ B → B
A → (B → (A ∧ B))
¬¬A → A
⊥ → A
(A → ¬A) → ¬A
¬A → (A → B)
Hilbert Style A → B A
B
Modus ponens
is the only available
inference rule
(A → (B → C)) → ((A → B) → (A → C))
A ∨ B := ¬A → B := ¬B → A
A ∧ B := ¬(A → ¬B) := ¬(B → ¬A)
¬A := A → ⊥
NOTE: ∨, ∧, ¬ can be rewritten using → and ⊥ only
B → (A → B)
Slide 39
Slide 39 text
Combinatory Logic
Kxy = x
Sxyz = xz(yz)
I = SKK
K : X → Y → X
S : (Z → Y → X) → (Z → Y) → Z → X
I : X → X
((A → B) → A) → A
A ∨ ¬A
¬¬A → A
¬(A ∧ B) → (¬A ∨ ¬B)
(A → B) → (¬A ∨ B)
(¬B → ¬A) → (A → B)
Law of Excluded Middle
Double Negation Elimination
(One of)
Law of Contraposition
(One of) De Morgan’s Law
Material Implication
Peirce’s Law
NOTE:
Converse
is
tautology
Tautologies that can’t be implemented in Swift
Curry-Howard Correspondence
Intuitionistic Logic Swift Programming
Proposition Type
Proof Program
→ Introduction Function / Closure
Modus Ponens Function Application
Axiom Global Variable
Assumption Free Variable
Discharged Assumption Bound Variable
Slide 55
Slide 55 text
Intuitionistic Logic
Interpreting the meaning of formula
by assigning truth value for each possible world
Slide 56
Slide 56 text
Possible World in Intuitionistic Logic
A 0
B 0
A 1
B 0
A 1
B 1
Slide 57
Slide 57 text
Inheritance of truth value
A 0
B 0
A 1
B 0
A 1
B 0
A = 1 will be
inherited to future
(Never becomes A = 0)
New Theorem
Slide 58
Slide 58 text
Inheritance of truth value
A 0
¬A 0
A 0
¬A 1
A 0
¬A 1
If ¬A = 1,
A = 0 from now & future
(Never becomes A = 1)
inherit
Slide 59
Slide 59 text
Inheritance of truth value
A 0
¬A 0
A 0
¬A 1
A 0
¬A 1
If ¬A = 1,
A = 0 from now & future
(Never becomes A = 1)
JOIFSJU
A 0
¬A 0
A ∨ ¬A
Slide 60
Slide 60 text
Inheritance of truth value
A → B 1
A 0
B 0
A → B 1
A 1
B 1
A → B 1
A 1
B 1
inherit
If A = 1, B = 1
can also be obtained
Never becomes
A = 1, B = 0
Slide 61
Slide 61 text
Inheritance of truth value
"͕ಘΒΕΔͱɺ
#ࣗಈతʹಘΒΕΔ
A 0
B 0
A 1
B 0
A 1
B 1
A 0
B 1
Slide 62
Slide 62 text
Kripke Semantics
• Kripke Frame l Ordered set of possible world
e.g. → →
• Kripke Model l Assigning inheriting truth value
for every possible world on the Frame
• Tautology in Intuitionistic Logic
… For any frame and for any valuation (= for any model),
formula is always true
"͕ಘΒΕΔͱɺ
#ࣗಈతʹಘΒΕΔ
Slide 63
Slide 63 text
Classical Logic ⊂ Intuitionistic Logic
Minimal
Intuitionistic
Classical
A ∨ ¬A
⊥ → A
→ , ∧ , ∨ , ¬, ⊥
Formulas using
A → A ∨ B
A ∧ B → A
Law of
Contradiction
Law of
Excluded Middle
⋮
NOTE: Doesn’t mean Intuitionistic Logic owns Law of Excluded Middle ”directly” (See next slide)
Slide 64
Slide 64 text
Glivenko’s Theorem: Classical to Intuitionistic Embedding
Intuitionistic
Classical
A ∨ ¬A ¬¬(A ∨ ¬A)
¬¬
Double
Negation
Translation
Law of
Excluded Middle
Double-negated
Excluded Middle
Slide 65
Slide 65 text
((A → B) → A) → A
A ∨ ¬A
¬¬A → A
¬(A ∧ B) → (¬A ∨ ¬B)
(A → B) → (¬A ∨ B)
(¬B → ¬A) → (A → B)
Law of Excluded Middle
Double Negation Elimination
(One of)
Law of Contraposition
(One of) De Morgan’s Law
Material Implication
Peirce’s Law
NOTE:
Converse
is
tautology
Tautologies that can’t be implemented in Swift
Slide 66
Slide 66 text
¬¬(((A → B) → A) → A)
¬¬(A ∨ ¬A)
¬¬(¬¬A → A)
¬¬(¬(A ∧ B) → (¬A ∨ ¬B))
¬¬((A → B) → (¬A ∨ B))
¬¬((¬B → ¬A) → (A → B))
Tautologies in Intuitionistic Logic
Adding
double-negation
will hold in
Intuitionistic
Logic!
Slide 67
Slide 67 text
¬¬((A → B) → A) → ¬¬A
¬¬(A ∨ ¬A)
¬¬¬¬A → ¬¬A
¬¬¬(A ∧ B) → ¬¬(¬A ∨ ¬B)
¬¬(A → B) → ¬¬(¬A ∨ B)
¬¬(¬B → ¬A) → ¬¬(A → B)
Tautologies in Intuitionistic Logic
Using
helper rule
¬¬(A → B)
¬¬A → ¬¬B
Peirce’s Law → Call with Current Continuation
¬¬(A → B)
¬¬A → ¬¬B
((A → ¬¬B) → ¬¬A) → ¬¬A
Here, are used to gain
¬¬(A → B)
A → ¬¬B
¬¬(((A → B) → A) → A) Peirce’s Law
Recap
•Syntax and Semantics
•Tautology as “always true” formula
•Formal System: Axioms and Inference Rules
•Intuitionistic Logic 㱻 Swift Programming (Curry-Howard)
•Writing Law of Excluded Middle in Swift (Glivenko)
•Learning Logic will help understand Swift’s type (system)