the recursive polarized dual calculus
play

The Recursive Polarized Dual Calculus Aaron Stump Computer Science - PowerPoint PPT Presentation

The Recursive Polarized Dual Calculus Aaron Stump Computer Science The University of Iowa Iowa City, Iowa, USA Aaron Stump Recursive Polarized Dual Calculus PLPV 14 Golden Age of Intuitionistic Type Theory All-time high interest in tools


  1. The Recursive Polarized Dual Calculus Aaron Stump Computer Science The University of Iowa Iowa City, Iowa, USA Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  2. Golden Age of Intuitionistic Type Theory All-time high interest in tools like Coq, Agda Many exciting applications: ◮ Software: Quark verified web-browser kernel [Jang et al. 2012] ◮ Mathematics: Feit-Thompson theorem [Gonthier et al. 2013] Important foundational developments: ◮ Homotopy Type Theory [Univalent Foundations 2013] ◮ Foundations of coinduction [Abel Pientka 2013, Atkey McBride 2013] Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  3. Whither Type Theory? More practical programming ◮ Mutable state and ownership ◮ General recursion ◮ Control operators More expressive reasoning ◮ Univalence: from isomorphism to equality ◮ Classical logic Let’s subsume everything Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  4. Computational Classical Type Theories Turning two stones into one bird: control, classicality ◮ λµ -calculus [Parigot 1992] ◮ ¯ µ -calculus [Curien, Herbelin 2000] λµ ˜ ◮ Dual Calculus (DC) [Wadler 2003] Key insight [Griffin 1990]: Control operators have strictly classical types Control operators: exceptions, call/cc , etc. Important line of research in PL (e.g., [Felleisen 1988]) Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  5. The Recursive Polarized Dual Calculus (RP-DC) Logically minimal version of Wadler’s DC 1 ◮ Just ∧ , ¬ ◮ Define ∨ , → as usual ◮ Obtain expected typings, reductions, for term constructs Simple definition of inductive types, recursion 2 ◮ cf. mono X . C A , B , x . M N in DC µν [Kimura, Tatstuta 2013] Supports mixed inductive/coinductive types 3 ◮ Inductive types µ X . T ◮ Define coinductive types ν X . T : = ¬ µ X . ¬ [ ¬ X / X ] T ◮ Similar to propositional µ -calculus [Kozen 1983] Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  6. RP-DC: Propositional Fragment Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  7. Syntax DC is based on sequent calculus : Γ ⊢ t : + T means term t proves type T in context Γ Γ ⊢ t : − T means t refutes T in context Γ Computation happens when we cut proofs against refutations X | T ∧ T ′ | ¬ T :: = types T x | halt T | ( t , t ′ ) | ι x . t | not t | δ x . t · t ′ :: = terms t :: = + | − polarities p :: = . | Γ , x : p T contexts Γ Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  8. Typing Ax Halt Γ 1 , x : p T , Γ 2 ⊢ x : p T Γ ⊢ halt T : − T Γ ⊢ t 1 : + T 1 Γ ⊢ t 2 : + T 2 Γ , x : + T 1 ⊢ t : − T 2 AndPos AndNeg Γ ⊢ ( t 1 , t 2 ) : + T 1 ∧ T 2 Γ ⊢ ι x . t : − T 1 ∧ T 2 p T ⊢ t 1 : + T ′ Γ , x : ¯ p T ⊢ t 2 : − T ′ Γ ⊢ t : ¯ Γ , x : ¯ p T Γ ⊢ δ x . t 1 · t 2 : p T Cut Not Γ ⊢ not t : p ¬ T Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  9. Reduction Judgments: p t 1 • t 2 � p ′ t ′ 1 • t ′ 2 Analysis rules: AnaAnd p ( t 1 , t 2 ) • ι x . t � p t 1 • δ x . t 2 · t AnaNot p t ′ • t p not t • not t ′ � ¯ Cut rules with value restriction (controlled by p ) RP + v • ( δ y . t 1 · t 2 ) � + [ v / y ] t 1 • [ v / y ] t 2 LP + ( δ y . t 1 · t 2 ) • t � + [ t / y ] t 1 • [ t / y ] t 2 Also have marshalling rules Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  10. Examples T ∨ T ′ ¬ ( ¬ T ∧ ¬ T ′ ) : = not ι x . δ y . x · not t : = in 1 t Disjunction: : = in 2 t not ι x . not t [ t 1 , t 2 ] : = not ( not t 1 , not t 2 ) Γ ⊢ t 1 : − T 1 Γ ⊢ t 2 : − T 2 Derived typing: Γ ⊢ [ t 1 , t 2 ] : − T 1 ∨ T 2 Derived analytic reduction: + in 2 t • [ t 1 , t 2 ] � ∗ + t • t 2 T → T ′ ¬ ( T ∧ ¬ T ′ ) : = : = λ x . t not ι x . not t Implication: � t 1 , t 2 � : = not ( t 1 , not t 2 ) δ x . t 1 · � t 2 , x � : = t 1 t 2 Strictly classical principles, control operators also derivable Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  11. RP-DC: Recursion and Corecursion Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  12. Inductive Types and Recursion types T :: = . . . | µ X . T . . . | rec x [ y = t ] . t ′ | x [ t ] terms t :: = contexts Γ :: = . . . | Γ , x : p X ⊲ T Accumulator y in rec x [ y = t 1 ] . t ′ Updated in recursive call x [ t 2 ] OccursOnly + X T Γ ⊢ t 1 : p T ′ Γ , x : p X ⊲ T ′ , y : p T ′ ⊢ t 2 : − T MuBar Γ ⊢ rec x [ y = t 1 ] . t 2 : − µ X . T x : p X ⊲ T ′ ∈ Γ Γ ⊢ t : p T ′ RecCall Γ ⊢ x [ t ] : − X Special substitution [ t / x ] rec t ′ updates the accumulator: [ rec x [ y = t ] . t ′ / x ] rec ( x [ t ′′ ]) = rec x [ y = t ′′ ] . t ′ Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  13. Example: Lists L A : = µ X . ⊤ ∨ ( A ∧ X ) ⊥ : = µ X . X N : = L ⊤ ⊤ : = ¬ ⊥ : = : = rec x [ y = t ] . x [ t ] nil in 1 true false : = λ x . λ y . in 2 ( x , y ) : = cons true not false Definition of append : λ x . λ y . δ r . x · rec f [ z = r ] . [ δ y ′ . y · z , ι a . f [ δ y ′ . cons a y ′ · z ]] Recursively update return continuation r in accumulator z To match on x use a cut. δ r . x · . . . Base case: return y . δ y ′ . y · z Step case: get element a , recurse with updated continuation. ι a . f [ δ y ′ . cons a y ′ · z ] Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  14. Corecursion : = ¬ µ X . ¬ [ ¬ X / X ] T ν X . T corec f [ z = t 1 ] . t 2 : = not rec f [ z = t 1 ] . not [ ¬ f / f ] t 2 Essentially, defining coinductive data by rec ◮ rec -terms have an infinite unfolding ◮ So do coinductive data! Must unfold lazily during reduction So rec x [ y = t 1 ] . t 2 is considered a value Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  15. Streams S A : = ν X . A ∧ X = ¬ µ X . ¬ ( A ∧ ¬ X ) λ x . δ y . x · not not ι y ′ . y : = tail λ x . δ y . x · not not ι y ′ . δ z . y ′ · y : = head Examples: : = λ x . corec f [ z = true ] . ( x , f [ true ]) repeat = λ x . not rec f [ z = true ] . not ( x , not f [ true ]) : = λ n . corec f [ x = n ] . ( n , f [ Suc n ]) nats : = λ f . λ x . corec h [ y = x ] . ( f ( head y ) , h [ tail y ]) map Mixed inductive/coinductive types (see paper) Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  16. RP-DC: Metatheoretic Results Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  17. Logical Consistency Theorem The type T ∧ ¬ T is not provable by any halt -free term in the empty context, for any type T. Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  18. Canonical Inhabitants Q. What makes RP-DC nonconstructive? A. Closed normal forms need not be canonical values One proposal Canon t : p T for when t is canonical of type T Canon t 1 : + T 1 Canon t 2 : + T 2 Canon t : − T 2 CanAndP CanAndN2 Canon ( t 1 , t 2 ) : + T 1 ∧ T 2 Canon ι x . t : − T 1 ∧ T 2 Canon t : − T 1 Canon t : p T CanNot Canon ι x . δ y . x · t : − T 1 ∧ T 2 CanAndN1 Canon not t : ¯ p T OccursOnly + X T Canon t : + [ µ X . T / X ] T CanMu CanHalt Canon t : + µ X . T Canon halt T : − T Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  19. A Canonicity Theorem Define the following (additionally, S � = X in µ X . S ): X | S ∧ S ′ | ¬ R | µ X . S positive canonical S :: = R ∧ R ′ | ¬ S | ⊥ :: = negative canonical R Theorem (Canonicity) Suppose that t is a value, and the only halt -subterms it contains are of the form halt S ′ . Also, suppose every declaration in Γ is of the form x : − S 1 or x : + R 1 . Then: If Γ ⊢ t : + S, then Canon t : + S If Γ ⊢ t : − R, then Canon t : − R Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  20. Conclusion Recursive Polarized Dual Calculus (RP-DC) ◮ Version of DC with just ∧ , ¬ , and µ types ◮ Others definable, like ν X . T = ¬ µ X . ¬ [ ¬ X / X ] T ◮ Mixed recursion/corecursion supported ◮ Logical consistency, canonicity Future work: ◮ More metatheory: normalization (cf. Krivine’s classical realizability ) ◮ Dependent types: Γ ⊢ t 1 : + T 1 Γ ⊢ t 2 : + [ t 1 / x ] T 2 Γ , x : + T 1 ⊢ t : − T 2 Γ ⊢ ( t 1 , t 2 ) : + x : T ∧ T ′ Γ ⊢ ι x . t : − x : T 1 ∧ T 2 Acknowledgments: NSF (Trellys project), Ott [Sewell et al. 2010] Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  21. Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  22. Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

  23. Typing Rules for Inductive Types OccursOnly + X T Γ ⊢ t 1 : p T ′ OccursOnly + X T Γ , x : p X ⊲ T ′ , y : p T ′ ⊢ t 2 : − T Γ ⊢ t : + [ µ X . T / X ] T MuBar Mu Γ ⊢ rec x [ y = t 1 ] . t 2 : − µ X . T Γ ⊢ t : + µ X . T x : p X ⊲ T ′ ∈ Γ Γ ⊢ t : p T ′ RecCall Γ ⊢ x [ t ] : − X Aaron Stump Recursive Polarized Dual Calculus PLPV ’14

Recommend


More recommend