combining proofs and programs
play

Combining Proofs and Programs Stephanie Weirich University of - PowerPoint PPT Presentation

Combining Proofs and Programs Stephanie Weirich University of Pennsylvania September 2011 Dependently Typed Programming Shonan Meeting Seminar 007 The Trellys project The Trellys project Stephanie Weirich Aaron Stump Tim Sheard Chris


  1. Combining Proofs and Programs Stephanie Weirich University of Pennsylvania September 2011 Dependently Typed Programming Shonan Meeting Seminar 007

  2. The Trellys project

  3. The Trellys project Stephanie Weirich Aaron Stump Tim Sheard Chris Casinghino Harley Eades Ki Yung Ahn Vilhelm Sj¨ oberg Peng (Frank) Fu Nathan Collins Garrin Kimmell A collaborative project to design a statically-typed functional programming language based on dependent type theory.

  4. The Trellys project Stephanie Weirich Aaron Stump Tim Sheard Chris Casinghino Harley Eades Ki Yung Ahn Vilhelm Sj¨ oberg Peng (Frank) Fu Nathan Collins Garrin Kimmell A collaborative project to design a statically-typed functional programming language based on dependent type theory. Work-in-progress

  5. Growing a new language Trellys Design strategy: Start with general purpose, call-by-value, functional programming language and strengthen its type system.

  6. Why call-by-value? Have to choose something. With nontermination, the order of evaluation makes a difference

  7. Why call-by-value? Have to choose something. With nontermination, the order of evaluation makes a difference Good cost model. Programmers can predict the running time and space usage of their programs

  8. Why call-by-value? Have to choose something. With nontermination, the order of evaluation makes a difference Good cost model. Programmers can predict the running time and space usage of their programs Distinction between values and computations built into the language. Variables stand for values, not computations

  9. Programming language vs. logic Even in the presence of nontermination, a call-by-value dependently-typed programming language provides partial correctness. Theorem (Syntactic type soundness) ⊢ P a : A then either a diverges or a � ∗ v and ⊢ P v : A. If

  10. Programming language vs. logic Even in the presence of nontermination, a call-by-value dependently-typed programming language provides partial correctness. Theorem (Syntactic type soundness) ⊢ P a : A then either a diverges or a � ∗ v and ⊢ P v : A. If A dependently-typed logic provides total correctness. Theorem (Termination) ⊢ L a : A then a � ∗ v and ⊢ L v : A. If

  11. Partial correctness Type soundness alone gives a logical interpretation for values . ⊢ P a : Σ x : Nat .even x = true If a terminates, then it must produce a pair of a natural number and a proof that the result is even. Canonical forms says the result must be ( i, join ), where even i � ∗ true by inversion.

  12. Partial correctness Type soundness alone gives a logical interpretation for values . ⊢ P a : Σ x : Nat .even x = true If a terminates, then it must produce a pair of a natural number and a proof that the result is even. Canonical forms says the result must be ( i, join ), where even i � ∗ true by inversion. But, implication is bogus. ⊢ P a : Σ x : Nat . ( even x = true ) → ( x = 3)

  13. Total correctness Partial correctness is not enough. Implication is useful Can’t compile this language efficiently (have to run “proofs”) “Proof” irrelevance is fishy Users are willing to work harder for stronger guarantees

  14. A logical language But, some programs do terminate. There is a terminating, logically-consistent logic hiding in a dependently-typed programming language.

  15. A logical language But, some programs do terminate. There is a terminating, logically-consistent logic hiding in a dependently-typed programming language. How do we identify it?

  16. A logical language But, some programs do terminate. There is a terminating, logically-consistent logic hiding in a dependently-typed programming language. How do we identify it? We use the type system!

  17. A logical language But, some programs do terminate. There is a terminating, logically-consistent logic hiding in a dependently-typed programming language. How do we identify it? We use the type system!

  18. A logical language But, some programs do terminate. There is a terminating, logically-consistent logic hiding in a dependently-typed programming language. How do we identify it? We use the type system! New typing judgement form: Γ ⊢ θ a : A where θ ::= L | P

  19. Subsumption Many rules are shared. x : θ A ∈ Γ Γ ⊢ θ b : Nat ⊢ Γ Γ ⊢ θ x : A Γ ⊢ θ S b : Nat

  20. Subsumption Many rules are shared. x : θ A ∈ Γ Γ ⊢ θ b : Nat ⊢ Γ Γ ⊢ θ x : A Γ ⊢ θ S b : Nat Programmatic language allows features (general recursion, type-in-type, abort etc.) that do not type check in the logical language. Γ ⊢ P ⋆ : ⋆

  21. Subsumption Many rules are shared. x : θ A ∈ Γ Γ ⊢ θ b : Nat ⊢ Γ Γ ⊢ θ x : A Γ ⊢ θ S b : Nat Programmatic language allows features (general recursion, type-in-type, abort etc.) that do not type check in the logical language. Γ ⊢ P ⋆ : ⋆ Logical language is a sublanguage of the programmatic language. Γ ⊢ L a : A Γ ⊢ P a : A

  22. Mixing proofs and programs These two languages are not independent. Should be able to allow programs to manipulate proofs, and proofs to talk about programs. Data structures (in both languages) should have both logical and programmatic components.

  23. The @ Modality New type form A @ θ internalizes the judgement Γ ⊢ θ v : A

  24. The @ Modality New type form A @ θ internalizes the judgement Γ ⊢ θ v : A Introduction form embeds values from one language into the other. Γ ⊢ θ v : A Γ ⊢ θ ′ box v : A @ θ

  25. The @ Modality New type form A @ θ internalizes the judgement Γ ⊢ θ v : A Introduction form embeds values from one language into the other. Γ ⊢ θ v : A Γ ⊢ θ ′ box v : A @ θ Elimination form derived from modal type systems. Γ , x : θ ′ A , z : L box x = a ⊢ θ b : B Γ ⊢ θ a : A @ θ ′ Γ ⊢ θ B : s Γ ⊢ θ unbox z x = a in b : B

  26. Datastructructures Components of a pair are from the same language by default. Γ ⊢ θ a : A Γ ⊢ θ b : [ a / x ] B Γ ⊢ θ [ a / x ] B : s Γ ⊢ θ Σ x : A . B : s Γ ⊢ θ ( a , b ) : Σ x : A . B Programs can embed proofs about data. ⊢ P (0 , box v ) : Σ x : Nat . (( y : Nat ) → ( x ≤ y ))@ L Data structures are parametric in their logicality. The same datatype can store a list of proofs as well as a list of program values.

  27. Abstraction Standard abstraction rule conflicts with subsumption. Γ , x : θ A ⊢ θ a : B Γ ⊢ θ ( x : A ) → B : s Γ ⊢ θ λ x . a : ( x : A ) → B

  28. Solution Require every argument type to be an A @ θ type, so subsumption has no effect. Γ , x : θ ′ A ⊢ θ b : B Γ ⊢ θ ( x : θ ′ A ) → B : s Γ ⊢ θ λ x . b : ( x : θ ′ A ) → B Application implicitly boxes. Γ ⊢ θ a : ( x : θ ′ A ) → B Γ ⊢ θ box b : A @ θ ′ Γ ⊢ θ [ b / x ] B : s Γ ⊢ θ a b : [ b / x ] B

  29. Logical preconditions Programmatic functions can have logical parameters: Γ ⊢ P div : ( n d : P Nat ) → ( p : L d � = 0) → Nat Such arguments are “proofs” that the preconditions of the function are satisfied.

  30. Freedom of Speech Logical functions can have programmatic parameters: Γ ⊢ L ds : ( n d : P Nat ) → ( p : L d � = 0) → (Σ z : Nat .z = div n d )

  31. Freedom of Speech Logical functions can have programmatic parameters: Γ ⊢ L ds : ( n d : P Nat ) → ( p : L d � = 0) → (Σ z : Nat .z = div n d ) ds is a proof that div terminates for nonzero arguments, even if div was originally defined with general recursion.

  32. Shared values Some values are shared between the two languages.

  33. Shared values Some values are shared between the two languages. For example, all natural numbers are values in the logical language as well as in the programmatic language.

  34. Shared values Some values are shared between the two languages. For example, all natural numbers are values in the logical language as well as in the programmatic language. This means that it is sound to treat a variable of type Nat as logical, no matter what it is assumed to be in the context. Γ ⊢ P v : Nat Γ ⊢ L v : Nat

  35. Uniform equality Equality proofs are also shared. Γ ⊢ P v : A = B Γ ⊢ L v : A = B This supports incremental verification. We can have a partial function return an equality proof and then use its result to satisfy logical preconditions.

  36. Uniform equality Equality proofs are also shared. Γ ⊢ P v : A = B Γ ⊢ L v : A = B This supports incremental verification. We can have a partial function return an equality proof and then use its result to satisfy logical preconditions. However, we currently only know how to add this rule to logical languages with predicative polymorphism. Girard’s trick interferes.

  37. Uniform box Challenge: the internalized type. Γ ⊢ P v : A @ θ Γ ⊢ L v : A @ θ This allows proofs embedded in programs to be used when reasoning about those programs (not just as preconditions to other programs). Promising initial results via step-indexed semantics, limitations necessary.

  38. Related work Bar types in Nuprl - no admisibility required Partiality Monad F-star kinds ML5, distributed ML

  39. Future work What can we add to the logical language? Large Eliminations?

  40. Future work What can we add to the logical language? Large Eliminations? Interaction with classical reasoning: allow proofs to branch on whether a program halts or diverges

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend