An Assertion-Based Program Logic for Probabilistic Programs Gilles - - PowerPoint PPT Presentation

an assertion based program logic for probabilistic
SMART_READER_LITE
LIVE PREVIEW

An Assertion-Based Program Logic for Probabilistic Programs Gilles - - PowerPoint PPT Presentation

An Assertion-Based Program Logic for Probabilistic Programs Gilles Barthe, Thomas Espitau, Marco Gaboardi, Benjamin Grgoire, Justin Hsu, and Pierre-Yves Strub 1 Randomized algorithms are everywhere! 2 Complex programs 3 Complex proofs 4


slide-1
SLIDE 1

Gilles Barthe, Thomas Espitau, Marco Gaboardi, Benjamin Grégoire, Justin Hsu, and Pierre-Yves Strub

An Assertion-Based Program Logic for Probabilistic Programs

1

slide-2
SLIDE 2

Randomized algorithms are everywhere!

2

slide-3
SLIDE 3

Complex programs

3

slide-4
SLIDE 4

Complex proofs

4

slide-5
SLIDE 5

A simple randomized algorithm and property

Noisy sum

sum ← 0; for i = 1, . . . , n do toss

$

← flip(p); sum ← sum + toss; return(sum)

5

slide-6
SLIDE 6

A simple randomized algorithm and property

Noisy sum

sum ← 0; for i = 1, . . . , n do toss

$

← flip(p); sum ← sum + toss; return(sum)

To show: sum not too small

Pr[sum ≤ n · p − 4√n · p] is at most 0.0005

5

slide-7
SLIDE 7

A simple randomized algorithm and property

Noisy sum

sum ← 0; for i = 1, . . . , n do toss

$

← flip(p); sum ← sum + toss; return(sum)

To show: sum not too small

Pr[sum ≤ n · p − 4√n · p] is at most 0.0005

Proof of correctness, on paper?

  • 1. sum is sum of n independent p-biased coins.
  • 2. Apply standard concentration bound, done.

5

slide-8
SLIDE 8

Deductive verification? Not so easy.

Expectation-based approaches

◮ Rules manipulate single expected value/probability ◮ Can’t directly express properties like independence ◮ Kozen’s PPDL (1985); Morgan, McIver, Seidel’s pGCL (1996) 6

slide-9
SLIDE 9

Deductive verification? Not so easy.

Expectation-based approaches

◮ Rules manipulate single expected value/probability ◮ Can’t directly express properties like independence ◮ Kozen’s PPDL (1985); Morgan, McIver, Seidel’s pGCL (1996)

Program logic (assertion-based) approaches

◮ Use general boolean assertions on distributions ◮ Complex loop rules, more limited programming languages ◮ Chadha et al. (2007); Rand and Zdancewic (2015) 6

slide-10
SLIDE 10

Overall goal: Narrow this gap

Work with higher-level properties as much as possible

◮ Minimize reasoning about single probabilities

Avoid reasoning at level of program semantics

◮ Side-conditions should be easy to check

Incorporate proof methods from paper proofs

◮ Structure the proof, abstract away unimportant details 7

slide-11
SLIDE 11

More concretely: Our contributions

  • A new program logic

for probabilistic programs

  • Embeddings of several

specialized proof techniques

  • Implementation and

formalized examples

8

slide-12
SLIDE 12

The Ellora Framework: A Lightning Tour

9

slide-13
SLIDE 13

The core: A program logic for probabilistic programs

The pWhile imperative language

c ::= x ← e | x

$

← d | c; c | if e then c else c | while e do c

10

slide-14
SLIDE 14

The core: A program logic for probabilistic programs

The pWhile imperative language

c ::= x ← e | x

$

← d | c; c | if e then c else c | while e do c

Sample from primitive distributions

◮ Biased coin flips, uniform distribution, ... ◮ Geometric distribution, Laplace distribution, ... 10

slide-15
SLIDE 15

The core: A program logic for probabilistic programs

The pWhile imperative language

c ::= x ← e | x

$

← d | c; c | if e then c else c | while e do c

Sample from primitive distributions

◮ Biased coin flips, uniform distribution, ... ◮ Geometric distribution, Laplace distribution, ...

Commands transform (sub-)distributions over memories

◮ Distribution over inputs → Distribution over outputs 10

slide-16
SLIDE 16

Assertion language: two layers

State assertions: model memories

φ, ψ ::= e = e′ | e < e′ | . . .

11

slide-17
SLIDE 17

Assertion language: two layers

State assertions: model memories

φ, ψ ::= e = e′ | e < e′ | . . .

Distribution assertions: model distributions

Φ, Ψ ::= E[e] = E[e′] | E[e] < E[e′] | . . .

11

slide-18
SLIDE 18

Assertion language: two layers

State assertions: model memories

φ, ψ ::= e = e′ | e < e′ | . . .

Distribution assertions: model distributions

Φ, Ψ ::= E[e] = E[e′] | E[e] < E[e′] | . . .

Examples: defined notation

P[φ] E[1φ] φ P[φ] = 1

11

slide-19
SLIDE 19

Proof system

Typical program logic judgment

{Φ} c {Ψ}

12

slide-20
SLIDE 20

Proof system

Typical program logic judgment

{Φ} c {Ψ}

System rules

12

slide-21
SLIDE 21

How to reason about loops?

Well-known pitfall: naive rule unsound!

◮ Always have:

{P[⊤] = 1} skip {P[⊤] = 1}

◮ But not:

{P[⊤] = 1} while true do skip {P[⊤] = 1}

13

slide-22
SLIDE 22

How to reason about loops?

Well-known pitfall: naive rule unsound!

◮ Always have:

{P[⊤] = 1} skip {P[⊤] = 1}

◮ But not:

{P[⊤] = 1} while true do skip {P[⊤] = 1}

Tradeoff

Generality of invariants/allowed termination behavior

13

slide-23
SLIDE 23

Our solution: A family of loop rules

{Φ ∧ b} c {Φ} {Φ} while b do c {Φ ∧ ¬b}

14

slide-24
SLIDE 24

Our solution: A family of loop rules

{Φ ∧ b} c {Φ} {Φ} while b do c {Φ ∧ ¬b}

Loop: Bounded number of iterations (“for-loops”)

◮ Invariant Φ: arbitrary predicate 14

slide-25
SLIDE 25

Our solution: A family of loop rules

{Φ ∧ b} c {Φ} {Φ} while b do c {Φ ∧ ¬b}

Loop: Bounded number of iterations (“for-loops”)

◮ Invariant Φ: arbitrary predicate

Loop: Terminates with probability 1

◮ Invariant Φ: “topologically closed” (e.g., P[φ] = 1/2) 14

slide-26
SLIDE 26

Our solution: A family of loop rules

{Φ ∧ b} c {Φ} {Φ} while b do c {Φ ∧ ¬b}

Loop: Bounded number of iterations (“for-loops”)

◮ Invariant Φ: arbitrary predicate

Loop: Terminates with probability 1

◮ Invariant Φ: “topologically closed” (e.g., P[φ] = 1/2)

Loop: Arbitrary termination

◮ Invariant Φ: “downwards closed” (e.g., P[φ] < 1/2) 14

slide-27
SLIDE 27

Adding to the Toolbox: Specialized Proof Techniques

15

slide-28
SLIDE 28

Two common properties in paper proofs

Probabilistic independence

◮ In our assertions:

e # e′ ∀a, b. P[e = a ∧ e′ = b] = P[e = a] · P[e′ = b]

16

slide-29
SLIDE 29

Two common properties in paper proofs

Probabilistic independence

◮ In our assertions:

e # e′ ∀a, b. P[e = a ∧ e′ = b] = P[e = a] · P[e′ = b]

Distribution laws

◮ In our assertions:

e ∼ Unif(A) ∀a ∈ A. P[e = a] = 1/|A|

16

slide-30
SLIDE 30

Reasoning about independence and distribution laws

Useful facts about independence

(e1, e2) # e3 = ⇒ (e1 # e3) ∧ (e2 # e3)

Combining independence and uniformity

e ∼ Unif(A)∧e′ ∼ Unif(A′)∧(e # e′) = ⇒ (e, e′) ∼ Unif(A×A′)

Incorporating this reasoning in Ellora

Build a program logic IL around these assertions, soundness by embedding into core program logic.

17

slide-31
SLIDE 31

Other tools available in Ellora

Prior work: union bound logic [ICALP 2016]

◮ Designed for proving proeprties of the form P[φ] < β

Precondition calculus

◮ Similar to Morgan and McIver’s weakest pre-expectations ◮ Defined on syntax of assertions 18

slide-32
SLIDE 32

Implementation and Formalized Examples

19

slide-33
SLIDE 33

Implementation

Part of the EasyCrypt system

◮ Tactic-based proofs, SMT support

Formalization of basic discrete probability theory

◮ Definitions: independence, basic distributions, ... ◮ Theorems: Markov inequality, Chernoff bound, ... 20

slide-34
SLIDE 34

Examples: Nine verified algorithms

Name Lines of Code Lines of Proof hypercube 100 1140 coupon 27 184 vertex-cover 30 61 pairwise-indep 30 231 private-sums 22 80 poly-id-test 22 32 random-walk 16 42 dice-sampling 10 64 matrix-prod-test 20 75

21

slide-35
SLIDE 35

Examples: Nine verified algorithms

Name Lines of Code Lines of Proof hypercube 100 1140 coupon 27 184 vertex-cover 30 61 pairwise-indep 30 231 private-sums 22 80 poly-id-test 22 32 random-walk 16 42 dice-sampling 10 64 matrix-prod-test 20 75

21

slide-36
SLIDE 36

A classic example: Valiant’s hypercube routing

Hypergraph network

◮ Nodes: {0, 1}d ◮ Given: permutation π ◮ Edge capacity 1 ◮ Goal: route i to π(i) 22

slide-37
SLIDE 37

A classic example: Valiant’s hypercube routing

Hypergraph network

◮ Nodes: {0, 1}d ◮ Given: permutation π ◮ Edge capacity 1 ◮ Goal: route i to π(i)

Routing 111 to 100 (d = 3)

001 101 011 010 111 000 100 110

22

slide-38
SLIDE 38

A classic example: Valiant’s hypercube routing

Hypergraph network

◮ Nodes: {0, 1}d ◮ Given: permutation π ◮ Edge capacity 1 ◮ Goal: route i to π(i)

Valiant’s routing plan

◮ Uniformly random ρ(i) ◮ Route: i → ρ(i) → π(i)

Routing 111 to 100 (d = 3)

001 101 011 010 111 000 100 110

22

slide-39
SLIDE 39

A classic example: Valiant’s hypercube routing

Hypergraph network

◮ Nodes: {0, 1}d ◮ Given: permutation π ◮ Edge capacity 1 ◮ Goal: route i to π(i)

Valiant’s routing plan

◮ Uniformly random ρ(i) ◮ Route: i → ρ(i) → π(i)

Routing 111 to 100 (d = 3)

001 101 011 010 111 000 100 110

Show: with high probability, routes all 2d packets in O(d) steps

22

slide-40
SLIDE 40

Future Directions and Open Design Questions

23

slide-41
SLIDE 41

The story so far

Ellora

24

slide-42
SLIDE 42

The story so far

Ellora

Union Bound

WP IL

24

slide-43
SLIDE 43

Next steps?

Ellora

Union Bound

WP IL

EasyCrypt

25

slide-44
SLIDE 44

Next steps?

Ellora

Union Bound

WP IL

EasyCrypt

??? ???

25

slide-45
SLIDE 45

Next steps?

Ellora

Union Bound

WP IL

EasyCrypt

??? ???

25

slide-46
SLIDE 46

Open design questions

How to structure the assertion language?

◮ Need help managing large assertions and invariants 26

slide-47
SLIDE 47

Open design questions

How to structure the assertion language?

◮ Need help managing large assertions and invariants

Deterministic inputs or distribution over inputs?

◮ Deterministic gives simpler but less flexible pre-conditions 26

slide-48
SLIDE 48

Open design questions

How to structure the assertion language?

◮ Need help managing large assertions and invariants

Deterministic inputs or distribution over inputs?

◮ Deterministic gives simpler but less flexible pre-conditions

How to combine different proof techniques?

◮ Want to support many tools, but not all can be freely mixed 26

slide-49
SLIDE 49

Open design questions

How to structure the assertion language?

◮ Need help managing large assertions and invariants

Deterministic inputs or distribution over inputs?

◮ Deterministic gives simpler but less flexible pre-conditions

How to combine different proof techniques?

◮ Want to support many tools, but not all can be freely mixed

Should reasoning be code-directed?

◮ Maybe easier: lift random sampling instructions out 26

slide-50
SLIDE 50

Gilles Barthe, Thomas Espitau, Marco Gaboardi, Benjamin Grégoire, Justin Hsu, and Pierre-Yves Strub

An Assertion-Based Program Logic for Probabilistic Programs

27