logic stuff & fv basics

38
Logic Stuff & FV Basics Erik Seligman CS 510, Lecture 2, January 2009

Upload: fawn

Post on 19-Jan-2016

48 views

Category:

Documents


0 download

DESCRIPTION

Logic Stuff & FV Basics. Erik Seligman CS 510, Lecture 2, January 2009. Goals of This Session. Review basics of boolean logic, and some fundamental FV algorithms Logic should just be a review for people in this class! Establish common symbols & terms Variety of ways to express common ops - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Logic Stuff & FV Basics

Logic Stuff & FV Basics

Erik Seligman

CS 510, Lecture 2, January 2009

Page 2: Logic Stuff & FV Basics

Goals of This Session

Review basics of boolean logic, and some fundamental FV algorithms• Logic should just be a review for people in this class!

Establish common symbols & terms• Variety of ways to express common ops

Have basic foundation for discussing FV• Getting a flavor for contents of tools

• NOT describing full internal algorithms

• NOT full mathematical rigor– If you want screenfuls of symbols, take Xie or Song class!

Page 3: Logic Stuff & FV Basics

Basic Boolean Logic

Page 4: Logic Stuff & FV Basics

Fundamental operations

For consistency, will use Verilog-like notation:

AND: a & b

OR: a | b

NOT: ~a Sometimes AND represented as multiplication,

and OR as addition• Like arithmetic, except 1+1 == 1

Implication: a -> b• Same as: ~a | b

• Terms: a is the antecedent, b is the consequent

Page 5: Logic Stuff & FV Basics

Basic Boolean Identities

Commutative, Associative Distributive both ways

• a & (b|c) == (a&b) | (a&c)

• a | (b&c) == (a|b) & (a|c)

Idempotence: a&a == a, a|a == a DeMorgan

• ~(a&b) = ~a | ~b

• ~(a|b) = ~a & ~b

Page 6: Logic Stuff & FV Basics

Implication relationships

a -> b Converse: b -> a Inverse: ~a -> ~b Contrapositive: ~b -> ~a

Which pairs are identical in truth value? Can be useful when restating for FV Use |= (“logically entails”) symbol as distinct

from implication when appropriate(a -> b) |= (~b -> ~a)

Page 7: Logic Stuff & FV Basics

Inference Rules

Rules to derive new statements Some basic rules

(a -> b) , (a) (modus ponens)

b

(a | b), (~a)

b

a -> F (contradiction)

~a

Page 8: Logic Stuff & FV Basics

What is a Proof?

Apply sequence of inference rules Example:

• Known: S1: a, S2: (a -> b), S3: (d -> ~b))

• Prove: ~d– C1: S1, S2 |= b

– C2: S3 |= (~d | ~b)

– C3: C1, D3 |= ~d

Page 9: Logic Stuff & FV Basics

Predicate Logic

Add predicates, or functions, and quantifiers: For All (A), Exists (E)

Examples:• A(x) Cat(x) -> Mammal(x)

• E(x) Cat(x) & ~Black(x)

Page 10: Logic Stuff & FV Basics

Linear Temporal Logic (LTL)

Page 11: Logic Stuff & FV Basics

What Is Linear Temporal Logic? Add notion of time to predicate logic

• X = Next time

• G = Globally / always

• F = Future / eventually

• U = Until

Statements evaluated at points in time• Discrete, “clocked” machine model

Lots of power for stating properties• Useful in real-life designs

• In upcoming 2009 SVA standard

Page 12: Logic Stuff & FV Basics

Equivalent operations in LTL

Ga == ~(F(~a)) Fa == ~(G(~a)) Fa == T U a Distributive laws

• G(a &b) = Ga & Gb

• F(a | b) = Fa | Fb

• But be careful… – can G(a|b) be distributed?

– How about F(a&b)?

Page 13: Logic Stuff & FV Basics

LTL examples

Eventually bus grant will occur• F(grant)

Requests will be held until there is a grant or a power down• req -> (req U (grant | power_down))

Deadlock free• Ai. req[i] -> F(grant[i])

At some point after reset, the reset signal will stay low forever• reset -> F(G(~reset))

Page 14: Logic Stuff & FV Basics

LTL: Strong and Weak Statements If the machine may exit/terminate, and an

“until” is waiting, did it pass?• Example: (a -> b U c)

Strong property: must finish Weak property: considered true if

evaluation may never complete• Usually the default

Page 15: Logic Stuff & FV Basics

Types of Properties

Safety: “Something bad won’t happen.” G(~ (grant & busy))

Liveness: “Something good will happen.”

F(grant)• Be careful: weak or strong?

Fairness: “Something happens infinitely often.”

G(F(!busy))• Usually considered subset of liveness

• Often required as assumption on design inputs

Page 16: Logic Stuff & FV Basics

Binary Decision Diagrams (BDDs)

Page 17: Logic Stuff & FV Basics

BDD Example

(a & c) | (~a & b & ~c)

a

b

c c

1

1

0

0

0

1

1 0 1

0

0 01

Page 18: Logic Stuff & FV Basics

BDD Reduction & Ordering

Always specify an order for the variables Reduction: merge identical nodes

a

b

c c

0

1

0

0

0

1

1 0 10

0 11

a

b

c

1

0

0

0

1

1

0

1 0

Page 19: Logic Stuff & FV Basics

Why are BDDs useful?

Canonical: unique for given var ordering• Assuming they are reduced

• Two formulas equivalent iff same BDD!

Easy to define operations• Complement

• Substitute constant (“Restrict”)

• Apply any boolean operator (&, |, etc)

Many cases proven efficient in practice• But danger of exponential blowup

Page 20: Logic Stuff & FV Basics

Complement A BDD

Replace f with ~f: just reverse terminals

a

b

c c

10

1

0

0

0

1

1 0 1

10

01

01

10

Page 21: Logic Stuff & FV Basics

Substitute Constant in BDD Just eliminate irrelevant subtrees, connect

correct nodes Example: c = 1

a

b

c c

1

1

0

0

0

1

1 0 1

0

0 01

Page 22: Logic Stuff & FV Basics

Substitute Constant in BDD Just eliminate irrelevant subtrees, connect

correct nodes Example: c = 1

a

b

1

0

0

1

0 0 1

Page 23: Logic Stuff & FV Basics

Substitute Constant in BDD Just eliminate irrelevant subtrees, connect

correct nodes Example: c = 1

a10

0

1

•Don’t forget to reduce

Page 24: Logic Stuff & FV Basics

Apply Operation to BDDs (AND, OR, etc) Basic idea: recursively examine, with

one var restricted to constant• Each recursive call reduced #vars by 1

• At terminal apply obvious function

APPLY(f1,f2,AND) =

v10 1

APPLY(f1,f2,AND)| v1=0

APPLY(f1,f2,AND)| v1=1

Page 25: Logic Stuff & FV Basics

APPLY example

Goal: BDD1(a,b) AND BDD2(a,b)

a10

0

1

b10

0

a10

1 0

BDD1 = a&b BDD2 = !a

Page 26: Logic Stuff & FV Basics

APPLY example: Step 1a

10

0

1

b10

0

a10

1 0

Use restrictions for a=0, a=1

a10

APPLY| a=0 APPLY| a=1

Page 27: Logic Stuff & FV Basics

APPLY example: Step 2a

10

0

1

b10

0

a10

1 0

Use restrictions for a=0, a=1

a10

0 AND 1 BDD1.b AND 0

Page 28: Logic Stuff & FV Basics

APPLY example: Step 3a

10

0

1

b10

0

a10

1 0

Compute results using constants if available

a10

0 0

Page 29: Logic Stuff & FV Basics

APPLY example: Result

0

• 2 recursive calls per variable

• But always reduces size of problem

• So eventual constants guaranteed

Page 30: Logic Stuff & FV Basics

BDDs: Exponential Blowup

(a&b) | (c&d)

a

b

c

10

d

Page 31: Logic Stuff & FV Basics

BDDs: Exponential Blowup

(a&b) | (c&d)

a

c

10

c

b b

dd

Page 32: Logic Stuff & FV Basics

SAT Algorithms

Page 33: Logic Stuff & FV Basics

What is SAT?

SAT= general problem: can boolean statement be satisfied?• Known NP-complete

• But good heuristics known

FV Focus was on BDDs in 1990s• Now seen as too restrictive

• Modern tools have BDD + SAT engines

Page 34: Logic Stuff & FV Basics

SAT Example: DPLL Algorithms Algorithms first proposed in 1960’s

• But renewed interest due to FV application

Start by converting formula to CNF form: product-of-sums (clauses)

(a+b+c)(a+~d+e)(~b+~c)…• Reminder: multiplication=AND, addition=OR

• Target: assignment satisfying every term

• If some clause is 0, assignment fails

Page 35: Logic Stuff & FV Basics

Outline of DPLL algs

(from Zhang/Malik paper, see ref slide)

Page 36: Logic Stuff & FV Basics

Sub-functions

Deduction: find what must be true• Example: (a+b)(~c+d)

• If c was assigned 1, then d must be 1

• Can spend compute cycles to be more aggressive

Choose_free_variable: tricky part!• Look for var that affects most clauses?

• Weight clauses strategically?

• Learn from conflicts/backtracks?

Page 37: Logic Stuff & FV Basics

Other DPLL SAT Aspects

Capacity: How to store set of clauses?• Direct: sparse matrix representation

• BDDs, tries, other options

Preprocessing• First pass: gather high-level data hints

Randomization• Random restart if seem to be dying?

Other approaches: SAT is still an active research area!• www.satlive.org

Page 38: Logic Stuff & FV Basics

References http://www.jimloy.com/logic/logic.htm http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and

-Computer-Science/6-042JFall-2005/LectureNotes/index.htm

http://en.wikipedia.org/wiki/Linear_temporal_logic http://www.inf.unibz.it/~artale/FM/slide3.pdf http://www.cerc.utexas.edu/~gnolkha/verif/BDD.ppt http://www.comp.nus.edu.sg/~abhik/CS4271/lectures/L

ec11-BDD.pdf http://www.satlive.org/ http://www.princeton.edu/~chaff/publication/cade_cav_

2002.pdf