Logic and Computation Zena M. Ariola University Of Oregon Outline - - PowerPoint PPT Presentation
Logic and Computation Zena M. Ariola University Of Oregon Outline - - PowerPoint PPT Presentation
Logic and Computation Zena M. Ariola University Of Oregon Outline of Lectures Lecture 1: - calculus Minimal Propositional Logic and simply typed - calculus as deduction system and as a computation engine
Outline of Lectures
- Lecture 1:
- Minimal Propositional Logic and simply typed
- as deduction system and as a computation engine
- Hilbert axioms and Combinatory Logic
- Lecture 2:
- Second-order Propositional Logic and System F
- Classical Logic and Control effects
- Lecture 3: Sequent calculus as a logic and as a PL
- Lecture 4: Applications in compilations, execution, design and
reasoning of program
2
λ-calculus λ-calculus
The foundational crisis of mathematics
3
Georg Cantor (1845-1918)
At the beginning of the 19th center set theory was born This theory was very promising because it offered a common foundation to all the fields of mathematics.
ℛ = {x ∣ x ∉ x} ℛ ∈ ℛ ⟺ ℛ ∉ ℛ
Need of logic to define mathematics
4
Let’s devise a complete and finite set of axioms from which all true statements can be derived.
David Hilbert (1862-1943) Kurt Gödel (1906-1978)
Gödel in 1935 published his incompleteness result.
Gerhard Gentzen (1909-1945)
Gentzen introduced a formal system which modeled mathematical reasoning quite directly
Natural Deduction
Natural Deduction - Gentzen (1935)
6
Judgement:
Γ ⊢ A A, B ::= X ∣ A ⊃ B ∣ A ∧ B ∣ A ∨ B
Formulae:
If all assumptions in Γ are true then A is true
Introduction and Elimination rules
Natural deduction
7
Γ, A ` A Ax Γ ` A Γ ` B Γ ` A ^ B ^I Γ ` A ^ B Γ ` A ^E1 Γ ` A ^ B Γ ` B ^E2 Γ, A ` B Γ ` A BI Γ ` A B Γ ` A Γ ` B E Γ ` A Γ ` A _ B_I1 Γ ` B Γ ` A _ B_I2 Γ ` A _ B Γ, A ` C Γ, B ` C Γ ` C _E
Harmony (Dummett 1976)
Local Soundness shows that the elimination rules are
not too strong.
8
Γ ` A _ B Γ ` B
Local Completeness show that the elimination rules are
not too weak
Γ ` A ^ B Γ ` A
Local Soundness
Elimination rules applied to the result of an introduction rule do not produce new information.
9
Local Reductions
D Γ ` A E Γ ` B Γ ` A ^ B ^I Γ ` A ^E
⟹
B E D Γ ` A
Local Soundness
Elimination rules applied to the result of an introduction rule do not produce new information.
10
D Γ, A ` B Γ ` A B I A B I E Γ ` A ` Γ ` B E
⟹
D[E/A] Γ ` B
Local Reductions
Local Soundness
11
A A, B ` A A A A ` B (A A) I ` (A A) B (A A) I A ` A ` A A I ` B (A A) E = ) B, A ` A B ` A A I ` B (A A) I D Γ, A ` B Γ ` A B I E Γ ` A Γ ` B E E D[E/A] Γ ` B E = )
Local Completeness
The elimination rules are strong enough to get all the pieces out of a structured proposition so that they can be
- recomposed. A proof can always end with an introduction
rule.
12
Γ ` A ^ B
A B = ) Γ ` A ^ B Γ ` A ^E Γ ` A ^ B Γ ` B ^E Γ ` A ^ B ^I
Local Expansion
Local completeness
The elimination rules are strong enough to get all the pieces out of a structured proposition so that they can be
- recomposed. A proof can always end with an introduction
rule.
13
Local Expansion
A B = ) Γ, A ` A B Γ, A ` A Γ, A ` B E Γ ` A BI
Γ ` A B A
14
Caution with variables
x = 0 ` x = 0 x = 0 ` 8x.x = 0
x x x ` 8x.9y.x 6= y ` 9y.y 6= y
n
[
i=1
ai
n
Y
i=1
ai
n
X
i=1
ai lim
n!1 n2
Z 1 x2 dx
Γ ` P(x) Γ ` 8x.P(x)8I ===== x P x I Γ ` 8x.P(x) Γ ` P(M) 8E
Lambda calculus
16
First [1932] version of lambda-calculus
- Church. Postulates for the Foundations of Logic, Annals of
Mathematics, 33(2), 1932
- Church. Postulates for the Foundations of Logic,
Annals of Mathematics, 34(4), 1934. Church proposes to encode all these different notations as
- perators which take a function as parameter:
∃x . P(x) = ∃(λx . P(x)) ∀x . P(x) = ∀(λx . P(x))
There is only one mechanism to introduce a variable - Higher-order abstract syntax
Alonzo Church (1903-1995)
Church introduced the notation for the function with parameter and body .Variable is bound and can be renamed without changing the meaning of the function.
λx . e
x
e
x
Lambda calculus
17
37 axioms (36 in the revision) and 5 inference rules
λx . M =α λz . M[z/x]
(λx . M)N =β M[N/x]
M, N ::= x variable λx.M abstraction M N application &(M, N) M and N ¬(M) not M ι(M) an integer x such that M x Y (M, N) forall x. if M(x) then N(x) X (M) ∃x, Mx A(M, N) abstraction from N with respect to M
Propositions as Terms
Predicates and propositions are lambda-calculus terms Similar to logic programming today (e.g. Prolog) Predicates takes predicates in input (higher-order logic) Sets are identified with their characteristic function: The set of all x's such that x does not belong to x:
18
A ⊃ (A & A)
λx . ¬(x x)
x ∈ A = A x {x | P(x)} = λx.P x {x} = λy.x = y A ∪ B = λx.A x ∨ B x
Given
19
Lambda calculus is inconsistent
How did Church react? This is not a paradox because he did not accept excluded middle (every proposition is either true or false). R is neither
R ∈ R ⟺ R ∉ R
R = λx . ¬(x x)
R 2 R = R R = (λx.¬(x x))(λx.¬(x x)) = ¬(R R) = R 62 R
Does R contains itself?
Curry paradox (1942)
Let’s focus on implication:
20
(X (X Y)) (X Y) (1) X Y, X ` Y (MP) X, X = Y ` Y (Eq)
We define the term/proposition:
term/proposition: X = X (X Z)
X = X (X Z) (4) = (X (X Z)) (X Z) (5)
- provable:
(6) (X (X Z)) (X Z) (1) (7) X (X Z) (5) and (Eq) (8) X (4) and (Eq) (9) X Z (MP) and (7), (8) (10) Z (MP) and (8), (9) It cannot use
- calculus as a logic, if we can define the formula X! For it is
Everything is provable
Fixed point theorem
Can we define the formula
21
X = X ⊃ (X ⊃ Z)
Take
becomes the fixed point of
Fixed point theorem. For every F there exists an X such that F X = X.
- Proof. Let
D = λx . F(x x) X = D D
X = D D = F(D D) = F(X)
X = X ⊃ (X ⊃ Z)
We were looking for a proposition:
X = (λx . x ⊃ (x ⊃ Z))X
λx . x ⊃ (x ⊃ Z)
X
How to solve the problem?
Let’s get rid off the logical connectives
Computation
22
Recognize that not all terms represent propositions
Type system
Church with his students Kleene and Rosser (1935) studied the pure lambda- calculus :
23
Pure Lambda-calculus
M ::= x ∣ λx . M ∣ M M
They orient the beta-axiom:
(λx . M) N → M[N/x]
Terms represent computation:
M → M1 → M2 → ⋯ → N →
Theorem (Church-Rosser). beta-reduction is confluent
A normal form (i.e. the answer of a program) if it exists is unique
Lambda-calculus as a computational model
Church (1936), it is undecidable if a term has a normal form
Hilbert program cannot be realized
Kleene (1935) and Turing (1937) show the correspondence of the following computational models:
- Partial recursive functions
- Turing machines
- Functions defined by lambda-terms
A function
24
f : N → N
F
such that
∀n ∈ N . F ⌜n⌝ = ⌜f n⌝
is lambda-definable if there exists a term
Lambda calculus as the prototypical Functional programming language
Functional language = lambda-calculus + evaluation strategy + data structures
25
Peter Landin described ISWIM (If you See What I Mean) in The Next 700 Programming Languages, published in the Communications of the ACM in 1966.
(1930-2009)
John McCarthy designed LISP (LISt Processor) in 1958 as an implementation of lambda-calculus, but implemented substitution incorrectly
(1927-2011)
Simple Theory of Types (Church, 1940)
Types
26
Terms
M ::= x ∣ λx : σ . M ∣ M M
Static semantics
Γ, x : σ ` x : σ
Γ ` M : σ ! τ Γ ` N : σ Γ ` M N : τ Γ, x : σ ` M : τ Γ ` λx : σ.M : σ ! τ
⊢ λx . σ . λy . τ . x : σ → τ → σ
⊢ λx : σ → τ . λy : τ → ρ . λz : σ . y(xz) : (σ→τ)→(τ→ρ)→σ→ρ
⊢ λx : σ . λy : (τ→σ)→σ . y (λz : τ . x) : σ→((τ→σ)→σ)→σ σ, τ ::= ι ∣ o ∣ σ → τ ⊃: o → o → o ∀ : (ι → o) → o ⊢ a ⊃ a : o
Properties
Not every type has an inhabitant (i.e. a closed term of that type):
27
(σ → σ) → σ
Theorem (Subject reduction)
and then .
Theorem (Strong Normalization)
Γ ⊢ M : τ M → → N Γ ⊢ N : τ Γ ⊢ M : τ
there is no infinite reduction sequence starting from M
Formulae as Types
Formulae
28
σ, τ ::= b ∣ σ → τ
Types
A, B ::= X ∣ A ⊃ B
Change of perspective: formulae are not terms
Proofs as programs
If 𝜌 is a proof of formula A then 𝜌 can be represented as a lambda-calculus term
29
A ! (A ! B), A ` A ! (A ! B) A ! (A ! B), A ` A A ! (A ! B), A ` B A ! (A ! B) ` A ! B ` (A ! (A ! B)) ! A ! B
Γ, A ` A Ax Γ, A ` B Γ ` A BI Γ ` A B Γ ` A Γ ` B E Γ, x : A ` x : A Ax Γ, x : A ` M : B Γ ` λx.M : A ! B!I Γ ` M : A ! B Γ ` N : A Γ ` M N : B !E
x : A ! (A ! B), y : A ` x : A ! (A ! B) x : A ! (A ! B), y : A ` y : A x : A ! (A ! B), y : A ` x y : B x : A ! (A ! B) ` λy : A.x y : A ! B ` λx : A ! (A ! B).λy : A.x y : (A ! (A ! B)) ! A ! B
Proofs as Programs
30
There is a one-to-one correspondence: Typable terms ≈ minimal propositional logic proofs
x1 : A1, x2 : A2, ⋯, xn : An ⊢ M : A
M is a proof of A from assumptions A1, A2, ⋯, An M is a program of type A with free variables
x1, x2, ⋯, xn
- f type A1, A2, ⋯, An
What does β-reduction correspond to?
Howard (1980) observes that β-reduction corresponds to elimination of a detour (local soundness)
31
D Γ, A ` B Γ ` A ! B !i E Γ ` A Γ ` B !e = ) D[E/A] Γ ` B
Γ, x : A ` M : B Γ ` λx : A.M : A ! B Γ ` N : A Γ ` (λx : A.M) N : B = ) Γ ` M[N/x] : B
Can all the detours be eliminated from a proof? A term in normal form (i.e. without β-redexes) corresponds to a proof without detours
What does η-reduction correspond to?
32
A B ) Γ, x : A ` M : A B Γ, x : A ` x : A Γ, x : A ` M x : B !E Γ ` λx.M x : A B!I
M A B = )
Γ ` M : A ! B =
Γ ` A B = A
A B = )
Γ, A ` A B Γ, A ` A Γ, A ` B E Γ ` A BI
Extensionality witnesses local completeness
Curry-Howard isomorphism
Logic Type Theory Formula Type Proof Program Detour eliminations β-reduction Expansions Extensionality Propositional logic STLC
Is this a coincidence?
33
Conjunction and pairing
34
Γ ` A Γ ` B Γ ` A ^ B Γ ` A ^ B Γ ` A Γ ` A ^ B Γ ` B
Γ ` M : A Γ ` N : B Γ ` (M, N) : A ⇥ B Γ ` M : A ⇥ B Γ ` π1M : A Γ ` M : A ⇥ B Γ ` π2M : B
D Γ ` A E Γ ` B Γ ` A ^ B ^I Γ ` A ^E
A E )
B E D Γ ` A
N A E )
A E ) Γ ` M : A
Γ ` M : A Γ ` N : B Γ ` (M, N) : A ⇥ B ^I Γ ` π1 (M, N) : A ^E D Γ ` A ^ B = )
D Γ ` A ^ B A ^E D Γ ` A ^ B Γ ` B ^E Γ ` A ^ B ^I
Γ ` M : A ^ B M A B = ) B Γ ` M : A ^ B π1 M : A ^E Γ ` M : A ^ B Γ ` π2 M : B ^E Γ ` (π1 M, π2 M) : A ^ B ^I
Logic Type theory Local reductions Local expansions
Disjunction and union
Logic
35
- Γ ` A
Γ ` A _ B_i Γ ` B Γ ` A _ B_i Γ ` A _ B Γ, A ` C Γ, B ` C Γ ` C _e
Type theory
- Γ ` M : A
Γ ` inj1 M : A + B +i Γ ` M : B Γ ` inj2 M : A + B +i Γ ` M : A + B Γ, x1 : A ` C Γ, x2 : B ` C Γ ` case M of inj1 x1 : A ) N1 | inj2x2 ) N2 end : C +e
Local reductions
D Γ ` A Γ ` A _ B_I E Γ, A ` C Γ, B ` C Γ ` C _E = ) E[D/A] Γ ` C Γ ` M : A Γ ` inj1 M : A + B+I Γ, x1 : A ` N1 : C Γ, x2 : B ` N2 : C Γ ` case M of inj1 x1 ) N1 | inj2 x2 ) N2 end : C +E = ) Γ ` N1[M/x1]
36
Local Expansion
A B = )
D Γ ` A _ B
D Γ ` A _ B Γ, A ` A Γ, A ` A _ B_I Γ, B ` B Γ, B ` A _ B_I Γ ` A _ B _E
Γ ` M : A+B
M A B = )
M A B Γ ` M : A + B Γ, x1 : A ` x1 : A Γ, x1 : A ` inj1 x1 : A + B+I Γ, x2 : B ` x2 : B Γ, x2 : B ` inj2 x2 : A + B+I Γ ` case M of inj1 x1 ) inj1 x1 | inj2 x2 ) inj2 x2 : A + B +E
Note that the elimination follows the introduction, instead of the other way around!
Disjunction and union - Local expansion
36
Hilbert axioms
37
Hilbert axioms ≈ Typed Combinatory Logic
- D. Hilbert
(1862-1943)
A ⊃ A (1)
A ⊃ B ⊃ A (2)
(A ⊃ B ⊃ C) ⊃ (A ⊃ B) ⊃ A ⊃ C (3)
Modus Ponens
` A ((B A) A) (2) ` (A ((B A) A)) (A (B A)) A A (3) ` ((A ((B A)) (A A)) MP ` A B A (2) ` A A MP
Combinatory Logic
Terms
38
M ::= I ∣ K ∣ S ∣ M M
Axioms
I M = M K M N = M S M N P = (M P)(N P)
Types I : A → A
K : A → B → A S : (A → B → C) → (A → B) → A → C
Hilbert axioms ≈ Typed Combinatory Logic
Haskell Curry (1900-1982)
Proofs as Programs
39
` A ((B A) A) (2) ` (A ((B A) A)) (A (B A)) A A (3) ` ((A ((B A)) (A A)) MP ` A B A (2) ` A A MP ` K : A ((B A) A) ` S : (A ((B A) A)) (A (B A)) A A ` S K : ((A ((B A)) (A A)) ` K : A B A ` S K K : A A