verified efficient implementation of gabow's strongly connected

56
Verified Efficient Implementation of Gabow’s Strongly Connected Component Algorithm Peter Lammich TU München July 2014

Upload: trannga

Post on 15-Feb-2017

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Verified Efficient Implementation of Gabow's Strongly Connected

Verified Efficient Implementation of Gabow’sStrongly Connected Component Algorithm

Peter Lammich

TU München

July 2014

Page 2: Verified Efficient Implementation of Gabow's Strongly Connected

Motivation

• Verify algorithm that computes SCCs of a digraph• Variants/Applications of algorithm

• Enumerate SCCs• Emptiness check of Generalized Büchi-Automata• . . .

• Re-use formalization between variants• Generate efficiently executable code

Page 3: Verified Efficient Implementation of Gabow's Strongly Connected

Outline

1 Gabow’s SCC Algorithm

2 Isabelle/HOL Formalization

3 Performance Evaluation

Page 4: Verified Efficient Implementation of Gabow's Strongly Connected

Outline

1 Gabow’s SCC Algorithm

2 Isabelle/HOL Formalization

3 Performance Evaluation

Page 5: Verified Efficient Implementation of Gabow's Strongly Connected

Strongly Connected Components• SCC is maximal set of mutually reachable nodes

A

B

C

D E

F

Page 6: Verified Efficient Implementation of Gabow's Strongly Connected

Strongly Connected Components• SCC is maximal set of mutually reachable nodes

A

B

C

D E

F

Page 7: Verified Efficient Implementation of Gabow's Strongly Connected

Path-Based Algorithms

• Depth first search• On back edge, collapse nodes of induced cycle• Eventually, each node represents SCC

Page 8: Verified Efficient Implementation of Gabow's Strongly Connected

Path-Based Algorithm Example

A

B

C

D E

F

Page 9: Verified Efficient Implementation of Gabow's Strongly Connected

Path-Based Algorithm Example

A

B

C

D E

F

Page 10: Verified Efficient Implementation of Gabow's Strongly Connected

Path-Based Algorithm Example

A

B

C

D E

F

Page 11: Verified Efficient Implementation of Gabow's Strongly Connected

Path-Based Algorithm Example

A

B

C

D E

F

Page 12: Verified Efficient Implementation of Gabow's Strongly Connected

Path-Based Algorithm Example

A

B

C

D E

F

Page 13: Verified Efficient Implementation of Gabow's Strongly Connected

Path-Based Algorithm Example

A

B

C

D E

F

Page 14: Verified Efficient Implementation of Gabow's Strongly Connected

Path-Based Algorithm Example

A

B

C

D E

F

Page 15: Verified Efficient Implementation of Gabow's Strongly Connected

Path-Based Algorithm Example

A

B

C

D E

F

Page 16: Verified Efficient Implementation of Gabow's Strongly Connected

Path-Based Algorithm Example

A

B

C

D E

F

Page 17: Verified Efficient Implementation of Gabow's Strongly Connected

Path-Based Algorithm Example

A

B

C

D E

F

Page 18: Verified Efficient Implementation of Gabow's Strongly Connected

Path-Based Algorithm Example

A

B

C

D E

F

Page 19: Verified Efficient Implementation of Gabow's Strongly Connected

Path-Based Algorithm Example

A

B

C

D E

F

Page 20: Verified Efficient Implementation of Gabow's Strongly Connected

Path-Based Algorithm Example

A

B

C

D E

F

Page 21: Verified Efficient Implementation of Gabow's Strongly Connected

Gabow’s Data Structure

• How to maintain collapsed nodes on stack?• Use boundary stack

• contains indexes of bounds between collapsed nodes

• Yields linear-time algorithm

Page 22: Verified Efficient Implementation of Gabow's Strongly Connected

Gabow’s Data Structure Example

A

B

C

D E

F

DFS stack:Boundary stack:

Page 23: Verified Efficient Implementation of Gabow's Strongly Connected

Gabow’s Data Structure Example

A

B

C

D E

F

DFS stack: ABoundary stack: 0

Page 24: Verified Efficient Implementation of Gabow's Strongly Connected

Gabow’s Data Structure Example

A

B

C

D E

F

DFS stack: A BBoundary stack: 0 1

Page 25: Verified Efficient Implementation of Gabow's Strongly Connected

Gabow’s Data Structure Example

A

B

C

D E

F

DFS stack: A BBoundary stack: 0

Page 26: Verified Efficient Implementation of Gabow's Strongly Connected

Gabow’s Data Structure Example

A

B

C

D E

F

DFS stack: A B CBoundary stack: 0 2

Page 27: Verified Efficient Implementation of Gabow's Strongly Connected

Gabow’s Data Structure Example

A

B

C

D E

F

DFS stack: A B CBoundary stack: 0

Page 28: Verified Efficient Implementation of Gabow's Strongly Connected

Gabow’s Data Structure Example

A

B

C

D E

F

DFS stack: A B C DBoundary stack: 0 4

Page 29: Verified Efficient Implementation of Gabow's Strongly Connected

Gabow’s Data Structure Example

A

B

C

D E

F

DFS stack: A B CBoundary stack: 0

Page 30: Verified Efficient Implementation of Gabow's Strongly Connected

Gabow’s Data Structure Example

A

B

C

D E

F

DFS stack: A B C EBoundary stack: 0 4

Page 31: Verified Efficient Implementation of Gabow's Strongly Connected

Gabow’s Data Structure Example

A

B

C

D E

F

DFS stack: A B C E FBoundary stack: 0 4 5

Page 32: Verified Efficient Implementation of Gabow's Strongly Connected

Gabow’s Data Structure Example

A

B

C

D E

F

DFS stack: A B C E FBoundary stack: 0 4

Page 33: Verified Efficient Implementation of Gabow's Strongly Connected

Gabow’s Data Structure Example

A

B

C

D E

F

DFS stack: A B CBoundary stack: 0

Page 34: Verified Efficient Implementation of Gabow's Strongly Connected

Gabow’s Data Structure Example

A

B

C

D E

F

DFS stack:Boundary stack:

Page 35: Verified Efficient Implementation of Gabow's Strongly Connected

Outline

1 Gabow’s SCC Algorithm

2 Isabelle/HOL Formalization

3 Performance Evaluation

Page 36: Verified Efficient Implementation of Gabow's Strongly Connected

Re-usable Formalization

• Goal: Formalize family of SCC-based algorithms• Enumerate SCCs• GBA emptiness check• ...

• Approach: Formalize “skeleton” SCC algorithm first• Just the node-contracting DFS, no output• Theorems for VCs (invariant preservation, . . .)• Stepwise refinement to executable code

• Reuse this formalization for actual algorithms• Utilize existing Isabelle technologies

• Collection Framework, Refinement Framework, Autoref tool• Code generator, locales

Page 37: Verified Efficient Implementation of Gabow's Strongly Connected

Re-usable Formalization

• Goal: Formalize family of SCC-based algorithms• Enumerate SCCs• GBA emptiness check• ...

• Approach: Formalize “skeleton” SCC algorithm first• Just the node-contracting DFS, no output• Theorems for VCs (invariant preservation, . . .)• Stepwise refinement to executable code

• Reuse this formalization for actual algorithms• Utilize existing Isabelle technologies

• Collection Framework, Refinement Framework, Autoref tool• Code generator, locales

Page 38: Verified Efficient Implementation of Gabow's Strongly Connected

Re-usable Formalization

• Goal: Formalize family of SCC-based algorithms• Enumerate SCCs• GBA emptiness check• ...

• Approach: Formalize “skeleton” SCC algorithm first• Just the node-contracting DFS, no output• Theorems for VCs (invariant preservation, . . .)• Stepwise refinement to executable code

• Reuse this formalization for actual algorithms

• Utilize existing Isabelle technologies• Collection Framework, Refinement Framework, Autoref tool• Code generator, locales

Page 39: Verified Efficient Implementation of Gabow's Strongly Connected

Re-usable Formalization

• Goal: Formalize family of SCC-based algorithms• Enumerate SCCs• GBA emptiness check• ...

• Approach: Formalize “skeleton” SCC algorithm first• Just the node-contracting DFS, no output• Theorems for VCs (invariant preservation, . . .)• Stepwise refinement to executable code

• Reuse this formalization for actual algorithms• Utilize existing Isabelle technologies

• Collection Framework, Refinement Framework, Autoref tool• Code generator, locales

Page 40: Verified Efficient Implementation of Gabow's Strongly Connected

Design of the Formalization

Skeleton Specification

Abstract Skeleton Algorithm

v

Gabow’s Implementation

v

SML Code

v

Actual Spec

Actual Algo

vre-use

Actual Impl

vre-use

SML Code

vre-use

Page 41: Verified Efficient Implementation of Gabow's Strongly Connected

Design of the Formalization

Skeleton Specification

Abstract Skeleton Algorithm

v

Gabow’s Implementation

v

SML Code

v

Actual Spec

Actual Algo

vre-use

Actual Impl

vre-use

SML Code

vre-use

Page 42: Verified Efficient Implementation of Gabow's Strongly Connected

Design of the Formalization

Skeleton Specification

Abstract Skeleton Algorithm

v

Gabow’s Implementation

v

SML Code

v

Actual Spec

Actual Algo

vre-use

Actual Impl

vre-use

SML Code

vre-use

Page 43: Verified Efficient Implementation of Gabow's Strongly Connected

Design of the Formalization

Skeleton Specification

Abstract Skeleton Algorithm

v

Gabow’s Implementation

v

SML Code

v

Actual Spec

Actual Algo

vre-use

Actual Impl

vre-use

SML Code

vre-use

Page 44: Verified Efficient Implementation of Gabow's Strongly Connected

Design of the Formalization

Skeleton Specification

Abstract Skeleton Algorithm

v

Gabow’s Implementation

v

SML Code

v

Actual Spec

Actual Algo

vre-use

Actual Impl

vre-use

SML Code

vre-use

Page 45: Verified Efficient Implementation of Gabow's Strongly Connected

Design of the Formalization

Skeleton Specification

Abstract Skeleton Algorithm

v

Gabow’s Implementation

v

SML Code

v

Actual Spec

Actual Algo

vre-use

Actual Impl

vre-use

SML Code

vre-use

Page 46: Verified Efficient Implementation of Gabow's Strongly Connected

Design of the Formalization

Skeleton Specification

Abstract Skeleton Algorithm

v

Gabow’s Implementation

v

SML Code

v

Actual Spec

Actual Algo

vre-use

Actual Impl

vre-use

SML Code

vre-use

Page 47: Verified Efficient Implementation of Gabow's Strongly Connected

Design of the Formalization

Skeleton Specification

Abstract Skeleton Algorithm

v

Gabow’s Implementation

v

SML Code

v

Actual Spec

Actual Algo

vre-use

Actual Impl

vre-use

SML Code

vre-use

Page 48: Verified Efficient Implementation of Gabow's Strongly Connected

Isabelle Refinement Framework• Nondeterministic monadic programs

• Supports stepwise refinement• Verification Condition Generator

Page 49: Verified Efficient Implementation of Gabow's Strongly Connected

Isabelle Refinement Framework• Nondeterministic monadic programs• Supports stepwise refinement• Verification Condition Generator

Page 50: Verified Efficient Implementation of Gabow's Strongly Connected

Autoref-Tool and Collections Framework• Automatic Refinement Tool (Autoref)

• Parametricity-based approach to data refinement• Automatic synthesis of implementation from abstract program

• Isabelle Collection Framework• Efficient data structures (Array, Hash-Table, Bitvector, . . .)• Generic Algorithm Library• Integrated with Autoref

Page 51: Verified Efficient Implementation of Gabow's Strongly Connected

Re-use of Invariants• Exploit locale mechanism to define extended invariants• Set up VCG: Only preservation of extension needs to be proved

Page 52: Verified Efficient Implementation of Gabow's Strongly Connected

Re-use of Refinements• Use basic operations in extended algorithm• Re-use refinements for basic operations

Page 53: Verified Efficient Implementation of Gabow's Strongly Connected

Outline

1 Gabow’s SCC Algorithm

2 Isabelle/HOL Formalization

3 Performance Evaluation

Page 54: Verified Efficient Implementation of Gabow's Strongly Connected

Benchmark against Java Reference Implementation

1

10

100

1000

105 106

Tim

e in m

s

Number of edges

Poly/MLMLton

JavaJava*

Page 55: Verified Efficient Implementation of Gabow's Strongly Connected

Conclusions

• Efficient, extensible formalization of Gabow’s Algorithm• Performance comparable to Java implementation (×3 . . .×4)• Variants: Enumerate SCCs, emptiness check for GBA

• Used by the CAVA fully verified LTL model checker [CAV ‘13]• Example of verified algorithm design in Isabelle/HOL

• Using Collection/Refinement/Autoref framework [ITP ’10,’12,’13]• Refinement separates algorithmic ideas from implementation• Sharing of proofs between variants of the algorithm

Page 56: Verified Efficient Implementation of Gabow's Strongly Connected

Questions

Questions?Remarks?