Fair Termination of Higher-Order Functional Programs Keiichi - - PowerPoint PPT Presentation

β–Ά
fair termination of
SMART_READER_LITE
LIVE PREVIEW

Fair Termination of Higher-Order Functional Programs Keiichi - - PowerPoint PPT Presentation

Automatically Disproving Fair Termination of Higher-Order Functional Programs Keiichi Watanabe , Ryosuke Sato Takeshi Tsukada, Naoki Kobayashi The University of Tokyo September 20 th , 2016 ICFP 2016 at Nara 1 2 Our Goal Automated method for


slide-1
SLIDE 1

Automatically Disproving Fair Termination of Higher-Order Functional Programs

Keiichi Watanabe, Ryosuke Sato Takeshi Tsukada, Naoki Kobayashi The University of Tokyo

September 20th, 2016

ICFP 2016 at Nara

1

slide-2
SLIDE 2

Our Goal

Automated method for disproving fair-termination

  • f higher-order functional programs
  • cf. Prove Fair-termination [Murase+ POPL16]

2

Verification of 𝝏-regular properties can be reduced to that of fair-termination [Vardi APAL91]

includes LTL properties

slide-3
SLIDE 3

Outline

  • Termination & Fair-Termination
  • Importance of Fair-Termination
  • Our Method
  • Implementation and Experiments
  • Related Work
  • Conclusion

3

slide-4
SLIDE 4

Outline

  • Termination & Fair-Termination
  • Importance of Fair-Termination
  • Our Method
  • Implementation and Experiments
  • Related Work
  • Conclusion

4

slide-5
SLIDE 5

Plain Termination

5

Program 𝑄 is terminating ⇔ Every execution eventually terminates

Terminating

main main

Not Terminating

slide-6
SLIDE 6

Fair-Termination

6

Fair-Terminating

Not Fair-Terminating

An example of fairness in this talk:

If A occurs infinitely often, so does B Program 𝑄 is fair-terminating ⇔ Every fair execution eventually terminates

slide-7
SLIDE 7

Outline

  • Termination & Fair-Termination
  • Importance of Fair-Termination
  • Our Method
  • Implementation and Experiments
  • Related Work
  • Conclusion

7

slide-8
SLIDE 8

Terminating, assuming randomness of *int

8 let rand_int () = *int let rec rand_pos () = let x = rand_int () in if 0 < x then x else rand_pos () let main = rand_pos ()

Termination assuming Randomness

slide-9
SLIDE 9

Terminating, assuming randomness of *int

9

Q.

How to incorporate randomness with termination verification?

let rand_int () = *int let rec rand_pos () = let x = rand_int () in if 0 < x then x else rand_pos () let main = rand_pos ()

Termination assuming Randomness

slide-10
SLIDE 10

10 let rand_int () = let r = *int in if 0 < r then (event B; r) else (event A; r) let rec rand_pos () = let x = rand_int () in if 0 < x then x else rand_pos () let main = rand_pos ()

Insert event expressions

Termination assuming Randomness

slide-11
SLIDE 11

11 let rand_int () = let r = *int in if 0 < r then (event B; r) else (event A; r) let rec rand_pos () = let x = rand_int () in if 0 < x then x else rand_pos () let main = rand_pos ()

If *int never returns a positive integer, execution is unfair

A β†’ A β†’ A β†’ A →…

Termination assuming Randomness

Termination assuming randomness β†’ Fair-termination

slide-12
SLIDE 12

Our Goal (Again)

Automated method for disproving fair-termination

  • f higher-order functional programs
  • cf. Prove Fair-termination [Murase+ POPL16]

12

Verification of 𝝏-regular properties can be reduced to that of fair-termination [Vardi APAL91]

includes LTL properties

slide-13
SLIDE 13

Our Goal (Again)

Automated method for disproving fair-termination

  • f higher-order functional programs

13

Verification of 𝝏-regular properties can be reduced to that of fair-termination [Vardi APAL91]

includes LTL properties

Proving the existence of fair infinite executions

slide-14
SLIDE 14

Outline

  • Termination & Fair-Termination
  • Importance of Fair-Termination
  • Our Method
  • Overview of Method
  • Step 1, Step 2, Step 3
  • Properties of Our Method
  • Implementation and Experiments
  • Related Work
  • Conclusion

14

slide-15
SLIDE 15

Overview of Method

Step 2: Higher-Order Model Checking

accept

Fairness Constraint Functional Program

Step 1: Reduction to Higher-Order Model Checking

15

Tree Generating Program Tree Automaton

reject

Predicates Step 3: Predicate Discovery Counterexample

Fair infinite executions exist!

An extension of a method for disproving plain termination [Kuwahara+ CAV15]

slide-16
SLIDE 16

Overview of Method

Step 2: Higher-Order Model Checking

accept

Fairness Constraint Functional Program

Step 1: Reduction to Higher-Order Model Checking

16

Tree Generating Program Tree Automaton

reject

Predicates Step 3: Predicate Discovery Counterexample Fair infinite paths exist

Computation Tree

Fair infinite executions exist!

slide-17
SLIDE 17

Fair infinite executions exist!

Overview of Method

Step 2: Higher-Order Model Checking

accept

Fairness Constraint Functional Program

Step 1: Reduction to Higher-Order Model Checking

17

Tree Generating Program Tree Automaton

reject

Predicates Step 3: Predicate Discovery Counterexample Abstracted Tree Accepted by the automaton Fair infinite paths exist

Computation Tree

slide-18
SLIDE 18

Overview of Method

Step 2: Higher-Order Model Checking

accept

Fairness Constraint Functional Program

Step 1: Reduction to Higher-Order Model Checking

18

Tree Generating Program Tree Automaton

reject

Predicates Step 3: Predicate Discovery

Fair infinite executions exist!

Counterexample Abstracted Tree Accepted by the automaton Fair infinite paths exist Sufficient condition

Computation Tree

slide-19
SLIDE 19

Overview of Method

Step 2: Higher-Order Model Checking

accept

Fairness Constraint Functional Program

Step 1: Reduction to Higher-Order Model Checking

19

Tree Generating Program Tree Automaton

reject

Predicates Step 3: Predicate Discovery Counterexample

Fair infinite executions exist!

Abstracted Tree Decide whether the automaton accepts the abstracted tree

slide-20
SLIDE 20

Overview of Method

Step 2: Higher-Order Model Checking

accept

Fairness Constraint Functional Program

Step 1: Reduction to Higher-Order Model Checking

20

Tree Generating Program Tree Automaton

reject

Predicates Step 3: Predicate Discovery Counterexample

Fair infinite executions exist!

Refine abstraction by using counterexamples

slide-21
SLIDE 21

Overview of Method

Step 2: Higher-Order Model Checking

accept

Fairness Constraint Functional Program

Step 1: Reduction to Higher-Order Model Checking

21

Tree Generating Program Tree Automaton

reject

Predicates Step 3: Predicate Discovery Counterexample

Fair infinite executions exist!

slide-22
SLIDE 22

Overview of Method

Step 2: Higher-Order Model Checking

accept

Fairness Constraint Functional Program

Step 1: Reduction to Higher-Order Model Checking

22

Tree Generating Program Tree Automaton

reject

Predicates Step 3: Predicate Discovery

Fair infinite executions exist!

Counterexample Abstracted Tree Accepted by the automaton Fair infinite paths exist Sufficient condition

Computation Tree

slide-23
SLIDE 23

23

Two Branching Nodes in Abstracted Trees

[Kuwahara+ CAV15]

  • Represents inherent non-determinism in programs
  • e.g. random integer, inputs
  • We should check if there exists a fair infinite branch
  • Represents non-determinism introduced by abstraction
  • We should check if every branch is fair and infinite

βˆƒ-node βˆ€-node

slide-24
SLIDE 24

Tree(𝐸)

let f x = let y = x+1 in if 0 < y then event B; g y else event A; g y in f *int

𝑄

let f bx=0 = if bx=0 then βˆ€(B(g true)) else βˆ€(B(g true), A(g false)) in βˆƒ(f true, f false)

𝐸

Computation tree of 𝑄

Abstract by π’š = 𝟏, 𝟏 < 𝒛 24

*

if A if A if B if B ・・・ ・・・ 0<y x=0 βˆ€ βˆ€ βˆƒ B A B Β¬(x=0) 0<y Β¬(0<y)

[Kuwahara+ CAV15]

Two Branching Nodes in Abstracted Trees

slide-25
SLIDE 25

Tree(𝐸)

let f x = let y = x+1 in if 0 < y then event B; g y else event A; g y in f *int

𝑄

let f bx=0 = if bx=0 then βˆ€(B(g true)) else βˆ€(B(g true), A(g false)) in βˆƒ(f true, f false)

𝐸

Computation tree of 𝑄

Abstract by π’š = 𝟏, 𝟏 < 𝒛 25

*

if A if A if B if B ・・・ ・・・

x=0

merged

βˆƒ Β¬(x=0)

0<y

x=0

βˆ€ βˆ€ B A B 0<y Β¬(0<y)

Inherent Non-Determinism

βˆƒ-node:

x=1 x=-1 x=-2

slide-26
SLIDE 26

Tree(𝐸)

let f x = let y = x+1 in if 0 < y then event B; g y else event A; g y in f *int

𝑄

let f bx=0 = if bx=0 then βˆ€(B(g true)) else βˆ€(B(g true), A(g false)) in βˆƒ(f true, f false)

𝐸

Computation tree of 𝑄

Abstract by π’š = 𝟏, 𝟏 < 𝒛 26

*

if A if A if B if B ・・・ ・・・

x=0 βˆƒ Β¬(x=0)

0<y

x=0

βˆ€ βˆ€ B A B 0<y Β¬(0<y)

Inherent Non-Determinism

βˆƒ-node:

x=1 x=-1 x=-2

Check if either branch is fair and infinite

slide-27
SLIDE 27

Tree(𝐸)

let f x = let y = x+1 in if 0 < y then event B; g y else event A; g y in f *int

𝑄

let f bx=0 = if bx=0 then βˆ€(B(g true)) else βˆ€(B(g true), A(g false)) in βˆƒ(f true, f false)

𝐸

Computation tree of 𝑄

Abstract by π’š = 𝟏, 𝟏 < 𝒛 27

*

if

A

if A if B

if

B

・・・ Β¬(x=0) 0<y Β¬(0<y) 0<y x=0 βˆ€ βˆƒ B

βˆ€

・・・

Non-Determinism introduced by Abstraction

βˆ€-node:

then else then else

A B

slide-28
SLIDE 28

Tree(𝐸)

let f x = let y = x+1 in if 0 < y then event B; g y else event A; g y in f *int

𝑄

let f bx=0 = if bx=0 then βˆ€(B(g true)) else βˆ€(B(g true), A(g false)) in βˆƒ(f true, f false)

𝐸

Computation tree of 𝑄

Abstract by π’š = 𝟏, 𝟏 < 𝒛 28

*

if

A

if A if B

if

B

・・・ Β¬(x=0) 0<y Β¬(0<y) 0<y x=0 βˆ€ βˆƒ B

βˆ€

・・・

then else then else

A B

Non-Determinism introduced by Abstraction

βˆ€-node:

Check if both branches are fair and infinite

slide-29
SLIDE 29

Parity Tree Automaton 𝐡𝐷

Tree(𝐸) is accepted by 𝐡𝐷 if

  • βˆƒ-node

Some branches have fair infinite paths

  • βˆ€-node

All branches have fair infinite paths

Β¬(x=0) 0<y Β¬(0<y) 0<y x=0 βˆ€ βˆ€ βˆƒ B A B

29

If Tree(𝐸) is accepted by 𝐡𝐷, 𝑄 is NOT fair-terminating

slide-30
SLIDE 30

Parity Tree Automaton 𝐡𝐷

Tree(𝐸) is accepted by 𝐡𝐷 if

  • βˆƒ-node

Some branches have fair infinite paths

  • βˆ€-node

All branches have fair infinite paths

Β¬(x=0) 0<y Β¬(0<y) 0<y x=0 βˆ€ βˆ€ βˆƒ B A B

30

If Tree(𝐸) is accepted by 𝐡𝐷, 𝑄 is NOT fair-terminating Needed to express fairness

slide-31
SLIDE 31

Overview of Method

Step 2: Higher-Order Model Checking

accept

Fairness Constraint Functional Program

Step 1: Reduction to Higher-Order Model Checking

31

Tree Generating Program Tree Automaton

reject

Predicates Step 3: Predicate Discovery Counterexample

Fair infinite executions exist!

Abstracted Tree Decide whether the automaton accepts the abstracted tree

slide-32
SLIDE 32

Input:

  • Tree generating Boolean Program 𝐸
  • Parity tree automaton 𝐡𝐷

Output of Step 1 32

Step 2

Output: Whether 𝐡𝐷 accepts π”π¬πŸπŸ 𝐸 If 𝐡𝑑 rejects the tree,

counterexample will be returned

slide-33
SLIDE 33

Input:

  • Tree generating Boolean Program 𝐸
  • Parity tree automaton 𝐡𝐷

Output of Step 1 33

Step 2

Output: Whether 𝐡𝐷 accepts π”π¬πŸπŸ 𝐸 If 𝐡𝑑 rejects the tree,

counterexample will be returned

Higher-order model checking

[Ong LICS06]

slide-34
SLIDE 34

Counterexample Tree

Subtree that is NOT accepted by 𝐡𝐷

Abstracted computation tree Counterexample tree

34

βˆ€ End βˆƒ A A A βˆƒ βˆ€ End βˆƒ A A A

slide-35
SLIDE 35

Counterexample Representation

35

Challenge: How to represent an infinite counterexample tree?

slide-36
SLIDE 36

Counterexample Representation

  • cf. Type based effective selection

[Carayol&Serre LICS12] [Tsukada&Ong LICS14]

main = βˆƒ (End, βˆ€ f) f = βˆ€(𝐡 f)

36

Solution: Use a finite program that generates a counterexample tree

generates

Challenge: How to represent an infinite counterexample tree?

slide-37
SLIDE 37

Overview of Method

Step 2: Higher-Order Model Checking

accept

Fairness Constraint Functional Program

Step 1: Reduction to Higher-Order Model Checking

37

Tree Generating Program Tree Automaton

reject

Predicates Step 3: Predicate Discovery Counterexample

Fair infinite executions exist!

Refine abstraction by using counterexamples

slide-38
SLIDE 38

38

Discover predicates from counterexample paths

Abstraction Refinement

Example:

if flag then fair_loop() else ()

[Kobayashi+ PLDI11] [Kuwahara+ CAV15]

if

( )

(AB)πœ• Computation tree

always true

slide-39
SLIDE 39

39

Discover predicates from counterexample paths

Abstraction Refinement

Example:

if flag then fair_loop() else ()

[Kobayashi+ PLDI11] [Kuwahara+ CAV15]

if

( )

(AB)πœ• Coarse abstraction Abstracted tree βˆ€

End

(AB)πœ• Computation tree

Spurious

slide-40
SLIDE 40

40

Discover predicates from counterexample paths

Abstraction Refinement

Example:

if flag then fair_loop() else ()

[Kobayashi+ PLDI11] [Kuwahara+ CAV15]

if

( )

(AB)πœ• Coarse abstraction Abstracted tree βˆ€

End

(AB)πœ• Computation tree

Discover new predicates by analyzing counterexample paths

slide-41
SLIDE 41

41

Discover predicates from counterexample paths

Abstraction Refinement

Example:

if flag then fair_loop() else ()

[Kobayashi+ PLDI11] [Kuwahara+ CAV15]

if

( )

(AB)πœ• Coarse abstraction Abstracted tree βˆ€

End

(AB)πœ•

Abstraction with discovered predicates

Computation tree (AB)πœ• βˆ€

slide-42
SLIDE 42

42

Challenge: Previous techniques are limited to finite counterexample paths

Predicates Discovery from Infinite Paths

Infinite counterexample path

βˆ€

A𝝏

(AB)πœ•

slide-43
SLIDE 43

Solution:

Use finite prefixes of counterexample paths

43

Finite length

Challenge: Previous techniques are limited to finite counterexample paths

βˆ€

Aπœ•

(AB)πœ•

Predicates Discovery from Infinite Paths

slide-44
SLIDE 44

Overview of Method

Step 2: Higher-Order Model Checking

accept

Fairness Constraint Functional Program

Step 1: Reduction to Higher-Order Model Checking

44

Tree Generating Program Tree Automaton

reject

Predicates Step 3: Predicate Discovery Counterexample

Fair infinite executions exist!

slide-45
SLIDE 45

Our Method is …

  • Sound
  • Incomplete
  • Not terminating, when 𝑄 is fair-terminating

β†’ Run a fair-termination verifier at the same time

45 [Murase+ POPL16]

slide-46
SLIDE 46

Outline

  • Termination & Fair-Termination
  • Importance of Fair-Termination
  • Our Method
  • Implementation and Experiments
  • Related Work
  • Conclusion

46

slide-47
SLIDE 47

Implementation

  • An extension of MoCHi [Kobayashi+ PLDI11]
  • Backend
  • Higher-order model checker:

HorSatP [Fujima 15] οΌ‹ Counterexample generation

  • SMT solver:

Z3 [de Moura & BjΓΈrner TACAS08]

47

slide-48
SLIDE 48

Experiments

Two Benchmarks

  • 1. Small, original benchmark programs
  • 2. Variants of the benchmark programs in

[Koskinen&Terauchi LICS14] and [Murase+ POPL16]

All programs are NOT fair-terminating

48

slide-49
SLIDE 49

49

  • Spec: Xeon E5-2680 v3 (2.50GHz, 16GB of memory)
  • Time Limit: 300 seconds

Program Order Cycles Time[sec] murase-repeat 2 2 0.98 murase-closure 2 2 0.8 koskinen-1 2 3 2.96 koskinen-2 1 5 9.5 koskinen-3-1 1 4 4.94 koskinen-3-2 1 ≧2 timeout koskinen-3-2

(predicates given by hand)

1 1 0.87 koskinen-3-3 1 4 5.63 (Excerpt)

Experiment Results

slide-50
SLIDE 50

Outline

  • Termination & Fair-Termination
  • Importance of Fair-Termination
  • Our Method
  • Implementation and Experiments
  • Related Work
  • Conclusion

50

slide-51
SLIDE 51

Related Work

  • Proving fair CTL and CTL* properties

[Cook+ TACAS15] [Cook+ CAV15]

  • Disproving fair-termination of

multi-threaded programs [Atig+ CAV12]

51

Automated verification for higher-order programs

  • Proving fair-termination [Murase+ POPL16]
  • Disproving plain termination [Kuwahara+ CAV15]

Temporal verification for first-order programs

slide-52
SLIDE 52

Conclusion

Future work

  • Tighter integration with fair-termination verification
  • Scalability
  • General temporal property verification
  • Reduction to parity tree automata HO model checking
  • Finite representations of infinite counterexample trees
  • Predicate discovery from finite counterexample prefixes

52

Automated method for disproving fair-termination

  • f higher-order functional programs
slide-53
SLIDE 53

Program that Our Method Cannot Verify

53

let rec repeat n = if n = 0 then () else (event A; repeat (n-1)) let rec f x = repeat x; event B; f (x+1) let main = f 0 Extra: In order to prove the existence

  • f fair infinite path,

we must prove that event B occurs infinitely often For this, we must prove that repeat eventually terminates for arbitrary input x Our method cannot prove the termination automatically

slide-54
SLIDE 54

Program that Our Method Cannot Verify

54

let rec repeat n = if n = 0 then () else (event A; repeat (n-1)) let rec f x = repeat x; event B; f (x+1) let main = f 0 Extra: In order to prove the existence

  • f fair infinite path,

we must prove that event B occurs infinitely often For this, we must prove that repeat eventually terminates for arbitrary input x Our method cannot prove the termination automatically

  • cf. Termination verification

for higher-order programs

[Giesl+ TOPLAS11] [Kuwahara+ ESOP14]