• Non ci sono risultati.

Introduction to Formal Methods Chapter 09: SAT-Based Model Checking

N/A
N/A
Protected

Academic year: 2021

Condividi "Introduction to Formal Methods Chapter 09: SAT-Based Model Checking"

Copied!
176
0
0

Testo completo

(1)

Introduction to Formal Methods Chapter 09: SAT-Based Model Checking

Roberto Sebastiani

DISI, Università di Trento, Italy – roberto.sebastiani@unitn.it URL: http://disi.unitn.it/rseba/DIDATTICA/fm2020/

Teaching assistant:Enrico Magnago– enrico.magnago@unitn.it

CDLM in Informatica, academic year 2019-2020

last update: Monday 18thMay, 2020, 14:49

Copyright notice: some material (text, figures) displayed in these slides is courtesy of R. Alur, M. Benerecetti, A. Cimatti, M.

Di Natale, P. Pandya, M. Pistore, M. Roveri, and S.Tonetta, who detain its copyright. Some exampes displayed in these slides are taken from [Clarke, Grunberg & Peled, “Model Checking”, MIT Press], and their copyright is detained by the authors. All the other material is copyrighted by Roberto Sebastiani. Every commercial use of this material is strictly forbidden by the copyright laws without the authorization of the authors. No copy of these slides can be displayed in public

without containing this copyright notice.

(2)

Outline

1 Background on SAT Solving

2 SAT-based Model Checking: Generalities

3 Bounded Model Checking: Intuitions

4 Bounded Model Checking: General Encoding

5 Bounded Model Checking: Relevant Subcases

6 Bounded Model Checking: An Example

7 Computing upper bounds for k

8 Inductive reasoning on invariants (aka “K-Induction”)

9 K-Induction: An Example

10 Exercises

(3)

Background on SAT Solving

Outline

1 Background on SAT Solving

2 SAT-based Model Checking: Generalities

3 Bounded Model Checking: Intuitions

4 Bounded Model Checking: General Encoding

5 Bounded Model Checking: Relevant Subcases

6 Bounded Model Checking: An Example

7 Computing upper bounds for k

8 Inductive reasoning on invariants (aka “K-Induction”)

9 K-Induction: An Example

10 Exercises

(4)

Background on SAT Solving

Resolution

Searchfor a refutation of ϕ

ϕis represented as a set of clauses

Applies iteratively theresolution ruleto pairs of clauses containing a conflicting literal, until a false clause is generated or the

resolution rule is no more applicable Many different strategies

(5)

Background on SAT Solving

Resolution Rule

Resolution of two clauses with exactly one incompatible literal:

(

common

z }| { l1∨ ... ∨ lk

resolvent

z}|{l

C0

z }| {

lk +10 ∨ ... ∨ lm0 ) (

common

z }| { l1∨ ... ∨ lk

resolvent

z}|{¬l

C00

z }| {

lk +100 ∨ ... ∨ ln00) (l1∨ ... ∨ lk

| {z }

common

lk +10 ∨ ... ∨ lm0

| {z }

C0

lk +100 ∨ ... ∨ ln00

| {z }

C00

)

EXAMPLE:

(A ∨ B C ∨ D ∨ E ) (A ∨ B ¬C ∨ F ) (A ∨ B ∨ D ∨ E ∨ F )

NOTE: many standard inference rules subcases of resolution:

A → B B → C

A → C (Transit.) A A → B

B (M. Ponens) ¬B A → B

¬A (M. Tollens)

(6)

Background on SAT Solving

Resolution Rules: unit propagation

Unit resolution:

Γ0∧ (l) ∧ (¬lW

ili) Γ0∧ (l) ∧ (W

ili) Unit subsumption:

Γ0∧ (l) ∧ (lW

ili) Γ0∧ (l)

Unit propagation= unit resolution + unit subsumption

“Deterministic” rule: appliedbeforeother “non-deterministic” rules!

(7)

Background on SAT Solving

DPLL

Davis-Putnam-Longeman-Loveland procedure(DPLL) Tries to build recursively an assignment µ satisfying ϕ;

At each recursive step assigns a truth value to (all instances of) one atom.

Performsdeterministic choicesfirst.

(8)

Background on SAT Solving

The DPLL Algorithm

function DPLL(ϕ, µ)

ifϕ = > /* base */

then return True;

ifϕ = ⊥ /* backtrack */

then return False;

if{a unit clause (l) occurs in ϕ} /* unit propagation */

then return DPLL(assign(l, ϕ), µ ∧ l);

(...)

l := choose-literal(ϕ); /* split */

return DPLL(assign(l, ϕ), µ ∧ l) or DPLL(assign(¬l, ϕ), µ ∧ ¬l);

(9)

Background on SAT Solving

“Classic” chronological backtracking

Non-recursive versions of DPLL:

variable assignments (literals) stored in a stack

each variable assignments labeled as “unit”, “open”, “closed”

when a conflict is encountered, the stack is popped up to the most recent open assignment l

l is toggled, is labeled as “closed”, and the search proceeds.

Perform “classic” chronological backtracking:

jump back to the most-recent open branching point

=⇒source of large inefficiencies

(10)

Background on SAT Solving

“Classic” chronological backtracking

Non-recursive versions of DPLL:

variable assignments (literals) stored in a stack

each variable assignments labeled as “unit”, “open”, “closed”

when a conflict is encountered, the stack is popped up to the most recent open assignment l

l is toggled, is labeled as “closed”, and the search proceeds.

Perform “classic” chronological backtracking:

jump back to the most-recent open branching point

=⇒source of large inefficiencies

(11)

Background on SAT Solving

Classic chronological backtracking – example

c1: ¬A1∨ A2 c2: ¬A1∨ A3∨ A9 c3: ¬A2∨ ¬A3∨ A4

c4: ¬A4∨ A5∨ A10 c5: ¬A4∨ A6∨ A11 c6: ¬A5∨ ¬A6

c7:A1∨ A7∨ ¬A12 c8:A1∨ A8

c9: ¬A7∨ ¬A8∨ ¬A13

...

{...,¬A9, ¬A10, ¬A11,A12,A13, ...} (initial assignment)

(12)

Background on SAT Solving

Classic chronological backtracking – example

c1: ¬A1∨ A2 c2: ¬A1∨ A3A9 c3: ¬A2∨ ¬A3∨ A4

c4: ¬A4∨ A5A10 c5: ¬A4∨ A6A11 c6: ¬A5∨ ¬A6

c7:A1∨ A7¬A12 c8:A1∨ A8

c9: ¬A7∨ ¬A8¬A13

...

¬A11 A12

A13

¬A10

¬A9

{...,¬A9, ¬A10, ¬A11,A12,A13, ...}

(initial assignment)

(13)

Background on SAT Solving

Classic chronological backtracking – example

c1:¬A1∨ A2 c2:¬A1∨ A3A9 c3: ¬A2∨ ¬A3∨ A4

c4: ¬A4∨ A5A10 c5: ¬A4∨ A6A11 c6: ¬A5∨ ¬A6

c7:A1∨ A7¬A12 c8:A1∨ A8 c9: ¬A7∨ ¬A8¬A13

...

A1

¬A11

A12

A13

¬A10

¬A9

{...,¬A9, ¬A10, ¬A11,A12,A13, ...,A1} ... (branch onA1)

(14)

Background on SAT Solving

Classic chronological backtracking – example

c1:¬A1A2 c2:¬A1A3A9 c3:¬A2¬A3∨ A4

c4: ¬A4∨ A5A10 c5: ¬A4∨ A6A11 c6: ¬A5∨ ¬A6

c7:A1∨ A7¬A12 c8:A1∨ A8 c9: ¬A7∨ ¬A8¬A13

... AA23

A1

¬A11

A12

A13

¬A10

¬A9

{...,¬A9, ¬A10, ¬A11,A12,A13, ...,A1,A2,A3} (unitA2,A3)

(15)

Background on SAT Solving

Classic chronological backtracking – example

c1:¬A1A2 c2:¬A1A3A9 c3:¬A2¬A3A4 c4:¬A4∨ A5A10 c5:¬A4∨ A6A11 c6: ¬A5∨ ¬A6

c7:A1∨ A7¬A12 c8:A1∨ A8 c9: ¬A7∨ ¬A8¬A13

...

A4

A2

A3

A1

¬A11

A12

A13

¬A10

¬A9

{...,¬A9, ¬A10, ¬A11,A12,A13, ...,A1,A2,A3,A4} (unitA4)

(16)

Background on SAT Solving

Classic chronological backtracking – example

c1:¬A1A2 c2:¬A1A3A9 c3:¬A2¬A3A4 c4:¬A4A5A10 c5:¬A4A6A11 c6:¬A5¬A6 × c7:A1∨ A7¬A12 c8:A1∨ A8 c9: ¬A7∨ ¬A8¬A13

...

A5

A6

A4

A2

A3

A1

¬A11

A12

A13

¬A10

¬A9

{...,¬A9, ¬A10, ¬A1¬A41,A12,A13, ...,A1,A2,A3,A4,A5,A6} (unitA5,A6)=⇒conflict

(17)

Background on SAT Solving

Classic chronological backtracking – example

c1: ¬A1∨ A2 c2: ¬A1∨ A3A9 c3: ¬A2∨ ¬A3∨ A4

c4: ¬A4∨ A5A10 c5: ¬A4∨ A6A11 c6: ¬A5∨ ¬A6

c7:A1∨ A7¬A12 c8:A1∨ A8

c9: ¬A7∨ ¬A8¬A13

...

A5

A6

A4

A2

A3

A1

¬A11

A12

A13

¬A10

¬A9

{...,¬A9, ¬A10, ¬A11,A12,A13, ...}

=⇒backtrack up to A1

(18)

Background on SAT Solving

Classic chronological backtracking – example

c1:¬A1∨ A2 c2:¬A1∨ A3A9 c3: ¬A2∨ ¬A3∨ A4

c4: ¬A4∨ A5A10 c5: ¬A4∨ A6A11 c6: ¬A5∨ ¬A6

c7:A1∨ A7¬A12 c8:A1∨ A8

c9: ¬A7∨ ¬A8¬A13

...

¬A1

A5

A6

A4

A2

A3

A1

¬A11

A12

A13

¬A10

¬A9

{...,¬A9, ¬A10, ¬A11,A12,A13, ...,¬A1} (unit¬A1)

(19)

Background on SAT Solving

Classic chronological backtracking – example

c1:¬A1∨ A2 c2:¬A1∨ A3A9 c3: ¬A2∨ ¬A3∨ A4

c4: ¬A4∨ A5A10 c5: ¬A4∨ A6A11 c6: ¬A5∨ ¬A6

c7:A1A7¬A12 c8:A1A8 c9:¬A7¬A8¬A13 × ...

A7

A8

¬A1

A5

A6

A4

A2

A3

A1

¬A11

A12

A13

¬A10

¬A9

{...,¬A9, ¬A10, ¬A11,A12,A13, ...,¬A1,A7,A8} (unitA7, A8) =⇒conflict

(20)

Background on SAT Solving

Classic chronological backtracking – example

c1: ¬A1∨ A2 c2: ¬A1∨ A3A9 c3: ¬A2∨ ¬A3∨ A4

c4: ¬A4∨ A5A10 c5: ¬A4∨ A6A11 c6: ¬A5∨ ¬A6

c7:A1∨ A7¬A12 c8:A1∨ A8

c9: ¬A7∨ ¬A8¬A13

...

A7

A8

¬A1

A5

A6

A4

A2

A3

A1

¬A11 A12

A13

¬A10

¬A9

{...,¬A9, ¬A10, ¬A11,A12,A13, ...}

=⇒backtrack to the most recent open branching point

(21)

Background on SAT Solving

Classic chronological backtracking – example

c1: ¬A1∨ A2 c2: ¬A1∨ A3A9 c3: ¬A2∨ ¬A3∨ A4

c4: ¬A4∨ A5A10 c5: ¬A4∨ A6A11 c6: ¬A5∨ ¬A6

c7:A1∨ A7¬A12 c8:A1∨ A8

c9: ¬A7∨ ¬A8¬A13

...

A7

A8

¬A1

A5

A6

A4

A2

A3

A1

¬A11 A12

A13

¬A10

¬A9

{...,¬A9, ¬A10, ¬A11,A12,A13, ...}

=⇒lots of useless search before backtracking up to A13!

(22)

Background on SAT Solving

Classic chronological backtracking: drawbacks

often the branch heuristic delays the “right” choice

chronological backtracking always backtracks to the most recent branching point, even though a higher backtrack could be possible

=⇒lots of useless search!

(23)

Background on SAT Solving

Modern DPLL implementations

[Silva & Sakallah ’96, Moskewicz et al. ’01]

Conflict-Driven Clause-Learning (CDCL)DPLL solvers:

Non-recursive: stack-based representation of data structures Efficient data structures for doing and undoing assignments Performconflict-driven backtracking (backjumping)and learning May perform search restarts

Reason on total assignments

Dramatically efficient: solve industrial-derived problems with ≈ 107 Boolean variables and ≈ 107− 108clauses

(24)

Background on SAT Solving

Conflict-directed backtracking (backjumping) and learning

Idea: when a branch µ fails,

(i) conflict analysis: reveal the sub-assignment η ⊆ µ causing the failure (conflict set η):

find η ⊆ µ by generating theconflict clause Cdef= ¬ηvia resolution from the falsified clause

by construction ϕ ∧ η |= ⊥, henceϕ |=C, so that(ϕ ∧C) ⇔ ϕ (ii) learning: add the conflict clause C to the clause set

(iii) backjumping: backtrack to the highest branching point s.t. the stack contains all-but-one literals in η, and then unit-propagate the unassigned literal on C

may jump back up much more than one decision level in the stack

=⇒may avoid lots of redundant search!!.

(25)

Background on SAT Solving

State-of-the-art backjumping and learning: intuitions

Conflict analysis:find η ⊂ µ (typically much smaller than µ!) s.t.

assigning only the literals in η would have falsified the same clause after a chain of unit propagations

intuition: “η contains only the relevant assignments which caused the failure”

Backjumping: climb up to many decision levels in the stack intuition: “go back to the oldest decision where you’d have done something different if only you had known η”

=⇒ may avoid lots of redundant search

=⇒ choose η s.t. all but one literals in η are as “old” as possible Learning:in future branches, when all-but-one literals in η are assigned, the remaining literal is assigned to false by

unit-propagation:

intuition: “when you’re about to repeat the mistake, do the opposite of the last step”

=⇒ avoid finding the same conflict again

(26)

Background on SAT Solving

State-of-the-art backjumping and learning: intuitions

Conflict analysis:find η ⊂ µ (typically much smaller than µ!) s.t.

assigning only the literals in η would have falsified the same clause after a chain of unit propagations

intuition: “η contains only the relevant assignments which caused the failure”

Backjumping: climb up to many decision levels in the stack intuition: “go back to the oldest decision where you’d have done something different if only you had known η”

=⇒ may avoid lots of redundant search

=⇒ choose η s.t. all but one literals in η are as “old” as possible Learning:in future branches, when all-but-one literals in η are assigned, the remaining literal is assigned to false by

unit-propagation:

intuition: “when you’re about to repeat the mistake, do the opposite of the last step”

=⇒ avoid finding the same conflict again

(27)

Background on SAT Solving

State-of-the-art backjumping and learning: intuitions

Conflict analysis:find η ⊂ µ (typically much smaller than µ!) s.t.

assigning only the literals in η would have falsified the same clause after a chain of unit propagations

intuition: “η contains only the relevant assignments which caused the failure”

Backjumping: climb up to many decision levels in the stack intuition: “go back to the oldest decision where you’d have done something different if only you had known η”

=⇒ may avoid lots of redundant search

=⇒ choose η s.t. all but one literals in η are as “old” as possible Learning:in future branches, when all-but-one literals in η are assigned, the remaining literal is assigned to false by

unit-propagation:

intuition: “when you’re about to repeat the mistake, do the opposite of the last step”

=⇒ avoid finding the same conflict again

(28)

Background on SAT Solving

Stack-based representation of a truth assignment µ

stack partitioned intodecision levels:

onedecision literal itsimplied literals

each implied literal tagged with the clause causing its unit-propagation (antecedent clause)

equivalent to animplication graph:

a node without incoming edges represent adecision literal

the graph contains l17−→ l,...,lc n7−→ l iffc cdef=Wn

j=1¬li ∨ l is the antecedent clause of l

representation of the dependencies between literals in µ

implied literals dec. level N

dec. level 1 dec. level 0

decision literal . . .

. . .

. . . . . .

. . .

. . . l01

l02

l11

l12

l1

lN2

lN1

lN

CN1

C12

C11

C02

C01

CN2

(29)

Background on SAT Solving

Implication graph - example

c1:¬A1A2 c2:¬A1A3A9 c3:¬A2¬A3A4 c4:¬A4A5A10 c5:¬A4A6A11 c6:¬A5¬A6 × c7:A1∨ A7¬A12 c8:A1∨ A8 c9: ¬A7∨ ¬A8¬A13

...

Conflict!

A5

A6

c4

c6

c6

c5

c4

c5

A5

A6

c3

c3

A4

A4

A2

A3

c2

c2

c1

A2

A3

A1

A1

A12

A13

¬A9 ¬A11

¬A10

¬A11

A12

A13

¬A10

¬A9

(30)

Background on SAT Solving

Building a conflict set/clause by resolution

1. C := conflicting clause 2. repeat

(i) resolve current clause C with the antecedent clause of the last unit-propagated literal l in C

until C verifies some given termination criteria Idea: “Undo” unit-propagations.

Decision strategy: repeat until C contains only decision literals

¬A1A2

¬A1A3A9

¬A2¬A3A4

¬A4A5A10

¬A4A6A11

Conflicting cl.

z }| {

¬A5¬A6

¬A4¬A5A11 (A6)

¬A4A10A11

(A5)

¬A2¬A3A10A11

(A4)

¬A2¬A1A9A10A11

(A3)

¬A1A9A10A11

(A2)

(31)

Background on SAT Solving

Building a conflict set/clause by resolution

1. C := conflicting clause 2. repeat

(i) resolve current clause C with the antecedent clause of the last unit-propagated literal l in C

until C verifies some given termination criteria Idea: “Undo” unit-propagations.

Decision strategy: repeat until C contains only decision literals

¬A1A2

¬A1A3A9

¬A2¬A3A4

¬A4A5A10

¬A4A6A11

Conflicting cl.

z }| {

¬A5¬A6

¬A4¬A5A11 (A6)

¬A4A10A11

(A5)

¬A2¬A3A10A11

(A4)

¬A2¬A1A9A10A11

(A3)

¬A1A9A10A11

(A2)

(32)

Background on SAT Solving

Building a conflict set/clause by resolution

1. C := conflicting clause 2. repeat

(i) resolve current clause C with the antecedent clause of the last unit-propagated literal l in C

until C verifies some given termination criteria Idea: “Undo” unit-propagations.

Decision strategy: repeat until C contains only decision literals

¬A1A2

¬A1A3A9

¬A2¬A3A4

¬A4A5A10

¬A4A6A11

Conflicting cl.

z }| {

¬A5¬A6

¬A4¬A5A11 (A6)

¬A4A10A11

(A5)

¬A2¬A3A10A11

(A4)

¬A2¬A1A9A10A11

(A3)

¬A1A9A10A11

(A2)

(33)

Background on SAT Solving

State-of-the-art in backjumping & learning

First Unique Implication Point (1st UIP)strategy:

corresponds to consider the first clause encountered containing one literal of the current decision level (1st UIP).

¬A4A5A10

¬A4A6A11

Conflicting cl.

z }| {

¬A5¬A6

¬A4¬A5A11 (A6)

¬A4

|{z}

1st UIP

∨A10A11 (A5)

(34)

Background on SAT Solving

1st UIP strategy – example

c1:¬A1A2 c2:¬A1A3A9 c3:¬A2¬A3A4 c4:¬A4A5A10 c5:¬A4A6A11 c6:¬A5¬A6 × c7:A1∨ A7¬A12

c8:A1∨ A8 c9: ¬A7∨ ¬A8¬A13 ...

1st UIP Decision

Conflict!

A5

A6

c4

c6

c6

c5

c4

c5

A5

A6

c3

c3

A4

A4

A2

A3

c2

c2

c1

A2

A3

A1

A1

A12

A13

¬A9 ¬A11

¬A10

¬A11

A12

A13

¬A10

¬A9

=⇒Conflict set: {¬A10, ¬A11,A4}, learn c10:=A10∨ A11∨ ¬A4

(35)

Background on SAT Solving

1st UIP strategy and backjumping

The added conflict clause states the reason for the conflict The procedure backtracks to the most recent decision level of the variables in the conflict clause which are not the UIP.

then the conflict clause forces the negation of the UIP by unit propagation.

E.g.: c10:=A10∨ A11∨ ¬A4

=⇒backtrack to A11, then assign ¬A4

(36)

Background on SAT Solving

1st UIP strategy – example (7)

c1:¬A1A2 c2:¬A1A3A9 c3:¬A2¬A3A4 c4:¬A4A5A10 c5:¬A4A6A11 c6:¬A5¬A6 × c7:A1∨ A7¬A12

c8:A1∨ A8 c9: ¬A7∨ ¬A8¬A13 ...

1st UIP Decision

Conflict!

A5

A6

c4

c6

c6

c5

c4

c5

A5

A6

c3

c3

A4

A4

A2

A3

c2

c2

c1

A2

A3

A1

A1

A12

A13

¬A9 ¬A11

¬A10

¬A11

A12

A13

¬A10

¬A9

=⇒Conflict set: {¬A10, ¬A11,A4}, learn c10:=A10∨ A11∨ ¬A4

(37)

Background on SAT Solving

1st UIP strategy – example (8)

c1: ¬A1∨ A2

c2: ¬A1∨ A3A9 c3: ¬A2∨ ¬A3∨ A4 c4: ¬A4∨ A5A10 c5: ¬A4∨ A6A11 c6: ¬A5∨ ¬A6 c7:A1∨ A7∨ ¬A12

c8:A1∨ A8

c9: ¬A7∨ ¬A8∨ ¬A13 c10:A10A11∨ ¬A4

...

A5

A6

A4

A2

A3

A1

¬A9 ¬A11

¬A10

¬A11

A12

A13

¬A10

¬A9

=⇒backtrack up to A11=⇒ {...,¬A9, ¬A10, ¬A11}

(38)

Background on SAT Solving

1st UIP strategy – example (9)

c1: ¬A1∨ A2

c2: ¬A1∨ A3A9 c3: ¬A2∨ ¬A3A4 c4:¬A4∨ A5A10 c5:¬A4∨ A6A11 c6: ¬A5∨ ¬A6

c7:A1∨ A7∨ ¬A12

c8:A1∨ A8

c9: ¬A7∨ ¬A8∨ ¬A13 c10:A10A11¬A4

...

c9

c9

¬A4

¬A4

A5

A6

A4

A2

A3

A1

¬A9 ¬A11

¬A10

¬A11

A12

A13

¬A10

¬A9

=⇒unit propagate ¬A4=⇒ {...,¬A9, ¬A10, ¬A11,A4}...

Riferimenti

Documenti correlati

handle temporal operators AX, EX by computing pre-images handle temporal operators AG, EG, AF, EF, AU, EU, by (implicitly) applying tableaux rules, until a fixpoint is

handle temporal operators AX, EX by computing pre-images handle temporal operators AG, EG, AF, EF, AU, EU, by (implicitly) applying tableaux rules, until a fixpoint is reached..

Kripke structure encoded as Boolean formulas (OBDDs) All operations handled as (quantified) Boolean operations Avoids building the state graph explicitly. reduces dramatically the

(E.g., 300 Boolean vars =⇒ up to 2 300 ≈ 10 100 states!) State Space Explosion:.. too much

Copyright notice: some material (text, figures) displayed in these slides is courtesy of R..

Given a fair Kripke model M, a fair non-trivial SCC is an SCC with at least one edge that contains at least one state for every fair condition. =⇒ all states in a fair (non-trivial)

Example: although state 3 belongs to sat(¬heat Uclose), the path which loops forever in 3 does not satisfy ¬heatUclose, as close never holds in that path. We restrict the

[Alternatively: there is no positive U-subformula, so that we must add a AGAF> fairness condition, which is equivalent to say that all states belong to the fairness