reducibility and lifting for computation types
play

Reducibility and -lifting for Computation Types Ian Stark and Sam - PowerPoint PPT Presentation

Reducibility and -lifting for Computation Types Ian Stark and Sam Lindley Laboratory for Foundations of Computer Science School of Informatics University of Edinburgh S eminaire PPS Mardi 17 mai N I V E U R S E I H T Y T


  1. Reducibility and ⊤⊤ -lifting for Computation Types Ian Stark and Sam Lindley Laboratory for Foundations of Computer Science School of Informatics University of Edinburgh S´ eminaire PPS Mardi 17 mai N I V E U R S E I H T Y T O H F G R E U D http://www.ed.ac.uk/ ∼ stark/reducibility.html I B N

  2. Overview Summary We present ⊤⊤ -lifting: an operational technique to define and prove properties of terms of Moggi’s monadic computation types. Demonstrate application to Girard-Tait reducibility, with a proof of strong normalisation for the computational metalanguage. Talk outline The computational metalanguage λ ml ⊤⊤ -lifting for reducibility = ⇒ proof of strong normalisation Robustness: extension to sum types and exceptions Ian Stark Reducibility and ⊤⊤ -lifting for Computation Types S´ eminaire PPS 1 / 17

  3. The computational metalanguage λ ml Moggi’s computational metalanguage λ ml : how to capture effectful computation within a pure typed lambda-calculus. Computation types For each type A of values there is a type TA of programs that compute a value of type A Sample computational effects: Non-termination, exceptions, input/output, state, non-deterministic choice, jumps, . . . Ian Stark Reducibility and ⊤⊤ -lifting for Computation Types S´ eminaire PPS 2 / 17

  4. The computational metalanguage λ ml Moggi’s computational metalanguage λ ml : how to capture effectful computation within a pure typed lambda-calculus. Computation types For each type A of values there is a type TA of programs that compute a value of type A Sample computational effects: Non-termination TA = A ⊥ , exceptions TA = A + E , input/output TA = µX . ( A + O × X + X I ) , state TA = ( S × A ) S , non-deterministic choice TA = P ( A ) , jumps TA = R R A , . . . Ian Stark Reducibility and ⊤⊤ -lifting for Computation Types S´ eminaire PPS 2 / 17

  5. The computational metalanguage λ ml Moggi’s computational metalanguage λ ml : how to capture effectful computation within a pure typed lambda-calculus. Computation types For each type A of values there is a type TA of programs that compute a value of type A Sample computational effects: Non-termination, exceptions, input/output, state, non-deterministic choice, jumps, . . . Ian Stark Reducibility and ⊤⊤ -lifting for Computation Types S´ eminaire PPS 2 / 17

  6. Types and terms of λ ml Types A , B :: = ι Ground values | A → B Functions | A × B Products | TA Computations x A | λx A . M | MN Terms L , M , N , P :: = | � M , N � | fst ( M ) | snd ( M ) [ M ] | let x A ⇐ M in N | M : A M : TA N : TB Typing let x A ⇐ M in N : TB [ M ] : TA Lift value to Compute M , bind result computation to x , compute N Ian Stark Reducibility and ⊤⊤ -lifting for Computation Types S´ eminaire PPS 3 / 17

  7. Applications of λ ml For example. . . Denotational semantics: extend pure models uniformly to handle computational effects. Haskell: monads for mixing functional and effectful code, programming interactions with the real world. Compilers: MLj and SML.NET use a monadic intermediate language to carry out type-preserving compilation. Generic vs. concrete Different applications may use λ ml generically (any T ), or concretely (fixed T for specific computational features). We look at strong normalisation for generic λ ml . Ian Stark Reducibility and ⊤⊤ -lifting for Computation Types S´ eminaire PPS 4 / 17

  8. Reductions for λ ml Standard βη for functions and products, and for computations: T . β let x ⇐ [ N ] in M − → M [ x : = N ] T . η let x ⇐ M in [ x ] − → M T . assoc let y ⇐ ( let x ⇐ L in M ) in N − → let x ⇐ L in ( let y ⇐ M in N ) Theorem (To prove) λ ml is strongly normalising: no term M ∈ λ ml has an infinite reduction sequence M → M 1 → · · · Ian Stark Reducibility and ⊤⊤ -lifting for Computation Types S´ eminaire PPS 5 / 17

  9. Reducibility Straightforward induction on term structure fails to prove strong normalisation. Standard step: use an auxiliary reducibility predicate. Define red A ⊆ A by induction on structure of type A . Show useful properties of red A by induction on A ; in particular that all elements are strongly normalising: ∀ M ∈ red A . M ↓ Show all M are in red A , by induction on structure of term M . Roughly, reducibility will be the logical predicate induced by SN at ground type Ian Stark Reducibility and ⊤⊤ -lifting for Computation Types S´ eminaire PPS 6 / 17

  10. Reducibility for λ βη Standard reducibility for ground, function and product types: Definition (Reducibility, begun) red ι = { M : ι | M ↓ } red A → B = { F : A → B | ∀ M ∈ red A . FM ∈ red B } red A × B = { P : A × B | fst ( P ) ∈ red A & snd ( P ) ∈ red B } . . . but how to define this “semantic” predicate at TA , when T has no fixed semantics? Ian Stark Reducibility and ⊤⊤ -lifting for Computation Types S´ eminaire PPS 7 / 17

  11. Structured continuations A term abstraction ( x ) N is a computation term N with a distinguished free variable x . A typed continuation K is a finite list of term abstractions: K :: = Id | K ◦ ( x ) N Apply continuations to computations with nested let : K : TA ⊸ TB and M : TA Id @ M = M ⇒ K @ M : TB ( K ◦ ( x ) N ) @ M = K @ ( let x ⇐ M in N ) = Stack depth of K tracks the T . assoc commuting conversions. Continuations reduce: K → K ′ iff ∀ M . K @ M → K ′ @ M . Ian Stark Reducibility and ⊤⊤ -lifting for Computation Types S´ eminaire PPS 8 / 17

  12. Reducibility for computations Definition (Reducibility, completed) red ι = { M : ι | M ↓ } red A → B = { F : A → B | ∀ M ∈ red A . FM ∈ red B } red A × B = { P : A × B | fst ( P ) ∈ red A & snd ( P ) ∈ red B } red TA = { M : TA | ∀ K ∈ red ⊤ A . ( K @ M ) ↓ } red ⊤ A = { K : TA ⊸ TB | ∀ N ∈ red A . ( K @ [ N ]) ↓ } Structured continuations — specifically | K | — are vital for inductive proofs that let -terms preserve reducibility. Ian Stark Reducibility and ⊤⊤ -lifting for Computation Types S´ eminaire PPS 9 / 17

  13. Result Fundamental Theorem If N 1 ∈ red A 1 , . . . , N k ∈ red A k and M : B then M [ x 1 : = N 1 , . . . , x k : = N k ] ∈ red B . (Proof by induction on the structure of term M ) Corollary Each λ ml term M : A is in red A , and hence strongly normalising Ian Stark Reducibility and ⊤⊤ -lifting for Computation Types S´ eminaire PPS 10 / 17

  14. Leap-frog 1 Jump over continuations to lift properties from values to computations: General ⊤⊤ -lifting def Predicate φ ⊆ A ( K ⊤ M ⇐ ⇒ ( K @ M ) ↓ ) φ ⊤ = { K | K ⊤ [ N ] for all N ∈ φ } φ ⊤⊤ = { M | K ⊤ M for all K ∈ φ ⊤ } ⊆ TA Continuation K — “observation” Lifting φ ⊤⊤ — “best observable approximation to φ on computations” 1 Fran¸ cais saute-mouton Ian Stark Reducibility and ⊤⊤ -lifting for Computation Types S´ eminaire PPS 11 / 17

  15. λ ml + exceptions Exceptional syntax [Benton, Kennedy ’01; also Erlang ’05] An enhanced let that strictly extends the standard try . . . catch : try x ⇐ M in N unless { E 1 �→ P 1 , . . . } Evaluate M , bind result to x and evaluate N ; unless exception raised in M , in which case engage handler H = { E 1 �→ P 1 , . . . } . Types and terms E ∈ Exn M : TA N : TB E i ∈ Exn P i : TB try x A ⇐ M in N unless { E 1 �→ P 1 , . . . } : TB raise ( E ) : TA def let x ⇐ M in N = try x ⇐ M in N unless {} Ian Stark Reducibility and ⊤⊤ -lifting for Computation Types S´ eminaire PPS 12 / 17

  16. ⊤⊤ -lifting with exceptions Put a handler within each continuation frame: K :: = Id | K ◦ � ( x ) N , H � H = { E 1 �→ P 1 , . . . } Id @ M = M ( K ◦ � ( x ) N , H � ) @ M = K @ ( try x ⇐ M in N unless H ) Reducibility with exceptions and handlers . . . red ⊤ A = { K : TA ⊸ TB | ∀ N ∈ red A . ( K @ [ N ]) ↓ & ∀ E ∈ Exn . ( K @ raise ( E )) ↓ } red TA = { M : TA | ∀ K ∈ red ⊤ A . ( K @ M ) ↓ } Sufficient to prove strong normalisation for λ ml + exceptions Ian Stark Reducibility and ⊤⊤ -lifting for Computation Types S´ eminaire PPS 13 / 17

  17. λ ml + sums Types and terms Sum type A + B , with constructors inl ( M ) , inr ( N ) and destructor case L of ( inl ( x ) ⇒ M | inr ( y ) ⇒ N ) : TC Reductions + . β l case inl ( M ) of ( inl ( x ) ⇒ P | inr ( y ) ⇒ Q ) − → P [ x : = M ] + . β r case inr ( N ) of ( inl ( x ) ⇒ P | inr ( y ) ⇒ Q ) − → Q [ x : = N ] + . η case L of ( inl ( x ) ⇒ inl ( x ) | inr ( y ) ⇒ inr ( y )) − → L + . T let z ⇐ ( case L of ( inl ( x ) ⇒ M | inr ( y ) ⇒ N )) in P − → case L of ( inl ( x ) ⇒ ( let z ⇐ M in P ) | inr ( y ) ⇒ ( let z ⇐ N in P )) Ian Stark Reducibility and ⊤⊤ -lifting for Computation Types S´ eminaire PPS 14 / 17

  18. ⊤⊤ -lifting for sum types Introduce continuations especially for sums: S :: = K ◦ � ( x ) M , ( y ) N � ( K ◦ � ( x ) M , ( y ) N � ) @ L = K @ ( case L of ( inl ( x ) ⇒ M | inr ( y ) ⇒ M )) Reducibility for sums . . . red ⊤ A + B = { S : ( A + B ) ⊸ TC | ∀ M ∈ red A . ( S @ inl ( M )) ↓ & ∀ N ∈ red B . ( S @ inr ( N )) ↓ } red A + B = { L : A + B | ∀ S ∈ red ⊤ A + B . ( S @ L ) ↓ } Enough to show strong normalisation for λ ml + sums Further: use frame stacks for leap-frog definitions of reducibility at sums, products and function types, as well as computations. Ian Stark Reducibility and ⊤⊤ -lifting for Computation Types S´ eminaire PPS 15 / 17

Recommend


More recommend