Satisfiability Modulo Computable Functions Philippe Suter, Ali Sinan Köksal, and Viktor Kuncak ÉCOLE POLYTECHNIQUE FÉDÉRALE DE LAUSANNE, SWITZERLAND Photo:

Slides:



Advertisements
Similar presentations
Assertion Checking over Combined Abstraction of Linear Arithmetic and Uninterpreted Functions Sumit Gulwani Microsoft Research, Redmond Ashish Tiwari SRI.
Advertisements

SMELS: Sat Modulo Equality with Lazy Superposition Christopher Lynch – Clarkson Duc-Khanh Tran - MPI.
The behavior of SAT solvers in model checking applications K. L. McMillan Cadence Berkeley Labs.
Exploiting SAT solvers in unbounded model checking
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Completeness and Expressiveness
ScalaZ3 Integrating SMT and Programming
1 Decision Procedures An algorithmic point of view Equality Logic and Uninterpreted Functions.
Synthesis, Analysis, and Verification Lecture 04c Lectures: Viktor Kuncak VC Generation for Programs with Data Structures “Beyond Integers”
Automated Verification with HIP and SLEEK Asankhaya Sharma.
Semantics Static semantics Dynamic semantics attribute grammars
Satisfiability Modulo Theories (An introduction)
SMT Solvers (an extension of SAT) Kenneth Roe. Slide thanks to C. Barrett & S. A. Seshia, ICCAD 2009 Tutorial 2 Boolean Satisfiability (SAT) ⋁ ⋀ ¬ ⋁ ⋀
Automatic Verification Book: Chapter 6. What is verification? Traditionally, verification means proof of correctness automatic: model checking deductive:
22C:19 Discrete Structures Induction and Recursion Fall 2014 Sukumar Ghosh.
Verification of Functional Programs in Scala Philippe Suter (joint work w/ Ali Sinan Köksal and Viktor Kuncak) ÉCOLE POLYTECHNIQUE FÉDÉRALE DE LAUSANNE,
Proofs from SAT Solvers Yeting Ge ACSys NYU Nov
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
© M. Winter COSC 4P41 – Functional Programming Testing vs Proving Testing –uses a set of “typical” examples, –symbolic testing, –may find errors,
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 13.
© The McGraw-Hill Companies, Inc., Chapter 8 The Theory of NP-Completeness.
Functional Design and Programming Lecture 11: Functional reasoning.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
Search in the semantic domain. Some definitions atomic formula: smallest formula possible (no sub- formulas) literal: atomic formula or negation of an.
Last time Proof-system search ( ` ) Interpretation search ( ² ) Quantifiers Equality Decision procedures Induction Cross-cutting aspectsMain search strategy.
Review: forward E { P } { P && E } TF { P && ! E } { P 1 } { P 2 } { P 1 || P 2 } x = E { P } { \exists … }
Program Verification using Templates over Predicate Abstraction Saurabh Srivastava University of Maryland, College Park Sumit Gulwani Microsoft Research,
Describing Syntax and Semantics
Ofer Strichman, Technion 1 Decision Procedures in First Order Logic Part II – Equality Logic and Uninterpreted Functions.
CS 267: Automated Verification Lecture 13: Bounded Model Checking Instructor: Tevfik Bultan.
272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 4: SMT-based Bounded Model Checking of Concurrent Software.
Induction and recursion
Equational Reasoning Math Foundations of Computer Science.
Deciding a Combination of Theories - Decision Procedure - Changki pswlab Combination of Theories Daniel Kroening, Ofer Strichman Presented by Changki.
The ACL2 Proof Assistant Formal Methods Jeremy Johnson.
1 Program Correctness CIS 375 Bruce R. Maxim UM-Dearborn.
SAT and SMT solvers Ayrat Khalimov (based on Georg Hofferek‘s slides) AKDV 2014.
1 Inference Rules and Proofs (Z); Program Specification and Verification Inference Rules and Proofs (Z); Program Specification and Verification.
CSI 3125, Axiomatic Semantics, page 1 Axiomatic semantics The assignment statement Statement composition The "if-then-else" statement The "while" statement.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
CS 363 Comparative Programming Languages Semantics.
Reading and Writing Mathematical Proofs Spring 2015 Lecture 4: Beyond Basic Induction.
Lazy Annotation for Program Testing and Verification Speaker: Chen-Hsuan Adonis Lin Advisor: Jie-Hong Roland Jiang November 26,
Chapter 5: Sequences, Mathematical Induction, and Recursion 5.5 Application: Correctness of Algorithms 1 [P]rogramming reliability – must be an activity.
Reasoning about programs March CSE 403, Winter 2011, Brun.
ARTIFICIAL INTELLIGENCE [INTELLIGENT AGENTS PARADIGM] Professor Janis Grundspenkis Riga Technical University Faculty of Computer Science and Information.
Chapter 3 Part II Describing Syntax and Semantics.
Semantics In Text: Chapter 3.
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
Verification & Validation By: Amir Masoud Gharehbaghi
Automated tactics for separation logic VeriML Reconstruct Z3 Proof Safe incremental type checker Certifying code transformation Proof carrying hardware.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
Daniel Kroening and Ofer Strichman Decision Procedures An Algorithmic Point of View Deciding Combined Theories.
Quantified Data Automata on Skinny Trees: an Abstract Domain for Lists Pranav Garg 1, P. Madhusudan 1 and Gennaro Parlato 2 1 University of Illinois at.
1/20 Arrays Changki PSWLAB Arrays Daniel Kroening and Ofer Strichman Decision Procedure.
Daniel Kroening and Ofer Strichman 1 Decision Procedures An Algorithmic Point of View Basic Concepts and Background.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
Formal Verification – Robust and Efficient Code Lecture 1
ML: a quasi-functional language with strong typing
Reasoning About Code.
Reasoning about code CSE 331 University of Washington.
Solving Linear Arithmetic with SAT-based MC
Relatively Complete Refinement Type System for Verification of Higher-Order Non-deterministic Programs Hiroshi Unno (University of Tsukuba) Yuki Satake.
Axiomatic semantics Points to discuss: The assignment statement
Semantics In Text: Chapter 3.
Predicate Transformers
Presentation transcript:

Satisfiability Modulo Computable Functions Philippe Suter, Ali Sinan Köksal, and Viktor Kuncak ÉCOLE POLYTECHNIQUE FÉDÉRALE DE LAUSANNE, SWITZERLAND Photo: Hisao Suzuki

~$./demo

This Project Building a verifier for Scala programs. The programming and specification languages are the same purely functional subset. def content(t: Tree) = t match { case Leaf ⇒ Set.empty case Node(l,v,r) ⇒ (content(l) ++ content(r)) + e } def insert(e:Int, t: Tree) = t match { case Leaf ⇒ Node(Leaf,e,Leaf) case Node(l,v,r) if e < v ⇒ Node(insert(e,l),v,r) case Node(l,v,r) if e > v ⇒ Node(l,v,insert(r)) case _ ⇒ t } ensuring( res ⇒ content(res) == content(t) + e)

t 1 = Node(t 2, e 1, t 3 ) ∧ e 1 > e 2 ∧ content(t 4 ) = content(t 2 ) ∪ { e 2 } ∧ content(Node(t 4, e 1, t 3 )) ≠ content(t 1 ) ∪ { e 2 } Tree ::= Leaf | Node(Tree, Int, Tree) content(Leaf) = ∅ content(Node( t 1, e, t 2 )) = content( t 1 ) ∪ { e } ∪ content( t 2 ) SMT + Computable Functions

Satisfiability Modulo Computable Functions …of quantifier-free formulas in a decidable base theory… …pure, total, deterministic, first- order and terminating on all inputs… Semi-decidable problem worthy of attention. What are general techniques for proving and disproving constraints? What are interesting decidable fragments?

Semi-decidable problem of great interest: – applications in verification, testing, theorem proving, constraint logic programming, … Our algorithm always finds counter-examples when they exist, and finds assume/guarantee style proofs. It is a decision procedure for infinitely and sufficiently surjective abstraction functions. Implemented as a part of a verification system for a purely functional subset of Scala. Satisfiability Modulo Computable Functions

Proving/Disproving Modulo Computable Functions

Proving with Inlining def size(lst: List) = lst match { case Nil ⇒ 0 case Cons(_, xs) ⇒ 1 + size(lst) } def sizeTR(lst: List, acc: Int) = lst match { case Nil ⇒ acc case Cons(_, xs) ⇒ sizeTR(xs, 1 + acc) } def size(lst: List) = if(lst = Nil) { 0 } else { 1 + size(lst.tail) } def sizeTR(lst: List, acc: Int) = if (lst = Nil) { acc } else { sizeTR(lst.tail, 1 + acc) } ensuring(res ⇒ res = size(lst) + acc) size(lst) = sizeTR(lst, 0) ensuring(res ⇒ res = size(lst) + acc)

Proving with Inlining def size(lst: List) = if(lst = Nil) { 0 } else { 1 + size(lst.tail) } def sizeTR(lst: List, acc: Int) = if (lst = Nil) { acc } else { sizeTR(lst.tail, 1 + acc) } ensuring(res ⇒ res = size(lst) + acc) ∀ lst, ∀ acc : (if(lst = Nil) acc else sizeTR(lst.tail, 1 + acc)) = size(lst) + acc ∃ lst, ∃ acc : (if(lst = Nil) acc else sizeTR(lst.tail, 1 + acc)) ≠ size(lst) + acc lst → Nil, acc → 0, size : { Nil → 1, _ → 0 }, sizeTR : { _ → 0 }

Proving with Inlining (if(lst = Nil) acc else sizeTR(lst.tail, 1 + acc)) ≠ size(lst) + acc lst → Nil, acc → 0, size : { Nil → 1, _ → 0 }, sizeTR : { _ → 0 } ∃ lst, ∃ acc : ∧ sizeTR(lst.tail, 1 + acc) = size(lst.tail) acc ∧ size(lst) = if(lst = Nil) 0 else 1 + size(lst.tail) lst → Cons(0, Nil), acc → 1, size : { _ → 0 }, sizeTR : { _ → 0 } ⇒ Unsatisfiable.

Disproving with Inlining def size(lst: List) = lst match { case Nil ⇒ 1 case Cons(_, Nil) ⇒ 1 case Cons(_, xs) ⇒ 1 + size(lst) } def sizeTR(lst: List, acc: Int) = lst match { case Nil ⇒ acc case Cons(_, xs) ⇒ sizeTR(xs, 1 + acc) } def size(lst: List) = if(lst = Nil) { 1 } else if(lst.tail = Nil) { 1 } else { 1 + size(lst.tail) } def sizeTR(lst: List, acc: Int) = if (lst = Nil) { acc } else { sizeTR(lst.tail, 1 + acc) } size(lst) = sizeTR(lst, 0)

Disproving with Inlining def size(lst: List) = if(lst = Nil) { 1 } else if(lst.tail = Nil) { 1 } else { 1 + size(lst.tail) } def sizeTR(lst: List, acc: Int) = if (lst = Nil) { acc } else { sizeTR(lst.tail, 1 + acc) } ∀ lst, ∀ acc : (if(lst = Nil) acc else sizeTR(lst.tail, 1 + acc)) = size(lst) + acc ∃ lst, ∃ acc : (if(lst = Nil) acc else sizeTR(lst.tail, 1 + acc)) ≠ size(lst) + acc lst → Cons(0, Nil), acc → 0, size : { _ → 1 }, sizeTR : { _ → 0 }

Disproving with Inlining (if(lst = Nil) 0 else sizeTR(lst.tail, 1 + acc)) ≠ size(lst) + acc ∃ lst, ∃ acc : ∧ size(lst) = if(lst = Nil ∨ lst.tail = Nil) 1 else 1 + size(lst.tail) lst → [ 0, 1 ], acc → 0, sizeTR : { _ → 0 } size : { [ 0 ] → 1, [ 0, 1 ] → 2, _ → 0 } lst → [ 0, 1 ], acc → 0, sizeTR : { _ → 0 } size : { [ 0 ] → 1, [ 0, 1 ] → 2, _ → 0 } ∧ sizeTR(lst.tail, 1 + acc) = if (lst.tail = Nil) 1 + acc else sizeTR(lst.tail.tail, 2 + acc) ∧ size(lst.tail) = if(lst.tail = Nil ∨ lst.tail.tail = Nil) 1 else 1 + size(lst.tail.tail) ∧ sizeTR(lst.tail.tail, 2 + acc) = if (lst.tail.tail = Nil) 2 + acc else sizeTR(lst.tail.tail.tail, 3 + acc) lst → [ 0, 1, 2 ], acc → 0, sizeTR : { _ → 0 }, size : { [ 0 ] → 1, [ 0, 1 ] → 2, [ 0, 1, 2 ] → 3, _ → 0 } lst → [ 0, 1, 2 ], acc → 0, sizeTR : { _ → 0 }, size : { [ 0 ] → 1, [ 0, 1 ] → 2, [ 0, 1, 2 ] → 3, _ → 0 } …

Disproving with Inlining size(lst)sizeTR(lst, aux) ?? There are always unknown branches in the evaluation tree. We can never be sure that there exists no smaller solution. ? ? ? ?

Branch Rewriting size(lst) = if(lst = Nil) { 1 } else if(lst.tail = Nil) { 1 } else { 1 + size(lst.tail) } size(lst) = ite 1 ∧ p 1 ⇔ lst = Nil ∧ p 1 ⇒ ite 1 = 1 ∧ ¬p 1 ⇒ ite 1 = ite 2 ∧ p 2 ⇔ lst.tail = Nil ∧ p 2 ⇒ ite 2 = 1 ∧ ¬p 2 ⇒ ite 2 = 1 + size(lst.tail) size(lst) p1p1 p 1 ∧ p 2 p 1 ∧ ¬p 2 … ∧ p 2

Algorithm ( φ, B) = unroll( φ, _ ) while(true) { solve( φ ∧ B) match { case “SAT” ⇒ return “SAT” case “UNSAT” ⇒ solve( φ ) match { case “UNSAT” ⇒ return “UNSAT” case “SAT” ⇒ ( φ, B) = unroll( φ, B) } Inlines some postconditions and bodies of function applications that were guarded by a literal in B, returns the new formula and new set of guards B. “I’m feeling lucky” Some literals in B may be implied by φ : no need to unroll what they guard. Inlining must be fair

Assumptions & Guarantees 1)All functions terminate on all inputs. 2)All functions satisfy their postconditions. 3)All function invocations satisfy the precondition. 4)All match expressions are exhaustive. 5)The SMT solver is sound and complete. (We currently prove 2) – 4).)

() Pattern-Matching Exhaustiveness We generate a formula that expresses that no case matches, and prove it unsatisfiable. def zip(l1: List, l2: List) : PairList = { require(size(l1) == size(l2)) l1 match { case Nil() ⇒ PNil() case Cons(x, xs) ⇒ l2 match { case Cons(y, ys) ⇒ PCons(P(x, y), zip(xs, ys)) } size(l1) == size(l2) ∧ l1 ≠ Nil ∧ l2 == Nil Unsatisfiable.

Properties of the Algorithm

1)The algorithm terminates when there exists an assume/guarantee style inductive proofs. 2)The algorithm terminates when the formula admits a counter-example. 3)The algorithm is a decision procedure for sufficiently surjective abstraction functions. Three Facts

Inductive Proofs If there exists a proof in assume/guarantee style, it will be found by sufficient inlining of the postconditions. Also succeeds when the property becomes inductive only after a certain number of iterations (à la k-induction).

Counter-examples Let a 1,… a n be the free variables of φ, and c 1,…,c n be a counter-example to φ. Let T be the evaluation tree of φ [a 1 →c 1, …, a n →c n ]. Eventually, the algorithm will reach a point where T is covered. ? ? ? ? T :

Sufficiently Surjective Abstractions The algorithm terminates, and is thus a decision procedure for the case of infinitely and sufficiently surjective abstraction functions. P.Suter, M.Dotta, V.Kuncak, Decision Procedures for Algebraic Data Types with Abstractions, POPL 2010 [] def α(tree: Tree) : C = tree match { case Leaf() ⇒ empty case Node(l, v, r) ⇒ combine(α(l), v, α(r)) }

{ 1, 5 } … ∅ content If one tree is mapped by α into an element, then many trees are mapped to the same one. « » There are only finitely many trees for which this does not hold. « »

def content(tree: Tree) : Set[Int] = tree match { case Leaf() ⇒ Set.empty case Node(l, v, r) ⇒ content(l) ++ content(r) ++ Set(v) } def allEven(list: List) : Boolean = list match { case Nil() ⇒ true case Cons(x, xs) ⇒ (x % 2 == 0) && allEven(list) } def max(tree: Tree) : Option[Int]= tree match { case Leaf() ⇒ None case Node(l, v, r) ⇒ Some(max(l), max(r)) match { case (None,None) ⇒ Some(v) case (Some(lm),None) ⇒ max(lm,v) case (None,Some(rm)) ⇒ max(rm,v) case (Some(lm),Some(rm)) ⇒ (max(lm,rm),v) })} …and any catamorphism that maps to a finite domain!

» « In the context of a project to reason about a domain specific language called Guardol for XML message processing applications […the] procedure has allowed us to prove a number of interesting things […], so I'm extremely grateful for it. Mike Whalen (Rockwell Collins & University of Minnesota)

Verification System. Photo: Hisao Suzuki

“The System” compiler.scala -prunes out -rewrites functions -generate VCs -solve VCs -(generate testcases) final report

“The System” Proves that all match expressions are exhaustive. Proves that the preconditions imply the postconditions. Proves that all function invocations satisfy the preconditions. Can generate testcases that satisfy some precondition.

Some Experimental Results BenchmarkLoC#Funs.#VCs.Time (s) ListOperations AssociativeList InsertionSort RedBlackTrees PropositionalLogic Functional correctness properties of data structures: red black trees implement a set and maintain height invariants, associative list has read-over-write property, insertion sort returns a sorted list of identical content, etc. Properties of propositional logic transformations: nnf and removing implications are stable, applying a (wrong) simplification to an nnf formula does not keep it in nnf, etc.

Limitations & Future work System features – Termination proofs. – Generic types. – Support for more Scala constructs (tuples, etc.). Proof system – Currently, supports only a limited form of induction on arguments – Folding is limited to functions present in the formula.

Related Work SMT Solvers + axioms – can be very efficient for well-formed axioms – in general, no guarantee than instantiations are fair – cannot in general conclude satisfiability (changing…) Interactive verification systems (ACL2, Isabelle, Coq) – very good at building inductive proofs – could benefit greatly from counter-example generation (as feedback to the user but also to prune out branches in the search) Sinha’s Inertial Refinement technique – similar use of “blocked paths” – no guarantee to find counter-examples

Related Work cont’d DSolve (Liquid Types) – because the proofs are based on type inference rules, cannot immediately be used to prove assertions relating different functions Bounded Model Checking – offer similar guarantees on the discovery of counter-examples – applied to the verification of temporal properties – reduces to SAT rather than SMT Finite Model Finding (Alloy, Paradox) – lack of theory reasoning, no proofs

Semi-decidable problem of great interest: – applications in verification, testing, theorem proving, constraint logic programming, … Our algorithm always finds counter-examples when they exist, and finds assume/guarantee style proofs. It is a decision procedure for infinitely and sufficiently surjective abstraction functions. Implemented as a part of a verification system for a purely functional subset of Scala. Satisfiability Modulo Computable Functions

Thank you. Photo: Hisao Suzuki