decision procedures
play

Decision Procedures An Algorithmic Point of View Revision 1.0 - PowerPoint PPT Presentation

Arrays Chapter 7 Decision Procedures An Algorithmic Point of View Revision 1.0 D.Kroening O.Strichman Outline 1 Introduction Definition Basic Operations Syntax Semantics Example 2 Arrays as Uninterpreted Functions 3 A Reduction Algorithm


  1. Arrays Chapter 7 Decision Procedures An Algorithmic Point of View Revision 1.0 D.Kroening O.Strichman

  2. Outline 1 Introduction Definition Basic Operations Syntax Semantics Example 2 Arrays as Uninterpreted Functions 3 A Reduction Algorithm for Array Logic Array Properties A Reduction Algorithm Decision Procedures – Arrays 2

  3. Motivation Arrays are an important data structure: “Native” implementation in most processor architectures Offered by most programming languages O (1) index operation E.g., all data structures in Minisat are based on arrays Hardware: memories Decision Procedures – Arrays 3

  4. Formalization Mapping from an index type to an element type T I : index type T E : element type T A = ( T I − → T E ) : array type Assumption: there are relations = I ⊆ ( T I × T I ) and = E ⊆ ( T E × T E ) The subscript is omitted if the type of the operands is clear. The theories used to reason about the indices and the elements are called index theory and element theory , respectively. Decision Procedures – Arrays 4

  5. Basic Operations Let a ∈ T A denote an array. There are two basic operations on arrays: 1 Reading : a [ i ] is the value of the element that has index i 2 Writing : the array a where element i has been replaced by e is denoted by a { i ← − e } Decision Procedures – Arrays 5

  6. More About the Index Theory What theory is suitable for the indices? Index logic should permit existential and universal quantification: “ there exists an array element that is zero ” “ all elements of the array are greater than zero ” Example: Presburger arithmetic , i.e., linear arithmetic over integers with quantification Decision Procedures – Arrays 6

  7. More About the Index Theory What theory is suitable for the indices? Index logic should permit existential and universal quantification: “ there exists an array element that is zero ” “ all elements of the array are greater than zero ” Example: Presburger arithmetic , i.e., linear arithmetic over integers with quantification n -dimensional arrays: For n ≥ 2 , add T A ( n − 1) to the element type of T A ( n ) . Decision Procedures – Arrays 6

  8. A Very General Definition of Array Logic Syntax defined by extending the syntactic rules for the index logic and the element logic atom I : atom in the index logic atom E : atom in the element logic term I : term in the index logic term E : term in the element logic Decision Procedures – Arrays 7

  9. Syntax : atom I | atom E | ¬ atom | atom ∧ atom | atom ∀ array-identifier . atom : array-identifier | term A { term I ← − term E } term A term E : term A [ term I ] Equality between arrays a 1 and a 2 : write as ∀ i. a 1 [ i ] = a 2 [ i ] Decision Procedures – Arrays 8

  10. Semantics Main axiom: Axiom (Read-over-write Axiom) ∀ a ∈ T A . ∀ e ∈ T E . ∀ i, j ∈ T I . � e : i = j a { i ← − e } [ j ] = a [ j ] : otherwise . Decision Procedures – Arrays 9

  11. Program Verification Example I 1 a: array 0..99 of integer ; 2 i: integer ; 3 4 for i:=0 to 99 do 5 /* ∀ x ∈ N 0 . x < i − → a [ x ] = 0 */ 6 a[i]:=0; 7 /* ∀ x ∈ N 0 . x ≤ i − → a [ x ] = 0 */ 8 done ; 9 /* ∀ x ∈ N 0 . x ≤ 99 − → a [ x ] = 0 */ Decision Procedures – Arrays 10

  12. Program Verification Example II Main step of the correctness argument: invariant in line 7 is maintained by the assignment in line 6 Verification condition: ( ∀ x ∈ N 0 . x < i − → a [ x ] = 0) a ′ = a { i ← ∧ − 0 } → a ′ [ x ] = 0) − → ( ∀ x ∈ N 0 . x ≤ i − Decision Procedures – Arrays 11

  13. Decidability Q: Is this logic decidable? Decision Procedures – Arrays 12

  14. Decidability Q: Is this logic decidable? A: No, even if the combination of the index logic and the element logic is decidable Decision Procedures – Arrays 12

  15. Arrays as Uninterpreted Functions Fragment: no quantification over arrays Decision Procedures – Arrays 13

  16. Arrays as Uninterpreted Functions Fragment: no quantification over arrays Arrays are functions! (From indices to elements) Decision Procedures – Arrays 13

  17. Arrays as Uninterpreted Functions Fragment: no quantification over arrays Arrays are functions! (From indices to elements) Idea: use procedures for uninterpreted functions! Decision Procedures – Arrays 13

  18. Example ( i = j ∧ a [ j ] = ’z’ ) − → a [ i ] = ’z’ ’z’ : read as an integer number Decision Procedures – Arrays 14

  19. Example ( i = j ∧ a [ j ] = ’z’ ) − → a [ i ] = ’z’ ’z’ : read as an integer number F a : uninterpreted function introduced for the array a : ( i = j ∧ F a ( j ) = ’z’ ) − → F a ( i ) = ’z’ Decision Procedures – Arrays 14

  20. Example ( i = j ∧ F a ( j ) = ’z’ ) − → F a ( i ) = ’z’ Apply Bryant’s reduction: ( i = j ∧ F ∗ → F ∗ 1 = ’z’ ) − 2 = ’z’ where � f 1 : i = j F ∗ F ∗ 1 = f 1 and 2 = f 2 : otherwise Prove this using a decision procedure for equality logic. Decision Procedures – Arrays 15

  21. Array Updates What about a { i ← − e } ? Decision Procedures – Arrays 16

  22. Array Updates What about a { i ← − e } ? − e } by a fresh variable a ′ of array type 1 Replace a { i ← 2 Add two constraints: a) a ′ [ i ] = e for the value that is written, b) ∀ j � = i. a ′ [ j ] = a [ j ] for the values that are unchanged. Compare to the read-over-write axiom! This is called the write rule . Decision Procedures – Arrays 16

  23. Array Updates: Example I Transform a { i ← − e } [ i ] ≥ e into: a ′ [ i ] = e − → a ′ [ i ] ≥ e Decision Procedures – Arrays 17

  24. Array Updates: Example II Transform a [0] = 10 − → a { 1 ← − 20 } [0] = 10 into: ( a [0] = 10 ∧ a ′ [1] = 20 ∧ ( ∀ j � = 1 . a ′ [ j ] = a [ j ])) − → a ′ [0] = 10 Decision Procedures – Arrays 18

  25. Array Updates: Example II Transform a [0] = 10 − → a { 1 ← − 20 } [0] = 10 into: ( a [0] = 10 ∧ a ′ [1] = 20 ∧ ( ∀ j � = 1 . a ′ [ j ] = a [ j ])) − → a ′ [0] = 10 and then replace a , a ′ : ( F a (0) = 10 ∧ F a ′ (1) = 20 ∧ ( ∀ j � = 1 . F a ′ ( j ) = F a ( j ))) − → F a ′ (0) = 10 Decision Procedures – Arrays 18

  26. Array Updates: Example II Transform a [0] = 10 − → a { 1 ← − 20 } [0] = 10 into: ( a [0] = 10 ∧ a ′ [1] = 20 ∧ ( ∀ j � = 1 . a ′ [ j ] = a [ j ])) − → a ′ [0] = 10 and then replace a , a ′ : ( F a (0) = 10 ∧ F a ′ (1) = 20 ∧ ( ∀ j � = 1 . F a ′ ( j ) = F a ( j ))) − → F a ′ (0) = 10 Q: Is this decidable in general? Say Presburger plus uninterpreted functions? Decision Procedures – Arrays 18

  27. Array Properties Now: restricted class of array logic formulas in order to obtain decidability. We consider formulas that are Boolean combinations of array properties . Definition (array property) A formula is an array property iff if it is of the form ∀ i 1 , . . . , i k ∈ T I . φ I ( i 1 , . . . , i k ) − → φ V ( i 1 , . . . , i k ) , and satisfies the following conditions: 1 The predicate φ I must be an index guard . 2 The index variables i 1 , . . . , i k can only be used in array read expressions of the form a [ i j ] . The predicate φ V is called the value constraint . Decision Procedures – Arrays 19

  28. Index Guards Definition (Index Guard) A formula is an index guard iff if follows the grammar iguard : iguard ∧ iguard | iguard ∨ iguard | iterm ≤ iterm | iterm = iterm iterm : i 1 | . . . | i k | term term : integer-constant | integer-constant · index-identifier | term + term The “ index-identifier ” used in “ term ” must not be one of i 1 , . . . , i k . Decision Procedures – Arrays 20

  29. Array Properties: Example The extensionality rule defines the equality of two arrays a 1 and a 2 as element-wise equality. Extensionality is an array property: ∀ i. a 1 [ i ] = a 2 [ i ] Decision Procedures – Arrays 21

  30. Array Properties: Example The extensionality rule defines the equality of two arrays a 1 and a 2 as element-wise equality. Extensionality is an array property: ∀ i. a 1 [ i ] = a 2 [ i ] How about the array update? a ′ = a { i ← − 0 } Is this an array property as well? Decision Procedures – Arrays 21

  31. Array Properties: Array Update An array update expression can be replaced by adding two constraints: a ′ [ i ] = 0 ∀ j � = i. a ′ [ j ] = a [ j ] ∧ The first conjunct is obviously an array property. Decision Procedures – Arrays 22

  32. Array Properties: Array Update An array update expression can be replaced by adding two constraints: a ′ [ i ] = 0 ∀ j � = i. a ′ [ j ] = a [ j ] ∧ The first conjunct is obviously an array property. The second conjunct can be rewritten as → a ′ [ j ] = a [ j ] ∀ j. ( j ≤ i − 1 ∨ i + 1 ≤ j ) − Decision Procedures – Arrays 22

  33. Algorithm Input: Array property formula φ A in NNF Output: Formula φ UF 1 Apply the write rule to remove all array updates from φ A . 2 Replace all existential quantifications of the form ∃ i ∈ T I . P ( i ) by P ( j ) , where j is a fresh variable. 3 Replace all universal quantifications of the form ∀ i ∈ T I . P ( i ) by � P ( i ) . i ∈I ( φ ) 4 Replace the array read operators by uninterpreted functions and obtain φ UF ; 5 return φ UF ; Decision Procedures – Arrays 23

Recommend


More recommend