operational semantics for disintegration
play

Operational semantics for disintegration Chung-chieh Shan (Indiana - PowerPoint PPT Presentation

Operational semantics for disintegration Chung-chieh Shan (Indiana University) Norman Ramsey (Tufts University) Mathematical Foundations of Programming Semantics 2016-05-25 1 What is semantics for? 1. Language for composing generative stories


  1. Operational semantics for disintegration Chung-chieh Shan (Indiana University) Norman Ramsey (Tufts University) Mathematical Foundations of Programming Semantics 2016-05-25 1

  2. What is semantics for? 1. Language for composing generative stories do { x � normal 0 10 ; (monadic bind, unit) 2. Guarantee that terms denote distributions (product measure tricky ) 2

  3. What is semantics for? 1. Language for composing generative stories do { x � normal 0 10 ; normal x 1 } (monadic bind, unit) 2. Guarantee that terms denote distributions (product measure tricky ) 2

  4. What is semantics for? 1. Language for composing generative stories do { x � normal 0 10 ; return e x } (monadic bind, unit) 2. Guarantee that terms denote distributions (product measure tricky ) 2

  5. What is semantics for? 1. Language for composing generative stories do { x � normal 0 10 ; return e x } (monadic bind, unit) 2. Guarantee that terms denote distributions do { x � m ; do { y � n ; return ( x , y ) }} (product measure tricky ) 2

  6. What is semantics for? 1. Language for composing generative stories do { x � normal 0 10 ; return e x } (monadic bind, unit) 2. Guarantee that terms denote distributions do { x � m ; = do { x � m ; do { y � n ; y � n ; return ( x , y ) }} return ( x , y ) } (product measure tricky ) 2

  7. What is semantics for? 3. Equational reasoning by semantics-preserving rewriting! Fubini do { x � m ; = do { y � n ; y � n ; x � m ; return ( x , y ) } return ( x , y ) } Conjugacy √ do { x � normal 0 1 ; = do { factor ( 1 / 3 ); √ factor e − x 2 ; x � normal 0 3 ; return x } return x } 3

  8. What is semantics for? 3. Equational reasoning by semantics-preserving rewriting! Fubini do { x � m ; = do { y � n ; y � n ; x � m ; return ( x , y ) } return ( x , y ) } Conjugacy √ do { x � normal 0 1 ; = do { factor ( 1 / 3 ); √ factor e − x 2 ; x � normal 0 3 ; return x } return x } 3

  9. What is semantics for? 3. Equational reasoning by semantics-preserving rewriting! Fubini do { x � m ; = do { y � n ; y � n ; x � m ; return ( x , y ) } return ( x , y ) } Conjugacy √ do { x � normal 0 1 ; = do { factor ( 1 / 3 ); √ factor e − x 2 ; x � normal 0 3 ; return x } return x } (convenient factor expresses non-(sub)probability measures) 3

  10. Two program transformations specified semantically 1. Simplification m ′ = m 2. Disintegration m = do { t � m 1 ; x � m 2 ; return ( t , x ) } (typically t appears free in m 2 ) 4

  11. Two program transformations specified semantically 1. Simplification m ′ = m 2. Disintegration m = do { t � m 1 ; x � m 2 ; return ( t , x ) } (typically t appears free in m 2 ) 4

  12. Two program transformations specified semantically 1. Simplification m ′ = m 2. Disintegration m = do { t � m 1 ; x � m 2 ; return ( t , x ) } (typically t appears free in m 2 ) 4

  13. Two program transformations specified semantically 1. Simplification m ′ = m 2. Disintegration m = do { t � m 1 ; = do { t ⋆ ∼ m 1 ; x � m 2 ; m 2 } return ( t , x ) } (typically t appears free in m 2 ) 4

  14. What is disintegration for? = do { t � m 1 ; = do { t ⋆ ∼ m 1 ; m x � m 2 ; m 2 } return ( t , x ) } 5

  15. What is disintegration for? = do { t � m 1 ; = do { t ⋆ ∼ m 1 ; m x � m 2 ; m 2 } return ( t , x ) } Disintegration defines conditional distributions do { x � normal 0 10 ; -- latent cause t t � normal x 1 ; -- observed effect return ( t , x ) } x 5

  16. What is disintegration for? = do { t � m 1 ; = do { t ⋆ ∼ m 1 ; m x � m 2 ; m 2 } return ( t , x ) } Disintegration defines conditional distributions do { x � normal 0 10 ; -- latent cause t t � normal x 1 ; -- observed effect return ( t , x ) } x √ = do { t � normal 0 101 ; √ x � normal ( t × 100 / 101 ) ( 10 / 101 ); return ( t , x ) } 5

  17. What is disintegration for? = do { t � m 1 ; = do { t ⋆ ∼ m 1 ; m x � m 2 ; m 2 } return ( t , x ) } Disintegration defines conditional distributions do { x � normal 0 10 ; -- latent cause t t � normal x 1 ; -- observed effect return ( t , x ) } x √ = do { t ⋆ 101 ; ∼ normal 0 √ normal ( t × 100 / 101 ) ( 10 / 101 ) } 5

  18. What is disintegration for? = do { t � m 1 ; = do { t ⋆ ∼ m 1 ; m x � m 2 ; m 2 } return ( t , x ) } Disintegration allows an uncountable space of observations 1 do { x � uniform 0 1 ; y � uniform 0 1 ; ; t � return ( t , ( x , y )) } 0 1 6

  19. What is disintegration for? = do { t � m 1 ; = do { t ⋆ ∼ m 1 ; m x � m 2 ; m 2 } return ( t , x ) } Disintegration allows an uncountable space of observations 1 do { x � uniform 0 1 ; y � uniform 0 1 ; t � return ( y − 2 × x ); return ( t , ( x , y )) } 0 1 6

  20. What is disintegration for? = do { t � m 1 ; = do { t ⋆ ∼ m 1 ; m x � m 2 ; m 2 } return ( t , x ) } Disintegration allows an uncountable space of observations 1 do { x � uniform 0 1 ; y � uniform 0 1 ; t � return ( y / x ); return ( t , ( x , y )) } 0 1 6

  21. From denotation to operation Denotation: equivalence relation Operation: directed graph So denotation justifies soundness of operation 7

  22. From denotation to operation Denotation: equivalence relation Operation: directed graph So denotation justifies soundness of operation 7

  23. From denotation to operation Denotation: equivalence relation Operation: directed graph So denotation justifies soundness of operation This setup is typical for execution, but what about disintegration? Rest of this talk: a disintegrator that justifies its work, step by step A contextual operational semantics, implemented in PLT Redex 7

  24. Syntax � � do { x � m ; m } � � do { x ⋆ Term e , m ::= do { factor e ; m } ∼ m ; m } � return e � uniform e e � normal e e � lebesgue � � � � � ( e , e ) � · · · � � � fst e � � snd e � � number � � e − e � � e / e � � x � (not shown: conditionals) 8

  25. Syntax Stratified syntax during disintegration � � do { x � m ; s } � � do { delimit ; t } State s ::= do { factor e ; s } � do { x � m ; t } � do { x ⋆ � � t ::= do { factor e ; t } ∼ m ; m } Thread � do { x � m ; m } � Term e , m ::= do { factor e ; m } � return e � uniform e e � normal e e � lebesgue � � � � � ( e , e ) � · · · � � � fst e � � snd e � � number � � e − e � � e / e � � x � (not shown: conditionals) 8

  26. Example disintegration do { delimit ; r � do { x � uniform 0 1 ; y � uniform 0 1 ; return ( y / x , ( x , y )) } ∼ return ( fst r ); t ⋆ return ( snd r ) } Stage 1: Isolate (evaluate) Stage 2: Invert (unevaluate) 9

  27. Example disintegration do { delimit ; r � do { x � uniform 0 1 ; y � uniform 0 1 ; return ( y / x , ( x , y )) } ; ∼ return ( fst r ); t ⋆ return ( snd r ) } 9

  28. Example disintegration (step 1) bind do { delimit ; − − → do { delimit ; r � do { x � uniform 0 1 ; x � uniform 0 1 ; y � uniform 0 1 ; r � do { y � uniform 0 1 ; return ( y / x , ( x , y )) } ; return ( y / x , ( x , y )) } ; ∼ return ( fst r ); ∼ return ( fst r ); t ⋆ t ⋆ return ( snd r ) } return ( snd r ) } 9

  29. Example disintegration (step 1) bind do { delimit ; − − → do { delimit ; r � do { x � uniform 0 1 ; x � uniform 0 1 ; y � uniform 0 1 ; r � do { y � uniform 0 1 ; return ( y / x , ( x , y )) } ; return ( y / x , ( x , y )) } ; ∼ return ( fst r ); ∼ return ( fst r ); t ⋆ t ⋆ return ( snd r ) } return ( snd r ) } bind do { delimit ; − − → do { delimit ; H ; H ; r � do { x � m 1 ; x � m 1 ; m 2 } ; r � m 2 ; P [ r ] } P [ r ] } H is a heap of bindings P [ r ] is a program that demands r 9

  30. Example disintegration (step 1) do { delimit ; x � uniform 0 1 ; r � do { y � uniform 0 1 ; return ( y / x , ( x , y )) } ; ∼ return ( fst r ); t ⋆ return ( snd r ) } 9

  31. Example disintegration (step 2) do { delimit ; x � uniform 0 1 ; r � do { y � uniform 0 1 ; return ( y / x , ( x , y )) } ; ∼ return ( fst r ); t ⋆ return ( snd r ) } 10

  32. Example disintegration (step 2) bind do { delimit ; − − → do { delimit ; x � uniform 0 1 ; x � uniform 0 1 ; r � do { y � uniform 0 1 ; y � uniform 0 1 ; return ( y / x , ( x , y )) } ; r � return ( y / x , ( x , y )); ∼ return ( fst r ); ∼ return ( fst r ); t ⋆ t ⋆ return ( snd r ) } return ( snd r ) } bind do { delimit ; − − → do { delimit ; H ; H ; r � do { x � m 1 ; x � m 1 ; m 2 } ; r � m 2 ; P [ r ] } P [ r ] } 10

  33. Example disintegration (step 3) return do { delimit ; − − − → do { delimit ; x � uniform 0 1 ; x � uniform 0 1 ; y � uniform 0 1 ; y � uniform 0 1 ; r � return ( y / x , ( x , y )); r � return ( y / x , ( x , y )); ∼ return ( fst r ); ∼ return ( fst ( y / x , ( x , y ))); t ⋆ t ⋆ return ( snd r ) } return ( snd r ) } return do { delimit ; − − − → do { delimit ; H ; H ; r � return v ; r � return v ; P [ r ] } P [ v ] } v is head normal form for lazy evaluation 11

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