call by name is dual to call by value
play

Call-by-name is dual to call-by-value Philip Wadler University of - PowerPoint PPT Presentation

Call-by-name is dual to call-by-value Philip Wadler University of Edinburgh wadler@inf.ed.ac.uk Part 1 A Deal with the Devil Either (a) I will give you $1,000,000,000 or (b) I will grant you one wish if you pay me $1,000,000,000. Either


  1. Call-by-name is dual to call-by-value Philip Wadler University of Edinburgh wadler@inf.ed.ac.uk

  2. Part 1 A Deal with the Devil

  3. Either (a) I will give you $1,000,000,000 or (b) I will grant you one wish if you pay me $1,000,000,000.

  4. Either (a) I will give you $1,000,000,000 or (b) I will grant you one wish if you pay me $1,000,000,000.

  5. Either (a) I will give you $1,000,000,000 or (b) I will grant you one wish if you pay me $1,000,000,000.

  6. Part 2 A Question

  7. Lambda Calculus ? = Natural Deduction Sequent Calculus (Intuitonistic) (Classical)

  8. Lambda Calculus Dual Calculus = Natural Deduction Sequent Calculus (Intuitonistic) (Classical)

  9. Part 3 The History

  10. Logic Gottlob Frege (1848–1925) George Boole (1815–1864) Boole (1847): Laws of Thought Frege (1879): Begriffsschrift

  11. Duality A & ¬ A = ⊥ A ∨ ¬ A = ⊤ A & ( B ∨ C ) = ( A & B ) ∨ ( A & C ) A ∨ ( B & C ) = ( A ∨ B ) & ( A ∨ C ) Poncelet (1818), Gergonne (1826): duals in projective geometry Boole (1847), Frege (1879): no duality! Schr¨ oder (1890): duals in logic

  12. Natural Deduction and Lambda Calculus Alonzo Church (1903–1995) Gerhard Gentzen (1909–1945) Church (1932): λ -calculus Gentzen (1935): natural deduction Church (1940): simply-typed λ -calculus

  13. The Curry-Howard Isomorphism William Howard Haskell Curry (1900–1982) Curry and Feys (1958): combinatory logic Prawitz (1965): proof reduction de Bruijn (1968): encoding of proofs Howard (1980): natural deduction ≃ λ -calculus

  14. Curry-Howard for Classical Logic Gentzen (1935): sequent calculus Filinski (1989): symmetric λ -calculus Griffin (1990): Curry-Howard for classical logic Parigot (1992): λµ -calculus Danos, Joinet, and Schellinx (1995): dual encodings in linear logic Barbanera and Berardi (1996): symmetric λ -calculus Streicher and Reus (1998): dual cps transforms Selinger (1998): dual control categories Curien and Herbelin (2000): Curry-Howard for classical sequent calculus Wadler (2003): dual calculus

  15. Part 4 Natural Deduction (Intuitionistic)

  16. Gentzen 1935: Natural Deduction

  17. Gentzen 1935: Natural Deduction · · · · · · · · · · · · A B A & B A & B &I &E A & B A B { } { } { } { A } { B } · · · · · · · · · · · · · · · A B A ∨ B C C ∨ I ∨ E A ∨ B A ∨ B C { A } { } { } · · · · · · · · · B A ⊃ B A ⊃ I ⊃ E A ⊃ B B

  18. Prawitz 1965: Simplifying proofs · · · · · · A B · · &I · − → A & B A &E A · · · · { A } { B } · A · · · · · A ∨ I · · − → · · A ∨ B C C · ∨ E C C { A } · · · · · · B A · − → · ⊃ I · · · · A ⊃ B A B ⊃ E B

  19. Part 5 The Lambda Calculus

  20. Church 1932: Lambda Calculus

  21. Church 1940: Simply-typed Lambda Calculus · · · · · · · · · · · · M : A N : B O : A & B O : A & B &I &E ( M, N ) : A & B fst O : A snd O : B { } { x : A } { y : B } { } { } · · · · · · · · · · · · · · · O : A ∨ B P : C Q : C M : A N : B ∨ E ∨ I case O of inl x ⇒ P , inr y ⇒ Q : C inl M : A ∨ B inr N : A ∨ B { x : A } { } { } · · · · · · · · · N : B O : A ⊃ B M : A ⊃ I ⊃ E λx. N : A ⊃ B O M : B

  22. Church 1932, 1940: Reducing terms · · · · · · M : A N : B · &I · · − → ( M, N ) : A & B M : A &E fst ( M, N ) : A · · · · { x : A } { y : B } · M : A · · · · · M : A ∨ I · · − → · · inl M : A ∨ B P : C Q : C · ∨ E P { M/x } : C case (inl M ) of inl x ⇒ P , inr y ⇒ Q : C { x : A } · · · · · · N : B M : A · · − → · ⊃ I · · · λx. N : A ⊃ B M : A N { M/x } : B ⊃ E ( λx. N ) M : B

  23. Church 1932: Call-by-name ( β &) fst ( M, N ) − → n M ( β &) snd ( M, N ) − → n N ( β ∨ ) case (inl M ) of inl x ⇒ P , inr y ⇒ Q − → n P { M/x } ( β ∨ ) case (inr N ) of inl x ⇒ P , inr y ⇒ Q − → n Q { N/y } ( β ⊃ ) ( λx. N ) M − → n N { M/x }

  24. Rosser 1936, Plotkin 1975: Call-by-value Value V, W ::= x | ( V, W ) | inl V | inr W | λx. N ( β &) fst ( V, W ) − → v V ( β &) snd ( V, W ) − → v W ( β ∨ ) case inl V of inl x ⇒ P , inr y ⇒ Q − → v P { V/x } ( β ∨ ) case inr W of inl x ⇒ P , inr y ⇒ Q − → v Q { W/y } ( β ⊃ ) ( λx. N ) V − → v N { V/x }

  25. Part 6 Sequent Calculus (Classical)

  26. Gentzen 1935: Sequent Calculus

  27. Gentzen 1935: Logical rules Γ ➞ Θ , A Γ ➞ Θ , B &R Γ ➞ Θ , A & B A, Γ ➞ Θ B, Γ ➞ Θ &L A & B, Γ ➞ Θ A & B, Γ ➞ Θ Γ ➞ Θ , A Γ ➞ Θ , B ∨ R Γ ➞ Θ , A ∨ B Γ ➞ Θ , A ∨ B A, Γ ➞ Θ B, Γ ➞ Θ ∨ L A ∨ B, Γ ➞ Θ A, Γ ➞ Θ Γ ➞ Θ , A ¬ R ¬ L Γ ➞ Θ , ¬ A ¬ A, Γ ➞ Θ

  28. Gentzen 1935: Structural rules Id A ➞ A Γ ➞ Θ , A A, ∆ ➞ Λ Cut Γ , ∆ ➞ Θ , Λ

  29. Gentzen 1935: Duality ( X ) ◦ ≡ X A ◦ ∨ B ◦ ( A & B ) ◦ ≡ A ◦ & B ◦ ( A ∨ B ) ◦ ≡ ( ¬ A ) ◦ ≡ ¬ A ◦ ( A 1 , . . . , A n ) ◦ ≡ A ◦ n , . . . , A ◦ 1 Proposition 1 A sequent is derivable if and only if its dual is derivable, Θ ◦ ➞ Γ ◦ . Γ ➞ Θ iff

  30. Gentzen 1935: Cut Elimination Γ ➞ Θ , A Γ ➞ Θ , B A, Γ ➞ Θ &R &L Γ ➞ Θ , A & B A & B, Γ ➞ Θ Cut Γ ➞ Θ Γ ➞ Θ , A A, Γ ➞ Θ − → Cut Γ ➞ Θ A, Γ ➞ Θ Γ ➞ Θ , A ¬ R ¬ L Γ ➞ Θ , ¬ A ¬ A, Γ ➞ Θ Cut Γ ➞ Θ Γ ➞ Θ , A A, Γ ➞ Θ − → Cut Γ ➞ Θ

  31. Part 7 The dual calculus

  32. Intuitionistic natural deduction x 1 : A 1 , . . . , x m : A m ➞ M : A Term Classical sequent calculus x 1 : A 1 , . . . , x m : A m ➞ α 1 : B 1 , . . . , α n : B n ❙ M : A Term K : A ❙ x 1 : A 1 , . . . , x m : A m ➞ α 1 : B 1 , . . . , α n : B n Coterm x 1 : A 1 , . . . , x m : A m ❙ S ❙ ➞ α 1 : B 1 , . . . , α n : B n Statement

  33. Terms, Coterms, Statements Term M, N ::= x | � M, N � | � M � inl | � N � inr | [ K ]not | ( S ) .α Coterm K, L ::= α | [ K, L ] | fst[ K ] | snd[ L ] | not � M � | x. ( S ) Statement S, T ::= M • K Γ ➞ Θ ❙ M : A Right sequent K : A ❙ Γ ➞ Θ Left sequent Γ ❙ S ❙ ➞ Θ Center sequent

  34. Logical rules Γ ➞ Θ ❙ M : A Γ ➞ Θ ❙ N : B &R Γ ➞ Θ ❙ � M, N � : A & B K : A ❙ Γ ➞ Θ L : B ❙ Γ ➞ Θ &L fst[ K ] : A & B ❙ Γ ➞ Θ snd[ L ] : A & B ❙ Γ ➞ Θ Γ ➞ Θ ❙ M : A Γ ➞ Θ ❙ N : B ∨ R Γ ➞ Θ ❙ � M � inl : A ∨ B Γ ➞ Θ ❙ � N � inr : A ∨ B K : A ❙ Γ ➞ Θ L : B ❙ Γ ➞ Θ ∨ L [ K, L ] : A ∨ B ❙ Γ ➞ Θ K : A ❙ Γ ➞ Θ Γ ➞ Θ ❙ M : A ¬ R ¬ L Γ ➞ Θ ❙ [ K ]not : ¬ A not � M � : ¬ A ❙ Γ ➞ Θ

  35. Structural rules IdR IdL x : A ➞ ❙ x : A α : A ❙ ➞ α : A Γ ❙ S ❙ ➞ Θ , α : A x : A, Γ ❙ S ❙ ➞ Θ RI LI Γ ➞ Θ ❙ ( S ) .α : A x. ( S ) : A ❙ Γ ➞ Θ Γ ➞ Θ ❙ M : A K : A ❙ ∆ ➞ Λ Cut Γ , ∆ ❙ M • K ❙ ➞ Θ , Λ

  36. Duality ( X ) ◦ ≡ X A ◦ ∨ B ◦ ( A & B ) ◦ ≡ A ◦ & B ◦ ( A ∨ B ) ◦ ≡ ( ¬ A ) ◦ ≡ ¬ A ◦ ( x ) ◦ ( α ) ◦ ≡ x ◦ ≡ α ◦ ( � M, N � ) ◦ ([ K, L ]) ◦ ≡ [ M ◦ , N ◦ ] ≡ � K ◦ , L ◦ � ( � M � inl) ◦ (fst[ K ]) ◦ ≡ fst[ M ◦ ] ≡ � K ◦ � inl ( � N � inr) ◦ (snd[ L ]) ◦ ≡ snd[ M ◦ ] ≡ � K ◦ � inr ([ K ]not) ◦ (not � M � ) ◦ ≡ not � K ◦ � ≡ [ M ◦ ]not (( S ) .α ) ◦ ( x. ( S )) ◦ ≡ α ◦ . ( S ◦ ) ≡ ( S ◦ ) .x ◦ K ◦ • M ◦ ( M • K ) ◦ ≡

  37. Duality Proposition 2 A sequent is derivable if and only if its dual is derivable, M ◦ : A ◦ ❙ Θ ◦ ➞ Γ ◦   Γ ➞ Θ ❙ M : A       Θ ◦ ➞ Γ ◦ ❙ K ◦ : A ◦ K : A ❙ Γ ➞ Θ iff Θ ◦ ❙ S ◦ ❙     Γ ❙ S ❙ ➞ Θ ➞ Γ ◦ .  

  38. Gentzen (1935): Cut Elimination Γ ➞ Θ ❙ M : A Γ ➞ Θ ❙ N : B K : A ❙ Γ ➞ Θ &R &L Γ ➞ Θ ❙ � M, N � : A & B fst[ K ] : A & B ❙ Γ ➞ Θ Cut Γ ❙ � M, N � • fst[ K ] ❙ ➞ Θ Γ ➞ Θ ❙ M : A K : A ❙ Γ ➞ Θ − → Cut Γ ❙ M • K ❙ ➞ Θ K : A ❙ Γ ➞ Θ Γ ➞ Θ ❙ M : A ¬ R ¬ L Γ ➞ Θ ❙ [ K ]not : ¬ A not � M � : ¬ A ❙ Γ ➞ Θ Cut Γ ❙ [ K ]not • not � M � ❙ ➞ Θ Γ ➞ Θ ❙ M : A K : A ❙ Γ ➞ Θ − → Cut Γ ❙ M • K ❙ ➞ Θ

  39. Part 8 Call-by-value is Dual to Call-by-name

  40. Critical pair ( β L) M • x. ( S ) − → S { M/x } ( β R) ( S ) .α • K − → S { K/α } Sometimes confluent. ( x • α ) .α • y. ( y • β ) ւ ց x • y. ( y • β ) ( x • α ) .α • β ց ւ x • β Sometimes not. ( x • α ) .β • y. ( z • γ ) ւ ց x • α z • γ

Recommend


More recommend