constraint logic programming over infinite domains with an

27
Constraint Logic Programming over Infinite Domains with an Application to Proof Sebastian Krings and Michael Leuschel Institut f ¨ ur Informatik Heinrich-Heine-Universit ¨ at D ¨ usseldorf Germany

Upload: others

Post on 23-Apr-2022

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Constraint Logic Programming over Infinite Domains with an

Constraint Logic Programming over InfiniteDomains with an Application to Proof

Sebastian Krings and Michael Leuschel

Institut fur InformatikHeinrich-Heine-Universitat Dusseldorf

Germany

Page 2: Constraint Logic Programming over Infinite Domains with an

Background

• Model Checking• Data Validation• Proof and Disproof

2 / 24

Page 3: Constraint Logic Programming over Infinite Domains with an

B ExampleMACHINE BinarySearchCONSTANTS arr , sze , goalPROPERTIES

sze : NAT & a r r : 1 . . sze −−> INT &! ( i ) . ( i : 1 . . ( sze−1) => a r r ( i ) <= a r r ( i +1) ) &goal : INT &a r r = [−1 ,0 ,1 ,2 ,3 ,5] & goal : {5 ,4 ,2 ,6}

VARIABLES i , j , foundINVARIANT

found :BOOL & i :NAT & j :NAT &( found=TRUE => a r r ( i )= goal ) &

INITIALISATION found , i , j := FALSE,1 , szeOPERATIONS

Step = SELECT found=FALSE & i< j THEN. . .

3 / 24

Page 4: Constraint Logic Programming over Infinite Domains with an

PROB Kernel

• Based on SICStus Prolog• 150k LoC• + Extensions in Tcl/Tk, Java, C, . . .

• CLP(FD) + CHR• Custom solvers for high-level structures

• Sets, lists, tuples, records, . . .• Nested quantification• Comprehensions & lambdas

4 / 24

Page 5: Constraint Logic Programming over Infinite Domains with an

PROB Kernel

Formula ProB BooleanPredicate Solver

ProB IntegerSolver

SICStusCLP(FD)

ProB BaseSets Solver

ProB Pairs,Sets,

Relations, Records Solver

ProB Waitflags StoreEnumeration

ProBKernel

5 / 24

Page 6: Constraint Logic Programming over Infinite Domains with an

PROB Kernel

Formula ProB BooleanPredicate Solver

ProB IntegerSolver

SICStusCLP(FD)

ProB BaseSets Solver

ProB Pairs,Sets,

Relations, Records Solver

ProB Waitflags StoreEnumeration

ProBKernel

5 / 24

Page 7: Constraint Logic Programming over Infinite Domains with an

PROB Kernel

Formula ProB BooleanPredicate Solver

ProB IntegerSolver

SICStusCLP(FD)

ProB BaseSets Solver

ProB Pairs,Sets,

Relations, Records Solver

ProB Waitflags StoreEnumeration

ProBKernel

5 / 24

Page 8: Constraint Logic Programming over Infinite Domains with an

Techniques for Large or Infinite Domains

• Tracking of enumeration scopes• Randomized enumeration• High-level reasoning

6 / 24

Page 9: Constraint Logic Programming over Infinite Domains with an

Types of Enumeration

Distinguish based on effect on overall result:• No enumeration, result not influenced

• e.g., no valuation⇒ formula unsatisfiable

• Exhaustive enumeration• Non-exhaustive enumeration with or w/o result

• ⇒ consider scope

7 / 24

Page 10: Constraint Logic Programming over Infinite Domains with an

Nested Enumeration Scopes

∃x .(x ∈ [−10,10] ∧ ∀y .y ∈ [−15,5]⇒ y ≤ x)

existential scope

x can be enumerated exhaustively but is not

∀y .y ∈ [−15,5]⇒ y ≤ x

universal scope

y is enumerated exhaustively

y ≤ x

CLP(FD) constraint

8 / 24

Page 11: Constraint Logic Programming over Infinite Domains with an

Nested Enumeration Scopes

∃x .(¬∀y .y ∈ [−15,5]⇒ y ≤ x)

existential scope

non-exhaustively search for x

∀y .y ∈ [−15,5]⇒ y ≤ x

existential scope

y can be enumerated exhaustively but is not

y ≤ x

CLP(FD) constraint

9 / 24

Page 12: Constraint Logic Programming over Infinite Domains with an

Examples

• x*x=10000, solution found w/o enumeration• {x|x*x=10000}, (all) solutions found w/o enumeration• x>10000 & x mod 1234 = 1, solution found despite

enumeration• {x|x>10000 & x mod 1234 = 1} can thus not be

solved• x*x = 10001 unsat by CLP(FD) propagation w/o

enumeration• x>10000 & x mod 1234 = 1 & x*x = 10*x partial

enumeration, no result

10 / 24

Page 13: Constraint Logic Programming over Infinite Domains with an

Randomized Enumeration

• Try values of different size / characteristics• Less likely to get stuck in some part of the search space• Increase variance, e.g., for test case generation

11 / 24

Page 14: Constraint Logic Programming over Infinite Domains with an

Randomized Enumeration - Challenges

• Random permutation• ⇒ avoid duplicates

• Detect exhaustive traversal

12 / 24

Page 15: Constraint Logic Programming over Infinite Domains with an

Fisher-Yates / Knuth Shuffle!

Data: List aResult: Random permutation of aprocedure shuffle(a)

for i ∈ [0, length(a)− 1] dochose j randomly such that 0 ≤ j ≤ iif j 6= i then

perm[i] := perm[j]endperm[j] := a[i]

endreturn perm

13 / 24

Page 16: Constraint Logic Programming over Infinite Domains with an

Fisher-Yates / Knuth Shuffle :(

Data: List aResult: Random permutation of aprocedure shuffle(a)

for i ∈ [0, length(a)− 1] dochose j randomly such that 0 ≤ j ≤ iif j 6= i then

perm[i] := perm[j]endperm[j] := a[i]

endreturn perm

13 / 24

Page 17: Constraint Logic Programming over Infinite Domains with an

Randomized Enumeration - Solution

• Use techniques from cryptography!• “Encrypt” [l ,u]→ [l ,u]• Using random encryption key

• ⇒ random enumeration of [l ,u]• Unique encryption

• ⇒ no duplicates, random permutation

14 / 24

Page 18: Constraint Logic Programming over Infinite Domains with an

Feistel Network

Plaintext

Left

Right

Round / Hash

X

Round / Hash

X

Cyphertext

Right

Left

Round / Hash

X

Left

Right

15 / 24

Page 19: Constraint Logic Programming over Infinite Domains with an

High-Level Reasoning using CHR

• CLP(FD) weak without bounds• e.g. no unsat for X < Y ∧ Y < X• High-level reasoning:

• Infer falsity• Find new CLP(FD) constraints

16 / 24

Page 20: Constraint Logic Programming over Infinite Domains with an

CHR Rules (excerpt)

r e f l e x i v i t y @ leq (X,X) <=> t r ue .ant isymmetry @ leq (X,Y) , leq (Y,X) <=> X = Y.idempotence @ leq (X,Y) \ leq (X,Y) <=> t r ue .t r a n s i t i v i t y @ leq (X,Y) , leq (Y, Z ) ==> leq (X, Z ) .

a n t i r e f l e x i v i t y @ l t (X,X) <=> f a i l .idempotence @ l t (X,Y) \ l t (X ,Y) <=> t r ue .t r a n s i t i v i t y @ l t (X,Y) , leq (Y, Z ) ==> l t (X , Z ) .t r a n s i t i v i t y @ leq (X,Y) , l t (Y , Z ) ==> l t (X , Z ) .t r a n s i t i v i t y @ l t (X,Y) , l t (Y , Z ) ==> l t (X , Z ) .

17 / 24

Page 21: Constraint Logic Programming over Infinite Domains with an

Comparison

predicate with CHR without CHR

x > 3 1.2 1.08x > y ∧ y > x 0.92 timeoutx = 3 ∧ x > y ∧ y = 4 0.98 1.07x = 3 ∧ x > y 0.86 1.0x = 3 ∧ x < y 1.1 1.11w > x ∧ x > y ∧ y > z ∧ w = 1 ∧ z = 1 0.98 0.95w > x ∧ x > y ∧ y > z ∧ z > w 0.88 timeoutx + 2 > y + 1 ∧ y > x timeout timeoutx > y ∧ y > x + 1 0.9 timeout

18 / 24

Page 22: Constraint Logic Programming over Infinite Domains with an

Application - Proof

• Given Event-B sequent Hi(x1, . . . , xk ) |= G(x1, . . . , xk )

• Build ∃x1, . . . , xk : (H1(x1, . . . , xk ) ∧ . . . ∧ Hn(x1, . . . , xk ))⇒¬G(x1, . . . , xk )

• Search for counter-example• Exhaustive search⇒ proof

19 / 24

Page 23: Constraint Logic Programming over Infinite Domains with an

Results

192166

43

361

2581

631

2000

ML/PP (3300) SMT (3421)

ProB (5573)

20 / 24

Page 24: Constraint Logic Programming over Infinite Domains with an

Application - SMT Solving

• SMT-LIB standard fully supported• Translation from SMT-LIB to B• Competitive on integer arithmetic• Not competitive for bitvectors, arrays and sets

21 / 24

Page 25: Constraint Logic Programming over Infinite Domains with an

Results on Integer Arithmetic

7252

11

9070

Z3 (16322)ProB (9081)

22 / 24

Page 26: Constraint Logic Programming over Infinite Domains with an

SMT-COMP 2016 - NIA - Main Track

23 / 24

Page 27: Constraint Logic Programming over Infinite Domains with an

Thank you for your attention!Are there any questions left?

[email protected]

24 / 24