Tải bản đầy đủ (.pdf) (25 trang)

Chapter 1b Propositional Logic II (SAT Solving and Application) Discrete Mathematics II BK TPHCM

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (448.55 KB, 25 trang )

Propositional Logic II
Nguyen An Khuong,
Huynh Tuong Nguyen

Chapter 1b
Propositional Logic II
(SAT Solving and Application)
Contents

Discrete Mathematics II

Introduction
Quick review
Boolean Satisfiability (SAT)

SAT Solvers
WalkSAT: Idea
DPLL: Idea
A Linear Solver

(Materials drawn from Chapter 1 in:
“Michael Huth and Mark Ryan. Logic in Computer Science: Modelling and
Reasoning about Systems, 2nd Ed., Cambridge University Press, 2006”
and some other sources)

A Cubic Solver

Application of SAT
Solving
Homeworks and Next
Week Plan?



Nguyen An Khuong, Huynh Tuong Nguyen
Faculty of Computer Science and Engineering
University of Technology, VNU-HCM
1b.1


Contents

Propositional Logic II
Nguyen An Khuong,
Huynh Tuong Nguyen

1 Introduction

Quick review
Boolean Satisfiability (SAT)

Contents
Introduction
Quick review

2 SAT Solvers

WalkSAT: Idea
DPLL: Idea
A Linear Solver
A Cubic Solver

Boolean Satisfiability (SAT)


SAT Solvers
WalkSAT: Idea
DPLL: Idea
A Linear Solver
A Cubic Solver

Application of SAT
Solving
Homeworks and Next
Week Plan?

3 An Application of SAT Solving: Sudoku

1b.2


Propositional Logic II
Nguyen An Khuong,
Huynh Tuong Nguyen

1 Introduction

Quick review
Boolean Satisfiability (SAT)

Contents
Introduction

2 SAT Solvers


Quick review
Boolean Satisfiability (SAT)

SAT Solvers
WalkSAT: Idea

3 An Application of SAT Solving: Sudoku

DPLL: Idea
A Linear Solver
A Cubic Solver

Application of SAT
Solving
Homeworks and Next
Week Plan?

1b.3


Motivated Example – A Logic Puzzle

Propositional Logic II
Nguyen An Khuong,
Huynh Tuong Nguyen

• If the unicorn is mythical, then it is immortal;and
• If the unicorn is not mythical, then it is a mortal


mammal;and

Contents
Introduction
Quick review

• If the unicorn is either immortal or a mammal, then it is

horned;and
• The unicorn is magical if it is horned.

Boolean Satisfiability (SAT)

SAT Solvers
WalkSAT: Idea
DPLL: Idea
A Linear Solver
A Cubic Solver

Application of SAT
Solving

• Q: Is the unicorn mythical? Is it magical? Is it horned?

Homeworks and Next
Week Plan?

1b.4



Propositional Logic II

CNF

Nguyen An Khuong,
Huynh Tuong Nguyen

• Boolean formula φ is defined over a set of propositional

variables p1 , ..., pn , using the standard propositional
connectives ¬, ∧, ∨, −→, ←→, and parenthesis
• The domain of propositional variables is {0, 1}.
• Example: φ(p1 , p2 , p3 ) = ((¬p1 ∧ p2 ) ∨ p3 ) ∧ (¬p2 ∨ p3 ).

• A formula φ in conjunctive normal form (CNF) is a

conjunction of disjunctions (clauses) of literals, where a literal
is a variable or its complement.
• Example: φ(p1 , p2 , p3 ) = (¬p1 ∨ p2 ) ∧ (¬p2 ∨ p3 ).

Contents
Introduction
Quick review
Boolean Satisfiability (SAT)

SAT Solvers
WalkSAT: Idea
DPLL: Idea
A Linear Solver
A Cubic Solver


Proposition (see [2, Subsection 1.5.1])

There is an algorithm to translate any Boolean formula into CNF.

Application of SAT
Solving
Homeworks and Next
Week Plan?

Proposition 1.45, p. 57

φ-satisfiable iff ¬φ-not valid.

1b.5


Propositional Logic II

SAT

Nguyen An Khuong,
Huynh Tuong Nguyen

Problem

Find an assignment to the variables p1 , ..., pn such that
φ(p1 , ..., pn ) = 1, or prove that no such assignment exists.

Contents

Introduction
Quick review

Facts: SAT is an NP-complete decision problem [Cook’71]

Boolean Satisfiability (SAT)

SAT Solvers

• SAT was the first problem to be shown NP-complete.
• There are no known polynomial time algorithms for SAT.
• 36-year old conjecture:

“Any algorithm that solves SAT is exponential in the number
of variables, in the worst-case.”

WalkSAT: Idea
DPLL: Idea
A Linear Solver
A Cubic Solver

Application of SAT
Solving
Homeworks and Next
Week Plan?

1b.6


Propositional Logic II

Nguyen An Khuong,
Huynh Tuong Nguyen

1 Introduction
2 SAT Solvers

WalkSAT: Idea
DPLL: Idea
A Linear Solver
A Cubic Solver

Contents
Introduction
Quick review
Boolean Satisfiability (SAT)

SAT Solvers
WalkSAT: Idea
DPLL: Idea
A Linear Solver

3 An Application of SAT Solving: Sudoku

A Cubic Solver

Application of SAT
Solving
Homeworks and Next
Week Plan?


1b.7


WalkSAT: An Incomplete Solver

Propositional Logic II
Nguyen An Khuong,
Huynh Tuong Nguyen

• Idea: Start with a random truth assignment, and then

iteratively improve the assignment until model is found.
• Details: In each step, choose an unsatisfied clause (clause

selection), and “flip” one of its variables (variable selection).
Contents

WalkSAT: Details

Introduction
Quick review
Boolean Satisfiability (SAT)

• Termination criterion: No unsatisfied clauses are left.
• Clause selection: Choose a random unsatisfied clause.
• Variable selection:
• If there are variables that when flipped make no currently

satisfied clause unsatisfied, flip one which makes the most
unsatisfied clauses satisfied.

• Otherwise, make a choice with a certain probability between:

SAT Solvers
WalkSAT: Idea
DPLL: Idea
A Linear Solver
A Cubic Solver

Application of SAT
Solving
Homeworks and Next
Week Plan?

• picking a random variable, and
• picking a variable that when flipped minimizes the number of
unsatisfied clauses.

1b.8


DPLL: Idea

Propositional Logic II
Nguyen An Khuong,
Huynh Tuong Nguyen

Contents
Introduction

• Simplify formula based on pure literal elimination and unit


propagation
• If not done, pick an atom p and split: φ ∧ p or φ ∧ ¬p

Quick review
Boolean Satisfiability (SAT)

SAT Solvers
WalkSAT: Idea
DPLL: Idea
A Linear Solver
A Cubic Solver

Application of SAT
Solving
Homeworks and Next
Week Plan?

1b.9


A Linear Solver: Idea

Propositional Logic II
Nguyen An Khuong,
Huynh Tuong Nguyen

• Transform formula to tree of conjunctions and negations.
• Transform tree into graph.
• Mark the top of the tree as T.


Contents
Introduction
Quick review
Boolean Satisfiability (SAT)

SAT Solvers

• Propagate constraints using obvious rules.

WalkSAT: Idea

• If all leaves are marked, check that corresponding assignment

A Linear Solver

makes the formula true.

DPLL: Idea

A Cubic Solver

Application of SAT
Solving
Homeworks and Next
Week Plan?

1b.10



Propositional Logic II

Transformation

Nguyen An Khuong,
Huynh Tuong Nguyen

T (p)

=

p

T (φ1 ∧ φ2 )

=

T (φ1 ) ∧ T (φ2 )

T (¬φ)

=

¬φ(T )

T (φ1 → φ2 )

=

¬(T (φ1 ) ∧ ¬T (φ2 ))


T (φ1 ∨ φ2 )

=

¬(¬T (φ1 ) ∧ ¬T (φ2 ))

Contents
Introduction
Quick review
Boolean Satisfiability (SAT)

SAT Solvers
WalkSAT: Idea
DPLL: Idea
A Linear Solver
A Cubic Solver

Example

Application of SAT
Solving

φ = p ∧ ¬(q ∨ ¬p)

Homeworks and Next
Week Plan?

T (φ) = p ∧ ¬¬(¬q ∧ ¬¬p)


1b.11


Binary Decision Tree: Example

Propositional Logic II
Nguyen An Khuong,
Huynh Tuong Nguyen

Contents
Introduction
Quick review

See Example 1.48 and Figure 1.12 on page 70.

Boolean Satisfiability (SAT)

SAT Solvers
WalkSAT: Idea
DPLL: Idea
A Linear Solver
A Cubic Solver

Application of SAT
Solving
Homeworks and Next
Week Plan?

1b.12



Problem

Propositional Logic II
Nguyen An Khuong,
Huynh Tuong Nguyen

Contents
Introduction
Quick review

What happens to formulas of the kind ¬(φ1 ∧ φ2 )?

Boolean Satisfiability (SAT)

SAT Solvers
WalkSAT: Idea
DPLL: Idea
A Linear Solver
A Cubic Solver

Application of SAT
Solving
Homeworks and Next
Week Plan?

1b.13


A Cubic Solver: Idea


Propositional Logic II
Nguyen An Khuong,
Huynh Tuong Nguyen

Improve the linear solver as follows:
• Run linear solver
• For every node n that is still unmarked:
• Mark n with T and run linear solver, possibly resulting in
temporary marks.
• Mark n with F and run linear solver, possibly resulting in
temporary marks.
• Combine temporary marks, resulting in possibly new
permanent marks

Contents
Introduction
Quick review
Boolean Satisfiability (SAT)

SAT Solvers
WalkSAT: Idea
DPLL: Idea
A Linear Solver
A Cubic Solver

Application of SAT
Solving
Homeworks and Next
Week Plan?


1b.14


Propositional Logic II

A Sudoku Grid and Variables

Nguyen An Khuong,
Huynh Tuong Nguyen

Sudoku

Variables

/>
1
1
2
3
4
5

2

3

4

5


6

7

8

9

8
9

Introduction
Quick review

• Xijk true iff cell at row i column j

equals k.

Boolean Satisfiability (SAT)

SAT Solvers
WalkSAT: Idea

• |V | = 93 = 729

6
7

Contents


11/3/09 11:40 AM

V = {Xijk | 1 ≤ i, j, k ≤ 9}

• X726 is true
• X72k is false for k = 6

DPLL: Idea
A Linear Solver
A Cubic Solver

Application of SAT
Solving
Homeworks and Next
Week Plan?

1b.15


Constraining exactly one variable to be true

Propositional Logic II
Nguyen An Khuong,
Huynh Tuong Nguyen

Variables = {p, q, r, s}
• At least one is true:

α=p∨q∨r∨s


Contents
Introduction
Quick review
Boolean Satisfiability (SAT)

• No more than one is true:

SAT Solvers
WalkSAT: Idea

β

=


p ∨ q¯) ∧ (¯
p ∨ r¯) ∧ (¯
p ∨ s¯) ∧

q ∨ r¯) ∧ (¯
q ∨ s¯) ∧ (¯
r ∨ s¯)

DPLL: Idea
A Linear Solver
A Cubic Solver

Application of SAT
Solving

Homeworks and Next
Week Plan?

• Exactly one is true

ψ =α∧β

1b.16


Propositional Logic II

Sudoku row 2 contains exactly one 8

Nguyen An Khuong,
Huynh Tuong Nguyen

• Row 2 must contain at least one 8

α2,8 =

X2j8
1≤j≤9

Contents
Introduction
Quick review

• Row 2 has at most one 8


Boolean Satisfiability (SAT)

SAT Solvers

¯ 2j8 ∨ X
¯ 2m8
X

β2,8 =

WalkSAT: Idea
DPLL: Idea
A Linear Solver

1≤j,m≤9

j=m

A Cubic Solver

Application of SAT
Solving

• Row 2 has exactly one 8

Homeworks and Next
Week Plan?

ψ2,8 = α2,8 ∧ β2,8


1b.17


Propositional Logic II

Sudoku row constraints

Nguyen An Khuong,
Huynh Tuong Nguyen

• Row 2 contains all 9 values exactly once

γ2 =

ψ2,k
1≤k≤9

Contents
Introduction
Quick review

• All 9 rows contain all 9 values exactly once

Boolean Satisfiability (SAT)

SAT Solvers

R

=


γi =
1≤i≤9

ψi,k

WalkSAT: Idea
DPLL: Idea

1≤i≤9 1≤k≤9

A Linear Solver
A Cubic Solver

(αi,k ∧ βi,k )

=

Application of SAT
Solving

1≤i≤9 1≤k≤9

=
1≤i≤9 1≤k≤9









1≤j≤9






Xijk  ∧ 


¯ ijk ∨ X
¯ imk
X
1≤j,m≤9

Homeworks and Next
Week Plan?





j=m

1b.18



Propositional Logic II

Column constraints

Nguyen An Khuong,
Huynh Tuong Nguyen

• All 9 columns contain all 9 values exactly once






¯ ijk ∨ X
¯ mjk

C =
Xijk  ∧ 
X


1≤j≤9 1≤k≤9

1≤i≤9

1≤i,m≤9

i=m


Contents
Introduction






Quick review
Boolean Satisfiability (SAT)

SAT Solvers
WalkSAT: Idea
DPLL: Idea
A Linear Solver
A Cubic Solver

Application of SAT
Solving
Homeworks and Next
Week Plan?

1b.19


Propositional Logic II

3 × 3 box constraints

Nguyen An Khuong,

Huynh Tuong Nguyen

• 3 × 3 box containing cell (4, 7) has at least one 5

ξ475 =

Xij5
Contents

i = 4, 5, 6
j = 7, 8, 9

Introduction
Quick review
Boolean Satisfiability (SAT)

SAT Solvers

• 3 × 3 box containing cell (4, 7) has at most one 5

WalkSAT: Idea
DPLL: Idea
A Linear Solver

¯ ij5 ∨ X
¯ mn5 )
(X

ζ475 =
i, m = 4, 5, 6

j, n = 7, 8, 9
i=m∨j =n

A Cubic Solver

Application of SAT
Solving
Homeworks and Next
Week Plan?

1b.20


Propositional Logic II

3 × 3 box constraints, cont. . .

Nguyen An Khuong,
Huynh Tuong Nguyen

• 3 × 3 box containing cell (4, 7) has exactly one 5

θ475 = ξ475 ∧ ζ475

Contents
Introduction
Quick review
Boolean Satisfiability (SAT)

• All 9 3 × 3 boxes contains exactly one 5


SAT Solvers
WalkSAT: Idea
DPLL: Idea
A Linear Solver

µ5 =

θij5
i = 1, 4, 7
j = 1, 4, 7

A Cubic Solver

Application of SAT
Solving
Homeworks and Next
Week Plan?

1b.21


Propositional Logic II

3 × 3 box constraints, cont. . .

Nguyen An Khuong,
Huynh Tuong Nguyen

Contents


• All 9 3 × 3 boxes contain all 9 values

Introduction
Quick review

B

µk =

=
1≤k≤9

θijk
1≤k≤9

i = 1, 4, 7
j = 1, 4, 7

Boolean Satisfiability (SAT)

SAT Solvers
WalkSAT: Idea
DPLL: Idea
A Linear Solver
A Cubic Solver

Application of SAT
Solving
Homeworks and Next

Week Plan?

1b.22


Propositional Logic II

Initial predefined values

Nguyen An Khuong,
Huynh Tuong Nguyen

I = X115 ∧ X123 ∧ · · · ∧ X999
/>
1
1

2

3

4

5

6

7

8


11/3/09 11:40 AM

9
Contents
Introduction

2

Quick review
Boolean Satisfiability (SAT)

3

SAT Solvers

4

WalkSAT: Idea

5

A Linear Solver

DPLL: Idea

A Cubic Solver

6
7

8

Application of SAT
Solving
Homeworks and Next
Week Plan?

9

1b.23


Sudoku Boolean Formula

Propositional Logic II
Nguyen An Khuong,
Huynh Tuong Nguyen

Contents

φ=I ∧R∧C ∧B

Introduction
Quick review
Boolean Satisfiability (SAT)

• Note that φ is in CNF.
• φ can be altered so that it contains exactly 3 literals per

clause (can be fed to 3-SAT solver).


SAT Solvers
WalkSAT: Idea
DPLL: Idea
A Linear Solver
A Cubic Solver

Application of SAT
Solving
Homeworks and Next
Week Plan?

1b.24


Homeworks and Next Week Plan?

Propositional Logic II
Nguyen An Khuong,
Huynh Tuong Nguyen

Homeworks
• Do ALL marked questions of Exercises 1.6.
• Read carefully Subsections 1.6.1 and 1.6.2.

Contents
Introduction
Quick review
Boolean Satisfiability (SAT)


SAT Solvers
WalkSAT: Idea
DPLL: Idea

Next Week?

Predicate Logic

A Linear Solver
A Cubic Solver

Application of SAT
Solving
Homeworks and Next
Week Plan?

1b.25


×