Top Banner
Decision Procedures for Algebraic Data Types with Abstractions Philippe Suter, Mirco Dotta and Viktor Kuncak
55

Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Apr 03, 2018

Download

Documents

nguyennhu
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Decision Procedures for Algebraic Data Types with Abstractions

Philippe Suter, Mirco Dotta

and Viktor Kuncak

Page 2: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Verification of functional programs

proof

counterexample(input, trace)

Page 3: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

sealed abstract class Treecase class Node(left: Tree, value: Int, right: Tree) extends Treecase 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

Page 4: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Proving verification conditions

(tree = Node(l, v, r) ∧ v > element ∧ result ≠ Leaf())⇒ Node(result, v, r) ≠ Leaf()

D.C. Oppen, Reasoning about RecursivelyDefined Data Structures, POPL ’78

G. Nelson, D.C. Oppen, Simplification byCooperating Decision Procedure, TOPLAS ’79

Previous work gives decision procedures that can handle certain verification conditions

Page 5: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

sealed abstract class Treecase class Node(left: Tree, value: Int, right: Tree) extends Treecase 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)

}}

Page 6: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Complex verification condition

Set Expressions

Recursive FunctionAlgebraic Data Types

t1 = Node(t2, e1, t3)∧ content(t4) = content(t2) ∪ { e2 }∧ content(Node(t4, e1, t3)) ≠ content(t1) ∪ { e2 }

where def content(tree: Tree) : Set[Int] = tree match {case Leaf() ⇒∅case Node(l, v, r) ⇒ content(l) ∪ { v } ∪ content(r)

}

Page 7: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Our contribution

Decision procedures for extensions of algebraic data types with certain recursive functions

Page 8: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Formulas we aim to proveQuantifier-free Formula

Generalized Fold Function

where def content(tree: Tree) : Set[Int] = tree match {case Leaf() ⇒∅case Node(l, v, r) ⇒ content(l) ∪ { v } ∪ content(r)

}

t1 = Node(t2, e1, t3)∧ content(t4) = content(t2) ∪ { e2 }∧ content(Node(t4, e1, t3)) ≠ content(t1) ∪ { e2 }

Domain with a Decidable Theory

Page 9: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

def α(tree: Tree) : C = tree match {case Leaf() ⇒ emptycase Node(l, v, r) ⇒ combine(α(l), v, α(r))

}

General form of our recursive functions

def content(tree: Tree) : Set[Int] = tree match {case Leaf() ⇒∅case Node(l, v, r) ⇒ content(l) ∪ { v } ∪ content(r)

}

empty : Ccombine : (C, E, C) → C

Page 10: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Scope of our result - Examples

Tree content abstraction, as a:Set

Multiset

List

Tree size, height, min

Invariants (sortedness,…)

*Kuncak,Rinard’07+

*Piskac,Kuncak’08+

*Plandowski’04+

*Papadimitriou’81+

*Nelson,Oppen’79+

Page 11: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

How do we prove such formulas?Quantifier-free Formula

Generalized Fold Function

where def content(tree: Tree) : Set[Int] = tree match {case Leaf() ⇒∅case Node(l, v, r) ⇒ content(l) ∪ { v } ∪ content(r)

}

t1 = Node(t2, e1, t3)∧ content(t4) = content(t2) ∪ { e2 }∧ content(Node(t4, e1, t3)) ≠ content(t1) ∪ { e2 }

Domain with a Decidable Theory

Page 12: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Separate the Conjuncts

c1 = content(t1) ∧ … ∧ c5 = content(t5)

t1 = Node(t2, e1, t3) ∧ t5 = Node(t4, e1, t3) ∧

c4 = c2 ∪ { e2 } ∧ c5 ≠ c1 ∪ { e2 } ∧

t1 = Node(t2, e1, t3)∧ content(t4) = content(t2) ∪ { e2 }∧ content(Node(t4, e1, t3)) ≠ content(t1) ∪ { e2 }

Page 13: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

1

4

2 t2

t3

t1

1

7

0

t5

t4=4

2 t2

t3

t4

c2

c3

∪∪

4

2c4 =

c4 = { 4 } ∪ { 2 } ∪ ∅ ∪ c3 ∪ c2

content=

t1 7

0

t5

=

Page 14: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Overview of the decision procedure

c4 = c2 ∪ { e2 } ∧ c5 ≠ c1 ∪ { e2 }t1 = Node(t2, e1, t3)t5 = Node(t4, e1, t3) ∧

The resulting formula is in the decidable theory of sets

c1 = c2 ∪ { e1 } ∪ c3

c5 = c4 ∪ { e1 } ∪ c3∧

additional derived constraints

set constraints from the input formula

c4 = c2 ∪ { e2 }c5 ≠ c1 ∪ { e2 }c1 = c2 ∪ { e1 } ∪ c3

c5 = c4 ∪ { e1 } ∪ c3

∧∧∧

resulting formula

ci = content(ti), i ∈ , 1, …, 5 -

tree constraints from the input formula

mappings from the input formula

Decision Procedure for Sets

Page 15: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

What we have seen is a simple correct algorithm

But is it complete?

Page 16: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

A verifier based on such procedure

val c1 = content(t1) val c2 = content(t2)if (t1 ≠ t2) ,if (c1 == ∅) {

assert(c2 ≠ ∅)x = c2.chooseElement

}}

c1 = content(t1) ∧ c2 = content(t2) ∧ t1 ≠ t2 ∧ c1 = ∅ ∧ c2 = ∅

Warning: possible assertion violation

Page 17: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Source of incompleteness

c1 = ∅ ∧ c2 = ∅

Models for the formula in the logic of sets must not contradict the disequalities over trees

c1 = content(t1) ∧ c2 = content(t2) ∧ t1 ≠ t2 ∧ c1 = ∅ ∧ c2 = ∅

t1 ≠ t2

Page 18: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

How to make the algorithm complete

• Case analysis for each tree variable:

– is it Leaf ?

– Is it not Leaf ?

c1 = content(t1) ∧ c2 = content(t2) ∧ t1 ≠ t2 ∧ c1 = ∅ ∧ c2 = ∅

This gives a complete decision procedure for the content function that maps to sets

∧ t1 = Leaf ∧ t2 = Node(t3, e, t4)

∧ t1 = Leaf ∧ t2 = Leaf

∧ t1 = Node(t3, e1, t4) ∧ t2 = Node(t5, e2, t6)

∧ t1 Node(t3, e, t4) ∧ t2 = Leaf

Page 19: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

What about other content functions?

Tree content abstraction, as a:Set

Multiset

List

Tree size, height, min

Invariants (sortedness,…)

Page 20: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Sufficient Surjectivity

How and when we can havea complete algorithm

Page 21: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Decision Procedure for Sets

Choice of trees is constrained by sets

c4 = c2 ∪ { e2 } ∧ c5 ≠ c1 ∪ { e2 }t1 = Node(t2, e1, t3)t5 = Node(t4, e1, t3) ∧

c1 = c2 ∪ { e1 } ∪ c3

c5 = c4 ∪ { e1 } ∪ c3∧

c4 = c2 ∪ { e2 }c5 ≠ c1 ∪ { e2 }c1 = c2 ∪ { e1 } ∪ c3

c5 = c4 ∪ { e1 } ∪ c3

∧∧∧

additional derived constraints

set constraints from the input formula

resulting formula

ci = content(ti), i ∈ , 1, …, 5 -

tree constraints from the input formula

mappings from the input formula

Page 22: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Inverse images

• When we have a model for c1, c2, … how can we pick distinct values for t1, t2,… ?

α

α-1

The cardinality of α-1 (ci) is what matters.

ci = content(ti)ti ∈ content-1 (ci) ⇔

Page 23: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

‘Surjectivity’ of set abstraction

{ 1, 5 } 5

1

1

5

5

5 1

1

∅content-1

content-1

|content-1(∅)| = 1|content-1(,1, 5-)| = ∞

Page 24: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

In-order traversal

2

1 7

4

[ 1, 2, 4, 7 ]inorder-

Page 25: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

‘Surjectivity’ of in-order traversal

[ 1, 5 ] 5

1

1

5

[ ]inorder-1

inorder-1

|inorder-1(list)| =

(number of trees of size n = length(list))

Page 26: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

|inorder-1(list)|

length(list)

More trees map to longer lists

Page 27: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

An abstraction function α (e.g. content, inorder) issufficiently surjective if and only if, for eachnumber p > 0, there exist, computable as afunction of p:

such that, for every term t, Mp(α(t)) or š(t) in Sp.

a finite set of shapes Sp

a closed formula Mp in the collection theorysuch that Mp(c) implies |α-1(c)| > 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.

Page 28: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

For a conjunction of n disequalities over treeterms, if for each term we can pick a valuefrom a set of trees of size at least n+1, then wecan pick values that satisfy all disequalities.

We can make sure there will be sufficiently many trees to choose from.

Generalization of the Independence of Disequations Lemma

Page 29: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

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!

Page 30: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Related Work

G. Nelson, D.C. Oppen, Simplification byCooperating Decision Procedure, TOPLAS ’79

V. Sofronie-Stokkermans, Locality Results forCertain Extensions of Theories with BridgingFunctions, CADE ’09

Some implemented systems:ACL2, Isabelle, Coq, Verifun, Liquid Types

Page 31: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

• Reasoning about functional programsreduces to proving formulas

• Decision procedures always find a proof or acounterexample

• Previous decision procedures handlerecursion-free formulas

• We introduced decision procedures forformulas with recursive fold functions

Decision Procedures for Algebraic Data Types with Abstractions

Page 32: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Thank you !

Page 33: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Extra Slides

Page 34: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Decision procedure for data structure hierarchy

bag (multiset)

set

setof

mcontent

msize

7ssize

3

tree

Supports all natural operationson trees, multisets, sets, and homomorphisms between them

Page 35: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

When we are not complete

• When α-1 does not grow

• The only natural example we found so far: when there is no abstraction!

– Map trees into trees by mirroring them or

– Reversing the list

Page 36: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Sortedness

Page 37: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

End of extra slides

Stop clicking

Page 38: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

An abstraction function α is sufficiently surjectiveif and only if, for each number p > 0, there exist,computable as a function of p:

such that, for every term t, Mp(α(t)) or š(t) in Sp.

a finite set of shapes Sp

a closed formula Mp in the collection theorysuch that Mp(c) implies |α-1(c)| > p

--

5

3 2

3

š

Page 39: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

lim inf |α-1(α(t))| = ∞p→∞ š (t) ∉ Sp

An abstraction function α is sufficiently surjectiveif and only if, for each number p > 0, there exist,computable as a function of p:

such that, for every term t, Mp(α(t)) or š(t) in Sp.

a finite set of shapes Sp

a closed formula Mp in the collection theorysuch that Mp(c) implies |α-1(c)| > p

--

This definition implies:

Page 40: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

lim inf |α-1(α(t))| = ∞p→∞ š (t) ∉ Sp

Page 41: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

To copy-paste

1

Wc1W ∧ ∨ ∪ ≠ ⊢ ∈ ∉ ⇒ → α Wα-1W š ⇔∅ α

Page 42: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

1

4

2 t2

t3

t1

1

7

0

t5

t4=

t1 = 7

0

t5

4

2 t2

t3

t4 =

c1 =

c5

∪∅

∅∪7

0

c2

c3

∪∪

4

2c4 =

= { 0, 7 } ∪ c5

= { 2, 4 } ∪ c2 ∪ c3

content

content

Page 43: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Trees Trees Trees

Page 44: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Overview of the Decision Procedure

t1 = Node(t2, e1, t3) ∧ t5 = Node(t4, e1, t3)

∧ t1 ≠ t2 ∧ t1 ≠ t3 ∧ …∧ e1 = e2

ci = content(ti), i ∈ , 1, …, 5 -

t1 = Node(t2, e1, t3)t5 = Node(t4, e1, t3) ∧

unification

def content(tree: Tree) : Set[Int] = tree match {case Leaf() ⇒ ∅case Node(l, v, r) ⇒ content(l) ∪ { v } ∪ content(r)

}

= content(t1)c1

= content(t2) ∪ { e1 } ∪ content(t3)

= c2 ∪ { e1 } ∪ c3

= content(Node(t2, e1, t3))

Page 45: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Ghost Variables?

Page 46: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

object BST {def contains(tree: Tree, element: Int): Tree = tree match {case Leaf() => falsecase Node(l, v, r) if v > element => contains(l, element)case Node(l, v, r) if v < element => contains(r, element)case Node(l, v, r) if v == element => true

} ensuring (result <=> element ∈ tree.content)}

Requires stating and proving an invariant such as:

∀ (l : Leaf) .l.content = ∅∀ (n : Node) .n.content = n.left.content ∪ { n.element } ∪ n.right.content

Page 47: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

sealed abstract class Tree { val content: Set[Int] }case class Node(content: Set[Int], left: Tree, value: Int, right: Tree) extends Treecase class Leaf() extends Tree { val content = ∅ }

object BST {def add(tree: Tree, element: Int): Tree = tree match {case Leaf() => Node({ element }, Leaf(), element, Leaf())case Node(l, v, r) if v > element =>Node(tree.content ∪ { element }, add(l, element), v, r)

case Node(l, v, r) if v < element =>Node(tree.content ∪ { element }, l, v, add(r, element))

case Node(l, v, r) if v == element => tree} ensuring (result.content == tree.content ∪ { element })

}

Page 48: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

• Essentially duplicates the code

Page 49: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Our Approach: No Ghosts!

Page 50: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

• In a functional setting, specification variables are just another view on the same data

• Idea: provide the view explicitly, in the PL

Page 51: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with
Page 52: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Completeness

In general, we need a way to encode:

in the domain theory.

ti ≠ tj ∧ tk ≠ tl∧ …∧ ci = α(ti) ∧ cj = α(tj) ∧ …

Page 53: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Sufficient Surjectivity

- For each tree t in the formula, guess its shape in Sp, or write Mp(t)

- Populate the shapes with fresh variables

- Trees with different shapes are different by construction.

- For the other ones, create a disjunction of disequalitiesover their elements

f1

f2 f4

f3

Page 54: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Sufficient Surjectivity

- All the trees such that Mp(t) can be made distinct and still map to the same collection

Independence of Disequations Lemma:

For a conjunction of n disequalities of treeterms, if for each term we can pick a valuefrom a set of trees of size at least n, then wecan pick values that satisfy all disequalities.

Page 55: Decision Procedures for Algebraic Data Types with Abstractionsargo.matf.bg.ac.rs/events/2010/fatpa2010/slides/Suter_Decision... · Decision Procedures for Algebraic Data Types with

Sufficient Surjectivity

5

5 1

1

shape

š