decision procedures for algebraic data types with
play

Decision Procedures for Algebraic Data Types with Abstractions - PowerPoint PPT Presentation

Decision Procedures for Algebraic Data Types with Abstractions Philippe Suter, Mirco Dotta and Viktor Kuncak Verification of functional programs proof counterexample (input, trace) sealed abstract class Tree case class Node(left: Tree, value:


  1. Decision Procedures for Algebraic Data Types with Abstractions Philippe Suter, Mirco Dotta and Viktor Kuncak

  2. Verification of functional programs proof counterexample (input, trace)

  3. sealed abstract class Tree case class Node(left: Tree, value: Int, right: Tree) extends Tree case class Leaf() extends Tree object BST { def add(tree: Tree, element: Int): Tree = tree match { case Leaf() ⇒ Node(Leaf(), element, Leaf()) case Node(l, v, r) if v > element ⇒ Node(add(l, element), v, r) case Node(l, v, r) if v < element ⇒ Node(l, v, add(r, element)) case Node(l, v, r) if v == element ⇒ tree } ensuring ( result ≠ Leaf()) } (tree = Node(l, v, r) ∧ v > element ∧ result ≠ Leaf()) ⇒ Node(result, v, r) ≠ Leaf() We know how to generate verification conditions for functional programs

  4. Proving verification conditions (tree = Node(l, v, r) ∧ v > element ∧ result ≠ Leaf()) ⇒ Node(result, v, r) ≠ Leaf() D.C. Oppen, Reasoning about Recursively Defined Data Structures , POPL ’ 78 G. Nelson, D.C. Oppen, Simplification by Cooperating Decision Procedure , TOPLAS ’ 79 Previous work gives decision procedures that can handle certain verification conditions

  5. sealed abstract class Tree case class Node(left: Tree, value: Int, right: Tree) extends Tree case class Leaf() extends Tree object BST { def add(tree: Tree, element: Int): Tree = tree match { case Leaf() ⇒ Node(Leaf(), element, Leaf()) case Node(l, v, r) if v > element ⇒ Node(add(l, element), v, r) case Node(l, v, r) if v < element ⇒ Node(l, v, add(r, element)) case Node(l, v, r) if v == element ⇒ tree } ensuring (content( result ) == content(tree) ∪ { element }) def content(tree: Tree) : Set[Int] = tree match { case Leaf() ⇒ ∅ case Node(l, v, r) ⇒ content(l) ∪ { v } ∪ content(r) } }

  6. Complex verification condition Set Expressions t 1 = Node(t 2 , e 1 , t 3 ) ∧ content(t 4 ) = content(t 2 ) ∪ { e 2 } ∧ content(Node(t 4 , e 1 , t 3 )) ≠ content(t 1 ) ∪ { e 2 } where def content(tree: Tree) : Set[Int] = tree match { case Leaf() ⇒ ∅ case Node(l, v, r) ⇒ content(l) ∪ { v } ∪ content(r) } Recursive Function Algebraic Data Types

  7. Our contribution Decision procedures for extensions of algebraic data types with certain recursive functions

  8. Formulas we aim to prove Quantifier-free Formula t 1 = Node(t 2 , e 1 , t 3 ) ∧ content(t 4 ) = content(t 2 ) ∪ { e 2 } ∧ content(Node(t 4 , e 1 , t 3 )) ≠ content(t 1 ) ∪ { e 2 } where def content(tree: Tree) : Set[Int] = tree match { case Leaf() ⇒ ∅ case Node(l, v, r) ⇒ content(l) ∪ { v } ∪ content(r) } Generalized Fold Function Domain with a Decidable Theory

  9. General form of our recursive functions empty : C combine : ( C , E , C) → C def content(tree: Tree) : Set[Int] = tree match { def α (tree: Tree) : C = tree match { case Leaf() ⇒ ∅ case Leaf() ⇒ empty case Node(l, v, r) ⇒ content(l) ∪ { v } ∪ content(r) case Node(l, v, r) ⇒ combine ( α (l), v, α (r)) } }

  10. Scope of our result - Examples Tree content abstraction, as a: Set *Kuncak,Rinard’07+ Multiset *Piskac,Kuncak’08+ List *Plandowski’04+ Tree size, height, min *Papadimitriou’81+ Invariants (sortedness ,…) *Nelson,Oppen’79+

  11. How do we prove such formulas? Quantifier-free Formula t 1 = Node(t 2 , e 1 , t 3 ) ∧ content(t 4 ) = content(t 2 ) ∪ { e 2 } ∧ content(Node(t 4 , e 1 , t 3 )) ≠ content(t 1 ) ∪ { e 2 } where def content(tree: Tree) : Set[Int] = tree match { case Leaf() ⇒ ∅ case Node(l, v, r) ⇒ content(l) ∪ { v } ∪ content(r) } Generalized Fold Function Domain with a Decidable Theory

  12. Separate the Conjuncts t 1 = Node(t 2 , e 1 , t 3 ) ∧ content(t 4 ) = content(t 2 ) ∪ { e 2 } ∧ content(Node(t 4 , e 1 , t 3 )) ≠ content(t 1 ) ∪ { e 2 } t 1 = Node(t 2 , e 1 , t 3 ) ∧ t 5 = Node(t 4 , e 1 , t 3 ) ∧ c 4 = c 2 ∪ { e 2 } ∧ c 5 ≠ c 1 ∪ { e 2 } ∧ c 1 = content(t 1 ) ∧ … ∧ c 5 = content(t 5 )

  13. 1 1 t 1 t 1 t 4 t 4 7 7 4 4 = t 2 t 2 0 0 2 2 t 3 t 3 t 5 t 5 ∪ 4 content = c 4 = ∪ c 2 2 ∅ c 3 = c 4 = { 4 } ∪ { 2 } ∪ ∅ ∪ c 3 ∪ c 2

  14. Overview of the decision procedure tree constraints from the input formula set constraints from the input formula c 4 = c 2 ∪ { e 2 } ∧ c 5 ≠ c 1 ∪ { e 2 } t 1 = Node(t 2 , e 1 , t 3 ) ∧ t 5 = Node(t 4 , e 1 , t 3 ) mappings from the input formula c i = content(t i ), i ∈ , 1, …, 5 - c 4 = c 2 ∪ { e 2 } c 5 ≠ c 1 ∪ { e 2 } ∧ c 1 = c 2 ∪ { e 1 } ∪ c 3 c 1 = c 2 ∪ { e 1 } ∪ c 3 ∧ ∧ c 5 = c 4 ∪ { e 1 } ∪ c 3 c 5 = c 4 ∪ { e 1 } ∪ c 3 ∧ resulting formula additional derived constraints The resulting formula is in the Decision decidable theory of sets Procedure for Sets

  15. What we have seen is a simple correct algorithm But is it complete?

  16. A verifier based on such procedure val c1 = content(t1) val c2 = content(t2) if (t1 ≠ t2) , if (c1 == ∅ ) { assert (c2 ≠ ∅ ) x = c2.chooseElement } } Warning : possible assertion violation c 1 = content(t 1 ) ∧ c 2 = content(t 2 ) ∧ t 1 ≠ t 2 ∧ c 1 = ∅ ∧ c 2 = ∅

  17. Source of incompleteness c 1 = content(t 1 ) ∧ c 2 = content(t 2 ) ∧ t 1 ≠ t 2 ∧ c 1 = ∅ ∧ c 2 = ∅ t 1 ≠ t 2 … ∅ c 1 = ∅ ∧ c 2 = ∅ Models for the formula in the logic of sets must not contradict the disequalities over trees

  18. How to make the algorithm complete • Case analysis for each tree variable: – is it Leaf ? – Is it not Leaf ? c 1 = content(t 1 ) ∧ c 2 = content(t 2 ) ∧ t 1 ≠ t 2 ∧ c 1 = ∅ ∧ c 2 = ∅ ∧ t 1 = Leaf ∧ t 2 = Node(t 3 , e, t 4 ) ∧ t 1 = Leaf ∧ t 2 = Leaf ∧ t 1 = Node(t 3 , e 1 , t 4 ) ∧ t 2 = Node(t 5 , e 2 , t 6 ) ∧ t 1 Node(t 3 , e, t 4 ) ∧ t 2 = Leaf This gives a complete decision procedure for the content function that maps to sets

  19. What about other content functions? Tree content abstraction, as a: Set Multiset List Tree size, height, min Invariants (sortedness ,…)

  20. Sufficient Surjectivity How and when we can have a complete algorithm

  21. Choice of trees is constrained by sets tree constraints from the input formula set constraints from the input formula c 4 = c 2 ∪ { e 2 } ∧ c 5 ≠ c 1 ∪ { e 2 } t 1 = Node(t 2 , e 1 , t 3 ) ∧ t 5 = Node(t 4 , e 1 , t 3 ) mappings from the input formula c i = content(t i ), i ∈ , 1, …, 5 - c 4 = c 2 ∪ { e 2 } c 5 ≠ c 1 ∪ { e 2 } ∧ c 1 = c 2 ∪ { e 1 } ∪ c 3 c 1 = c 2 ∪ { e 1 } ∪ c 3 ∧ ∧ c 5 = c 4 ∪ { e 1 } ∪ c 3 c 5 = c 4 ∪ { e 1 } ∪ c 3 ∧ resulting formula additional derived constraints Decision Procedure for Sets

  22. Inverse images • When we have a model for c 1 , c 2 , … how can we pick distinct values for t 1 , t 2 ,… ? t i ∈ content -1 (c i ) ⇔ c i = content(t i ) α α -1 The cardinality of α -1 (c i ) is what matters.

  23. ‘ Surjectivity ’ of set abstraction content -1 ∅ content -1 { 1, 5 } 5 5 5 1 … 1 1 1 5 |content -1 ( ∅ )| = 1 |content -1 (,1, 5-)| = ∞

  24. In-order traversal 2 inorder - 1 [ 1, 2, 4, 7 ] 7 4

  25. ‘ Surjectivity ’ of in -order traversal inorder -1 [ ] 1 inorder -1 5 [ 1, 5 ] 5 1 |inorder -1 ( list )| = (number of trees of size n = length( list ))

  26. More trees map to longer lists |inorder -1 ( list )| … … length( list )

  27. An abstraction function α (e.g. content, inorder) is sufficiently surjective if and only if, for each number p > 0 , there exist, computable as a function of p : - a finite set of shapes S p - a closed formula M p in the collection theory such that M p (c) implies | α -1 (c)| > p such that, for every term t, M p ( α (t)) or š(t) in S p . Pick p sufficiently large. Guess which trees have a problematic shape. Guess their shape and their elements. By construction values for all other trees can be found.

  28. Generalization of the Independence of Disequations Lemma For a conjunction of n disequalities over tree terms, if for each term we can pick a value from a set of trees of size at least n+1 , then we can pick values that satisfy all disequalities. We can make sure there will be sufficiently many trees to choose from.

  29. Sufficiently surjectivity holds in practice Theorem: For every sufficiently surjective abstraction our procedure is complete. Theorem: The following abstractions are sufficiently surjective: set content, multiset content, list (any-order), tree height, tree size, minimum, sortedness A complete decision procedure for all these cases!

  30. Related Work G. Nelson, D.C. Oppen, Simplification by Cooperating Decision Procedure , TOPLAS ’ 79 V. Sofronie-Stokkermans, Locality Results for Certain Extensions of Theories with Bridging Functions , CADE ’ 09 Some implemented systems: ACL2, Isabelle, Coq, Verifun, Liquid Types

  31. Decision Procedures for Algebraic Data Types with Abstractions • Reasoning about functional programs reduces to proving formulas • Decision procedures always find a proof or a counterexample • Previous decision procedures handle recursion-free formulas • We introduced decision procedures for formulas with recursive fold functions

  32. Thank you !

  33. Extra Slides

  34. Decision procedure for data structure hierarchy tree bag (multiset) mcontent setof msize set 7 ssize 3 Supports all natural operations on trees, multisets, sets, and homomorphisms between them

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend