Program Transformation and Constraint-based Verification Valerio - - PowerPoint PPT Presentation

program transformation and constraint based verification
SMART_READER_LITE
LIVE PREVIEW

Program Transformation and Constraint-based Verification Valerio - - PowerPoint PPT Presentation

Program Transformation and Constraint-based Verification Valerio Senni Department of Computer Science, Systems and Production University of Rome Tor Vergata, Italy joint work with E. De Angelis, F . Fioravanti, A. Pettorossi, M.


slide-1
SLIDE 1

Program Transformation and Constraint-based Verification

Valerio Senni

Department of Computer Science, Systems and Production University of Rome ‘Tor Vergata’, Italy

joint work with

  • E. De Angelis, F

. Fioravanti,

  • A. Pettorossi, M. Proietti

CPmeetsCAV 2012, Turunç

1 / 99

slide-2
SLIDE 2

Introduction

Rule-Based Program Transformation - Origins

initial P0 − → . . . − → Pn final M(P0) = . . . = M(Pn) rule-based model-preserving (local) rewriting An approach to developing correct & efficient programs [Burstall-Darlington 77]

’easy-to-prove-correct’

P0 − →∗ Pn

correct & efficient

M(P0) = M(Pn) − →∗ ≡

  • ptimization

Separate correctness concerns from efficiency concerns − →∗ constructed according to a strategy

2 / 99

slide-3
SLIDE 3

Introduction

Constraint Logic Programming

Programs as sets of rules (clauses) of the form:

H ← c

∧ ∧ B

(meaning, H holds if c is satisfiable in T and B holds)

Example:

  • rdered([])
  • rdered([x])
  • rdered([x1,x2|L]) ← x1 ≤ x2

solver for T ∧ ∧

  • rdered([x2|L])
  • resolution

Query evaluation: d ∧

∧G

= ⇒k

ρ

c1 ∧

∧ . . . ∧ ∧ cn

(with c1 ∧

∧ . . . ∧ ∧ cn T -satisfiable)

(and ρ = ϑ1 · . . . · ϑk)

= ⇒1

ϑ

is

  • 1. d ∧

∧G = d ∧ ∧A ∧ ∧R

current goal

  • 2. (A = H)ϑ

find unifying head

  • 3. (d ∧

∧ c ∧ ∧B ∧ ∧R)ϑ

rewrite

3 / 99

slide-4
SLIDE 4

Introduction

Transformation of Constraint Logic Programs

A program as a first order theory: theory transformation (changing the axioms of a theory, while preserving the model) Syntax Semantics logic programs least Herbrand model + negation perfect model, stable models + constraints least/perfect D-model

4 / 99

slide-5
SLIDE 5

Introduction

Rules

Definition Introduction − → newp(x) ← c(x) ∧ p1(x) ∧ . . . ∧ pn(x) Unfolding p(x) ← d1 ∧ B1 . . . p(x) ← dn ∧ Bn H ← c ∧ p(x) ∧ R − → H ← c ∧ d1 ∧ B1 ∧ R . . . H ← c ∧ dn ∧ Bn ∧ R Folding c ⊑ d p(x) ← d ∧ B H ← c ∧ B ∧ R − → H ← c ∧ p(x) ∧ R Clause Removal

  • 1. H ← c ∧ B

H ← d − → H ← d if c ⊑ d (c entails d)

  • 2. H ← c ∧ B

− → ∅ if c is unsatisfiable Rearrangement, Addition/Deletion, Constraint Rewriting

5 / 99

slide-6
SLIDE 6

Introduction

An Introductory Example

6 / 99

slide-7
SLIDE 7

Introduction

An Introductory Example

7 / 99

slide-8
SLIDE 8

Introduction

An Introductory Example

8 / 99

slide-9
SLIDE 9

Introduction

An Introductory Example

9 / 99

slide-10
SLIDE 10

Introduction

An Introductory Example

10 / 99

slide-11
SLIDE 11

Introduction

An Introductory Example

11 / 99

slide-12
SLIDE 12

Introduction

An Introductory Example

12 / 99

slide-13
SLIDE 13

Introduction

An Introductory Example

13 / 99

slide-14
SLIDE 14

Introduction

An Introductory Example

14 / 99

slide-15
SLIDE 15

Introduction

An Introductory Example

15 / 99

slide-16
SLIDE 16

Introduction

An Introductory Example

16 / 99

slide-17
SLIDE 17

Introduction

An Introductory Example

17 / 99

slide-18
SLIDE 18

Introduction

An Introductory Example

18 / 99

slide-19
SLIDE 19

Introduction

Transformation Strategies

Directed by syntactic features of programs: Specializing programs to the context of use (pre-computing) snm(S) ← near_match([2,0],2,S) Avoiding the computation of unnecessary values near_match(P ,K,S) ← a(L,T,S) ∧

∧ a(Q,R,T) ∧ ∧ near(P

,K,Q) Avoding multiple visits of data structures and repeated computations near_match(P ,K,S) ← a(L,T,S) ∧

∧ a(Q,R,T) ∧ ∧ near(P

,K,Q) Reducing nondeterminism (avoid multiple matchings per call-pattern) snm([X|S]) ← 0≤X≤4 ∧

∧ a(Q,R,S) ∧ ∧ n([0],2,Q)

snm([X|S]) ← 0≤X≤4 ∧

∧ a(L,T,S) ∧ ∧ a(Q,R,T) ∧ ∧ near([2,0],2,Q)

snm([X|S]) ← 0≤X≤4 ∧

∧ new1(S)

19 / 99

slide-20
SLIDE 20

Introduction

Transformation Strategies

Directed by syntactic features of programs: Specializing programs to the context of use (pre-computing) snm(S) ← near_match([2,0],2,S) Avoiding the computation of unnecessary values near_match(P ,K,S) ← a(L,T,S) ∧

∧ a(Q,R,T) ∧ ∧ near(P

,K,Q) Avoding multiple visits of data structures and repeated computations near_match(P ,K,S) ← a(L,T,S) ∧

∧ a(Q,R,T) ∧ ∧ near(P

,K,Q) Reducing nondeterminism (avoid multiple matchings per call-pattern) snm([X|S]) ← 0≤X≤4 ∧

∧ a(Q,R,S) ∧ ∧ n([0],2,Q)

snm([X|S]) ← 0≤X≤4 ∧

∧ a(L,T,S) ∧ ∧ a(Q,R,T) ∧ ∧ near([2,0],2,Q)

snm([X|S]) ← 0≤X≤4 ∧

∧ new1(S)

20 / 99

slide-21
SLIDE 21

Introduction

Transformation Strategies

Directed by syntactic features of programs: Specializing programs to the context of use (pre-computing) snm(S) ← near_match([2,0],2,S) Avoiding the computation of unnecessary values near_match(P ,K,S) ← a(L,T,S) ∧

∧ a(Q,R,T) ∧ ∧ near(P

,K,Q) Avoding multiple visits of data structures and repeated computations near_match(P ,K,S) ← a(L,T,S) ∧

∧ a(Q,R,T) ∧ ∧ near(P

,K,Q) Reducing nondeterminism (avoid multiple matchings per call-pattern) snm([X|S]) ← 0≤X≤4 ∧

∧ a(Q,R,S) ∧ ∧ n([0],2,Q)

snm([X|S]) ← 0≤X≤4 ∧

∧ a(L,T,S) ∧ ∧ a(Q,R,T) ∧ ∧ near([2,0],2,Q)

snm([X|S]) ← 0≤X≤4 ∧

∧ new1(S)

21 / 99

slide-22
SLIDE 22

Introduction

Transformation Strategies

Directed by syntactic features of programs: Specializing programs to the context of use (pre-computing) snm(S) ← near_match([2,0],2,S) Avoiding the computation of unnecessary values near_match(P ,K,S) ← a(L,T,S) ∧

∧ a(Q,R,T) ∧ ∧ near(P

,K,Q) Avoding multiple visits of data structures and repeated computations near_match(P ,K,S) ← a(L,T,S) ∧

∧ a(Q,R,T) ∧ ∧ near(P

,K,Q) Reducing nondeterminism (avoid multiple matchings per call-pattern) snm([X|S]) ← 0≤X≤4 ∧

∧ a(Q,R,S) ∧ ∧ n([0],2,Q)

snm([X|S]) ← 0≤X≤4 ∧

∧ a(L,T,S) ∧ ∧ a(Q,R,T) ∧ ∧ near([2,0],2,Q)

snm([X|S]) ← 0≤X≤4 ∧

∧ new1(S)

22 / 99

slide-23
SLIDE 23

Introduction

Rule-Based Program Transformation - More

P0 − → . . . − → Pn What do we preserve? M(P0) = . . . = M(Pn) a model A ∈ M(P0) iff . . . iff A ∈ M(Pn) selected predicates M(P0) ϕ iff . . . iff M(Pn) ϕ a class of formulas − →∗ ≡ deduction Depending on the choice of the set of rules and the transformation strategy

23 / 99

slide-24
SLIDE 24

Introduction

Applications

Theorem Proving

[Kott,P ,P ,Roychoudhury,Seki]

T ∪ {p ← ϕ} − →∗ S ∪ {p ←}

Program Verification

[Albert,Gallagher,Puebla]

[ [P] ] ∪ {p ← ϕ} − →∗ Q ∪ {p ←} where [ [P] ] is an encoding of the program semantics (e.g., an interpreter)

Program Synthesis

[Darlington,Deville,Flener,Hogger,Lau,Manna,Waldinger]

T ∪ {p(x) ← ϕ(x)} − →∗ P s.t. T | = ϕ(a) iff p(a) ∈ M(P)

24 / 99

slide-25
SLIDE 25

Improving Infinite-state and Software Model Checking

Improving Infinite-state Systems Model Checking

25 / 99

slide-26
SLIDE 26

Improving Infinite-state and Software Model Checking

Specialization-based Model Checking

Program Specialization P : I1 × I2 − → O By partial evaluation P1 : I2 − → O A faster residual program Take advantage of static knowledge Specialization-based Symbolic Model Checking CTL : TS × ϕ × Parameters − → yes/no By partial evaluation MCϕ

TS : Parameters

− → yes/no An ad-hoc model checker

26 / 99

slide-27
SLIDE 27

Improving Infinite-state and Software Model Checking

Specialization-based Model Checking

Program Specialization P : I1 × I2 − → O By partial evaluation P1 : I2 − → O A faster residual program Take advantage of static knowledge Specialization-based Symbolic Model Checking CTL : TS × ϕ × Parameters − → yes/no By partial evaluation MCϕ

TS : Parameters

− → yes/no An ad-hoc model checker

27 / 99

slide-28
SLIDE 28

Improving Infinite-state and Software Model Checking

Specialization Strategy

Input: P and a clause δ0: psp(x) ← c(x) ∧ p(x) Output: SpecP s.t. psp(z) ∈ M(P ∪ {δ0}) iff psp(z) ∈ M(SpecP) SpecP := ∅; Defs := {δ0}; while ∃ δ ∈ Defs do Γ := Unfold δ ∆ := Simplify Γ (Φ, NewDefs) := Generalize&Fold ∆ Defs := (Defs − {δ}) ∪ NewDefs SpecP := SpecP ∪ Φ

  • d

Test

28 / 99

slide-29
SLIDE 29

Improving Infinite-state and Software Model Checking

Specialization Strategy

Input: P and a clause δ0: psp(x) ← c(x) ∧ p(x) Output: SpecP s.t. psp(z) ∈ M(P ∪ {δ0}) iff psp(z) ∈ M(SpecP) SpecP := ∅; Defs := {δ0}; while ∃ δ ∈ Defs do Γ := Unfold δ ∆ := Simplify Γ (Φ, NewDefs) := Generalize&Fold ∆ Defs := (Defs − {δ}) ∪ NewDefs SpecP := SpecP ∪ Φ

  • d

Test

29 / 99

slide-30
SLIDE 30

Improving Infinite-state and Software Model Checking

Specialization Strategy

Input: P and a clause δ0: psp(x) ← c(x) ∧ p(x) Output: SpecP s.t. psp(z) ∈ M(P ∪ {δ0}) iff psp(z) ∈ M(SpecP) SpecP := ∅; Defs := {δ0}; while ∃ δ ∈ Defs do Γ := Unfold δ (Propagate Context) ∆ := Simplify Γ (Φ, NewDefs) := Generalize&Fold ∆ (Apply Induction) Defs := (Defs − {δ}) ∪ NewDefs SpecP := SpecP ∪ Φ

  • d

Test

30 / 99

slide-31
SLIDE 31

Improving Infinite-state and Software Model Checking

Specialization Strategy

Input: P and a clause δ0: psp(x) ← c(x) ∧ p(x) Output: SpecP s.t. psp(z) ∈ M(P ∪ {δ0}) iff psp(z) ∈ M(SpecP) SpecP := ∅; Defs := {δ0}; while ∃ δ ∈ Defs do Γ := Unfold δ ∆ := Simplify Γ (Φ, NewDefs) := Generalize&Fold ∆ Defs := (Defs − {δ}) ∪ NewDefs SpecP := SpecP ∪ Φ

  • d

We ensure termination by using wqos and generalization operators [à la Cousot-Halbwachs 78]

⇐ =

Test

31 / 99

slide-32
SLIDE 32

Improving Infinite-state and Software Model Checking

Specialization Strategy

Input: P and a clause δ0: psp(x) ← c(x) ∧ p(x) Output: SpecP s.t. psp(z) ∈ M(P ∪ {δ0}) iff psp(z) ∈ M(SpecP) SpecP := ∅; Defs := {δ0}; while ∃ δ ∈ Defs do Γ := Unfold δ ∆ := Simplify Γ (Φ, NewDefs) := Generalize&Fold ∆ Defs := (Defs − {δ}) ∪ NewDefs SpecP := SpecP ∪ Φ

  • d

We ensure termination by using wqos and generalization operators [à la Cousot-Halbwachs 78]

⇐ =

  • Automated
  • Terminating

32 / 99

slide-33
SLIDE 33

Improving Infinite-state and Software Model Checking

Application to Backward Reachability

Infinite-State System : Var, I, T, U (constraints on Zlin) Given a set S of states, PRE(T,S ) = {X | ∃X ′ ∈ S s.t. T(X, X ′)} Goal: Check that PREω(T,U ) ∩ I = ∅ (undecidable) Problem: The computation of PREω(T,U ) may not terminate

I U (I,T,U) 5 shift down

33 / 99

slide-34
SLIDE 34

Improving Infinite-state and Software Model Checking

Application to Backward Reachability

Infinite-State System : Var, I, T, U (constraints on Zlin) Given a set S of states, PRE(T,S ) = {X | ∃X ′ ∈ S s.t. T(X, X ′)} Goal: Check that PREω(T,U ) ∩ I = ∅ (undecidable) Problem: The computation of PREω(T,U ) may not terminate

pre

2(U)

I U

. . .

1(U)

pre

(I,T,U) 5 shift down

34 / 99

slide-35
SLIDE 35

Improving Infinite-state and Software Model Checking

Application to Backward Reachability

Infinite-State System : Var, I, T, U (constraints on Zlin) Given a set S of states, PRE(T,S ) = {X | ∃X ′ ∈ S s.t. T(X, X ′)} Goal: Check that PREω(T,U ) ∩ I = ∅ (undecidable) Problem: The computation of PREω(T,U ) may not terminate

U I (I,T,U) 5 shift down ?

pre*

(U)

35 / 99

slide-36
SLIDE 36

Improving Infinite-state and Software Model Checking

Application to Backward Reachability

Infinite-State System : Var, I, T, U (constraints on Zlin) Given a set S of states, PRE(T,S ) = {X | ∃X ′ ∈ S s.t. T(X, X ′)} Goal: Check that PREω(T,U ) ∩ I = ∅ (undecidable) Problem: The computation of PREω(T,U ) may not terminate

U I (I,T,U) 5 shift down ?

pre*

(U)

knowledge of the target (I ) is not taken into account in the construction of PREω(T,U )

36 / 99

slide-37
SLIDE 37

Improving Infinite-state and Software Model Checking

Encoding (Backward) Reachability in CLP

Sys = Var, I, T, U where I : init1(X) ∨

∨ . . . ∨ ∨ initk(X)

T : t1(X, X ′) ∨

∨ . . . ∨ ∨ tm(X, X ′)

U : u1(X) ∨

∨ . . . ∨ ∨ un(X)

I1 : not_safe ← init1(X) ∧

∧ bwReach(X)

. . . Ik : not_safe ← initk(X) ∧

∧ bwReach(X)

T1 : bwReach(X) ← t1(X, X ′) ∧

∧ bwReach(X ′)

. . . Tm : bwReach(X) ← tm(X, X ′) ∧

∧ bwReach(X ′)

U1 : bwReach(X) ← u1(X) . . . Un : bwReach(X) ← un(X)

see also [Fribourg 97, Delzanno-Podelski 99] full CTL encoded similarly [e.g. LOPSTR10]

37 / 99

slide-38
SLIDE 38

Improving Infinite-state and Software Model Checking

Source-to-Source Specialization

System S Specialized System SpecS ⇓ ⇑

specialize

PS ∈ CLP(Z) = ⇒ SpecPS ∈ CLP(Z) Input: S = Var, I, T, U

BACKWARD we specialize w.r.t. the Initial States PREω(T,U ) ∩ I = ∅

iff

PRE ω

T,I(U) = ∅

Output: SpecS = SpecVar, SpecI, SpecT, SpecU The standard operator PRE ω behaves on SpecS as PRE ω

T,I

38 / 99

slide-39
SLIDE 39

Improving Infinite-state and Software Model Checking

Source-to-Source Specialization

System S Specialized System SpecS ⇓ ⇑

specialize

PS ∈ CLP(Z) = ⇒ SpecPS ∈ CLP(Z) Input: S = Var, I, T, U

BACKWARD we specialize w.r.t. the Initial States PREω(T,U ) ∩ I = ∅

iff

PRE ω

T,I(U) = ∅

Output: SpecS = SpecVar, SpecI, SpecT, SpecU The standard operator PRE ω behaves on SpecS as PRE ω

T,I

39 / 99

slide-40
SLIDE 40

Improving Infinite-state and Software Model Checking

Source-to-Source Specialization

System S Specialized System SpecS ⇓ ⇑

specialize

PS ∈ CLP(Z) = ⇒ SpecPS ∈ CLP(Z) Input: S = Var, I, T, U

BACKWARD we specialize w.r.t. the Initial States PREω(T,U ) ∩ I = ∅

iff

PRE ω

T,I(U) = ∅

Output: SpecS = SpecVar, SpecI, SpecT, SpecU The standard operator PRE ω behaves on SpecS as PRE ω

T,I

40 / 99

slide-41
SLIDE 41

Improving Infinite-state and Software Model Checking

default F EXAMPLES Sys SpSys Sys SpSys Bakery2 0.03 0.05 0.06 0.04 Bakery3 0.70 0.25 ∞ 3.68 MutAst 1.46 0.37 0.22 0.59 Peterson 56.49 0.10 ∞ 13.48 Ticket ∞ 0.03 0.02 0.19 Berkeley RISC 0.01 0.04 0.01 0.02 DEC Firefly 0.01 0.02 0.01 0.07 IEEE Futurebus 0.26 0.68 ∞ ∞ Illinois Cache Coherence 0.01 0.03 ∞ 0.07 Barber 0.62 0.21 ∞ 0.08 CSM 56.39 7.69 ∞ 125.32 Consistency ∞ 0.11 ∞ 324.14 Insertion Sort 0.03 0.06 0.18 0.02 Selection Sort ∞ 0.21 ∞ 0.33 Reset Petri Net ∞ 0.02 ∞ 0.01 Train 42.24 59.21 ∞ 0.46

  • No. of verified properties

12 16 6 15

BACKWARD FORWARD

Timings : Sys = fixpoint only fixpoint computed using ALV [Bultan et al. 09], SpSys = specialization + fixpoint based on the Omega library ‘⊥’ = ‘Unable to verify’ and ‘∞’ = ‘Timeout’ (10 minutes)

41 / 99

slide-42
SLIDE 42

Improving Infinite-state and Software Model Checking

default F EXAMPLES Sys SpSys Sys SpSys Bakery2 0.03 0.05 0.06 0.04 Bakery3 0.70 0.25 ∞ 3.68 MutAst 1.46 0.37 0.22 0.59 Peterson 56.49 0.10 ∞ 13.48 Ticket ∞ 0.03 0.02 0.19 Berkeley RISC 0.01 0.04 0.01 0.02 DEC Firefly 0.01 0.02 0.01 0.07 IEEE Futurebus 0.26 0.68 ∞ ∞ Illinois Cache Coherence 0.01 0.03 ∞ 0.07 Barber 0.62 0.21 ∞ 0.08 CSM 56.39 7.69 ∞ 125.32 Consistency ∞ 0.11 ∞ 324.14 Insertion Sort 0.03 0.06 0.18 0.02 Selection Sort ∞ 0.21 ∞ 0.33 Reset Petri Net ∞ 0.02 ∞ 0.01 Train 42.24 59.21 ∞ 0.46

  • No. of verified properties

12 16 6 15

BACKWARD FORWARD

Specialization improves precision Overall, it does not deteriorate verification time Applicable in both forward and backward analyses

42 / 99

slide-43
SLIDE 43

Improving Infinite-state and Software Model Checking

Specialization-based Software Model Checking

a ::= n | x | a1+a2 | a1−a2 | a1×a2 b ::= true | false | a1 op a2 | ! b | b1 && b2 | b1 || b2 t ::= ∗ | b c ::= skip | x = a | c1; c2 | if t then c1 else c2 | while t do c od CLP interpreter for the operational semantics of SIMP

t(s(skip,S), E) t(s(asgn(var(X),A),E),s(skip,E1)) ← aeval(A,S,V), update(var(X),V,S,E1) t(s(comp(C0,C1),S), s(C1,S1)) ← t(s(C0,S),S1) t(s(comp(C0,C1),S), s(comp(C0’,C1),S’)) ← t(s(C0,S), s(C0’,S’)) t(s(ite(B,C0,_),S), s(C0,S)) ← beval(B,S) t(s(ite(B,_,C1),S), s(C1,S)) ← beval(not(B) ,S) t(s(ite(ndc,S1,_),E),s(S1,E)) t(s(ite(ndc,_,S2),E),s(S3,E)) t(s(while(B,C),S),s(ite(B,comp(C,while(B,C)),skip),S))

see also [Peralta,Gallagher SAS98+LOPSTR99]

43 / 99

slide-44
SLIDE 44

Improving Infinite-state and Software Model Checking

Summarizing

Pros/Cons: improvement of termination but increase in size ϕ-preserving and terminating independent of the verification tool/independent of the verification tool Features: control on termination/precision (wqos and generalizations) Z hard to solve: precise relaxation to R logics: CTL* and ω-regular languages residual program size: controlling polyvariance

44 / 99

slide-45
SLIDE 45

Reasoning on Data Structures + Constraints

Reasoning on Data Structures + Constraints

45 / 99

slide-46
SLIDE 46

Reasoning on Data Structures + Constraints

Context & Related Work

Transformation and Theorem Proving: equivalence proofs by unfold/fold [Kott-82, PP-99, Roychoudhury et al-99] first order theorem proving by unfold/fold [PP-00] a Deforestation [Wadler-90] used for quantifier elimination A technique for the elimination of intermediate data structures No existential variables entails No intermediate data structures Existential variables occur in the body of a clause and not in the head E.g., X existential in p ← q(X) ∧ r(X) Since ∀X( p ← q(X) ∧ r(X) ) ≡ p ← ∃X(q(X)∧r(X))

46 / 99

slide-47
SLIDE 47

Reasoning on Data Structures + Constraints

Context & Related Work

Transformation and Theorem Proving: equivalence proofs by unfold/fold [Kott-82, PP-99, Roychoudhury et al-99] first order theorem proving by unfold/fold [PP-00] a Deforestation [Wadler-90] used for quantifier elimination A technique for the elimination of intermediate data structures No existential variables entails No intermediate data structures Existential variables occur in the body of a clause and not in the head E.g., X existential in p ← q(X) ∧ r(X) Since ∀X( p ← q(X) ∧ r(X) ) ≡ p ← ∃X(q(X)∧r(X))

47 / 99

slide-48
SLIDE 48

Reasoning on Data Structures + Constraints

Context & Related Work

Transformation and Theorem Proving: equivalence proofs by unfold/fold [Kott-82, PP-99, Roychoudhury et al-99] first order theorem proving by unfold/fold [PP-00] a Deforestation [Wadler-90] used for quantifier elimination A technique for the elimination of intermediate data structures No existential variables entails No intermediate data structures Existential variables occur in the body of a clause and not in the head E.g., X existential in p ← q(X) ∧ r(X) Since ∀X( p ← q(X) ∧ r(X) ) ≡ p ← ∃X(q(X)∧r(X))

48 / 99

slide-49
SLIDE 49

Reasoning on Data Structures + Constraints

Proving Properties of LR programs

LR programs: linear constraints on R/Q linear recursion + negation no existential variables Example:

P: member(X, [Y|L ]) ← X = Y member(X, [Y|L ]) ← member(X, L) ϕ: ∀L ∃U ∀X (member(X, L) → X ≤U)

Checking M(P) | = ϕ, for any LR-program P and closed formula ϕ, is undecidable (Peano arithmetic can be encoded) Quantifier elimination cannot be algorithmic

49 / 99

slide-50
SLIDE 50

Reasoning on Data Structures + Constraints

Proving Properties of LR programs

LR programs: linear constraints on R/Q linear recursion + negation no existential variables Example:

P: member(X, [Y|L ]) ← X = Y member(X, [Y|L ]) ← member(X, L) ϕ: ∀L ∃U ∀X (member(X, L) → X ≤U)

Checking M(P) | = ϕ, for any LR-program P and closed formula ϕ, is undecidable (Peano arithmetic can be encoded) Quantifier elimination cannot be algorithmic

50 / 99

slide-51
SLIDE 51

Reasoning on Data Structures + Constraints

QE for CLP(Rlin) via Program Transformation

Step 1. Using a variant of Lloyd-Topor transformation,

we obtain a clause form CF for ϕ s.t. M(P) | = ϕ iff M(P ∪ CF) | = f ∀L ∃U ∀Y (member(Y, L) → Y ≤ U) p ← ¬ ∃L ¬ ∃U ¬ ∃Y(member(Y, L) ∧ Y > U)

  • s
  • r
  • q

CF: D4: p ← ¬q D3: q ← list(L) ∧ ¬r(L) D2: r(L) ← list(L) ∧ ¬s(L, U) D1: s(L, U) ← Y > U ∧ list(L) ∧ member(Y, U)

  • stratified
  • non LR-clauses

(existential variables, nonlinear)

Resolution does not terminate on the query p Quantifiers can be eliminated by deriving LR-programs

51 / 99

slide-52
SLIDE 52

Reasoning on Data Structures + Constraints

QE for CLP(Rlin) via Program Transformation

Step 1. Using a variant of Lloyd-Topor transformation,

we obtain a clause form CF for ϕ s.t. M(P) | = ϕ iff M(P ∪ CF) | = f ∀L ∃U ∀Y (member(Y, L) → Y ≤ U) p ← ¬ ∃L ¬ ∃U ¬ ∃Y(member(Y, L) ∧ Y > U)

  • s
  • r
  • q

CF: D4: p ← ¬q D3: q ← list(L) ∧ ¬r(L) D2: r(L) ← list(L) ∧ ¬s(L, U) D1: s(L, U) ← Y > U ∧ list(L) ∧ member(Y, U)

  • stratified
  • non LR-clauses

(existential variables, nonlinear)

Resolution does not terminate on the query p Quantifiers can be eliminated by deriving LR-programs

52 / 99

slide-53
SLIDE 53

Reasoning on Data Structures + Constraints

QE for CLP(Rlin) via Program Transformation

Step 1. Using a variant of Lloyd-Topor transformation,

we obtain a clause form CF for ϕ s.t. M(P) | = ϕ iff M(P ∪ CF) | = f ∀L ∃U ∀Y (member(Y, L) → Y ≤ U) p ← ¬ ∃L ¬ ∃U ¬ ∃Y(member(Y, L) ∧ Y > U)

  • s
  • r
  • q

CF: D4: p ← ¬q D3: q ← list(L) ∧ ¬r(L) D2: r(L) ← list(L) ∧ ¬s(L, U) D1: s(L, U) ← Y > U ∧ list(L) ∧ member(Y, U)

  • stratified
  • non LR-clauses

(existential variables, nonlinear)

Resolution does not terminate on the query p Quantifiers can be eliminated by deriving LR-programs

53 / 99

slide-54
SLIDE 54

Reasoning on Data Structures + Constraints

QE for CLP(Rlin) via Program Transformation

Step 1. Using a variant of Lloyd-Topor transformation,

we obtain a clause form CF for ϕ s.t. M(P) | = ϕ iff M(P ∪ CF) | = f ∀L ∃U ∀Y (member(Y, L) → Y ≤ U) p ← ¬ ∃L ¬ ∃U ¬ ∃Y(member(Y, L) ∧ Y > U)

  • s
  • r
  • q

CF: D4: p ← ¬q D3: q ← list(L) ∧ ¬r(L) D2: r(L) ← list(L) ∧ ¬s(L, U) D1: s(L, U) ← Y > U ∧ list(L) ∧ member(Y, U)

  • stratified
  • non LR-clauses

(existential variables, nonlinear)

Resolution does not terminate on the query p Quantifiers can be eliminated by deriving LR-programs

54 / 99

slide-55
SLIDE 55

Reasoning on Data Structures + Constraints

QE for CLP(Rlin) via Program Transformation - Cont.

Step 2. Apply a strategy that combines

unfold/fold transformations and constraint reasoning on Rlin Goal: from P ∪ CF derive a propositional program Prop s.t. M(P ∪ CF) | = f iff M(Prop) | = f Prop: p ← ¬ q q ← newp newp ← newp As a consequence, M(P) | = ϕ iff M(Prop) | = p The transformation from P ∪ CF to Prop consists in eliminating all existential variables from CF

55 / 99

slide-56
SLIDE 56

Reasoning on Data Structures + Constraints

QE for CLP(Rlin) via Program Transformation - Cont.

Step 2. Apply a strategy that combines

unfold/fold transformations and constraint reasoning on Rlin Goal: from P ∪ CF derive a propositional program Prop s.t. M(P ∪ CF) | = f iff M(Prop) | = f Prop: p ← ¬ q q ← newp newp ← newp As a consequence, M(P) | = ϕ iff M(Prop) | = p The transformation from P ∪ CF to Prop consists in eliminating all existential variables from CF

56 / 99

slide-57
SLIDE 57

Reasoning on Data Structures + Constraints

The Transformational Proof Method

D1: s(L,U) ← X > U ∧

∧ list(L) ∧ ∧ member(X,L) 57 / 99

slide-58
SLIDE 58

Reasoning on Data Structures + Constraints

The Transformational Proof Method

D1: s(L,U) ← X > U ∧

∧ list(L) ∧ ∧ member(X,L)

Unfold: s([X|T],U) ← X > U ∧

∧ list(T)

s([Y|T],U) ← X > U ∧

∧ list(T) ∧ ∧ member (X,T) 58 / 99

slide-59
SLIDE 59

Reasoning on Data Structures + Constraints

The Transformational Proof Method

D1: s(L,U) ← X > U ∧

∧ list(L) ∧ ∧ member(X,L)

Unfold: s([X|T],U) ← X > U ∧

∧ list(T)

s([Y|T],U) ← X > U ∧

∧ list(T) ∧ ∧ member (X,T)

Fold: s([X|T],U) ← X > U ∧

∧ list(T)

s([X|T],U) ← s(T,U) LR-clauses

59 / 99

slide-60
SLIDE 60

Reasoning on Data Structures + Constraints

The Transformational Proof Method

D1: s(L,U) ← X > U ∧

∧ list(L) ∧ ∧ member(X,L)

Unfold: s([X|T],U) ← X > U ∧

∧ list(T)

s([Y|T],U) ← X > U ∧

∧ list(T) ∧ ∧ member (X,T)

Fold: s([X|T],U) ← X > U ∧

∧ list(T)

s([X|T],U) ← s(T,U) LR-clauses D4: p ← ¬ q D3: q ← list(L) ∧ ¬ r(L) D2: r(L) ← list(L) ∧ ¬ s(L, U) D1: s([X|T],U) ← X > U ∧

∧ list(T)

s([X|T],U) ← s(T,U)

60 / 99

slide-61
SLIDE 61

Reasoning on Data Structures + Constraints

The Transformational Proof Method

D2: r(L) ← list(L) ∧

∧ ¬ s(L,U) 61 / 99

slide-62
SLIDE 62

Reasoning on Data Structures + Constraints

The Transformational Proof Method

D2: r(L) ← list(L) ∧

∧ ¬ s(L,U)

Unfold: r([ ]) r([X|Xs]) ← X≤U ∧

∧ list(Xs) ∧ ∧ ¬ s(Xs,U) 62 / 99

slide-63
SLIDE 63

Reasoning on Data Structures + Constraints

The Transformational Proof Method

D2: r(L) ← list(L) ∧

∧ ¬ s(L,U)

Unfold: r([ ]) r([X|Xs]) ← X≤U ∧

∧ list(Xs) ∧ ∧ ¬ s(Xs,U)

BAD folding

63 / 99

slide-64
SLIDE 64

Reasoning on Data Structures + Constraints

The Transformational Proof Method

D2: r(L) ← list(L) ∧

∧ ¬ s(L,U)

Unfold: r([ ]) r([X|Xs]) ← X≤U ∧

∧ list(Xs) ∧ ∧ ¬ s(Xs,U)

Define: new1(X,L) ← X≤U ∧

∧ list(L) ∧ ∧ ¬ s(L,U) 64 / 99

slide-65
SLIDE 65

Reasoning on Data Structures + Constraints

The Transformational Proof Method

D2: r(L) ← list(L) ∧

∧ ¬ s(L,U)

Unfold: r([ ]) r([X|Xs]) ← X≤U ∧

∧ list(Xs) ∧ ∧ ¬ s(Xs,U)

Define: new1(X,L) ← X≤U ∧

∧ list(L) ∧ ∧ ¬ s(L,U)

Fold: r([ ]) ← r([X|Xs]) ← new1(X,Xs) LR-clauses

65 / 99

slide-66
SLIDE 66

Reasoning on Data Structures + Constraints

The Transformational Proof Method

D2: r(L) ← list(L) ∧

∧ ¬ s(L,U)

Unfold: r([ ]) r([X|Xs]) ← X≤U ∧

∧ list(Xs) ∧ ∧ ¬ s(Xs,U)

Define: new1(X,L) ← X≤U ∧

∧ list(L) ∧ ∧ ¬ s(L,U)

Fold: r([ ]) ← r([X|Xs]) ← new1(X,Xs) LR-clauses Unfold: new1(X,[ ]) ← new1(X,[Y|Ys]) ← X≤U ∧

∧ Y≤U ∧ ∧ list(Ys) ∧ ∧ ¬ s(Ys,U) 66 / 99

slide-67
SLIDE 67

Reasoning on Data Structures + Constraints

The Transformational Proof Method

D2: r(L) ← list(L) ∧

∧ ¬ s(L,U)

Unfold: r([ ]) r([X|Xs]) ← X≤U ∧

∧ list(Xs) ∧ ∧ ¬ s(Xs,U)

Define: new1(X,L) ← X≤U ∧

∧ list(L) ∧ ∧ ¬ s(L,U)

Fold: r([ ]) ← r([X|Xs]) ← new1(X,Xs) LR-clauses Unfold: new1(X,[ ]) ← new1(X,[Y|Ys]) ← X≤U ∧

∧ Y≤U ∧ ∧ list(Ys) ∧ ∧ ¬ s(Ys,U)

≡ (Y<X ∧

∧ X≤U) ∨ ∨ (X≤Y ∧ ∧ Y≤U)

(linear order)

67 / 99

slide-68
SLIDE 68

Reasoning on Data Structures + Constraints

The Transformational Proof Method

D2: r(L) ← list(L) ∧

∧ ¬ s(L,U)

Unfold: r([ ]) r([X|Xs]) ← X≤U ∧

∧ list(Xs) ∧ ∧ ¬ s(Xs,U)

Define: new1(X,L) ← X≤U ∧

∧ list(L) ∧ ∧ ¬ s(L,U)

Fold: r([ ]) ← r([X|Xs]) ← new1(X,Xs) LR-clauses Unfold: new1(X,[ ]) ← new1(X,[Y|Ys]) ← X≤U ∧

∧ Y≤U ∧ ∧ list(Ys) ∧ ∧ ¬ s(Ys,U)

≡ (Y<X ∧

∧ X≤U) ∨ ∨ (X≤Y ∧ ∧ Y≤U)

(linear order)

Replace: new1(X,[Y|Ys]) ← Y<X ∧

∧ X≤U ∧ ∧ list(Ys) ∧ ∧ ¬ s(Ys,U)

new1(X,[Y|Ys]) ← X≤Y ∧

∧ Y≤U ∧ ∧ list(Ys) ∧ ∧ ¬ s(Ys,U) 68 / 99

slide-69
SLIDE 69

Reasoning on Data Structures + Constraints

The Transformational Proof Method

D2: r(L) ← list(L) ∧

∧ ¬ s(L,U)

Unfold: r([ ]) r([X|Xs]) ← X≤U ∧

∧ list(Xs) ∧ ∧ ¬ s(Xs,U)

Define: new1(X,L) ← X≤U ∧

∧ list(L) ∧ ∧ ¬ s(L,U)

Fold: r([ ]) ← r([X|Xs]) ← new1(X,Xs) LR-clauses Unfold: new1(X,[ ]) ← new1(X,[Y|Ys]) ← X≤U ∧

∧ Y≤U ∧ ∧ list(Ys) ∧ ∧ ¬ s(Ys,U)

≡ (Y<X ∧

∧ X≤U) ∨ ∨ (X≤Y ∧ ∧ Y≤U)

(linear order)

Replace: new1(X,[Y|Ys]) ← Y<X ∧

∧ X≤U ∧ ∧ list(Ys) ∧ ∧ ¬ s(Ys,U)

new1(X,[Y|Ys]) ← X≤Y ∧

∧ Y≤U ∧ ∧ list(Ys) ∧ ∧ ¬ s(Ys,U)

Fold: new1(X,[ ]) ← new1(X,[Y|Ys]) ← Y<X ∧

∧ new1(X,Ys)

new1(X,[Y|Ys]) ← X≤Y ∧

∧ new1(Y,Ys)

LR-clauses

69 / 99

slide-70
SLIDE 70

Reasoning on Data Structures + Constraints

The Transformational Proof Method

D2: r(L) ← list(L) ∧

∧ ¬ s(L,U)

Unfold: r([ ]) r([X|Xs]) ← X≤U ∧

∧ list(Xs) ∧ ∧ ¬ s(Xs,U)

Define: new1(X,L) ← X≤U ∧

∧ list(L) ∧ ∧ ¬ s(L,U)

Fold: r([ ]) ← r([X|Xs]) ← new1(X,Xs) LR-clauses Unfold: new1(X,[ ]) ← new1(X,[Y|Ys]) ← X≤U ∧

∧ Y≤U ∧ ∧ list(Ys) ∧ ∧ ¬ s(Ys,U)

≡ (Y<X ∧

∧ X≤U) ∨ ∨ (X≤Y ∧ ∧ Y≤U)

(linear order)

Replace: new1(X,[Y|Ys]) ← Y<X ∧

∧ X≤U ∧ ∧ list(Ys) ∧ ∧ ¬ s(Ys,U)

new1(X,[Y|Ys]) ← X≤Y ∧

∧ Y≤U ∧ ∧ list(Ys) ∧ ∧ ¬ s(Ys,U)

Fold: new1(X,[ ]) ← new1(X,[Y|Ys]) ← Y<X ∧

∧ new1(X,Ys)

new1(X,[Y|Ys]) ← X≤Y ∧

∧ new1(Y,Ys)

LR-clauses

70 / 99

slide-71
SLIDE 71

Reasoning on Data Structures + Constraints

The Transformational Proof Method

D4: p ← ¬ q D3: q ← list(L) ∧ ¬ r(L) D2: r([ ]) ← r([X|Xs]) ← new1(X,Xs) new1(X,[ ]) ← new1(X,[Y|Ys]) ← Y<X ∧

∧ new1(X,Ys)

new1(X,[Y|Ys]) ← X≤Y ∧

∧ new1(Y,Ys)

D1: s([X|T],U) ← X > U ∧

∧ list(T)

s([X|T],U) ← s(T,U) A

71 / 99

slide-72
SLIDE 72

Reasoning on Data Structures + Constraints

The Transformational Proof Method

D4: p ← ¬ q D3: q ← new2 new2 ← new2 D2: r([ ]) ← r([X|Xs]) ← new1(X,Xs) new1(X,[ ]) ← new1(X,[Y|Ys]) ← Y<X ∧

∧ new1(X,Ys)

new1(X,[Y|Ys]) ← X≤Y ∧

∧ new1(Y,Ys)

D1: s([X|T],U) ← X > U ∧

∧ list(T)

s([X|T],U) ← s(T,U) Using: domain axioms quantifier elimination

  • n constraints

A

72 / 99

slide-73
SLIDE 73

Reasoning on Data Structures + Constraints

The Transformational Proof Method

D4: p ← ¬ q D3: q ← new2 new2 ← new2 D2: r([ ]) ← r([X|Xs]) ← new1(X,Xs) new1(X,[ ]) ← new1(X,[Y|Ys]) ← Y<X ∧

∧ new1(X,Ys)

new1(X,[Y|Ys]) ← X≤Y ∧

∧ new1(Y,Ys)

D1: s([X|T],U) ← X > U ∧

∧ list(T)

s([X|T],U) ← s(T,U) Using: domain axioms quantifier elimination

  • n constraints

Since M(Prop) | = p, we conclude M(P) | = ϕ

73 / 99

slide-74
SLIDE 74

Reasoning on Data Structures + Constraints

Some Observations

Summary: a heuristic a decision procedure for wS1S Challenge: property driven, automatic inference of needed axioms

74 / 99

slide-75
SLIDE 75

Optimizing Test-case Generation

Optimizing Test-case Generation

75 / 99

slide-76
SLIDE 76

Optimizing Test-case Generation

Filter Promotion

N-Queens queens(X,C) ← generate(N,C) ∧

∧ check(C)

generate(N,C) ← permutation(N,C) check([ ]) ← check([Q|Qs]) ← ¬ attack(Q,Qs) ∧

check(Qs)

76 / 99

slide-77
SLIDE 77

Optimizing Test-case Generation

Filter Promotion

N-Queens queens(X,C) ← generate(N,C) ∧

∧ check(C)

generate(N,C) ← permutation(N,C) check([ ]) ← check([Q|Qs]) ← ¬ attack(Q,Qs) ∧

check(Qs) Q Q Q Q X

77 / 99

slide-78
SLIDE 78

Optimizing Test-case Generation

Filter Promotion

N-Queens queens(X,C) ← generate(N,C) ∧

∧ check(C)

generate(N,C) ← permutation(N,C) check([ ]) ← check([Q|Qs]) ← ¬ attack(Q,Qs) ∧

check(Qs) Q Q Q Q

  • 78 / 99
slide-79
SLIDE 79

Optimizing Test-case Generation

Filter Promotion

N-Queens queens(X,C) ← generate(N,C) ∧

∧ check(C)

generate(N,C) ← permutation(N,C) check([ ]) ← check([Q|Qs]) ← ¬ attack(Q,Qs) ∧

check(Qs) Q Q Q Q

  • queens(X,C)

← queens(N,[ ],C) queens(0,Qs,Qs) ← queens(N,SafeQs,Qs) ← place(SafeQs,Q) ∧

¬ attack(Q,SafeQs) ∧

M>0 ∧

∧ M is N-1 ∧ ∧

queens(M,[Q|SafeQs],Qs) aaa ⇐ = promoted

79 / 99

slide-80
SLIDE 80

Optimizing Test-case Generation

Filter Promotion

N-Queens queens(X,C) ← generate(N,C) ∧

∧ check(C)

generate(N,C) ← permutation(N,C) check([ ]) ← check([Q|Qs]) ← ¬ attack(Q,Qs) ∧

check(Qs) Q Q Q Q

  • queens(X,C)

← queens(N,[ ],C) queens(0,Qs,Qs) ← queens(N,SafeQs,Qs) ← place(SafeQs,Q) ∧

¬ attack(Q,SafeQs) ∧

M>0 ∧

∧ M is N-1 ∧ ∧

queens(M,[Q|SafeQs],Qs) Q Q Q Q

80 / 99

slide-81
SLIDE 81

Optimizing Test-case Generation

Filter Promotion

N-Queens queens(X,C) ← generate(N,C) ∧

∧ check(C)

generate(N,C) ← permutation(N,C) check([ ]) ← check([Q|Qs]) ← ¬ attack(Q,Qs) ∧

check(Qs) Q Q Q Q

  • queens(X,C)

← queens(N,[ ],C) queens(0,Qs,Qs) ← queens(N,SafeQs,Qs) ← place(SafeQs,Q) ∧

¬ attack(Q,SafeQs) ∧

M>0 ∧

∧ M is N-1 ∧ ∧

queens(M,[Q|SafeQs],Qs) Q Q Q Q Q X

81 / 99

slide-82
SLIDE 82

Optimizing Test-case Generation

Filter Promotion

N-Queens queens(X,C) ← generate(N,C) ∧

∧ check(C)

generate(N,C) ← permutation(N,C) check([ ]) ← check([Q|Qs]) ← ¬ attack(Q,Qs) ∧

check(Qs) Q Q Q Q

  • queens(X,C)

← queens(N,[ ],C) queens(0,Qs,Qs) ← queens(N,SafeQs,Qs) ← place(SafeQs,Q) ∧

¬ attack(Q,SafeQs) ∧

M>0 ∧

∧ M is N-1 ∧ ∧

queens(M,[Q|SafeQs],Qs) Q Q Q Q

  • 82 / 99
slide-83
SLIDE 83

Optimizing Test-case Generation

Filter Promotion

N-Queens queens(X,C) ← generate(N,C) ∧

∧ check(C)

generate(N,C) ← permutation(N,C) check([ ]) ← check([Q|Qs]) ← ¬ attack(Q,Qs) ∧

check(Qs) Q Q Q Q

→∗ Derive automatically, by transformation queens(X,C) ← queens(N,[ ],C) queens(0,Qs,Qs) ← queens(N,SafeQs,Qs) ← place(SafeQs,Q) ∧

¬ attack(Q,SafeQs) ∧

M>0 ∧

∧ M is N-1 ∧ ∧

queens(M,[Q|SafeQs],Qs) Q Q Q Q

83 / 99

slide-84
SLIDE 84

Optimizing Test-case Generation

Enumeration of Complex Data-Structures

Red-Black Trees Nodes are: colored (red or black) marked (by a key) A binary tree satisfying the following invariants: (I1) red nodes have black children (I2) every root-to-leaf path has the same number of black nodes (I3) keys are ordered left-to-right imperative vs declarative languages for test-case generation

84 / 99

slide-85
SLIDE 85

Optimizing Test-case Generation

CLP Evaluation for Test Generation

  • rdered([])
  • rdered([x])
  • rdered([x1,x2|L]) ← x1 ≤ x2

solver for T ∧ ∧

  • rdered([x2|L])
  • resolution

As a generator:

  • rdered(L).

= ⇒ = ⇒ = ⇒ = ⇒

L = [ ]

= ⇒ = ⇒

L = [x]

= ⇒ = ⇒

L = [x1,x2] with x1 ≤ x2 . . . L = [x1,x2,x3] with x1 ≤ x2 ∧

∧ x2 ≤ x3

Constraint-based [DeMillo-Offutt ‘91, Meudec (ATGen) ‘01, Euclide ‘09] Constraint Logic Programming -based [PathCrawler ‘05, Charreteur-Botella-Gotlieb ‘01, jPET ‘11]

85 / 99

slide-86
SLIDE 86

Optimizing Test-case Generation

A CLP-based Encoding of Red-Black Trees

rbtree(T,MinSize,MaxSize,NumKeys) ← % Preamble ...DOMAINS..., % Symbolic Definition lbt(T,S,Keys,[ ]), % data structure shape pi(T,D), ci(T,Colors,[ ]), % filters

  • rdered(T,0,NumKeys),

% filters % Instantiation fd_labeling(Keys), fd_labeling(Colors). lbt(T,S,Keys,[ ]) if T is labeled binary tree with S nodes pi(T,D) if the tree T satisfies the path invariant ci(T,Colors) if the tree T satisfies the color invariant

  • rdered(T,0,NumKeys)

if the labels (keys) in T are ordered left-to-right fd_labeling(X) if the variable X is instantiated to a feasible value

86 / 99

slide-87
SLIDE 87

Optimizing Test-case Generation

Shape Rejection

Tree ::= e | Color × Key × Tree × Tree with Color in {0, 1} (red, black) and Key in {0, . . . , MaxKey} Size 3 (a possible solution): c1,k1 c2,k2 c3,k3

  • c1 = c1 + c2

∧ ∧

c1+c2 = c1+c2+c3

  • c1 + c2 > 0

∧ ∧

c2 + c3 > 0

  • k1 < k2

∧ ∧

k1 < k3

∧ ∧

k3 < k2 structure shape path invariant color invariant

  • rdering

87 / 99

slide-88
SLIDE 88

Optimizing Test-case Generation

Shape Rejection

Tree ::= e | Color × Key × Tree × Tree with Color in {0, 1} (red, black) and Key in {0, . . . , MaxKey} Size 3 (a possible solution): c1,k1 c2,k2 c3,k3

  • c1 = c1 + c2

∧ ∧

c1+c2 = c1+c2+c3

  • c1 + c2 > 0

∧ ∧

c2 + c3 > 0

  • k1 < k2

∧ ∧

k1 < k3

∧ ∧

k3 < k2 structure shape path invariant color invariant

  • rdering

lbt(T,S,Keys,[ ]) ∧ pi(T,D) ∧ ci(T,Colors) ∧

  • rdered(T,. . . )

88 / 99

slide-89
SLIDE 89

Optimizing Test-case Generation

Shape Rejection

Tree ::= e | Color × Key × Tree × Tree with Color in {0, 1} (red, black) and Key in {0, . . . , MaxKey} Size 3 (a possible solution): c1,k1 c2,k2 c3,k3

  • c1 = c1 + c2

∧ ∧

c1+c2 = c1+c2+c3

  • c1 + c2 > 0

∧ ∧

c2 + c3 > 0

  • k1 < k2

∧ ∧

k1 < k3

∧ ∧

k3 < k2

UNFEASIBLE

structure shape path invariant color invariant

  • rdering

lbt(T,S,Keys,[ ]) ∧ pi(T,D) ∧ ci(T,Colors) ∧

  • rdered(T,. . . )

No instantiation possible ⇒ c2 = 0 ∧

∧ c3 = 0 89 / 99

slide-90
SLIDE 90

Optimizing Test-case Generation

Shape Concretization

Tree ::= e | Color × Key × Tree × Tree with Color in {0, 1} (red, black) and Key in {0, . . . , MaxKey} Size 3 (another solution) : c1,k1 c2,k2 c3,k3

  • c1 + c2 = c1 + c3

c1 + c2 > 0

∧ ∧

c1 + c3 > 0

  • k2 < k1

∧ ∧

k1 < k3

FEASIBLE

Instantiations:

90 / 99

slide-91
SLIDE 91

Optimizing Test-case Generation

Shape Concretization

Tree ::= e | Color × Key × Tree × Tree with Color in {0, 1} (red, black) and Key in {0, . . . , MaxKey} Size 3 (another solution) : c1,k1 c2,k2 c3,k3

  • c1 + c2 = c1 + c3

c1 + c2 > 0

∧ ∧

c1 + c3 > 0

  • k2 < k1

∧ ∧

k1 < k3

FEASIBLE

Instantiations: r,k1 r,k2 r,k3 b,k1 b,k1 b,k2 b,k3 b,k2 b,k3

91 / 99

slide-92
SLIDE 92

Optimizing Test-case Generation

Shape Concretization

Tree ::= e | Color × Key × Tree × Tree with Color in {0, 1} (red, black) and Key in {0, . . . , MaxKey} Size 3 (another solution) : c1,k1 c2,k2 c3,k3

  • c1 + c2 = c1 + c3

c1 + c2 > 0

∧ ∧

c1 + c3 > 0

  • k2 < k1

∧ ∧

k1 < k3

FEASIBLE

Instantiations: r,k1 r,k2 r,k3 b,k1 b,k1 b,k2 b,k3 b,k2 b,k3 r,1 r,1 r,2 r,2 b,0 b,2 b,0 b,3 b,0 b,3 b,1 b,3

92 / 99

slide-93
SLIDE 93

Optimizing Test-case Generation

Shape Concretization

Tree ::= e | Color × Key × Tree × Tree with Color in {0, 1} (red, black) and Key in {0, . . . , MaxKey} Size 3 (another solution) : c1,k1 c2,k2 c3,k3

  • c1 + c2 = c1 + c3

c1 + c2 > 0

∧ ∧

c1 + c3 > 0

  • k2 < k1

∧ ∧

k1 < k3

FEASIBLE

Instantiations: r,k1 r,k2 r,k3 b,k1 b,k1 b,k2 b,k3 b,k2 b,k3 r,1 r,1 r,2 r,2 b,0 b,2 b,0 b,3 b,0 b,3 b,1 b,3 5 shapes 1 feasible 12 instantiations . . .

we let the solver choose an instantiation order to minimize backtracking

93 / 99

slide-94
SLIDE 94

Optimizing Test-case Generation

Optimizing Generators by Transformation

Size 20 c1,k1 c2,k2 c3,k3 No way of placing the remaining 17 nodes to build a feasible tree c1 = c1 + c2 ∧

∧ c1 = c1 + c2 + c3 + X ∧ ∧

X ≥ 0 ∧

∧ c1 + c2 > 0 ∧ ∧ c2 + c3 > 0

UNFEASIBLE

Yet, there would be 35357670 shapes (and corresponding feasiblity tests) Idea: apply filter earlier

94 / 99

slide-95
SLIDE 95

Optimizing Test-case Generation

Optimizing Generators by Transformation

Size 20 c1,k1 c2,k2 c3,k3 No way of placing the remaining 17 nodes to build a feasible tree c1 = c1 + c2 ∧

∧ c1 = c1 + c2 + c3 + X ∧ ∧

X ≥ 0 ∧

∧ c1 + c2 > 0 ∧ ∧ c2 + c3 > 0

UNFEASIBLE

Yet, there would be 35357670 shapes (and corresponding feasiblity tests) Idea: apply filter earlier The Synchronization transformation strategy

  • automates optimization
  • filter promotion + tupling + folding (local optimization inductively propagated)
  • force the generator to have the desired behavior
  • reduces don’t care nondeterminism (less failures)
  • guided by the inductive traversal of (a slice of) the data-structure

95 / 99

slide-96
SLIDE 96

Optimizing Test-case Generation

Optimizing Generators by Transformation

Size 20 c1,k1 c2,k2 c3,k3 No way of placing the remaining 17 nodes to build a feasible tree c1 = c1 + c2 ∧

∧ c1 = c1 + c2 + c3 + X ∧ ∧

X ≥ 0 ∧

∧ c1 + c2 > 0 ∧ ∧ c2 + c3 > 0

UNFEASIBLE

Yet, there would be 35357670 shapes (and corresponding feasiblity tests) Idea: apply filter earlier The Synchronization transformation strategy

  • automates optimization
  • filter promotion + tupling + folding (local optimization inductively propagated)
  • force the generator to have the desired behavior
  • reduces don’t care nondeterminism (less failures)
  • guided by the inductive traversal of (a slice of) the data-structure

Related techniques : compiling control, co-routining

96 / 99

slide-97
SLIDE 97

Optimizing Test-case Generation

Experiments

Size RB Trees Time Original Synchronized Korat 6 20 0.47 7 35 0.01 0.63 8 64 0.02 1.49 9 122 0.08 4.51 10 260 0.29 0.01 21.14 11 586 1.07 0.03 116.17 12 1296 3.98 0.06

  • 13

2708 14.85 0.12

  • 14

5400 55.77 0.26

  • 15

10468

  • 0.55
  • . . .

. . . . . . . . . . . . 20 279264

  • 25.90
  • Size = number of nodes

Zero means less than 10 ms, and RB Trees = number of structures found (-) means more than 200 seconds Time = (in seconds) for generating all the structures

97 / 99

slide-98
SLIDE 98

Optimizing Test-case Generation

Summarizing

improved declarativeness heaparrays, disjoint sets, various lists/trees, . . . baseline good, room for optimization a language of composable/refinable generators automatic extraction of CLP generators from contracts (a form of program synthesis) graph-like structures

98 / 99

slide-99
SLIDE 99