Logic and Computation Lecture 2 Zena M. Ariola University of - - PowerPoint PPT Presentation

logic and computation
SMART_READER_LITE
LIVE PREVIEW

Logic and Computation Lecture 2 Zena M. Ariola University of - - PowerPoint PPT Presentation

Logic and Computation Lecture 2 Zena M. Ariola University of Oregon 24th Estonian Winter School in Computer Science, EWSCS 19 Curry-Howard isomorphism A correspondence between minimal propositional logic and simply typed lambda-calculus


slide-1
SLIDE 1

Logic and Computation

Lecture 2

Zena M. Ariola

University of Oregon

24th Estonian Winter School in Computer Science, EWSCS ’19

slide-2
SLIDE 2

Curry-Howard isomorphism

A correspondence between minimal propositional logic and simply typed lambda-calculus Types (→, +, ×) are Propositions (→, ∧, ∨) Terms are Proofs Computation is Eliminations of detours Extensionality is Expansion A system is both a programming language and a logic (Coq, Agda, Idris)

slide-3
SLIDE 3

Outline

Extend the isomorphism to more expressive systems

slide-4
SLIDE 4

Outline

Extend the isomorphism to more expressive systems Logic Type Theory Second-order propositional logic Polymorphism

slide-5
SLIDE 5

Outline

Extend the isomorphism to more expressive systems Logic Type Theory Second-order propositional logic Polymorphism Intuitionistic logic λ-calculus + Abort

slide-6
SLIDE 6

Outline

Extend the isomorphism to more expressive systems Logic Type Theory Second-order propositional logic Polymorphism Intuitionistic logic λ-calculus + Abort Classical logic λ-calculus + Jumps

slide-7
SLIDE 7

Outline

Extend the isomorphism to more expressive systems Logic Type Theory Second-order propositional logic Polymorphism Intuitionistic logic λ-calculus + Abort Classical logic λ-calculus + Jumps Compilation ≈ logical embeddings

slide-8
SLIDE 8

Minimal Second-order Propositional Logic

A ⊢ A Ax ⊢ A → A →I

slide-9
SLIDE 9

Minimal Second-order Propositional Logic

A ⊢ A Ax ⊢ A → A →I A → B ⊢ A → B Ax ⊢ (A → B) → (A → B) →I

slide-10
SLIDE 10

Minimal Second-order Propositional Logic

A ⊢ A Ax ⊢ A → A →I A → B ⊢ A → B Ax ⊢ (A → B) → (A → B) →I A ∧ B ⊢ A ∧ B Ax ⊢ (A ∧ B) → (A ∧ B) →I

slide-11
SLIDE 11

Minimal Second-order Propositional Logic

A ⊢ A Ax ⊢ A → A →I A → B ⊢ A → B Ax ⊢ (A → B) → (A → B) →I A ∧ B ⊢ A ∧ B Ax ⊢ (A ∧ B) → (A ∧ B) →I How do we express the fact that they are the same proof?

slide-12
SLIDE 12

Minimal Second-order Propositional Logic

A ⊢ A Ax ⊢ A → A →I A → B ⊢ A → B Ax ⊢ (A → B) → (A → B) →I A ∧ B ⊢ A ∧ B Ax ⊢ (A ∧ B) → (A ∧ B) →I How do we express the fact that they are the same proof? X ⊢ X Ax ⊢ X → X →I

slide-13
SLIDE 13

Minimal Second-order Propositional Logic

A ⊢ A Ax ⊢ A → A →I A → B ⊢ A → B Ax ⊢ (A → B) → (A → B) →I A ∧ B ⊢ A ∧ B Ax ⊢ (A ∧ B) → (A ∧ B) →I How do we express the fact that they are the same proof? X ⊢ X Ax ⊢ X → X →I X ⊢ X Ax ⊢ X → X →I ⊢ ∀X.X → X ∀ I

slide-14
SLIDE 14

Minimal Second-order Propositional Logic

A ⊢ A Ax ⊢ A → A →I A → B ⊢ A → B Ax ⊢ (A → B) → (A → B) →I A ∧ B ⊢ A ∧ B Ax ⊢ (A ∧ B) → (A ∧ B) →I How do we express the fact that they are the same proof? X ⊢ X Ax ⊢ X → X →I X ⊢ X Ax ⊢ X → X →I ⊢ ∀X.X → X ∀ I What about this proof? X ⊢ X Ax X ⊢ ∀X.X ∀ I

slide-15
SLIDE 15

Minimal Second-order Propositional Logic

A ⊢ A Ax ⊢ A → A →I A → B ⊢ A → B Ax ⊢ (A → B) → (A → B) →I A ∧ B ⊢ A ∧ B Ax ⊢ (A ∧ B) → (A ∧ B) →I How do we express the fact that they are the same proof? X ⊢ X Ax ⊢ X → X →I X ⊢ X Ax ⊢ X → X →I ⊢ ∀X.X → X ∀ I What about this proof? X ⊢ X Ax X ⊢ ∀X.X ∀ I X ⊢ X X ⊢ ∀X.X ∀I X ⊢ B ∀E ⊢ X → B →I

slide-16
SLIDE 16

Minimal Second-order Propositional Logic

A ⊢ A Ax ⊢ A → A →I A → B ⊢ A → B Ax ⊢ (A → B) → (A → B) →I A ∧ B ⊢ A ∧ B Ax ⊢ (A ∧ B) → (A ∧ B) →I How do we express the fact that they are the same proof? X ⊢ X Ax ⊢ X → X →I X ⊢ X Ax ⊢ X → X →I ⊢ ∀X.X → X ∀ I What about this proof? X ⊢ X Ax X ⊢ ∀X.X ∀ I X ⊢ X X ⊢ ∀X.X ∀I X ⊢ B ∀E ⊢ X → B →I Γ ⊢ A X does not occur free in Γ Γ ⊢ ∀X.A ∀ I Γ ⊢ ∀X.A no variable capture occurs Γ ⊢ A[B/X] ∀ E

slide-17
SLIDE 17

Minimal Second-order Propositional Logic

A ⊢ A Ax ⊢ A → A →I A → B ⊢ A → B Ax ⊢ (A → B) → (A → B) →I A ∧ B ⊢ A ∧ B Ax ⊢ (A ∧ B) → (A ∧ B) →I How do we express the fact that they are the same proof? X ⊢ X Ax ⊢ X → X →I X ⊢ X Ax ⊢ X → X →I ⊢ ∀X.X → X ∀ I What about this proof? X ⊢ X Ax X ⊢ ∀X.X ∀ I X ⊢ X X ⊢ ∀X.X ∀I X ⊢ B ∀E ⊢ X → B →I Γ ⊢ A X does not occur free in Γ Γ ⊢ ∀X.A ∀ I Γ ⊢ ∀X.A no variable capture occurs Γ ⊢ A[B/X] ∀ E ⊢ (∀X.X) → A ⊢ A → ∀X.((A → X) → X) ⊢ A → ∀X.X

slide-18
SLIDE 18

System F - Jean-Yves Girard, 1972

Girard believed in Howard’s approach that proofs are mathematical objects. He introduced System F as a representations of proofs in second-order propositional logic

slide-19
SLIDE 19

System F - Jean-Yves Girard, 1972

Girard believed in Howard’s approach that proofs are mathematical objects. He introduced System F as a representations of proofs in second-order propositional logic A ∧ B = ∀X.(A → B → X) → X A ∨ B = ∀X.(A → X) → (B → X) → X ⊥ = ∀X.X nat = ∀X.X → (X → X) → X bool = ∀X.X → X → X

slide-20
SLIDE 20

System F - Jean-Yves Girard, 1972

Girard believed in Howard’s approach that proofs are mathematical objects. He introduced System F as a representations of proofs in second-order propositional logic A ∧ B = ∀X.(A → B → X) → X A ∨ B = ∀X.(A → X) → (B → X) → X ⊥ = ∀X.X nat = ∀X.X → (X → X) → X bool = ∀X.X → X → X

If Γ ⊢ M : A then it does not exists an infinite reduction starting from M

slide-21
SLIDE 21

Programming: Polymorphism

The simple type system we have seen so far forces us to duplicate code: sortI: int list -> (int->int->bool)->int list sortR: real list->(real->real->bool)->real list

slide-22
SLIDE 22

Programming: Polymorphism

The simple type system we have seen so far forces us to duplicate code: sortI: int list -> (int->int->bool)->int list sortR: real list->(real->real->bool)->real list Weaken the type system by introducing a universal type : void qsort (void* base, int num, int size, int (*comparator)(const void*,const void*));

slide-23
SLIDE 23

Programming: Polymorphism

The simple type system we have seen so far forces us to duplicate code: sortI: int list -> (int->int->bool)->int list sortR: real list->(real->real->bool)->real list Weaken the type system by introducing a universal type : void qsort (void* base, int num, int size, int (*comparator)(const void*,const void*)); Enrich the type system by allowing to express the fact that the function’s behavior is uniform for different type instantiation

slide-24
SLIDE 24

Polymorphic lambda calculus - John Reynold, 1974

Given the expressions M=(2+2)+(2+2) and N =(3+3)+(3+3) we are accustomed to abstract over the expressions 2+2 and 3+3 giving the function λx.x + x so that M=(λx.x + x) (2+2) N =(λx.x + x) (3+3) Given the types : τ = int list -> (int->int->bool)->int list σ = real list->(real->real->bool)->real list why not abstracting over the types int and real giving the function type: forall α.α list -> (α -> α -> bool) -> α list so that τ = ( forall α.α list -> (α -> α -> bool) -> α list) int σ = (forall α.α list -> (α -> α -> bool) -> α list) real The same idea to avoid duplication of code applies to avoid replication at the type level

slide-25
SLIDE 25

Polymorphic lambda calculus - John Reynold, 1974

Terms M ::= λx : σ.M | M M | x | Λα.M | M [σ] Types σ ::= α | σ → σ | ∀α.σ Type system Γ, x : σ ⊢ x : σ Γ ⊢ M : σ → τ Γ ⊢ N : σ Γ ⊢ M N : τ Γ, x : σ ⊢ M : τ Γ ⊢ λx : σ.M : σ → τ Γ ⊢ M : σ α not free in Γ Γ ⊢ Λα.M : ∀α.σ Γ ⊢ M : ∀α.σ Γ ⊢ M[τ] : σ[τ/α] Reduction (λx.M) N → M[N/x] (Λα.M) [σ] → M[σ/α] Expansion λx.M x → M Λα.M [α] → M

slide-26
SLIDE 26

Proofs are terms

⊢ (∀X.X) → A ⊢ A → ∀X.((A → X) → X) ⊢ A → ∀X.X ⊢ (∀α.α) → σ ⊢ σ → ∀α.((σ → α) → α) ⊢ σ → ∀α.α z : ∀α.α ⊢ z : ∀α.α Ax z : ∀α.α ⊢ z[σ] : σ ∀ E ⊢ λz : (∀α.α).z[σ] : (∀α.α) → σ →I z : σ, y : σ → α ⊢ y : σ → α Ax z : σ, y : σ → α ⊢ z : σ Ax z : σ, y : σ → α ⊢ y z : σ →E z : σ ⊢ λy : σ → α.y z : (σ → α) → α →I z : σ ⊢ Λα.λy : σ → α.y z : ∀α.((σ → α) → α) ∀ I ⊢ λz : σ.Λα.λy : σ → α.y z : σ → ∀α.((σ → α) → α) →I

slide-27
SLIDE 27

Barendregt’s lambda cube

λω λC λ2 λP2 λω λPω λ→ λP

slide-28
SLIDE 28

Intuitionistic Logic

Intuitionistic Logic = Minimal Logic + Ex Falso Qodlibet

slide-29
SLIDE 29

Intuitionistic Logic

Intuitionistic Logic = Minimal Logic + Ex Falso Qodlibet Formulae: A, B ::= X | A → B | A ∧ B | A ∨ B | ⊥ ¬A = A → ⊥

slide-30
SLIDE 30

Intuitionistic Logic

Intuitionistic Logic = Minimal Logic + Ex Falso Qodlibet Formulae: A, B ::= X | A → B | A ∧ B | A ∨ B | ⊥ ¬A = A → ⊥ No introduction rule for ⊥

slide-31
SLIDE 31

Intuitionistic Logic

Intuitionistic Logic = Minimal Logic + Ex Falso Qodlibet Formulae: A, B ::= X | A → B | A ∧ B | A ∨ B | ⊥ ¬A = A → ⊥ No introduction rule for ⊥ One elimination rule for ⊥ (Ex Falso Qodlibet): Γ ⊢ ⊥ Γ ⊢ A EFQ

slide-32
SLIDE 32

Intuitionistic Logic

Intuitionistic Logic = Minimal Logic + Ex Falso Qodlibet Formulae: A, B ::= X | A → B | A ∧ B | A ∨ B | ⊥ ¬A = A → ⊥ No introduction rule for ⊥ One elimination rule for ⊥ (Ex Falso Qodlibet): Γ ⊢ ⊥ Γ ⊢ A EFQ Local reduction: E ⊥ A EFQ D B

slide-33
SLIDE 33

Intuitionistic Logic

Intuitionistic Logic = Minimal Logic + Ex Falso Qodlibet Formulae: A, B ::= X | A → B | A ∧ B | A ∨ B | ⊥ ¬A = A → ⊥ No introduction rule for ⊥ One elimination rule for ⊥ (Ex Falso Qodlibet): Γ ⊢ ⊥ Γ ⊢ A EFQ Local reduction: E ⊥ A EFQ D B = ⇒ E ⊥ B EFQ

slide-34
SLIDE 34

Computational interpretation of IL

What are terms of type σ → ⊥?

slide-35
SLIDE 35

Computational interpretation of IL

What are terms of type σ → ⊥? They are special functions: they never return. We call these functions continuations

slide-36
SLIDE 36

Computational interpretation of IL

What are terms of type σ → ⊥? They are special functions: they never return. We call these functions continuations One predefined continuation is the top-level also called the prompt - tp

slide-37
SLIDE 37

Computational interpretation of IL

What are terms of type σ → ⊥? They are special functions: they never return. We call these functions continuations One predefined continuation is the top-level also called the prompt - tp Invoking the top-level means aborting the program.

slide-38
SLIDE 38

Computational interpretation of IL

What are terms of type σ → ⊥? They are special functions: they never return. We call these functions continuations One predefined continuation is the top-level also called the prompt - tp Invoking the top-level means aborting the program.

Terms:

M ::= x | λx.M | M M | Abort M

slide-39
SLIDE 39

Computational interpretation of IL

What are terms of type σ → ⊥? They are special functions: they never return. We call these functions continuations One predefined continuation is the top-level also called the prompt - tp Invoking the top-level means aborting the program.

Terms:

M ::= x | λx.M | M M | Abort M fun product nil = 0 | product (x :: xs) = if x=0 then Abort 0 else x∗(prod xs)

slide-40
SLIDE 40

Computational interpretation of IL

What is the type of Abort 0?

slide-41
SLIDE 41

Computational interpretation of IL

What is the type of Abort 0? Abort 0 + 2

slide-42
SLIDE 42

Computational interpretation of IL

What is the type of Abort 0? Abort 0 + 2 (Abort 0) 9

slide-43
SLIDE 43

Computational interpretation of IL

What is the type of Abort 0? Abort 0 + 2 (Abort 0) 9 if Abort 0 then...else.....

slide-44
SLIDE 44

Computational interpretation of IL

What is the type of Abort 0? Abort 0 + 2 (Abort 0) 9 if Abort 0 then...else..... It seems that Abort 0 can have any type. So we have: Γ ⊢ M :? Γ ⊢ Abort M : σ What is the restriction on M ?

slide-45
SLIDE 45

Computational interpretation of IL

What is the type of Abort 0? Abort 0 + 2 (Abort 0) 9 if Abort 0 then...else..... It seems that Abort 0 can have any type. So we have: Γ ⊢ M :? Γ ⊢ Abort M : σ What is the restriction on M ? Whatever the top-level is expecting! Γ, tp : ¬τ ⊢ M : τ Γ, tp : ¬τ ⊢ Abort M : σ Example

tp : ¬int ⊢ Abort 6 : σ tp : ¬bool ⊢ Abort true : σ tp : ¬bool ⊢ Abort 5 : σ

Abort M should be read as “ throw to the top-level M": throw tp M

Γ, tp : ¬τ ⊢ tp : ¬τ Γ, tp : ¬τ ⊢ M : τ Γ, tp : ¬τ ⊢ tp M : ⊥ →E Γ, tp : ¬τ ⊢ throw (tp M) : σ EFQ

slide-46
SLIDE 46

Evaluation semantics

E ⊥ A EFQ D B

slide-47
SLIDE 47

Evaluation semantics

E ⊥ A EFQ D B = ⇒ E ⊥ B EFQ product([2,3,0,9,8])=2*product([3,0,9,8])=2*3*product([0,9,8]) =2*3*Abort 0=2*Abort 0=Abort 0

slide-48
SLIDE 48

Evaluation semantics

E ⊥ A EFQ D B = ⇒ E ⊥ B EFQ product([2,3,0,9,8])=2*product([3,0,9,8])=2*3*product([0,9,8]) =2*3*Abort 0=2*Abort 0=Abort 0

(λx.M) N → M[N/x] (Abort M) N → Abort M

slide-49
SLIDE 49

Evaluation semantics

E ⊥ A EFQ D B = ⇒ E ⊥ B EFQ product([2,3,0,9,8])=2*product([3,0,9,8])=2*3*product([0,9,8]) =2*3*Abort 0=2*Abort 0=Abort 0

(λx.M) N → M[N/x] (Abort M) N → Abort M

Example What is the result of (λx.Abort 0)(Abort 1)?

slide-50
SLIDE 50

Call-by-value (CBV) and Call-by-name (CBN)

Call-by-name Evaluation Contexts and the notion of Values: E ::= | E M V ::= M Call-by-value Evaluation Contexts and the notion of Values: E ::= | E M | V E V ::= x | λx.M Reduction semantics: (λx.M) V → M[V/x] E[Abort M] → Abort M

slide-51
SLIDE 51

Call-by-value (CBV) and Call-by-name (CBN)

Call-by-name Evaluation Contexts and the notion of Values: E ::= | E M V ::= M Call-by-value Evaluation Contexts and the notion of Values: E ::= | E M | V E V ::= x | λx.M Reduction semantics: (λx.M) V → M[V/x] E[Abort M] → Abort M Example (λx.Abort 0)(Abort 1) evaluates to 1 in CBV and to 0 in CBN

slide-52
SLIDE 52

Classical Logic

Classical Logic is obtained by adding one of the following axioms to Intuitionistic logic: A ∨ ¬A Tertium non datur - Law of Excluded Middle EM ¬¬A → A Law of Double Negation DN (¬A → ⊥) → A Reductio ad absurdum - Proof by Contradiction PBC (¬A → A) → A Consequentia mirabilis - Weak Pierce Law PL⊥ ((A → B) → A) → A Pierce law PL

slide-53
SLIDE 53

Classical Logic

Classical Logic is obtained by adding one of the following axioms to Intuitionistic logic: A ∨ ¬A Tertium non datur - Law of Excluded Middle EM ¬¬A → A Law of Double Negation DN (¬A → ⊥) → A Reductio ad absurdum - Proof by Contradiction PBC (¬A → A) → A Consequentia mirabilis - Weak Pierce Law PL⊥ ((A → B) → A) → A Pierce law PL

A B A∨¬A ¬¬A → A (¬A → ⊥) → A (¬A → A) → A ((A → B) → A) → A 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

slide-54
SLIDE 54

Truth versus evidence

Proving that something is true is the same as proving that it cannot be false

slide-55
SLIDE 55

Truth versus evidence

Proving that something is true is the same as proving that it cannot be false Since ¬¬(A ∨ ¬A) is true than A ∨ ¬A holds.

slide-56
SLIDE 56

Truth versus evidence

Proving that something is true is the same as proving that it cannot be false Since ¬¬(A ∨ ¬A) is true than A ∨ ¬A holds. Proving that A ∨ ¬A holds means providing evidence of either A or ¬A.

slide-57
SLIDE 57

Truth versus evidence

Proving that something is true is the same as proving that it cannot be false Since ¬¬(A ∨ ¬A) is true than A ∨ ¬A holds. Proving that A ∨ ¬A holds means providing evidence of either A or ¬A. David Hilbert’s words from 1927: Taking the principle of excluded middle from the mathematician would be the same, say, as proscribing the telescope to the astronomer or to the boxer the use of his fists. To prohibit the principle of excluded middle is tantamount to relinquishing the science of mathematics altogether.

slide-58
SLIDE 58

Truth versus evidence

Proving that something is true is the same as proving that it cannot be false Since ¬¬(A ∨ ¬A) is true than A ∨ ¬A holds. Proving that A ∨ ¬A holds means providing evidence of either A or ¬A. David Hilbert’s words from 1927: Taking the principle of excluded middle from the mathematician would be the same, say, as proscribing the telescope to the astronomer or to the boxer the use of his fists. To prohibit the principle of excluded middle is tantamount to relinquishing the science of mathematics altogether. ⊢ ∃x.Drink(x) → ∀x.Drink(x)

slide-59
SLIDE 59

Axioms are not all equivalent in Minimal Logic

Weak Pierce Law ((¬A → A) → A) and Excluded Middle (A ∨ ¬A) are equivalent Double negation (¬¬A → A) implies Pierce Law (((A → B) → A) → A ) but not conversely. Double negation, Excluded Middle + EFQ, Weak Pierce Law + EFQ, and Pierce Law + EFQ are all equivalent Intuitionist Logic = Minimal Logic + EFQ Minimal Classical Logic = Minimal Logic + Pierce Law Classical Logic = Minimal Logic + Pierce Law + EFQ

slide-60
SLIDE 60

Control operators

slide-61
SLIDE 61

Continuation

Given a program M and a subexpression e of M, the continuation of e is what remains to be done afer the execution of e has delivered a value.

slide-62
SLIDE 62

Continuation

Given a program M and a subexpression e of M, the continuation of e is what remains to be done afer the execution of e has delivered a value. The continuation can be seen as a function taking the value of e and delivering the value of the program M

slide-63
SLIDE 63

Continuation

Given a program M and a subexpression e of M, the continuation of e is what remains to be done afer the execution of e has delivered a value. The continuation can be seen as a function taking the value of e and delivering the value of the program M Given the expression (2 + 3) + (7 + 8) and assuming the evaluation of the arithmetic expressions is lef-to-right : The continuation of (2 + 3) is

slide-64
SLIDE 64

Continuation

Given a program M and a subexpression e of M, the continuation of e is what remains to be done afer the execution of e has delivered a value. The continuation can be seen as a function taking the value of e and delivering the value of the program M Given the expression (2 + 3) + (7 + 8) and assuming the evaluation of the arithmetic expressions is lef-to-right : The continuation of (2 + 3) is the function λv.v + (7 + 8)

slide-65
SLIDE 65

Continuation

Given a program M and a subexpression e of M, the continuation of e is what remains to be done afer the execution of e has delivered a value. The continuation can be seen as a function taking the value of e and delivering the value of the program M Given the expression (2 + 3) + (7 + 8) and assuming the evaluation of the arithmetic expressions is lef-to-right : The continuation of (2 + 3) is the function λv.v + (7 + 8) The continuation of (7 + 8) is

slide-66
SLIDE 66

Continuation

Given a program M and a subexpression e of M, the continuation of e is what remains to be done afer the execution of e has delivered a value. The continuation can be seen as a function taking the value of e and delivering the value of the program M Given the expression (2 + 3) + (7 + 8) and assuming the evaluation of the arithmetic expressions is lef-to-right : The continuation of (2 + 3) is the function λv.v + (7 + 8) The continuation of (7 + 8) is the function λv.5 + v. Note that the continuation is not λv.(7 + 8) + v since by the time the evaluation gets to the expression (7 + 8), the expression (2 + 3) has already been evaluated

slide-67
SLIDE 67

Continuation

Given a program M and a subexpression e of M, the continuation of e is what remains to be done afer the execution of e has delivered a value. The continuation can be seen as a function taking the value of e and delivering the value of the program M Given the expression (2 + 3) + (7 + 8) and assuming the evaluation of the arithmetic expressions is lef-to-right : The continuation of (2 + 3) is the function λv.v + (7 + 8) The continuation of (7 + 8) is the function λv.5 + v. Note that the continuation is not λv.(7 + 8) + v since by the time the evaluation gets to the expression (7 + 8), the expression (2 + 3) has already been evaluated What will happen if we now assume a right-to-lef evaluation?

slide-68
SLIDE 68

Control operators

Let’s add the possibility to the programmer to grab the continuation The first extension of functional programming with first-class control was done by Peter Landin (1965): Example (Code) f=fn x.let g1=fn y.N1 g2=J(fn z.N2) in M When g2 is called, it does not return to where it was called, but to where f was called. callcc (call with current continuation) in Scheme.

slide-69
SLIDE 69

callcc

Given callcc(λk.M):

slide-70
SLIDE 70

callcc

Given callcc(λk.M): Variable k is bound to the continuation of the callcc expression

slide-71
SLIDE 71

callcc

Given callcc(λk.M): Variable k is bound to the continuation of the callcc expression M is then evaluated

slide-72
SLIDE 72

callcc

Given callcc(λk.M): Variable k is bound to the continuation of the callcc expression M is then evaluated If continuation k is never invoked during the evaluation of M, then the value of M is the result of the entire callcc expression

slide-73
SLIDE 73

callcc

Given callcc(λk.M): Variable k is bound to the continuation of the callcc expression M is then evaluated If continuation k is never invoked during the evaluation of M, then the value of M is the result of the entire callcc expression If continuation k is invoked during the evaluation of M, with say value v, evaluation of M is aborted and control returns to k with value v E[callcc(λk.M)] → E[M[λx.E[x]/k]] E[throw k M] → throw k M] Example callcc(λk.1 + throw k 0 + fib 100) + 4 → (1 + throw (λx.(x + 4)) 0 + fib 100) + 4 → throw (λx.(x + 4)) 0 → 0 + 4 → 4

slide-74
SLIDE 74

Felleisen’s C control operator

Given C(λk.M): Variable k is bound to the continuation of the C expression M is then evaluated If continuation k is never invoked during the evaluation of M, then the value of M, say v, is the result of the entire program containing the C-expression. In

  • ther words, control returns to the top-level with value v

If continuation k is invoked during the evaluation of M, with value v, evaluation of M is aborted and control returns to k with value v E[C(λk.M)] → M[λx.(E[x])/k] Example C(λk.99) + 1 → 99 whereas callcc(λk.99) + 1 → 100.

slide-75
SLIDE 75

Expressive power

Summarizing we have three control operators: Abort, callcc and C:

slide-76
SLIDE 76

Expressive power

Summarizing we have three control operators: Abort, callcc and C: C encodes Abort: Abort M = C(λ_.M)

slide-77
SLIDE 77

Expressive power

Summarizing we have three control operators: Abort, callcc and C: C encodes Abort: Abort M = C(λ_.M) C encodes callcc: callcc M = C(λk.k(M k))

slide-78
SLIDE 78

How do we type these control operators?

Γ ⊢ M : ⊥ Γ ⊢ Abort M : σ

slide-79
SLIDE 79

How do we type these control operators?

Γ ⊢ M : ⊥ Γ ⊢ Abort M : σ Γ, k : ¬A ⊢ M : A Γ ⊢ callcc(λk.M) : A

slide-80
SLIDE 80

How do we type these control operators?

Γ ⊢ M : ⊥ Γ ⊢ Abort M : σ Γ, k : ¬A ⊢ M : A Γ ⊢ callcc(λk.M) : A Γ, k : ¬A ⊢ M : ⊥ Γ ⊢ C(λk.M) : A

slide-81
SLIDE 81

C-H for classical logic

Intuitionist Logic = Minimal Logic + EFQ Minimal Classical Logic = Minimal Logic + Pierce Law Classical Logic = Intuitionist Logic + Pierce Law = Minimal Logic + EFQ + Pierce Law

slide-82
SLIDE 82

C-H for classical logic

Intuitionist Logic = Minimal Logic + EFQ Minimal Classical Logic = Minimal Logic + Pierce Law Classical Logic = Intuitionist Logic + Pierce Law = Minimal Logic + EFQ + Pierce Law Logic Type Theory Minimal Logic λ-calculus Intuitionistic Logic λ-calculus + Abort

slide-83
SLIDE 83

C-H for classical logic

Intuitionist Logic = Minimal Logic + EFQ Minimal Classical Logic = Minimal Logic + Pierce Law Classical Logic = Intuitionist Logic + Pierce Law = Minimal Logic + EFQ + Pierce Law Logic Type Theory Minimal Logic λ-calculus Intuitionistic Logic λ-calculus + Abort Minimal Classical λ-calculus + callcc + throw

slide-84
SLIDE 84

C-H for classical logic

Intuitionist Logic = Minimal Logic + EFQ Minimal Classical Logic = Minimal Logic + Pierce Law Classical Logic = Intuitionist Logic + Pierce Law = Minimal Logic + EFQ + Pierce Law Logic Type Theory Minimal Logic λ-calculus Intuitionistic Logic λ-calculus + Abort Minimal Classical λ-calculus + callcc + throw Classical logic λ-calculus + callcc + throw + tp

slide-85
SLIDE 85

Is classical logic constructive?

In Proofs and Types, Girard says: Intuitionistic logic is called constructive because of the correspondence be- tween proofs and algorithms. So, for example, if we prove a formula ∃n.P(n), we can exhibit an integer n which satisfies the property P. Such an interpreta- tion is not possible with classical logic: there is no sensible way of considering proofs as algorithms. In fact, classical logic has no denotational semantics, except the trivial one which identifies all the proofs of the same type. This is related to the nondeterministic behaviour of cut elimination.

slide-86
SLIDE 86

Continuation passing style

How do we compile programs with control operators?

slide-87
SLIDE 87

Continuation passing style

How do we compile programs with control operators? Embed the evaluation order directly in the program

slide-88
SLIDE 88

Continuation passing style

How do we compile programs with control operators? Embed the evaluation order directly in the program Call-by-name evaluation : [ [c] ] = λk.k c [ [x] ] = λk.x k [ [λx.M] ] = λk.k (λx. [ [M] ]) [ [M N] ] = λk. [ [M] ] (λf .f [ [N] ] k) Example ⊢ 5 : int and [ [5] ] = λk.k 5 : (int → ⊥) → ⊥. λx.x : int → int and [ [λx.x] ] = λk.k(λx.λq.x q) : ¬ [ [int → int] ] → ⊥, where [ [int → int] ] = (¬int → ⊥) → ¬int → ⊥. [ [callcc M] ] = λk. [ [M] ] (λf .f (λx.λk′.x k)k) [ [C M] ] = λk. [ [M] ] (λf .f (λx.λk′.x k)λx.x)

slide-89
SLIDE 89

Negative translations

Theorem If ⊢ M : σ then [ [M] ] : ¬¬σ∗, where σ∗ is (σ → τ)∗ = ¬¬σ∗ → ¬¬τ ∗ b∗ = b Continuation-passing style transformation is related to proof translations of classical mathematics into intuitionistic mathematics. These are referred to as negative translations. The most known are the translations due to Kolmogorov, Gödel, Gentzen, Kuroda and Krivine. Theorem If a formula A is provable in classical logic, then [ [A] ] is provable in intuitionistic logic.