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

operational semantics for disintegration
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

1

Operational semantics for disintegration

Chung-chieh Shan (Indiana University) Norman Ramsey (Tufts University) Mathematical Foundations of Programming Semantics 2016-05-25

slide-2
SLIDE 2

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)

slide-3
SLIDE 3

2

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)

slide-4
SLIDE 4

2

What is semantics for?

  • 1. Language for composing generative stories

do {x normal 0 10; return ex} (monadic bind, unit)

  • 2. Guarantee that terms denote distributions

(product measure tricky)

slide-5
SLIDE 5

2

What is semantics for?

  • 1. Language for composing generative stories

do {x normal 0 10; return ex} (monadic bind, unit)

  • 2. Guarantee that terms denote distributions

do {x m; do {y n; return (x, y)}} (product measure tricky)

slide-6
SLIDE 6

2

What is semantics for?

  • 1. Language for composing generative stories

do {x normal 0 10; return ex} (monadic bind, unit)

  • 2. Guarantee that terms denote distributions

do {x m; do {y n; return (x, y)}}

=

do {x m; y n; return (x, y)} (product measure tricky)

slide-7
SLIDE 7

3

What is semantics for?

  • 3. Equational reasoning by semantics-preserving rewriting!

Fubini do {x m; y n; return (x, y)}

=

do {y n; x m; return (x, y)} Conjugacy do {x normal 0 1; factor e−x2; return x}

=

do {factor (1/

3); x normal 0

3; return x}

slide-8
SLIDE 8

3

What is semantics for?

  • 3. Equational reasoning by semantics-preserving rewriting!

Fubini do {x m; y n; return (x, y)}

=

do {y n; x m; return (x, y)} Conjugacy do {x normal 0 1; factor e−x2; return x}

=

do {factor (1/

3); x normal 0

3; return x}

slide-9
SLIDE 9

3

What is semantics for?

  • 3. Equational reasoning by semantics-preserving rewriting!

Fubini do {x m; y n; return (x, y)}

=

do {y n; x m; return (x, y)} Conjugacy do {x normal 0 1; factor e−x2; return x}

=

do {factor (1/

3); x normal 0

3; return x} (convenient factor expresses non-(sub)probability measures)

slide-10
SLIDE 10

4

Two program transformations specified semantically

  • 1. Simplification

m

=

m′

  • 2. Disintegration

m

=

do {t m1; x m2; return (t, x)} (typically t appears free in m2)

slide-11
SLIDE 11

4

Two program transformations specified semantically

  • 1. Simplification

m

=

m′

  • 2. Disintegration

m

=

do {t m1; x m2; return (t, x)} (typically t appears free in m2)

slide-12
SLIDE 12

4

Two program transformations specified semantically

  • 1. Simplification

m

=

m′

  • 2. Disintegration

m

=

do {t m1; x m2; return (t, x)} (typically t appears free in m2)

slide-13
SLIDE 13

4

Two program transformations specified semantically

  • 1. Simplification

m

=

m′

  • 2. Disintegration

m

=

do {t m1; x m2; return (t, x)}

=

do {t ⋆

∼ m1;

m2} (typically t appears free in m2)

slide-14
SLIDE 14

5

What is disintegration for?

m

=

do {t m1; x m2; return (t, x)}

=

do {t ⋆

∼ m1;

m2}

slide-15
SLIDE 15

5

What is disintegration for?

m

=

do {t m1; x m2; return (t, x)}

=

do {t ⋆

∼ m1;

m2} Disintegration defines conditional distributions x t do {x normal 0 10;

  • - latent cause

t normal x 1;

  • - observed effect

return (t, x)}

slide-16
SLIDE 16

5

What is disintegration for?

m

=

do {t m1; x m2; return (t, x)}

=

do {t ⋆

∼ m1;

m2} Disintegration defines conditional distributions x t do {x normal 0 10;

  • - latent cause

t normal x 1;

  • - observed effect

return (t, x)}

= do {t normal 0 √

101; x normal (t × 100/101) (10/

101); return (t, x)}

slide-17
SLIDE 17

5

What is disintegration for?

m

=

do {t m1; x m2; return (t, x)}

=

do {t ⋆

∼ m1;

m2} Disintegration defines conditional distributions x t do {x normal 0 10;

  • - latent cause

t normal x 1;

  • - observed effect

return (t, x)}

= do {t ⋆ ∼ normal 0 √

101; normal (t × 100/101) (10/

101)}

slide-18
SLIDE 18

6

What is disintegration for?

m

=

do {t m1; x m2; return (t, x)}

=

do {t ⋆

∼ m1;

m2} Disintegration allows an uncountable space of observations 1 1 do {x uniform 0 1; y uniform 0 1; t

;

return (t, (x, y))}

slide-19
SLIDE 19

6

What is disintegration for?

m

=

do {t m1; x m2; return (t, x)}

=

do {t ⋆

∼ m1;

m2} Disintegration allows an uncountable space of observations 1 1 do {x uniform 0 1; y uniform 0 1; t return (y − 2 × x); return (t, (x, y))}

slide-20
SLIDE 20

6

What is disintegration for?

m

=

do {t m1; x m2; return (t, x)}

=

do {t ⋆

∼ m1;

m2} Disintegration allows an uncountable space of observations 1 1 do {x uniform 0 1; y uniform 0 1; t return (y/x); return (t, (x, y))}

slide-21
SLIDE 21

7

From denotation to operation

Denotation: equivalence relation Operation: directed graph So denotation justifies soundness of operation

slide-22
SLIDE 22

7

From denotation to operation

Denotation: equivalence relation Operation: directed graph So denotation justifies soundness of operation

slide-23
SLIDE 23

7

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

slide-24
SLIDE 24

8

Syntax

Term e, m ::= do {factor e; m}

  • do {x m; m}
  • do {x ⋆

∼ 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)

slide-25
SLIDE 25

8

Syntax

Stratified syntax during disintegration State s ::= do {factor e; s}

  • do {x m; s}
  • do {delimit; t}

Thread t ::= do {factor e; t}

  • do {x m; t}
  • do {x ⋆

∼ m; m}

Term e, m ::= do {factor e; m}

  • do {x 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)

slide-26
SLIDE 26

9

Example disintegration

do {delimit; r do {x uniform 0 1; y uniform 0 1; return (y/x, (x, y))} t ⋆

∼ return (fst r);

return (snd r)} Stage 1: Isolate (evaluate) Stage 2: Invert (unevaluate)

slide-27
SLIDE 27

9

Example disintegration

do {delimit; r do {x uniform 0 1; y uniform 0 1; return (y/x, (x, y))}; t ⋆

∼ return (fst r);

return (snd r)}

slide-28
SLIDE 28

9

Example disintegration (step 1)

do {delimit; r do {x uniform 0 1; y uniform 0 1; return (y/x, (x, y))}; t ⋆

∼ return (fst r);

return (snd r)}

bind

− − →

do {delimit; x uniform 0 1; r do {y uniform 0 1; return (y/x, (x, y))}; t ⋆

∼ return (fst r);

return (snd r)}

slide-29
SLIDE 29

9

Example disintegration (step 1)

do {delimit; r do {x uniform 0 1; y uniform 0 1; return (y/x, (x, y))}; t ⋆

∼ return (fst r);

return (snd r)}

bind

− − →

do {delimit; x uniform 0 1; r do {y uniform 0 1; return (y/x, (x, y))}; t ⋆

∼ return (fst r);

return (snd r)} do {delimit; H; r do {x m1; m2}; P[r]}

bind

− − →

do {delimit; H; x m1; r m2; P[r]} H is a heap of bindings P[r] is a program that demands r

slide-30
SLIDE 30

9

Example disintegration (step 1)

do {delimit; x uniform 0 1; r do {y uniform 0 1; return (y/x, (x, y))}; t ⋆

∼ return (fst r);

return (snd r)}

slide-31
SLIDE 31

10

Example disintegration (step 2)

do {delimit; x uniform 0 1; r do {y uniform 0 1; return (y/x, (x, y))}; t ⋆

∼ return (fst r);

return (snd r)}

slide-32
SLIDE 32

10

Example disintegration (step 2)

do {delimit; x uniform 0 1; r do {y uniform 0 1; return (y/x, (x, y))}; t ⋆

∼ return (fst r);

return (snd r)}

bind

− − →

do {delimit; x uniform 0 1; y uniform 0 1; r return (y/x, (x, y)); t ⋆

∼ return (fst r);

return (snd r)} do {delimit; H; r do {x m1; m2}; P[r]}

bind

− − →

do {delimit; H; x m1; r m2; P[r]}

slide-33
SLIDE 33

11

Example disintegration (step 3)

do {delimit; x uniform 0 1; y uniform 0 1; r return (y/x, (x, y)); t ⋆

∼ return (fst r);

return (snd r)}

return

− − − → do {delimit;

x uniform 0 1; y uniform 0 1; r return (y/x, (x, y)); t ⋆

∼ return (fst (y/x, (x, y)));

return (snd r)} do {delimit; H; r return v; P[r]}

return

− − − → do {delimit;

H; r return v; P[v]} v is head normal form for lazy evaluation

slide-34
SLIDE 34

12

Example disintegration (step 4)

do {delimit; x uniform 0 1; y uniform 0 1; r return (y/x, (x, y)); t ⋆

∼ return (fst (y/x, (x, y)));

return (snd r)}

fst

− → do {delimit;

x uniform 0 1; y uniform 0 1; r return (y/x, (x, y)); t ⋆

∼ return (y/x);

return (snd r)} do {delimit; P[fst (e1, e2)]}

fst

− → do {delimit;

P[e1]}

slide-35
SLIDE 35

13

Example disintegration (step 5)

do { delimit; x uniform 0 1; y uniform 0 1; r return (y/x, (x, y)); t ⋆

∼ return (y/x);

return (snd r)}

Fubini

− − − → do {x′ uniform 0 1;

delimit; x return x′; y uniform 0 1; r return (y/x, (x, y)); t ⋆

∼ return (y/x);

return (snd r)} do { delimit; H; x uniform v1 v2; P[x]}

Fubini

− − − → do {x′ uniform v1 v2;

delimit; H; x return x′; P[x]}

slide-36
SLIDE 36

14

Example disintegration (step 6)

do {x′ uniform 0 1; delimit; x return x′; y uniform 0 1; r return (y/x, (x, y)); t ⋆

∼ return (y/x);

return (snd r)}

return

− − − → do {x′ uniform 0 1;

delimit; x return x′; y uniform 0 1; r return (y/x, (x, y)); t ⋆

∼ return (y/x′);

return (snd r)} do {delimit; H; r return v; P[r]}

return

− − − → do {delimit;

H; r return v; P[v]}

slide-37
SLIDE 37

15

Example disintegration (step 7)

do {x′ uniform 0 1; delimit; x return x′; y uniform 0 1; r return (y/x, (x, y)); t ⋆

∼ return (y/x′);

return (snd r)}

un/

− − → do {x′ uniform 0 1;

delimit; z uniform (0/x′) (1/x′); y return (z × x′); x return x′; r return (y/x, (x, y)); t ⋆

∼ return (z);

return (snd r)} do {delimit; H1; y uniform v1 v2; H2; t ⋆

∼ return E[y/v];

m}

un/

− − → do {delimit;

z uniform (v1/v) (v2/v); y return (z × v); H1; H2; t ⋆

∼ return E[z];

m}

slide-38
SLIDE 38

16

Example disintegration (step 8)

do {x′ uniform 0 1; delimit; z uniform (0/x′) (1/x′); y return (z × x′); x return x′; r return (y/x, (x, y)); t ⋆

∼ return z;

return (snd r)}

unreturn

− − − − − → do {x′ uniform 0 1;

delimit; t ⋆

∼ uniform (0/x′) (1/x′);

z return t; y return (z × x′); x return x′; r return (y/x, (x, y)); return (snd r)} do {delimit; H1; z m1; H2; t ⋆

∼ return z;

m2}

unreturn

− − − − − → do {delimit;

H1; t ⋆

∼ m1;

z return t; H2; m2}

slide-39
SLIDE 39

17

Example disintegration (step 9)

do { x′ uniform 0 1; delimit; t ⋆

∼ uniform (0/x′) (1/x′);

z return t; y return (z × x′); x return x′; r return (y/x, (x, y)); return (snd r)}

done

− − − → do {t ⋆ ∼ lebesgue;

x′ uniform 0 1; factor if t is between 0/x′ and 1/x′ then |x| else 0; z return t; y return (z × x′); x return x′; r return (y/x, (x, y)); return (snd r)}

slide-40
SLIDE 40

18

Summary

Disintegration is useful:

◮ defines conditional distributions ◮ allows an uncountable space of observations

Disintegrator is useful:

◮ generates steps by operational semantics ◮ justifies steps by denotational semantics ◮ resembles lazy evaluator + change of variables ◮ leaves verification conditions behind for exchanging integrals