02917 Ad- 02917 Advanced Topics in Embedded Systems vanced Presburger Arithmetic: Cooper’s Top- ics in Em- Michael R. Hansen bed- ded Sys- tems Michael R. Hansen

1 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Introduction

02917 Ad- vanced Presburger Arithmetic (introduced by Mojzesz Presburger in 1929), is Top- the first-order theory of natural numbers with . ics in Em- Examples of formulas are: ∃x.2x = y and ∃x.∀y.x + y > z. bed- ded Unlike Peano Arithmetic, which also includes , Sys- Presburger Arithmetic is a decidable theory. tems Michael R. Hansen We shall consider the algorithm introduced by D.C Cooper in 1972. The presentation is based on: Chapter 7: Quantified Linear Arithmetic of The Calculus of Computation by Bradley and Manna.

2 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Introduction

02917 Ad- vanced Presburger Arithmetic (introduced by Mojzesz Presburger in 1929), is Top- the first-order theory of natural numbers with addition. ics in Em- Examples of formulas are: ∃x.2x = y and ∃x.∀y.x + y > z. bed- ded Unlike Peano Arithmetic, which also includes multiplication, Sys- Presburger Arithmetic is a decidable theory. tems Michael R. Hansen We shall consider the algorithm introduced by D.C Cooper in 1972. The presentation is based on: Chapter 7: Quantified Linear Arithmetic of The Calculus of Computation by Bradley and Manna.

3 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Introduction

02917 Ad- vanced Presburger Arithmetic (introduced by Mojzesz Presburger in 1929), is Top- the first-order theory of natural numbers with addition. ics in Em- Examples of formulas are: ∃x.2x = y and ∃x.∀y.x + y > z. bed- ded Unlike Peano Arithmetic, which also includes multiplication, Sys- Presburger Arithmetic is a decidable theory. tems Michael R. Hansen We shall consider the algorithm introduced by D.C Cooper in 1972. The presentation is based on: Chapter 7: Quantified Linear Arithmetic of The Calculus of Computation by Bradley and Manna.

4 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Introduction

02917 Ad- vanced Presburger Arithmetic (introduced by Mojzesz Presburger in 1929), is Top- the first-order theory of natural numbers with addition. ics in Em- Examples of formulas are: ∃x.2x = y and ∃x.∀y.x + y > z. bed- ded Unlike Peano Arithmetic, which also includes multiplication, Sys- Presburger Arithmetic is a decidable theory. tems Michael R. Hansen We shall consider the algorithm introduced by D.C Cooper in 1972. The presentation is based on: Chapter 7: Quantified Linear Arithmetic of The Calculus of Computation by Bradley and Manna.

5 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Presburger terms

02917 Ad- The terms are generated from vanced ∙ integer constants ..., −2, −1, 0, 1, 2,... and Top- ∙ variables x, y, z,... ics in Em- using the following operations: bed- ∙ addition + and subtraction − and ded ∙ multiplication by constants: ..., −2⋅, −1⋅, 0⋅, 1⋅, 2⋅, ... Sys- tems Notice Michael R. Hansen ∙ terms are interpreted over integers ∙ the terms do not really allow multiplication as, e.g. 3 ⋅ x is equal to x + x + x ∙ a term like 3 ⋅ x is usually written 3x

6 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Presburger terms

02917 Ad- The terms are generated from vanced ∙ integer constants ..., −2, −1, 0, 1, 2,... and Top- ∙ variables x, y, z,... ics in Em- using the following operations: bed- ∙ addition + and subtraction − and ded ∙ multiplication by constants: ..., −2⋅, −1⋅, 0⋅, 1⋅, 2⋅, ... Sys- tems Notice Michael R. Hansen ∙ terms are interpreted over integers ∙ the terms do not really allow multiplication as, e.g. 3 ⋅ x is equal to x + x + x ∙ a term like 3 ⋅ x is usually written 3x

7 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Presburger terms

02917 Ad- The terms are generated from vanced ∙ integer constants ..., −2, −1, 0, 1, 2,... and Top- ∙ variables x, y, z,... ics in Em- using the following operations: bed- ∙ addition + and subtraction − and ded ∙ multiplication by constants: ..., −2⋅, −1⋅, 0⋅, 1⋅, 2⋅, ... Sys- tems Notice Michael R. Hansen ∙ terms are interpreted over integers ∙ the terms do not really allow multiplication as, e.g. 3 ⋅ x is equal to x + x + x ∙ a term like 3 ⋅ x is usually written 3x

8 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Presburger terms

02917 Ad- The terms are generated from vanced ∙ integer constants ..., −2, −1, 0, 1, 2,... and Top- ∙ variables x, y, z,... ics in Em- using the following operations: bed- ∙ addition + and subtraction − and ded ∙ multiplication by constants: ..., −2⋅, −1⋅, 0⋅, 1⋅, 2⋅, ... Sys- tems Notice Michael R. Hansen ∙ terms are interpreted over integers ∙ the terms do not really allow multiplication as, e.g. 3 ⋅ x is equal to x + x + x ∙ a term like 3 ⋅ x is usually written 3x

9 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Formulas

02917 We consider formulas F, G, F1, G1, F2 . . . of the following forms: Ad- ∙ s = t, s < t, s > t, s ≤ t, and s ≥ t (comparisons) vanced Top- ∙ 1∣s, 2∣s, 3∣s,... (divisibility constraints) ics in Em- ∙ ⊤ (true) and ⊥ (false) (propositionalconstants) bed- ∙ F ∨ G (disjunction), F ∧ G (conjunction) and ¬F (negation) ded (propositional connectives) Sys- tems ∙ ∃x.F (reads ”there exists an x such that F”) and Michael R. Hansen ∀x.F (reads ”for all x: F”) (first-orderfragment)

where s and t are terms and x is a variable.

Furthermore, We allow brackets in formulas.

Notice: The formulas are interpreted over the integers.

10 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Formulas

02917 We consider formulas F, G, F1, G1, F2 . . . of the following forms: Ad- ∙ s = t, s < t, s > t, s ≤ t, and s ≥ t (comparisons) vanced Top- ∙ 1∣s, 2∣s, 3∣s,... (divisibility constraints) ics in Em- ∙ ⊤ (true) and ⊥ (false) (propositionalconstants) bed- ∙ F ∨ G (disjunction), F ∧ G (conjunction) and ¬F (negation) ded (propositional connectives) Sys- tems ∙ ∃x.F (reads ”there exists an x such that F”) and Michael R. Hansen ∀x.F (reads ”for all x: F”) (first-orderfragment)

where s and t are terms and x is a variable.

Furthermore, We allow brackets in formulas.

Notice: The formulas are interpreted over the integers.

11 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Formulas

02917 We consider formulas F, G, F1, G1, F2 . . . of the following forms: Ad- ∙ s = t, s < t, s > t, s ≤ t, and s ≥ t (comparisons) vanced Top- ∙ 1∣s, 2∣s, 3∣s,... (divisibility constraints) ics in Em- ∙ ⊤ (true) and ⊥ (false) (propositionalconstants) bed- ∙ F ∨ G (disjunction), F ∧ G (conjunction) and ¬F (negation) ded (propositional connectives) Sys- tems ∙ ∃x.F (reads ”there exists an x such that F”) and Michael R. Hansen ∀x.F (reads ”for all x: F”) (first-orderfragment)

where s and t are terms and x is a variable.

Furthermore, We allow brackets in formulas.

Notice: The formulas are interpreted over the integers.

12 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Formulas

02917 We consider formulas F, G, F1, G1, F2 . . . of the following forms: Ad- ∙ s = t, s < t, s > t, s ≤ t, and s ≥ t (comparisons) vanced Top- ∙ 1∣s, 2∣s, 3∣s,... (divisibility constraints) ics in Em- ∙ ⊤ (true) and ⊥ (false) (propositionalconstants) bed- ∙ F ∨ G (disjunction), F ∧ G (conjunction) and ¬F (negation) ded (propositional connectives) Sys- tems ∙ ∃x.F (reads ”there exists an x such that F”) and Michael R. Hansen ∀x.F (reads ”for all x: F”) (first-orderfragment)

where s and t are terms and x is a variable.

Furthermore, We allow brackets in formulas.

Notice: The formulas are interpreted over the integers.

13 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Formulas

02917 We consider formulas F, G, F1, G1, F2 . . . of the following forms: Ad- ∙ s = t, s < t, s > t, s ≤ t, and s ≥ t (comparisons) vanced Top- ∙ 1∣s, 2∣s, 3∣s,... (divisibility constraints) ics in Em- ∙ ⊤ (true) and ⊥ (false) (propositionalconstants) bed- ∙ F ∨ G (disjunction), F ∧ G (conjunction) and ¬F (negation) ded (propositional connectives) Sys- tems ∙ ∃x.F (reads ”there exists an x such that F”) and Michael R. Hansen ∀x.F (reads ”for all x: F”) (first-orderfragment)

where s and t are terms and x is a variable.

Furthermore, We allow brackets in formulas.

Notice: The formulas are interpreted over the integers.

14 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Formulas

02917 We consider formulas F, G, F1, G1, F2 . . . of the following forms: Ad- ∙ s = t, s < t, s > t, s ≤ t, and s ≥ t (comparisons) vanced Top- ∙ 1∣s, 2∣s, 3∣s,... (divisibility constraints) ics in Em- ∙ ⊤ (true) and ⊥ (false) (propositionalconstants) bed- ∙ F ∨ G (disjunction), F ∧ G (conjunction) and ¬F (negation) ded (propositional connectives) Sys- tems ∙ ∃x.F (reads ”there exists an x such that F”) and Michael R. Hansen ∀x.F (reads ”for all x: F”) (first-orderfragment)

where s and t are terms and x is a variable.

Furthermore, We allow brackets in formulas.

Notice: The formulas are interpreted over the integers.

15 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Formulas

02917 We consider formulas F, G, F1, G1, F2 . . . of the following forms: Ad- ∙ s = t, s < t, s > t, s ≤ t, and s ≥ t (comparisons) vanced Top- ∙ 1∣s, 2∣s, 3∣s,... (divisibility constraints) ics in Em- ∙ ⊤ (true) and ⊥ (false) (propositionalconstants) bed- ∙ F ∨ G (disjunction), F ∧ G (conjunction) and ¬F (negation) ded (propositional connectives) Sys- tems ∙ ∃x.F (reads ”there exists an x such that F”) and Michael R. Hansen ∀x.F (reads ”for all x: F”) (first-orderfragment)

where s and t are terms and x is a variable.

Furthermore, We allow brackets in formulas.

Notice: The formulas are interpreted over the integers.

16 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Notational conventions

02917 Ad- vanced ∙ Relative precedence: ¬ (highest – binds tightest), ∧, ∨ (lowest) Top- ics in ∙ The quantifiers ∀x and ∃x extend as far as possible to the right. Em- bed- ∙ ∀x1.∀x2.... ∀xn.F is abbreviated to ∀x1, x2,..., xn.F ded Sys- Example: tems ∀x.∃y.¬x + 1 = 2y ∧ x > 0 ∨ y < 2 Michael R. Hansen means ∀x.∃y.(((¬x + 1 = 2y) ∧ x > 0) ∨ y < 2)

17 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Notational conventions

02917 Ad- vanced ∙ Relative precedence: ¬ (highest – binds tightest), ∧, ∨ (lowest) Top- ics in ∙ The quantifiers ∀x and ∃x extend as far as possible to the right. Em- bed- ∙ ∀x1.∀x2.... ∀xn.F is abbreviated to ∀x1, x2,..., xn.F ded Sys- Example: tems ∀x.∃y.¬x + 1 = 2y ∧ x > 0 ∨ y < 2 Michael R. Hansen means ∀x.∃y.(((¬x + 1 = 2y) ∧ x > 0) ∨ y < 2)

18 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Notational conventions

02917 Ad- vanced ∙ Relative precedence: ¬ (highest – binds tightest), ∧, ∨ (lowest) Top- ics in ∙ The quantifiers ∀x and ∃x extend as far as possible to the right. Em- bed- ∙ ∀x1.∀x2.... ∀xn.F is abbreviated to ∀x1, x2,..., xn.F ded Sys- Example: tems ∀x.∃y.¬x + 1 = 2y ∧ x > 0 ∨ y < 2 Michael R. Hansen means ∀x.∃y.(((¬x + 1 = 2y) ∧ x > 0) ∨ y < 2)

19 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Notational conventions

02917 Ad- vanced ∙ Relative precedence: ¬ (highest – binds tightest), ∧, ∨ (lowest) Top- ics in ∙ The quantifiers ∀x and ∃x extend as far as possible to the right. Em- bed- ∙ ∀x1.∀x2.... ∀xn.F is abbreviated to ∀x1, x2,..., xn.F ded Sys- Example: tems ∀x.∃y.¬x + 1 = 2y ∧ x > 0 ∨ y < 2 Michael R. Hansen means ∀x.∃y.(((¬x + 1 = 2y) ∧ x > 0) ∨ y < 2)

20 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Notational conventions

02917 Ad- vanced ∙ Relative precedence: ¬ (highest – binds tightest), ∧, ∨ (lowest) Top- ics in ∙ The quantifiers ∀x and ∃x extend as far as possible to the right. Em- bed- ∙ ∀x1.∀x2.... ∀xn.F is abbreviated to ∀x1, x2,..., xn.F ded Sys- Example: tems ∀x.∃y.¬x + 1 = 2y ∧ x > 0 ∨ y < 2 Michael R. Hansen means ∀x.∃y.(((¬x + 1 = 2y) ∧ x > 0) ∨ y < 2)

21 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Some concepts

02917 Ad- ∙ In ∀x.F: vanced ∙ x is called the quantified variable Top- ∙ ∀x is called the quantifier ics in ∙ F is the scope of the quantifier Em- The case for ∃x.F is similar. bed- ∙ An occurrence of a variable x in a formula F is a bound ded occurrence if it occurs in the scope of a quantifier ∀x or ∃x in F. Sys- Otherwise, that occurrence of x is free in F. tems Michael R. Hansen ∙ x is a free variable of F if there is some free occurrence of x in F.

∙ A formula is called closed if it contains no free variables; otherwise it is called open.

22 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Some concepts

02917 Ad- ∙ In ∀x.F: vanced ∙ x is called the quantified variable Top- ∙ ∀x is called the quantifier ics in ∙ F is the scope of the quantifier Em- The case for ∃x.F is similar. bed- ∙ An occurrence of a variable x in a formula F is a bound ded occurrence if it occurs in the scope of a quantifier ∀x or ∃x in F. Sys- Otherwise, that occurrence of x is free in F. tems Michael R. Hansen ∙ x is a free variable of F if there is some free occurrence of x in F.

∙ A formula is called closed if it contains no free variables; otherwise it is called open.

23 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Some concepts

02917 Ad- ∙ In ∀x.F: vanced ∙ x is called the quantified variable Top- ∙ ∀x is called the quantifier ics in ∙ F is the scope of the quantifier Em- The case for ∃x.F is similar. bed- ∙ An occurrence of a variable x in a formula F is a bound ded occurrence if it occurs in the scope of a quantifier ∀x or ∃x in F. Sys- Otherwise, that occurrence of x is free in F. tems Michael R. Hansen ∙ x is a free variable of F if there is some free occurrence of x in F.

∙ A formula is called closed if it contains no free variables; otherwise it is called open.

24 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Some concepts

02917 Ad- ∙ In ∀x.F: vanced ∙ x is called the quantified variable Top- ∙ ∀x is called the quantifier ics in ∙ F is the scope of the quantifier Em- The case for ∃x.F is similar. bed- ∙ An occurrence of a variable x in a formula F is a bound ded occurrence if it occurs in the scope of a quantifier ∀x or ∃x in F. Sys- Otherwise, that occurrence of x is free in F. tems Michael R. Hansen ∙ x is a free variable of F if there is some free occurrence of x in F.

∙ A formula is called closed if it contains no free variables; otherwise it is called open.

25 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Semantics

02917 Ad- vanced Top- ics in Let ℤ denote the set of integers ..., 2, 1, 0, 1, 2,.... − − Em- The operations + and − and the relations =, <, ≤, >, ≥ have their bed- standard meaning. ded A I assigns an integer I(x) ∈ ℤ to every variable x. Sys- tems Let I ⊲ {x 7→ v} be the x-variant of I which is as I except that v is Michael R. Hansen assigned to x.

26 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Semantics

02917 Ad- vanced Top- ics in Let ℤ denote the set of integers ..., 2, 1, 0, 1, 2,.... − − Em- The operations + and − and the relations =, <, ≤, >, ≥ have their bed- standard meaning. ded A interpretation I assigns an integer I(x) ∈ ℤ to every variable x. Sys- tems Let I ⊲ {x 7→ v} be the x-variant of I which is as I except that v is Michael R. Hansen assigned to x.

27 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Semantics

02917 Ad- vanced Top- ics in Let ℤ denote the set of integers ..., 2, 1, 0, 1, 2,.... − − Em- The operations + and − and the relations =, <, ≤, >, ≥ have their bed- standard meaning. ded A interpretation I assigns an integer I(x) ∈ ℤ to every variable x. Sys- tems Let I ⊲ {x 7→ v} be the x-variant of I which is as I except that v is Michael R. Hansen assigned to x.

28 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Semantics

02917 Ad- vanced Top- ics in Let ℤ denote the set of integers ..., 2, 1, 0, 1, 2,.... − − Em- The operations + and − and the relations =, <, ≤, >, ≥ have their bed- standard meaning. ded A interpretation I assigns an integer I(x) ∈ ℤ to every variable x. Sys- tems Let I ⊲ {x 7→ v} be the x-variant of I which is as I except that v is Michael R. Hansen assigned to x.

29 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Semantics of terms

02917 Ad- vanced Top- Let an assignment I be given. ics in The semantics of a term s is an integer ˆI(s) ∈ ℤ defined as follows: Em- bed- ˆI(x) = I(x) ded ˆI(a) = a where a ∈ ℤ Sys- ˆI(s + t) = ˆI(s)+ ˆI(t) tems ˆI(s − t) = ˆI(s) − ˆI(t) Michael R. Hansen ˆI(a ⋅ s) = a ⋅ ˆI(s) where a ∈ ℤ

30 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Semantics of formulas

02917 Ad- vanced Let an assignment I be given. Top- The semantic relation I ∣= F is defined by structural induction on ics in formulas: Em- bed- I ∣= s < t iff ˆI(s) < ˆI(t) other relations are similar ded I ∣= a∣s iff a divides ˆI(s) where a ∈ ℤ Sys- I ∣= ¬F iff not(I ∣= F) tems I ∣= F ∨ G iff I ∣= F or I ∣= G Michael R. Hansen I ∣= F ∧ G iff I ∣= F and I ∣= G I ∣= ∀x.F iff I ⊲ {x 7→ v} ∣= F for every v ∈ ℤ I ∣= ∃x.F iff I ⊲ {x 7→ v} ∣= F for some v ∈ ℤ

31 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Concepts

02917 Ad- vanced Top- ics in A formula F is satisfiable if there is some assignment I for which the Em- formula is true. Otherwise it is unsatisfiable. bed- A formula is valid if it is true for all assignments. ded Sys- Notice: The truth value of a closed formula is independent of the chosen assignment. It is either valid (true for all assignments), or tems unsatisfiable (false for all assignments). Michael R. Hansen

32 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Concepts

02917 Ad- vanced Top- ics in A formula F is satisfiable if there is some assignment I for which the Em- formula is true. Otherwise it is unsatisfiable. bed- A formula is valid if it is true for all assignments. ded Sys- Notice: The truth value of a closed formula is independent of the chosen assignment. It is either valid (true for all assignments), or tems unsatisfiable (false for all assignments). Michael R. Hansen

33 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Concepts

02917 Ad- vanced Top- ics in A formula F is satisfiable if there is some assignment I for which the Em- formula is true. Otherwise it is unsatisfiable. bed- A formula is valid if it is true for all assignments. ded Sys- Notice: The truth value of a closed formula is independent of the chosen assignment. It is either valid (true for all assignments), or tems unsatisfiable (false for all assignments). Michael R. Hansen

34 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Examples

02917 Ad- vanced Top- ∙ ∃y.x = 2y —(x is even) is satisfiable but not valid ics in also expressible as 2∣x Em- bed- ∙ ∃y.x = 2y ∨ x = 2y + 1 —(x is even or x is odd) is valid ded also expressible as 2∣x ∨ 2∣x + 1 Sys- tems ∙ ∃x.∀y.x ≤ y is unsatifiable (false) Michael R. Hansen ∙ ∃x.∀y.x + y = y is valid (true)

35 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Examples

02917 Ad- vanced Top- ∙ ∃y.x = 2y —(x is even) is satisfiable but not valid ics in also expressible as 2∣x Em- bed- ∙ ∃y.x = 2y ∨ x = 2y + 1 —(x is even or x is odd) is valid ded also expressible as 2∣x ∨ 2∣x + 1 Sys- tems ∙ ∃x.∀y.x ≤ y is unsatifiable (false) Michael R. Hansen ∙ ∃x.∀y.x + y = y is valid (true)

36 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Examples

02917 Ad- vanced Top- ∙ ∃y.x = 2y —(x is even) is satisfiable but not valid ics in also expressible as 2∣x Em- bed- ∙ ∃y.x = 2y ∨ x = 2y + 1 —(x is even or x is odd) is valid ded also expressible as 2∣x ∨ 2∣x + 1 Sys- tems ∙ ∃x.∀y.x ≤ y is unsatifiable (false) Michael R. Hansen ∙ ∃x.∀y.x + y = y is valid (true)

37 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Examples

02917 Ad- vanced Top- ∙ ∃y.x = 2y —(x is even) is satisfiable but not valid ics in also expressible as 2∣x Em- bed- ∙ ∃y.x = 2y ∨ x = 2y + 1 —(x is even or x is odd) is valid ded also expressible as 2∣x ∨ 2∣x + 1 Sys- tems ∙ ∃x.∀y.x ≤ y is unsatifiable (false) Michael R. Hansen ∙ ∃x.∀y.x + y = y is valid (true)

38 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Quantifier elimination

In the theory of real numbers an example of quantifier elimination is: 02917 Ad- x.ax 2 bx c 0 is equivalentto b2 4ac 0 ∃ + + = − ≥ vanced where a, b, c ∈ ℝ and a ∕= 0. Top- ics in Presburger developed a method, which for an arbitrary Presburger Em- formula F gives to an equivalent quantifier-free formula G. bed- ded If F is a closed formula, then the truth value of G can be computed. Sys- tems For example, Cooper’s algorithm for Presburger Arithmetic Michael R. Hansen transforms: ∃x.(3x + 1 < 10 ∨ 7x − 6 > 7) ∧ 2∣x to the following variable- and quantifier-free formula:

42 42 j 21 j Wj=1( ∣ ∧ ∣ ) ∨ 42 39 j < 63 39 < 39 j 42 39 j 21 39 j Wj=1(( + ∨ + ) ∧ ∣ + ∧ ∣ + )

39 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Quantifier elimination

In the theory of real numbers an example of quantifier elimination is: 02917 Ad- x.ax 2 bx c 0 is equivalentto b2 4ac 0 ∃ + + = − ≥ vanced where a, b, c ∈ ℝ and a ∕= 0. Top- ics in Presburger developed a method, which for an arbitrary Presburger Em- formula F gives to an equivalent quantifier-free formula G. bed- ded If F is a closed formula, then the truth value of G can be computed. Sys- tems For example, Cooper’s algorithm for Presburger Arithmetic Michael R. Hansen transforms: ∃x.(3x + 1 < 10 ∨ 7x − 6 > 7) ∧ 2∣x to the following variable- and quantifier-free formula:

42 42 j 21 j Wj=1( ∣ ∧ ∣ ) ∨ 42 39 j < 63 39 < 39 j 42 39 j 21 39 j Wj=1(( + ∨ + ) ∧ ∣ + ∧ ∣ + )

40 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Quantifier elimination

In the theory of real numbers an example of quantifier elimination is: 02917 Ad- x.ax 2 bx c 0 is equivalentto b2 4ac 0 ∃ + + = − ≥ vanced where a, b, c ∈ ℝ and a ∕= 0. Top- ics in Presburger developed a method, which for an arbitrary Presburger Em- formula F gives to an equivalent quantifier-free formula G. bed- ded If F is a closed formula, then the truth value of G can be computed. Sys- tems For example, Cooper’s algorithm for Presburger Arithmetic Michael R. Hansen transforms: ∃x.(3x + 1 < 10 ∨ 7x − 6 > 7) ∧ 2∣x to the following variable- and quantifier-free formula:

42 42 j 21 j Wj=1( ∣ ∧ ∣ ) ∨ 42 39 j < 63 39 < 39 j 42 39 j 21 39 j Wj=1(( + ∨ + ) ∧ ∣ + ∧ ∣ + )

41 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Quantifier elimination

In the theory of real numbers an example of quantifier elimination is: 02917 Ad- x.ax 2 bx c 0 is equivalentto b2 4ac 0 ∃ + + = − ≥ vanced where a, b, c ∈ ℝ and a ∕= 0. Top- ics in Presburger developed a method, which for an arbitrary Presburger Em- formula F gives to an equivalent quantifier-free formula G. bed- ded If F is a closed formula, then the truth value of G can be computed. Sys- tems For example, Cooper’s algorithm for Presburger Arithmetic Michael R. Hansen transforms: ∃x.(3x + 1 < 10 ∨ 7x − 6 > 7) ∧ 2∣x to the following variable- and quantifier-free formula:

42 42 j 21 j Wj=1( ∣ ∧ ∣ ) ∨ 42 39 j < 63 39 < 39 j 42 39 j 21 39 j Wj=1(( + ∨ + ) ∧ ∣ + ∧ ∣ + )

42 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Quantifier elimination

In the theory of real numbers an example of quantifier elimination is: 02917 Ad- x.ax 2 bx c 0 is equivalentto b2 4ac 0 ∃ + + = − ≥ vanced where a, b, c ∈ ℝ and a ∕= 0. Top- ics in Presburger developed a method, which for an arbitrary Presburger Em- formula F gives to an equivalent quantifier-free formula G. bed- ded If F is a closed formula, then the truth value of G can be computed. Sys- tems For example, Cooper’s algorithm for Presburger Arithmetic Michael R. Hansen transforms: ∃x.(3x + 1 < 10 ∨ 7x − 6 > 7) ∧ 2∣x to the following variable- and quantifier-free formula:

42 42 j 21 j Wj=1( ∣ ∧ ∣ ) ∨ 42 39 j < 63 39 < 39 j 42 39 j 21 39 j Wj=1(( + ∨ + ) ∧ ∣ + ∧ ∣ + )

43 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Quantifier Elimination (II)

Excluding divisible predicates a∣s from the Presburger Formulas 02917 quantifier elimination is not possible. Ad- vanced Lemma: If F(y) is a quantifier-free formula with one free variable y. Top- Let ics in S = {n ∈ ℤ ∣ F(n) is valid} Em- Then either bed- ℤ+ ℤ+ S ∩ or ∖ S ded is finite Sys- tems Consider the formula: ∃x.2x = y. Michael R. Hansen ∙ S ∩ ℤ+ is the infinite set of positive even numbers ∙ ℤ+ ∖ S is the infinite set of positive odd numbers

The addition of divisibility predicates makes quantifier elimination possible for Presburger Arithmetic, and, e.g.

∃x.2x = y isequivalentto 2∣y

44 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Quantifier Elimination (II)

Excluding divisible predicates a∣s from the Presburger Formulas 02917 quantifier elimination is not possible. Ad- vanced Lemma: If F(y) is a quantifier-free formula with one free variable y. Top- Let ics in S = {n ∈ ℤ ∣ F(n) is valid} Em- Then either bed- ℤ+ ℤ+ S ∩ or ∖ S ded is finite Sys- tems Consider the formula: ∃x.2x = y. Michael R. Hansen ∙ S ∩ ℤ+ is the infinite set of positive even numbers ∙ ℤ+ ∖ S is the infinite set of positive odd numbers

The addition of divisibility predicates makes quantifier elimination possible for Presburger Arithmetic, and, e.g.

∃x.2x = y isequivalentto 2∣y

45 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Quantifier Elimination (II)

Excluding divisible predicates a∣s from the Presburger Formulas 02917 quantifier elimination is not possible. Ad- vanced Lemma: If F(y) is a quantifier-free formula with one free variable y. Top- Let ics in S = {n ∈ ℤ ∣ F(n) is valid} Em- Then either bed- ℤ+ ℤ+ S ∩ or ∖ S ded is finite Sys- tems Consider the formula: ∃x.2x = y. Michael R. Hansen ∙ S ∩ ℤ+ is the infinite set of positive even numbers ∙ ℤ+ ∖ S is the infinite set of positive odd numbers

The addition of divisibility predicates makes quantifier elimination possible for Presburger Arithmetic, and, e.g.

∃x.2x = y isequivalentto 2∣y

46 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Quantifier Elimination (II)

Excluding divisible predicates a∣s from the Presburger Formulas 02917 quantifier elimination is not possible. Ad- vanced Lemma: If F(y) is a quantifier-free formula with one free variable y. Top- Let ics in S = {n ∈ ℤ ∣ F(n) is valid} Em- Then either bed- ℤ+ ℤ+ S ∩ or ∖ S ded is finite Sys- tems Consider the formula: ∃x.2x = y. Michael R. Hansen ∙ S ∩ ℤ+ is the infinite set of positive even numbers ∙ ℤ+ ∖ S is the infinite set of positive odd numbers

The addition of divisibility predicates makes quantifier elimination possible for Presburger Arithmetic, and, e.g.

∃x.2x = y isequivalentto 2∣y

47 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Quantifier Elimination (II)

Excluding divisible predicates a∣s from the Presburger Formulas 02917 quantifier elimination is not possible. Ad- vanced Lemma: If F(y) is a quantifier-free formula with one free variable y. Top- Let ics in S = {n ∈ ℤ ∣ F(n) is valid} Em- Then either bed- ℤ+ ℤ+ S ∩ or ∖ S ded is finite Sys- tems Consider the formula: ∃x.2x = y. Michael R. Hansen ∙ S ∩ ℤ+ is the infinite set of positive even numbers ∙ ℤ+ ∖ S is the infinite set of positive odd numbers

The addition of divisibility predicates makes quantifier elimination possible for Presburger Arithmetic, and, e.g.

∃x.2x = y isequivalentto 2∣y

48 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Quantifier Elimination (II)

Excluding divisible predicates a∣s from the Presburger Formulas 02917 quantifier elimination is not possible. Ad- vanced Lemma: If F(y) is a quantifier-free formula with one free variable y. Top- Let ics in S = {n ∈ ℤ ∣ F(n) is valid} Em- Then either bed- ℤ+ ℤ+ S ∩ or ∖ S ded is finite Sys- tems Consider the formula: ∃x.2x = y. Michael R. Hansen ∙ S ∩ ℤ+ is the infinite set of positive even numbers ∙ ℤ+ ∖ S is the infinite set of positive odd numbers

The addition of divisibility predicates makes quantifier elimination possible for Presburger Arithmetic, and, e.g.

∃x.2x = y isequivalentto 2∣y

49 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Cooper’s procedure - main idea

02917 Ad- Consider a formula ∃x.F[x], where F is quantifier free. vanced Main steps: Top-

∙ Put F[x] on negation normal form, yielding F1[x] ics in Em- ∙ Normalize F1[x] to use < as the only comparison operator, bed- yielding F2[x] ded Sys- ∙ Normalize F2[x] so that atomic formulas have one occurrence of x (at most), yielding F3[x] tems Michael R. Hansen

∙ Normalize F3[x] so that the coefficients of x is 1 (in atomic ′ formulas containing x), yielding F4[x ]

′ ∙ Construct from F4[x ] a quantifier-free formula F5 which is equivalent to ∃x.F[x]

50 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Cooper’s procedure - main idea

02917 Ad- Consider a formula ∃x.F[x], where F is quantifier free. vanced Main steps: Top-

∙ Put F[x] on negation normal form, yielding F1[x] ics in Em- ∙ Normalize F1[x] to use < as the only comparison operator, bed- yielding F2[x] ded Sys- ∙ Normalize F2[x] so that atomic formulas have one occurrence of x (at most), yielding F3[x] tems Michael R. Hansen

∙ Normalize F3[x] so that the coefficients of x is 1 (in atomic ′ formulas containing x), yielding F4[x ]

′ ∙ Construct from F4[x ] a quantifier-free formula F5 which is equivalent to ∃x.F[x]

51 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Cooper’s procedure - main idea

02917 Ad- Consider a formula ∃x.F[x], where F is quantifier free. vanced Main steps: Top-

∙ Put F[x] on negation normal form, yielding F1[x] ics in Em- ∙ Normalize F1[x] to use < as the only comparison operator, bed- yielding F2[x] ded Sys- ∙ Normalize F2[x] so that atomic formulas have one occurrence of x (at most), yielding F3[x] tems Michael R. Hansen

∙ Normalize F3[x] so that the coefficients of x is 1 (in atomic ′ formulas containing x), yielding F4[x ]

′ ∙ Construct from F4[x ] a quantifier-free formula F5 which is equivalent to ∃x.F[x]

52 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Cooper’s procedure - main idea

02917 Ad- Consider a formula ∃x.F[x], where F is quantifier free. vanced Main steps: Top-

∙ Put F[x] on negation normal form, yielding F1[x] ics in Em- ∙ Normalize F1[x] to use < as the only comparison operator, bed- yielding F2[x] ded Sys- ∙ Normalize F2[x] so that atomic formulas have one occurrence of x (at most), yielding F3[x] tems Michael R. Hansen

∙ Normalize F3[x] so that the coefficients of x is 1 (in atomic ′ formulas containing x), yielding F4[x ]

′ ∙ Construct from F4[x ] a quantifier-free formula F5 which is equivalent to ∃x.F[x]

53 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Cooper’s procedure - main idea

02917 Ad- Consider a formula ∃x.F[x], where F is quantifier free. vanced Main steps: Top-

∙ Put F[x] on negation normal form, yielding F1[x] ics in Em- ∙ Normalize F1[x] to use < as the only comparison operator, bed- yielding F2[x] ded Sys- ∙ Normalize F2[x] so that atomic formulas have one occurrence of x (at most), yielding F3[x] tems Michael R. Hansen

∙ Normalize F3[x] so that the coefficients of x is 1 (in atomic ′ formulas containing x), yielding F4[x ]

′ ∙ Construct from F4[x ] a quantifier-free formula F5 which is equivalent to ∃x.F[x]

54 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Negation Normal Form

02917 Ad- Input: A quantifier-free formula F[x]. vanced Top- Output: A formula F1[x], where negation is used on literals only. ics in Technique: Apply de Morgan’s laws Em- bed- ¬(F ∨ G) ⇐⇒ ¬F ∧ ¬G ded ¬(F ∧ G) ⇐⇒ ¬F ∨ ¬G Sys- from left to right, together with: tems Michael R. Hansen ¬¬F ⇐⇒ F ¬⊤ ⇐⇒ ⊥ ¬⊥ ⇐⇒ ⊤

until no further application is possible.

55 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Negation Normal Form

02917 Ad- Input: A quantifier-free formula F[x]. vanced Top- Output: A formula F1[x], where negation is used on literals only. ics in Technique: Apply de Morgan’s laws Em- bed- ¬(F ∨ G) ⇐⇒ ¬F ∧ ¬G ded ¬(F ∧ G) ⇐⇒ ¬F ∨ ¬G Sys- from left to right, together with: tems Michael R. Hansen ¬¬F ⇐⇒ F ¬⊤ ⇐⇒ ⊥ ¬⊥ ⇐⇒ ⊤

until no further application is possible.

56 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Construction of F2[x]

02917 Ad- vanced Top- Output: A formula F2[x] containing comparison < only, and where ics in negation is applied to divisibility constraints only. Em- Technique: Use bed- ded s = t ⇐⇒ s < t + 1 ∧ t < s + 1 Sys- ¬(s = t) ⇐⇒ s < t ∨ t < s tems ¬(s < t) ⇐⇒ t < s + 1 Michael R. Hansen

The other comparisons ≤, ≥,> can also be treated.

57 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Construction of F3[x]

02917 Ad- Output: A formula F3[x], where atomic formulas contain one vanced occurrence of x at most. Top- Technique: Use linear arithmetic to bring each atomic formula ics in containing x on the form Em- bed- hx < t or t < hx or k∣hx + t ded where h, k ∈ ℤ+ and x does not occur in t. Sys- tems Example: Michael R. Hansen 6x + z < 4x + 3y − 5 is transformed to 2x < 3y − z − 5

58 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Construction of F3[x]

02917 Ad- Output: A formula F3[x], where atomic formulas contain one vanced occurrence of x at most. Top- Technique: Use linear arithmetic to bring each atomic formula ics in containing x on the form Em- bed- hx < t or t < hx or k∣hx + t ded where h, k ∈ ℤ+ and x does not occur in t. Sys- tems Example: Michael R. Hansen 6x + z < 4x + 3y − 5 is transformed to 2x < 3y − z − 5

59 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 ′ Construction of F4[x ]

′ ′ Output: A formula F4[x ], where coefficients to x are all 1 and 02917 ′ ′ ∃x.F[x] is equivalent to ∃x .F[x ] Ad- vanced Top- Let  be the least common multiple (lcm) of all coefficients to x. ics in Em- Normalize each constraint so that  is the coefficient of x. The ′ ′ ′ ′ ′ bed- resulting formula is F3[x]. F4[x ] is F3[x ] ∧ ∣x ded Example: Sys- tems 2x < z + 6 ∧ y − 1 < 3x ∧ 4∣5x + 1 Michael R. Hansen

′ is transformed to F3[30x] 30x < 15z + 90 ∧ 10y − 10 < 30x ∧ 24∣30x + 6 ′ as 30 = lcm{2, 3, 5}, and F4[x ] is ′ ′ ′ ′ x < 15z + 90 ∧ 10y − 10 < x ∧ 24∣x + 6 ∧ 30∣x

60 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 ′ Construction of F4[x ]

′ ′ Output: A formula F4[x ], where coefficients to x are all 1 and 02917 ′ ′ ∃x.F[x] is equivalent to ∃x .F[x ] Ad- vanced Top- Let  be the least common multiple (lcm) of all coefficients to x. ics in Em- Normalize each constraint so that  is the coefficient of x. The ′ ′ ′ ′ ′ bed- resulting formula is F3[x]. F4[x ] is F3[x ] ∧ ∣x ded Example: Sys- tems 2x < z + 6 ∧ y − 1 < 3x ∧ 4∣5x + 1 Michael R. Hansen

′ is transformed to F3[30x] 30x < 15z + 90 ∧ 10y − 10 < 30x ∧ 24∣30x + 6 ′ as 30 = lcm{2, 3, 5}, and F4[x ] is ′ ′ ′ ′ x < 15z + 90 ∧ 10y − 10 < x ∧ 24∣x + 6 ∧ 30∣x

61 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 ′ Construction of F4[x ]

′ ′ Output: A formula F4[x ], where coefficients to x are all 1 and 02917 ′ ′ ∃x.F[x] is equivalent to ∃x .F[x ] Ad- vanced Top- Let  be the least common multiple (lcm) of all coefficients to x. ics in Em- Normalize each constraint so that  is the coefficient of x. The ′ ′ ′ ′ ′ bed- resulting formula is F3[x]. F4[x ] is F3[x ] ∧ ∣x ded Example: Sys- tems 2x < z + 6 ∧ y − 1 < 3x ∧ 4∣5x + 1 Michael R. Hansen

′ is transformed to F3[30x] 30x < 15z + 90 ∧ 10y − 10 < 30x ∧ 24∣30x + 6 ′ as 30 = lcm{2, 3, 5}, and F4[x ] is ′ ′ ′ ′ x < 15z + 90 ∧ 10y − 10 < x ∧ 24∣x + 6 ∧ 30∣x

62 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 ′ Construction of F4[x ]

′ ′ Output: A formula F4[x ], where coefficients to x are all 1 and 02917 ′ ′ ∃x.F[x] is equivalent to ∃x .F[x ] Ad- vanced Top- Let  be the least common multiple (lcm) of all coefficients to x. ics in Em- Normalize each constraint so that  is the coefficient of x. The ′ ′ ′ ′ ′ bed- resulting formula is F3[x]. F4[x ] is F3[x ] ∧ ∣x ded Example: Sys- tems 2x < z + 6 ∧ y − 1 < 3x ∧ 4∣5x + 1 Michael R. Hansen

′ is transformed to F3[30x] 30x < 15z + 90 ∧ 10y − 10 < 30x ∧ 24∣30x + 6 ′ as 30 = lcm{2, 3, 5}, and F4[x ] is ′ ′ ′ ′ x < 15z + 90 ∧ 10y − 10 < x ∧ 24∣x + 6 ∧ 30∣x

63 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Construction of F5 – part 1

Output: A quantifier-free formula F5 which is equivalent to ∃x.F[x] 02917 ′ ′ (and to ∃x .F4[x ]) Ad- ′ ′ vanced Each literal in F4[x ] containing x has one of the forms: (A) x ′ < a, (B) b < x ′, (C) h∣x ′ + c, (D) ¬(h∣x ′ + c) Top- ics in We distinguish two cases. Em-

′ bed- Case 1: there are infinitely many small satisfying assignments to x . ded ′ ′ Sys- Let F−∞[x ] be obtained from F4[x ] by replacing: ∙ (A)-literals by ⊤ and tems ∙ (B)-literals by ⊥. Michael R. Hansen Let  = lcm{h ∣ h∣x + c is a divisibility constraint in a (C) or (D) literal}.

Let F51 be  _ F−∞[j] j=1 All possible combinations of divisibility constraints are tested.

64 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Construction of F5 – part 1

Output: A quantifier-free formula F5 which is equivalent to ∃x.F[x] 02917 ′ ′ (and to ∃x .F4[x ]) Ad- ′ ′ vanced Each literal in F4[x ] containing x has one of the forms: (A) x ′ < a, (B) b < x ′, (C) h∣x ′ + c, (D) ¬(h∣x ′ + c) Top- ics in We distinguish two cases. Em-

′ bed- Case 1: there are infinitely many small satisfying assignments to x . ded ′ ′ Sys- Let F−∞[x ] be obtained from F4[x ] by replacing: ∙ (A)-literals by ⊤ and tems ∙ (B)-literals by ⊥. Michael R. Hansen Let  = lcm{h ∣ h∣x + c is a divisibility constraint in a (C) or (D) literal}.

Let F51 be  _ F−∞[j] j=1 All possible combinations of divisibility constraints are tested.

65 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Construction of F5 – part 1

Output: A quantifier-free formula F5 which is equivalent to ∃x.F[x] 02917 ′ ′ (and to ∃x .F4[x ]) Ad- ′ ′ vanced Each literal in F4[x ] containing x has one of the forms: (A) x ′ < a, (B) b < x ′, (C) h∣x ′ + c, (D) ¬(h∣x ′ + c) Top- ics in We distinguish two cases. Em-

′ bed- Case 1: there are infinitely many small satisfying assignments to x . ded ′ ′ Sys- Let F−∞[x ] be obtained from F4[x ] by replacing: ∙ (A)-literals by ⊤ and tems ∙ (B)-literals by ⊥. Michael R. Hansen Let  = lcm{h ∣ h∣x + c is a divisibility constraint in a (C) or (D) literal}.

Let F51 be  _ F−∞[j] j=1 All possible combinations of divisibility constraints are tested.

66 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Construction of F5 – part 1

Output: A quantifier-free formula F5 which is equivalent to ∃x.F[x] 02917 ′ ′ (and to ∃x .F4[x ]) Ad- ′ ′ vanced Each literal in F4[x ] containing x has one of the forms: (A) x ′ < a, (B) b < x ′, (C) h∣x ′ + c, (D) ¬(h∣x ′ + c) Top- ics in We distinguish two cases. Em-

′ bed- Case 1: there are infinitely many small satisfying assignments to x . ded ′ ′ Sys- Let F−∞[x ] be obtained from F4[x ] by replacing: ∙ (A)-literals by ⊤ and tems ∙ (B)-literals by ⊥. Michael R. Hansen Let  = lcm{h ∣ h∣x + c is a divisibility constraint in a (C) or (D) literal}.

Let F51 be  _ F−∞[j] j=1 All possible combinations of divisibility constraints are tested.

67 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Construction of F5 – part 2

′ ′ 02917 Each literal in F4[x ] containing x has one of the forms: (A) x ′ < a, (B) b < x ′, (C) h∣x ′ + c, (D) ¬(h∣x ′ + c) Ad- vanced ′ Case 2: there is a least satisfying assignments to x . Top- For that assignment an (B) literal is true and for smaller assignments ics in to x ′ the formula is false. Em- bed- Let B = {b∣b < x ′ is a (B) literal} ded Sys- Then F52 is:  tems _ _ F4[b + j] Michael R. Hansen j=1 b∈B

Then F5 is F51 ∨ F52 i.e.

  _ F−∞[j] ∨ _ _ F4[b + j] j=1 j=1 b∈B

68 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Construction of F5 – part 2

′ ′ 02917 Each literal in F4[x ] containing x has one of the forms: (A) x ′ < a, (B) b < x ′, (C) h∣x ′ + c, (D) ¬(h∣x ′ + c) Ad- vanced ′ Case 2: there is a least satisfying assignments to x . Top- For that assignment an (B) literal is true and for smaller assignments ics in to x ′ the formula is false. Em- bed- Let B = {b∣b < x ′ is a (B) literal} ded Sys- Then F52 is:  tems _ _ F4[b + j] Michael R. Hansen j=1 b∈B

Then F5 is F51 ∨ F52 i.e.

  _ F−∞[j] ∨ _ _ F4[b + j] j=1 j=1 b∈B

69 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Construction of F5 – part 2

′ ′ 02917 Each literal in F4[x ] containing x has one of the forms: (A) x ′ < a, (B) b < x ′, (C) h∣x ′ + c, (D) ¬(h∣x ′ + c) Ad- vanced ′ Case 2: there is a least satisfying assignments to x . Top- For that assignment an (B) literal is true and for smaller assignments ics in to x ′ the formula is false. Em- bed- Let B = {b∣b < x ′ is a (B) literal} ded Sys- Then F52 is:  tems _ _ F4[b + j] Michael R. Hansen j=1 b∈B

Then F5 is F51 ∨ F52 i.e.

  _ F−∞[j] ∨ _ _ F4[b + j] j=1 j=1 b∈B

70 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Example (I)

02917 Ad- ∃x. (3x + 1 < 10 ∨ 7x − 6 > 7) ∧ 2∣x vanced | F{z[x] } Top- F[x] is on Negation Normal Form. Isolate x and use < only: ics in Em- ∃x. (3x < 9 ∨ 13 < 7x) ∧ 2∣x bed- ded | F{z3[x] } Sys- Normalize coefficient to x, part 1: tems Michael R. Hansen ∃x. (21x < 63 ∨ 39 < 21x) ∧ 42∣21x

′ | F3{z[21x] } Normalize coefficient to x, part 2:

′ ′ ′ ′ ′ ∃x . (x < 63 ∨ 39 < x ) ∧ 42∣x ∧ 21∣x

′ | F4{z[x ] }

71 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Example (I)

02917 Ad- ∃x. (3x + 1 < 10 ∨ 7x − 6 > 7) ∧ 2∣x vanced | F{z[x] } Top- F[x] is on Negation Normal Form. Isolate x and use < only: ics in Em- ∃x. (3x < 9 ∨ 13 < 7x) ∧ 2∣x bed- ded | F{z3[x] } Sys- Normalize coefficient to x, part 1: tems Michael R. Hansen ∃x. (21x < 63 ∨ 39 < 21x) ∧ 42∣21x

′ | F3{z[21x] } Normalize coefficient to x, part 2:

′ ′ ′ ′ ′ ∃x . (x < 63 ∨ 39 < x ) ∧ 42∣x ∧ 21∣x

′ | F4{z[x ] }

72 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Example (I)

02917 Ad- ∃x. (3x + 1 < 10 ∨ 7x − 6 > 7) ∧ 2∣x vanced | F{z[x] } Top- F[x] is on Negation Normal Form. Isolate x and use < only: ics in Em- ∃x. (3x < 9 ∨ 13 < 7x) ∧ 2∣x bed- ded | F{z3[x] } Sys- Normalize coefficient to x, part 1: tems Michael R. Hansen ∃x. (21x < 63 ∨ 39 < 21x) ∧ 42∣21x

′ | F3{z[21x] } Normalize coefficient to x, part 2:

′ ′ ′ ′ ′ ∃x . (x < 63 ∨ 39 < x ) ∧ 42∣x ∧ 21∣x

′ | F4{z[x ] }

73 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Example (I)

02917 Ad- ∃x. (3x + 1 < 10 ∨ 7x − 6 > 7) ∧ 2∣x vanced | F{z[x] } Top- F[x] is on Negation Normal Form. Isolate x and use < only: ics in Em- ∃x. (3x < 9 ∨ 13 < 7x) ∧ 2∣x bed- ded | F{z3[x] } Sys- Normalize coefficient to x, part 1: tems Michael R. Hansen ∃x. (21x < 63 ∨ 39 < 21x) ∧ 42∣21x

′ | F3{z[21x] } Normalize coefficient to x, part 2:

′ ′ ′ ′ ′ ∃x . (x < 63 ∨ 39 < x ) ∧ 42∣x ∧ 21∣x

′ | F4{z[x ] }

74 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Example (II)

02917 ′ ′ ′ ′ ′ ∃x . (x < 63 ∨ 39 < x ) ∧ 42∣x ∧ 21∣x Ad- ′ | F4{z[x ] } vanced Top- Eliminate the quantifier: ics in ′ ′ ′ Em- F−∞[x ]:(⊤∨⊥) ∧ 42∣x ∧ 21∣x bed-  = lcm{21, 42} = 42 ded B = {39} Sys- tems 42 42 j 21 j Michael R. Hansen Wj=1( ∣ ∧ ∣ ) ∨ 42 39 j < 63 39 < 39 j 42 39 j 21 39 j Wj=1(( + ∨ + ) ∧ ∣ + ∧ ∣ + )

This formula is true and so is

∃x. (3x + 1 < 10 ∨ 7x − 6 > 7) ∧ 2∣x

| F{z[x] }

75 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Example (II)

02917 ′ ′ ′ ′ ′ ∃x . (x < 63 ∨ 39 < x ) ∧ 42∣x ∧ 21∣x Ad- ′ | F4{z[x ] } vanced Top- Eliminate the quantifier: ics in ′ ′ ′ Em- F−∞[x ]:(⊤∨⊥) ∧ 42∣x ∧ 21∣x bed-  = lcm{21, 42} = 42 ded B = {39} Sys- tems 42 42 j 21 j Michael R. Hansen Wj=1( ∣ ∧ ∣ ) ∨ 42 39 j < 63 39 < 39 j 42 39 j 21 39 j Wj=1(( + ∨ + ) ∧ ∣ + ∧ ∣ + )

This formula is true and so is

∃x. (3x + 1 < 10 ∨ 7x − 6 > 7) ∧ 2∣x

| F{z[x] }

76 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Example (II)

02917 ′ ′ ′ ′ ′ ∃x . (x < 63 ∨ 39 < x ) ∧ 42∣x ∧ 21∣x Ad- ′ | F4{z[x ] } vanced Top- Eliminate the quantifier: ics in ′ ′ ′ Em- F−∞[x ]:(⊤∨⊥) ∧ 42∣x ∧ 21∣x bed-  = lcm{21, 42} = 42 ded B = {39} Sys- tems 42 42 j 21 j Michael R. Hansen Wj=1( ∣ ∧ ∣ ) ∨ 42 39 j < 63 39 < 39 j 42 39 j 21 39 j Wj=1(( + ∨ + ) ∧ ∣ + ∧ ∣ + )

This formula is true and so is

∃x. (3x + 1 < 10 ∨ 7x − 6 > 7) ∧ 2∣x

| F{z[x] }

77 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Summary (I)

02917 Ad- vanced Top- ics in ∙ Cooper’s algorithm can decide arbitrary formulas of Presbruger Em- Arithmetic – even in the presence of arbitrary quantifications. bed- ∙ The problem has a double exponential lower bound and a triple ded exponential upper bound. Sys- ∙ Cooper’s algorithm has a triple exponential upper bound. tems ∙ Many optimizations are possible. Michael R. Hansen

78 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Summary (I)

02917 Ad- vanced Top- ics in ∙ Cooper’s algorithm can decide arbitrary formulas of Presbruger Em- Arithmetic – even in the presence of arbitrary quantifications. bed- ∙ The problem has a double exponential lower bound and a triple ded exponential upper bound. Sys- ∙ Cooper’s algorithm has a triple exponential upper bound. tems ∙ Many optimizations are possible. Michael R. Hansen

79 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Summary (I)

02917 Ad- vanced Top- ics in ∙ Cooper’s algorithm can decide arbitrary formulas of Presbruger Em- Arithmetic – even in the presence of arbitrary quantifications. bed- ∙ The problem has a double exponential lower bound and a triple ded exponential upper bound. Sys- ∙ Cooper’s algorithm has a triple exponential upper bound. tems ∙ Many optimizations are possible. Michael R. Hansen

80 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Summary (I)

02917 Ad- vanced Top- ics in ∙ Cooper’s algorithm can decide arbitrary formulas of Presbruger Em- Arithmetic – even in the presence of arbitrary quantifications. bed- ∙ The problem has a double exponential lower bound and a triple ded exponential upper bound. Sys- ∙ Cooper’s algorithm has a triple exponential upper bound. tems ∙ Many optimizations are possible. Michael R. Hansen

81 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Summary (II)

02917 Ad- vanced The advantage with Cooper’s algorithm is that it does not require Top- normal form, as some other decision methods do. Quantifier elimination in connection with DNF or CNF hurts a lot. ics in Em- A disadvantage with Cooper’s algorithm is that constants obtained bed- using lcm may be large. ded Sys- Ongoing work: Experiments with a declarative implementation of the tems algorithm including many optimizations aiming at: Michael R. Hansen ∙ including techniques from other decision methods, and ∙ a parallel implementation on a multi-core platform striving for a very efficient backend for DC-modelchecking.

82 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Summary (II)

02917 Ad- vanced The advantage with Cooper’s algorithm is that it does not require Top- normal form, as some other decision methods do. Quantifier elimination in connection with DNF or CNF hurts a lot. ics in Em- A disadvantage with Cooper’s algorithm is that constants obtained bed- using lcm may be large. ded Sys- Ongoing work: Experiments with a declarative implementation of the tems algorithm including many optimizations aiming at: Michael R. Hansen ∙ including techniques from other decision methods, and ∙ a parallel implementation on a multi-core platform striving for a very efficient backend for DC-modelchecking.

83 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010 Summary (II)

02917 Ad- vanced The advantage with Cooper’s algorithm is that it does not require Top- normal form, as some other decision methods do. Quantifier elimination in connection with DNF or CNF hurts a lot. ics in Em- A disadvantage with Cooper’s algorithm is that constants obtained bed- using lcm may be large. ded Sys- Ongoing work: Experiments with a declarative implementation of the tems algorithm including many optimizations aiming at: Michael R. Hansen ∙ including techniques from other decision methods, and ∙ a parallel implementation on a multi-core platform striving for a very efficient backend for DC-modelchecking.

84 DTU Informatics, Technical University of Denmark Presburger Arithmetic: Cooper’s algorithm MRH 17/06/2010