Decision Procedures An Algorithmic Point of View Equalities and - - PowerPoint PPT Presentation

decision procedures
SMART_READER_LITE
LIVE PREVIEW

Decision Procedures An Algorithmic Point of View Equalities and - - PowerPoint PPT Presentation

Decision Procedures An Algorithmic Point of View Equalities and Uninterpreted Functions D. Kroening O. Strichman ETH/Technion Version 1.0, 2007 Part III Equalities and Uninterpreted Functions Outline 1 Introduction to Equality Logic


slide-1
SLIDE 1

Decision Procedures

An Algorithmic Point of View Equalities and Uninterpreted Functions

  • D. Kroening
  • O. Strichman

ETH/Technion

Version 1.0, 2007

slide-2
SLIDE 2

Part III Equalities and Uninterpreted Functions

slide-3
SLIDE 3

Outline

1 Introduction to Equality Logic

Definition, complexity

2 Reducing uninterpreted functions to Equality Logic 3 Using uninterpreted functions in proofs 4 Simplifications

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 3 / 47

slide-4
SLIDE 4

Equality Logic A Boolean combination of Equalities and Propositions x1 = x2 ∧ (x2 = x3 ∨ ¬((x1 = x3) ∧ b ∧ x1 = 2)) We always push negations inside (NNF): x1 = x2 ∧ (x2 = x3 ∨ ((x1 = x3) ∧ ¬b ∧ x1 = 2))

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 4 / 47

slide-5
SLIDE 5

Syntax of Equality Logic formula : formula ∨ formula | ¬formula | atom atom : term-variable = term-variable | term-variable = constant | Boolean-variable The term-variables are defined over some (possible infinite) domain. The constants are from the same domain. The set of Boolean variables is always separate from the set of term variables

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 5 / 47

slide-6
SLIDE 6

Expressiveness and complexity Allows more natural description of systems, although technically it is as expressible as Propositional Logic. Obviously NP-hard. In fact, it is in NP, and hence NP-complete, for reasons we shall see later.

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 6 / 47

slide-7
SLIDE 7

Equality logic with uninterpreted functions formula : formula ∨ formula | ¬formula | atom atom : term = term | Boolean-variable term : term-variable | function ( list of terms ) The term-variables are defined over some (possible infinite) domain. Constants are functions with an empty list of terms.

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 7 / 47

slide-8
SLIDE 8

Uninterpreted Functions Every function is a mapping from a domain to a range. Example: the ’+’ function over the naturals N is a mapping from N × N to N.

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 8 / 47

slide-9
SLIDE 9

Uninterpreted Functions Suppose we replace ’+’ by an uninterpreted binary function f(a, b) Example: x1 + x2 = x3 + x4 is replaced by f(x1, x2) = f(x3, x4) We lost the ’semantics’ of ’+’, as f can represent any binary function. ’Loosing the semantics’ means that f is not restricted by any axioms

  • r rules of inference.

But f is still a function!

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 9 / 47

slide-10
SLIDE 10

Uninterpreted Functions The most general axiom for any function is functional consistency. Example: if x = y, then f(x) = f(y) for any function f. Functional consistency axiom schema: x1 = x′

1 ∧ . . . ∧ xn = x′ n

= ⇒ f(x1, . . . , xn) = f(x′

1, . . . , x′ n)

Sometimes, functional consistency is all that is needed for a proof.

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 10 / 47

slide-11
SLIDE 11

Example: Circuit Transformations Circuits consist of combinational gates and latches (registers)

R1 I Latch Combi- national part

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 11 / 47

slide-12
SLIDE 12

Example: Circuit Transformations Circuits consist of combinational gates and latches (registers)

R1 I Latch Combi- national part

The combinational gates can be modeled using functions The latches can be modeled with variables f(x, y) := x ∨ y R′

1

= f(R1, I)

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 11 / 47

slide-13
SLIDE 13

Example: Circuit Transformations

1 L5 F L2 L1 H K G L3 L4 in C D

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 12 / 47

slide-14
SLIDE 14

Example: Circuit Transformations

1 L5 F L2 L1 H K G L3 L4 in C D

in: a primary input of the circuit

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 12 / 47

slide-15
SLIDE 15

Example: Circuit Transformations

1 L5 F L2 L1 H K G L3 L4 in C D

in: a primary input of the circuit

P P P P P P P P P ✐ ✏ ✏ ✏ ✏ ✏ ✏ ✮

F, G, H, K, D: some functions

  • ver bit-vectors
  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 12 / 47

slide-16
SLIDE 16

Example: Circuit Transformations

1 L5 F L2 L1 H K G L3 L4 in C D

in: a primary input of the circuit

P P P P P P P P P ✐ ✏ ✏ ✏ ✏ ✏ ✏ ✮

F, G, H, K, D: some functions

  • ver bit-vectors

❅ ❅ ❅ ❅ ❅ ❅ ■ ✑ ✑ ✑ ✑ ✑ ✑ ✰ ✁ ✁ ✁ ✁ ✁ ✁ ✁ ✁ ✁ ✁ ✁ ☛

L1, . . . , L5: latches (registers)

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 12 / 47

slide-17
SLIDE 17

Example: Circuit Transformations

1 L5 F L2 L1 H K G L3 L4 in C D

in: a primary input of the circuit

P P P P P P P P P ✐ ✏ ✏ ✏ ✏ ✏ ✏ ✮

F, G, H, K, D: some functions

  • ver bit-vectors

❅ ❅ ❅ ❅ ❅ ❅ ■ ✑ ✑ ✑ ✑ ✑ ✑ ✰ ✁ ✁ ✁ ✁ ✁ ✁ ✁ ✁ ✁ ✁ ✁ ☛

L1, . . . , L5: latches (registers)

C: a predicate over bit-vectors

a multiplexer (case-split)

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 12 / 47

slide-18
SLIDE 18

Example: Circuit Transformations

1 L5 F L2 L1 H K G L3 L4 in C D

A pipeline processes data in stages Data is processed in parallel – as in an assembly line Formal model: L1 = f(I) L2 = L1 L3 = k(g(L1)) L4 = h(L1) L5 = c(L2) ? L3 : l(L4)

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 13 / 47

slide-19
SLIDE 19

Example: Circuit Transformations Stage 1

1 L5 F L2 L1 H K G L3 L4 in C D

A pipeline processes data in stages Data is processed in parallel – as in an assembly line Formal model: L1 = f(I) L2 = L1 L3 = k(g(L1)) L4 = h(L1) L5 = c(L2) ? L3 : l(L4)

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 13 / 47

slide-20
SLIDE 20

Example: Circuit Transformations Stage 2

1 L5 F L2 L1 H K G L3 L4 in C D

A pipeline processes data in stages Data is processed in parallel – as in an assembly line Formal model: L1 = f(I) L2 = L1 L3 = k(g(L1)) L4 = h(L1) L5 = c(L2) ? L3 : l(L4)

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 13 / 47

slide-21
SLIDE 21

Example: Circuit Transformations Stage 3

1 L5 F L2 L1 H K G L3 L4 in C D

A pipeline processes data in stages Data is processed in parallel – as in an assembly line Formal model: L1 = f(I) L2 = L1 L3 = k(g(L1)) L4 = h(L1) L5 = c(L2) ? L3 : l(L4)

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 13 / 47

slide-22
SLIDE 22

Example: Circuit Transformations

1 L5 F L2 L1 H K G L3 L4 in C D

The maximum clock frequency depends

  • n the longest path between two latches

Note that the output of g is used as input to k We want to speed up the design by postponing k to the third stage

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 14 / 47

slide-23
SLIDE 23

Example: Circuit Transformations

1 L5 F L2 L1 H K G L3 L4 in C D

The maximum clock frequency depends

  • n the longest path between two latches

Note that the output of g is used as input to k We want to speed up the design by postponing k to the third stage Also note that the circuit only uses one of L3 or L4, never both ⇒ We can remove one of the latches

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 14 / 47

slide-24
SLIDE 24

Example: Circuit Transformations

1 L5 F L2 L1 H K G L3 L4 in C D

= = ? ?

1 1 in F L′

2

L′

1

G C K L′

3

H L′

5

D

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 15 / 47

slide-25
SLIDE 25

Example: Circuit Transformations L1 = f(I) L2 = L1 L3 = k(g(L1)) L4 = h(L1) L5 = c(L2) ? L3 : l(L4) L′

1

= f(I) L′

2

= c(L′

1)

L′

3

= c(L′

1) ? g(L′ 1) : h(L′ 1)

L′

5

= L′

2 ? k(L′ 3) : l(L′ 3)

L5

?

= L′

5

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 16 / 47

slide-26
SLIDE 26

Example: Circuit Transformations L1 = f(I) L2 = L1 L3 = k(g(L1)) L4 = h(L1) L5 = c(L2) ? L3 : l(L4) L′

1

= f(I) L′

2

= c(L′

1)

L′

3

= c(L′

1) ? g(L′ 1) : h(L′ 1)

L′

5

= L′

2 ? k(L′ 3) : l(L′ 3)

L5

?

= L′

5

Equivalence in this case holds regardless of the actual functions Conclusion: can be decided using Equality Logic and Uninterpreted Functions

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 16 / 47

slide-27
SLIDE 27

Transforming UFs to Equality Logic using Ackermann’s reduction Given: a formula ϕUF with uninterpreted functions For each function in ϕUF : 1. Number function instances (from the inside out)

✲ F2( F1(x) ) = 0

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 17 / 47

slide-28
SLIDE 28

Transforming UFs to Equality Logic using Ackermann’s reduction Given: a formula ϕUF with uninterpreted functions For each function in ϕUF : 1. Number function instances (from the inside out)

✲ F2(

f1

F1(x) )

  • f2

= 0 2. Replace each function in- stance with a new variable

✲ f2 = 0

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 17 / 47

slide-29
SLIDE 29

Transforming UFs to Equality Logic using Ackermann’s reduction Given: a formula ϕUF with uninterpreted functions For each function in ϕUF : 1. Number function instances (from the inside out)

✲ F2(

f1

F1(x) )

  • f2

= 0 2. Replace each function in- stance with a new variable

✲ f2 = 0

3. Add functional consistency constraint to ϕUF for every pair of instances of the same function.

((x = f1) − → (f2 = f1)) − → f2 = 0

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 17 / 47

slide-30
SLIDE 30

Ackermann’s reduction: Example Suppose we want to check x1 = x2 ∨ F(x1) = F(x2) ∨ F(x1) = F(x3) for validity.

1 First number the function instances:

x1 = x2 ∨ F1(x1) = F2(x2) ∨ F1(x1) = F3(x3)

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 18 / 47

slide-31
SLIDE 31

Ackermann’s reduction: Example Suppose we want to check x1 = x2 ∨ F(x1) = F(x2) ∨ F(x1) = F(x3) for validity.

1 First number the function instances:

x1 = x2 ∨ F1(x1) = F2(x2) ∨ F1(x1) = F3(x3)

2 Replace each function with a new variable:

x1 = x2 ∨ f1 = f2 ∨ f1 = f3

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 18 / 47

slide-32
SLIDE 32

Ackermann’s reduction: Example Suppose we want to check x1 = x2 ∨ F(x1) = F(x2) ∨ F(x1) = F(x3) for validity.

1 First number the function instances:

x1 = x2 ∨ F1(x1) = F2(x2) ∨ F1(x1) = F3(x3)

2 Replace each function with a new variable:

x1 = x2 ∨ f1 = f2 ∨ f1 = f3

3 Add functional consistency constraints:

  (x1 = x2 → f1 = f2) ∧ (x1 = x3 → f1 = f3) ∧ (x2 = x3 → f2 = f3)   → ((x1 = x2) ∨ (f1 = f2) ∨ (f1 = f3))

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 18 / 47

slide-33
SLIDE 33

Transforming UFs to Equality Logic using Bryant’s reduction Given: a formula ϕUF with uninterpreted functions For each function in ϕUF : 1. Number function instances (from the inside out)

✲ F1(a) = F2(b)

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 19 / 47

slide-34
SLIDE 34

Transforming UFs to Equality Logic using Bryant’s reduction Given: a formula ϕUF with uninterpreted functions For each function in ϕUF : 1. Number function instances (from the inside out)

✲ F1(a) = F2(b)

2. Replace each function instance Fi with an expression F ∗

i

✲ F ∗

1 = F ∗ 2

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 19 / 47

slide-35
SLIDE 35

Transforming UFs to Equality Logic using Bryant’s reduction Given: a formula ϕUF with uninterpreted functions For each function in ϕUF : 1. Number function instances (from the inside out)

✲ F1(a) = F2(b)

2. Replace each function instance Fi with an expression F ∗

i

✲ F ∗

1 = F ∗ 2

F ∗

i :=

     

case x1 = xi : f1 x2 = xi : f2 . . . xi−1 = xi: fi−1 true : fi

     

✲ f1 =

  • case

a = b: f1 true : f2

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 19 / 47

slide-36
SLIDE 36

Example of Bryant’s reduction Original formula: a = b → F(G(a) = F(G(b))

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 20 / 47

slide-37
SLIDE 37

Example of Bryant’s reduction Original formula: a = b → F(G(a) = F(G(b)) Number the instances: a = b → F1(G1(a) = F2(G2(b))

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 20 / 47

slide-38
SLIDE 38

Example of Bryant’s reduction Original formula: a = b → F(G(a) = F(G(b)) Number the instances: a = b → F1(G1(a) = F2(G2(b)) Replace each function application with an expression: a = b → F ∗

1 = F ∗ 2

where F ∗

1

= f1 F ∗

2

= case G∗

1 = G∗ 2

: f1 true : f2

  • G∗

1

= g1 G∗

2

= case a = b : g1 true : g2

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 20 / 47

slide-39
SLIDE 39

Using uninterpreted functions in proofs Uninterpreted functions give us the ability to represent an abstract view of functions. It over-approximates the concrete system. 1 + 1 = 1 is a contradiction But F(1, 1) = 1 is satisfiable!

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 21 / 47

slide-40
SLIDE 40

Using uninterpreted functions in proofs Uninterpreted functions give us the ability to represent an abstract view of functions. It over-approximates the concrete system. 1 + 1 = 1 is a contradiction But F(1, 1) = 1 is satisfiable! Conclusion: unless we are careful, we can give wrong answers, and this way, loose soundness.

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 21 / 47

slide-41
SLIDE 41

Using uninterpreted functions in proofs In general, a sound but incomplete method is more useful than an unsound but complete method. A sound but incomplete algorithm for deciding a formula with uninterpreted functions ϕUF :

1

Transform it into Equality Logic formula ϕE

2

If ϕE is unsatisfiable, return ’Unsatisfiable’

3

Else return ’Don’t know’

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 22 / 47

slide-42
SLIDE 42

Using uninterpreted functions in proofs Question #1: is this useful?

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 23 / 47

slide-43
SLIDE 43

Using uninterpreted functions in proofs Question #1: is this useful? Question #2: can it be made complete in some cases?

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 23 / 47

slide-44
SLIDE 44

Using uninterpreted functions in proofs Question #1: is this useful? Question #2: can it be made complete in some cases? When the abstract view is sufficient for the proof, it enables (or at least simplifies) a mechanical proof.

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 23 / 47

slide-45
SLIDE 45

Using uninterpreted functions in proofs Question #1: is this useful? Question #2: can it be made complete in some cases? When the abstract view is sufficient for the proof, it enables (or at least simplifies) a mechanical proof. So when is the abstract view sufficient?

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 23 / 47

slide-46
SLIDE 46

Using uninterpreted functions in proofs (common) Proving equivalence between:

Two versions of a hardware design (one with and one without a pipeline) Source and target of a compiler (”Translation Validation”)

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 24 / 47

slide-47
SLIDE 47

Using uninterpreted functions in proofs (common) Proving equivalence between:

Two versions of a hardware design (one with and one without a pipeline) Source and target of a compiler (”Translation Validation”)

(rare) Proving properties that do not rely on the exact functionality of some of the functions

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 24 / 47

slide-48
SLIDE 48

Example: Translation Validation Assume the source program has the statement z = (x1 + y1) · (x2 + y2); which the compiler turned into: u1 = x1 + y1; u2 = x2 + y2; z = u1 · u2;

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 25 / 47

slide-49
SLIDE 49

Example: Translation Validation Assume the source program has the statement z = (x1 + y1) · (x2 + y2); which the compiler turned into: u1 = x1 + y1; u2 = x2 + y2; z = u1 · u2; We need to prove that: (u1 = x1 + y1 ∧ u2 = x2 + y2 ∧ z = u1 · u2) − → (z = (x1 + y1) · (x2 + y2))

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 25 / 47

slide-50
SLIDE 50

Example: Translation Validation Claim: ϕUF is valid We will prove this by reducing it to an Equality Logic formula ϕE =     (x1 = x2 ∧ y1 = y2 − → f1 = f2) ∧ (u1 = f1 ∧ u2 = f2 − → g1 = g2)     − → ((u1 = f1 ∧ u2 = f2 ∧ z = g1) − → z = g2)

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 26 / 47

slide-51
SLIDE 51

Uninterpreted functions: usability Good: each function on the left can be mapped to a function on the right with equivalent arguments

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 27 / 47

slide-52
SLIDE 52

Uninterpreted functions: usability Good: each function on the left can be mapped to a function on the right with equivalent arguments Bad: almost all other cases Example: Left Right x + x 2x

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 27 / 47

slide-53
SLIDE 53

Uninterpreted functions: usability This is easy to prove: (x1 = x2 ∧ y1 = y2) − → (x1 + y1 = x2 + y2)

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 28 / 47

slide-54
SLIDE 54

Uninterpreted functions: usability This is easy to prove: (x1 = x2 ∧ y1 = y2) − → (x1 + y1 = x2 + y2) This requires commutativity: (x1 = x2 ∧ y1 = y2) − → (x1 + y1 = y2 + x2)

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 28 / 47

slide-55
SLIDE 55

Uninterpreted functions: usability This is easy to prove: (x1 = x2 ∧ y1 = y2) − → (x1 + y1 = x2 + y2) This requires commutativity: (x1 = x2 ∧ y1 = y2) − → (x1 + y1 = y2 + x2) Fix by adding: (x1 + y1 = y1 + x1) ∧ (x2 + y2 = y2 + x2)

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 28 / 47

slide-56
SLIDE 56

Uninterpreted functions: usability This is easy to prove: (x1 = x2 ∧ y1 = y2) − → (x1 + y1 = x2 + y2) This requires commutativity: (x1 = x2 ∧ y1 = y2) − → (x1 + y1 = y2 + x2) Fix by adding: (x1 + y1 = y1 + x1) ∧ (x2 + y2 = y2 + x2) What about other cases? Use more rewriting rules!

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 28 / 47

slide-57
SLIDE 57

Example: equivalence of C programs (1/4)

int power3(int in) {

  • ut = in;

for(i=0; i<2; i++)

  • ut = out * in;

return out; } int power3 new(int in) {

  • ut = (in*in)*in;

return out; }

These two functions return the same value regardless if it is ’*’ or any

  • ther function.

Conclusion: we can prove equivalence by replacing ’*’ with an uninterpreted function

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 29 / 47

slide-58
SLIDE 58

From programs to equations But first we need to know how to turn programs into equations. There are several options – we will see static single assignment for bounded programs.

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 30 / 47

slide-59
SLIDE 59

Static Single Assignment (SSA) form → see compiler class Idea: Rename variables such that each variable is assigned exactly

  • nce

Example: x=x+y; x=x*2; a[i]=100; x1=x0+y0; x2=x1*2; a1[i0]=100;

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 31 / 47

slide-60
SLIDE 60

Static Single Assignment (SSA) form → see compiler class Idea: Rename variables such that each variable is assigned exactly

  • nce

Example: x=x+y; x=x*2; a[i]=100; x1=x0+y0; x2=x1*2; a1[i0]=100; Read assignments as equalities Generate constraints by simply conjoining these equalities Example: x1=x0+y0; x2=x1*2; a1[i0]=100; x1 = x0 + y0 ∧ x2 = x1 ∗ 2 ∧ a1[i0] = 100

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 31 / 47

slide-61
SLIDE 61

SSA for bounded programs What about if? Branches are handled using φ-nodes.

int main() { int x, y, z; y=8; if(x) y--; else y++; z=y+1; }

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 32 / 47

slide-62
SLIDE 62

SSA for bounded programs What about if? Branches are handled using φ-nodes.

int main() { int x, y, z; y=8; if(x) y--; else y++; z=y+1; } int main() { int x, y, z; y1=8; if(x0) y2=y1-1; else y3=y1+1; y4=φ(y2, y3); z1=y4+1; }

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 32 / 47

slide-63
SLIDE 63

SSA for bounded programs What about if? Branches are handled using φ-nodes.

int main() { int x, y, z; y=8; if(x) y--; else y++; z=y+1; } int main() { int x, y, z; y1=8; if(x0) y2=y1-1; else y3=y1+1; y4=φ(y2, y3); z1=y4+1; }

y1 = 8 ∧ y2 = y1 − 1 ∧ y3 = y1 + 1 ∧ y4 = (x0 =0 ? y2 : y3)∧ z1 = y4 + 1

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 32 / 47

slide-64
SLIDE 64

SSA for bounded programs What about loops? → We unwind them!

void f(...) { ... while(cond) { BODY; } ... Remainder; }

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 33 / 47

slide-65
SLIDE 65

SSA for bounded programs What about loops? → We unwind them!

void f(...) { ... if(cond) { BODY; while(cond) { BODY; } } ... Remainder; }

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 33 / 47

slide-66
SLIDE 66

SSA for bounded programs What about loops? → We unwind them!

void f(...) { ... if(cond) { BODY; if(cond) { BODY; while(cond) { BODY; } } } ... Remainder; }

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 33 / 47

slide-67
SLIDE 67

SSA for bounded programs Some caveats: Unwind how many times? Must preserve locality of variables declared inside loop

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 34 / 47

slide-68
SLIDE 68

SSA for bounded programs Some caveats: Unwind how many times? Must preserve locality of variables declared inside loop There is a tool available that does this CBMC – C Bounded Model Checker Bound is verified using unwinding assertions Used frequently for embedded software − → Bound is a run-time guarantee Integrated into Eclipse Decision problem can be exported

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 34 / 47

slide-69
SLIDE 69

SSA for bounded programs: CBMC

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 35 / 47

slide-70
SLIDE 70

Example: equivalence of C programs (2/4)

int power3(int in) {

  • ut = in;

for(i=0; i<2; i++)

  • ut = out * in;

return out; } int power3 new(int in) {

  • ut = (in*in)*in;

return out; }

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 36 / 47

slide-71
SLIDE 71

Example: equivalence of C programs (2/4)

int power3(int in) {

  • ut = in;

for(i=0; i<2; i++)

  • ut = out * in;

return out; } int power3 new(int in) {

  • ut = (in*in)*in;

return out; }

Static single assignment (SSA) form:

  • ut1 = in ∧
  • ut2 = out1 ∗ in ∧
  • ut3 = out2 ∗ in
  • ut′

1 = (in ∗ in) ∗ in

Prove that both functions return the same value:

  • ut3 = out′

1

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 36 / 47

slide-72
SLIDE 72

Example: equivalence of C programs (3/4) Static single assignment (SSA) form:

  • ut1 = in ∧
  • ut2 = out1 ∗ in ∧
  • ut3 = out2 ∗ in
  • ut′

1 = (in ∗ in) ∗ in

With uninterpreted functions:

  • ut1 = in ∧
  • ut2 = F(out1, in) ∧
  • ut3 = F(out2, in)
  • ut′

1 = F(F(in, in), in)

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 37 / 47

slide-73
SLIDE 73

Example: equivalence of C programs (3/4) Static single assignment (SSA) form:

  • ut1 = in ∧
  • ut2 = out1 ∗ in ∧
  • ut3 = out2 ∗ in
  • ut′

1 = (in ∗ in) ∗ in

With uninterpreted functions:

  • ut1 = in ∧
  • ut2 = F(out1, in) ∧
  • ut3 = F(out2, in)
  • ut′

1 = F(F(in, in), in)

With numbered uninterpreted functions:

  • ut1 = in ∧
  • ut2 = F1(out1, in) ∧
  • ut3 = F2(out2, in)
  • ut′

1 = F4(F3(in, in), in)

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 37 / 47

slide-74
SLIDE 74

Example: equivalence of C programs (4/4) With numbered uninterpreted functions:

  • ut1 = in ∧
  • ut2 = F1(out1, in) ∧
  • ut3 = F2(out2, in)
  • ut′

1 = F4(F3(in, in), in)

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 38 / 47

slide-75
SLIDE 75

Example: equivalence of C programs (4/4) With numbered uninterpreted functions:

  • ut1 = in ∧
  • ut2 = F1(out1, in) ∧
  • ut3 = F2(out2, in)
  • ut′

1 = F4(F3(in, in), in)

Ackermann’s reduction: ϕE

a :

  • ut1 = in ∧
  • ut2 = f1 ∧
  • ut3 = f2

ϕE

b : out′ 1 = f4

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 38 / 47

slide-76
SLIDE 76

Example: equivalence of C programs (4/4) With numbered uninterpreted functions:

  • ut1 = in ∧
  • ut2 = F1(out1, in) ∧
  • ut3 = F2(out2, in)
  • ut′

1 = F4(F3(in, in), in)

Ackermann’s reduction: ϕE

a :

  • ut1 = in ∧
  • ut2 = f1 ∧
  • ut3 = f2

ϕE

b : out′ 1 = f4

The verification condition:                 (out1 = out2→ f1 = f2) ∧ (out1 = in → f1 = f3) ∧ (out1 = f3 → f1 = f4) ∧ (out2 = in → f2 = f3) ∧ (out2 = f3 → f2 = f3) ∧ (in = f3 → f3 = f4)         ∧ ϕE

a ∧ ϕE b

        − → out3 = out′

1

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 38 / 47

slide-77
SLIDE 77

Uninterpreted functions: simplifications Let n be the number of instances of F() Both reduction schemes require O(n2) comparisons This can be the bottleneck of the verification effort

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 39 / 47

slide-78
SLIDE 78

Uninterpreted functions: simplifications Let n be the number of instances of F() Both reduction schemes require O(n2) comparisons This can be the bottleneck of the verification effort Solution: try to guess the pairing of functions Still sound: wrong guess can only make a valid formula invalid

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 39 / 47

slide-79
SLIDE 79

Simplifications (1) Given x1 = x′

1, x2 = x′ 2, x3 = x′ 3, prove |

= o1 = o2.

  • 1 = (x1 + (a · x2)
  • f1

) ∧ a = x3 + 5

f2

Left

  • 2 = (x′

1 + (b · x′ 2)

  • f3

) ∧ b = x′

3 + 5 f4

Right 4 function instances → 6 comparisons

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 40 / 47

slide-80
SLIDE 80

Simplifications (1) Given x1 = x′

1, x2 = x′ 2, x3 = x′ 3, prove |

= o1 = o2.

  • 1 = (x1 + (a · x2)
  • f1

) ∧ a = x3 + 5

f2

Left

  • 2 = (x′

1 + (b · x′ 2)

  • f3

) ∧ b = x′

3 + 5 f4

Right 4 function instances → 6 comparisons Guess: validity does not rely on f1 = f2 or on f3 = f4 Idea: only enforce functional consistency of pairs (Left,Right).

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 40 / 47

slide-81
SLIDE 81

Simplifications (2)

  • 1 = (x1 + (a · x2)
  • f1

) ∧ a = x3 + 5

f2

Left

  • 2 = (x′

1 + (b · x′ 2)

  • f3

) ∧ b = x′

3 + 5 f4

Right Down to 4 comparisons!

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 41 / 47

slide-82
SLIDE 82

Simplifications (2)

  • 1 = (x1 + (a · x2)
  • f1

) ∧ a = x3 + 5

f2

Left

  • 2 = (x′

1 + (b · x′ 2)

  • f3

) ∧ b = x′

3 + 5 f4

Right Down to 4 comparisons! Another guess: equivalence only depends on f1 = f3 and f2 = f4 Pattern matching may help here

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 41 / 47

slide-83
SLIDE 83

Simplifications (3)

  • 1 = (x1 + (a · x2)
  • f1

) ∧ a = x3 + 5

f2

Left

  • 2 = (x′

1 + (b · x′ 2)

  • f3

) ∧ b = x′

3 + 5 f4

Right Match according to patterns (’signatures’) +

❅ ❅ ❘

v ·

❅ ❅ ❘

v v f1, f3 +

❅ ❅ ❘

v 5 f2, f4 Down to 2 comparisons!

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 42 / 47

slide-84
SLIDE 84

Simplifications (4)

  • 1 = (x1 + (a · x2)
  • f1

) ∧ a = x3 + 5

f2

Left

  • 2 = (x′

1 + (b · x′ 2)

  • f3

) ∧ b = x′

3 + 5 f4

Right Substitute intermediate variables (in the example: a, b)

+

❅ ❅ ❘

v ·

❅ ❅ ❘

v v

+

❅ ❅ ❘

v 5

slide-85
SLIDE 85

Simplifications (4)

  • 1 = (x1 + (a · x2)
  • f1

) ∧ a = x3 + 5

f2

Left

  • 2 = (x′

1 + (b · x′ 2)

  • f3

) ∧ b = x′

3 + 5 f4

Right Substitute intermediate variables (in the example: a, b)

+

❅ ❅ ❘

v ·

❅ ❅ ❘

v v

+

❅ ❅ ❘

v 5

X

− → +

❅ ❅ ❘

v ·

❅ ❅ ❘

v +

❅ ❅ ❘

v 5 f1, f3

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 43 / 47

slide-86
SLIDE 86

The SSA example revisited (1) With numbered uninterpreted functions:

  • ut1 = in ∧
  • ut2 = F1(out1, in) ∧
  • ut3 = F2(out2, in)
  • ut′

1 = F4(F3(in, in), in)

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 44 / 47

slide-87
SLIDE 87

The SSA example revisited (1) With numbered uninterpreted functions:

  • ut1 = in ∧
  • ut2 = F1(out1, in) ∧
  • ut3 = F2(out2, in)
  • ut′

1 = F4(F3(in, in), in)

Map F1 to F3: F

❅ ❅ ❘

v v Map F2 to F4: F

❅ ❅ ❘

v F

❅ ❅ ❘

v v

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 44 / 47

slide-88
SLIDE 88

The SSA example revisited (2) With numbered uninterpreted functions:

  • ut1 = in ∧
  • ut2 = F1(out1, in) ∧
  • ut3 = F2(out2, in)
  • ut′

1 = F4(F3(in, in), in)

Ackermann’s reduction: ϕE

a :

  • ut1 = in ∧
  • ut2 = f1 ∧
  • ut3 = f2

ϕE

b : out′ 1 = f4

The verification condition has shrunk: (out1 = in − → f1 = f3) ∧ (out2 = f3 − → f2 = f4)

  • ∧ ϕE

a ∧ ϕE b

→ out3 = out′

1

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 45 / 47

slide-89
SLIDE 89

Same example with Bryant’s reduction With numbered uninterpreted functions:

  • ut1 = in ∧
  • ut2 = F1(out1, in) ∧
  • ut3 = F2(out2, in)
  • ut′

1 = F4(F3(in, in), in)

Bryant’s reduction: ϕE

a :

  • ut1 = in ∧
  • ut2 = f1 ∧
  • ut3 = f2

ϕE

b : out′ 1 =

  • case

„ case in = out1: f1 true : f3 « = out2: f2 true : f4

  • The verification condition:

(ϕE

a ∧ ϕE b ) −

→ out3 = out′

1

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 46 / 47

slide-90
SLIDE 90

So is Equality Logic with UFs interesting?

1 It is expressible enough to state something

interesting.

2 It is decidable and more efficiently solvable

than richer logics, for example in which some functions are interpreted.

3 Models which rely on infinite-type variables are

expressed more naturally in this logic in comparison with Propositional Logic.

  • D. Kroening, O. Strichman (ETH/Technion)

Decision Procedures Version 1.0, 2007 47 / 47