1 / 38

Integer Constraints

Integer Constraints. Presented by: Deepak Garg November 5, 2003. Motivation. Index Refinement Types with Integer Domains In particular, array bounds checking Rule Generating the Constraint: case pattern matching Rule Using the constraints. General Integer Constraints.

talor
Download Presentation

Integer Constraints

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Integer Constraints Presented by: DeepakGarg November 5, 2003

  2. Motivation • Index Refinement Types with Integer Domains • In particular, array bounds checking • Rule Generating the Constraint: case pattern matching • Rule Using the constraints

  3. General Integer Constraints • Linear integer constraint decision problem is NP-complete • Use approximate methods • Fourier-Motzkin Elimination and Omega Test (Pugh)

  4. Linear Integer Constraints • Assume integer variables x1,,xn • And integer constraints i aji xi· uj i bji xi¸ lj All coefficients are rational • Questions: Does there exist a solution? What are all the solutions?

  5. Fourier Motzkin Elimination • Eliminate variables one by one (reduction) • Guarantee: (Original System has solution) ) (Reduced System has solution) • Only an approximation

  6. Fourier Motzkin Elimination • Eliminate variables one by one x + y ¸ 16 (1) 4x + 7y · 28 (2) 3x-7y · 20 (3) 2x-3y ¸ -9 (4) • Given a fixed y, (1) and (4) are lower bounds for x • Given a fixed y, (2) and (3) are upper bounds for x

  7. Fourier-Motzkin Elimination • Eliminate x first (arbitrary choice) x ¸ 16-y x · 7 – (7/4) y x · 10 + (7/2) y x ¸ -9/2 + (3/2) y • “Safely combine” the inequalities • Safely means that (original system has solutions) ) (reduced system has solutions)

  8. Fourier-Motzkin Elimination • Suppose we have an integer solution to the original system • (Every lower bound on x) · x · (Every upper bound on x) • A good safe elimination: Min (upper bounds) ¸ Max (lower bounds) • Using this we get the new system 16-y · x · 7 – (7/4) y 16-y · x · 10 + (7/2) y -9/2 + (3/2) y · x · 7 – (7/4) y -9/2 + (3/2) y · x · 10 + (7/2) y

  9. Fourier-Motzkin Elimination • Eliminate x and rearrange to get y · -36 y ¸ 4/3 y · 46/13 y ¸ -29/4 • Now eliminate y to get 4/3 · y · -36 4/3 · y · 46/13 -29/4 · y · -36 -29/4 · y · 46/13

  10. Fourier-Motzkin Elimination • Clearly we have inconsistency: 4/3 · -36 ) Reduced System has no solution ) Original System has no solution (“Safety”) • What if the reduced system has solutions? Does the original system have solutions too? The answer is Maybe!

  11. Fourier-Motzkin Elimination • What if the reduced system has solutions? Does the original system have solutions too? The answer is Maybe! • We chose l(y) · x · u(y) • What if there is a solution to l(y) · u(y) without an integer in between l(y) and u(y)?

  12. Fourier-Motzkin Elimination • Let’s see what each elimination does y x-Eliminated solution space Solution Space x

  13. y x Fourier-Motzkin Elimination • A false solution: The solution space is empty, but the projected space has integer solutions! 1

  14. Fourier-Motzkin Elimination Summary • Reduced System has no integer solution ) Original System has no integer solution • Converse untrue • Remark: Reduced System has rational solutions if and only if the original system has rational solutions

  15. Eliminating False Solutions We now want to eliminate false solutions of the reduced system Option 1: Reduction guarantee is made stronger (iff) Option 2: We do extra work after the Fourier Motzkin Elimination

  16. No False Solutions: Exact Elimination • A Fourier Motzkin Elimination step is exact if Reduced System has solution ) Original System has solution • Sufficient Condition: All coefficients of eliminated variable in upper or lower bound equations are 1 or -1.

  17. Removing False Solutions: Enumeration Assumption: Inexact Elimination • (-) Very expensive • (+) Also finds all solutions • Iterate using the bounds at each step • Suppose elimination order is x, then y. Then the loops go: for y = max(4/3,-29/4) to min(46/13,-36) for x = max(16-y, -9/2+(3/2)y) to min(7-(7/4)y, 10+(7/2)y) …

  18. Removing False Solutions: Dark Shadows Assumption: Inexact Elimination • Repeat with a different approximation x ¸ lx · u )l + 1 · u • Guarantee: If this approximation has integer solutions, so does the original • (+) Fast • (-) Not exact (May miss solutions)

  19. Removing False Solutions: Omega Test (Pugh, 1991) Assumption: Inexact Elimination • Tells exactly if solution exists or not • Fast in practice (claimed by the author) • Based entirely on integer operations (no rationals involved) • Requires treatment of equalities

  20. Dealing With Equalities • Given a constraint i ai xi = 0, we eliminate can any xk using this • We have to avoid rational coefficients • If ak2 {1,-1} for any k, eliminate xk • Naive approach: Substitute the following everywhere xk = -(1/ak) i  k ai xi and standardize again. This doesn’t work • Pugh’s first idea: An alternate approach

  21. Dealing With Equalities: Pugh’s Approach • Let k = argmini |ai| • Define (a mod b) = if (a mod b) < b/2 then (a mod b) else ((a mod b) – b) • Observation: -b/2 · (a mod b) < b/2

  22. Dealing With Equalities: Pugh’s Approach • Let m = |ak| + 1 • Define  by m = i (aimod m) xi • Eliminate xk using this equation. Observe that: (akmod m) = -sign(ak) 2 {1,-1} • This gives a system with  in place of xk, but with reduced coefficients in the equality • Soon some coefficient becomes 1 or -1 • Eliminate that variable

  23. The Omega Test • Assume we have eliminated all equalities • We perform the Fourier Motzkin Elimination and we find some solutions in the reduced space • We want to check it they are true solutions • Omega Test: An extension of the dark shadow algorithm

  24. Fourier-Motzkin Elimination: An Alternate Formulation • Assume standardized constraints: i ai xi¸ 0 Assume x0 = 1, all ai are integers • This constraint is a lower bound on xk iff ak > 0 • This constraint is an upper bound on xk iff ak < 0

  25. Fourier-Motzkin Elimination: An Alternate Formulation • Given a lower bound on xk i ai xi¸ 0 (ak¸ 0) and an upper bound on xk i ai’ xi¸ 0 (ak’· 0) • Eliminate xk to get i  k ak ai’ xi¸ |ak ak’| xk¸i  k ak’ ai xi

  26. Alternate Dark Shadow • Original Formulation was: u ¸ xk¸ l • “Alternate” Formulation u = i  k akai’xi¸ |akak’|xk¸i  k ak’aixi = l • Original Dark Shadow: u ¸ 1+ l • “Alternate” Dark Shadow: i  k akai’xi¸ |akak’| + i  k ak’aixi

  27. The Omega Test • But we can miss solutions. Why? • Because we added a huge term |akak’| • We said u ¸ |akak’| + l We might have needed u = j + l where 0 · j < |akak’|

  28. The Omega Test • Pugh’s second idea: Make that term j smaller • This never creates a false solution: i  k akai’xi¸ (|akak’| - |ak’| - ak + 1) + i  k ak’aixi u ¸ (|akak’| - |ak’| - ak + 1) + l • Will produce less false solutions

  29. The Omega Test • What we have so far: • Perform Fourier Motzkin Elimination: If answer is “no”, there are no solutions • If answer is “yes”, perform the Omega Test. If Omega test says “yes”, there is a solution • What if the answer to (1) is “yes” and the answer to (2) is “no” ?

  30. The Omega Test • If that happens, we cannot say anything • We checked with : u ¸ l (FM-Elimination) u ¸ (|akak’| - |ak’| - ak +1) + l (Omega Test) • But missed many constraints (We could use many possible j values) • Pugh’s idea: Search the whole possible space of constraints in between. Set: u = j + l • This space is bounded 0 · j · |akak’|-|ak’|-ak

  31. The Omega Test We do the following: • Reduce the value of this approximation term and iterate. Set u = j + l for j 2 {0,1, …, C} • Error may be in any (lower, upper) constraint pair ) iterate over all (l,u) pairs

  32. The Pre-Omega Test Naive algorithm Algorithm Check (S, xk) Precondition: Fourier Motzkin on (S,xk) said yes, Omega Test on (S,xk) said no for each (l,u) of xk in S for j = 0 to (|akak’| - |ak’| - ak) b à Test (S [ { i  k akai’xi = j + I  k ak’aixi }) if (b = true) {Conclude S has solutions; exit} end for S à S [ {i  k akai’xi¸ (|akak’| - |ak’| - ak +1) + I  k ak’aixi} end for Conclude S has no solution

  33. The Omega Test • Pugh’s “implicit” claim: Let m be the most negative coefficient of xk among all the upper bound constraints on xk. Say it occurs in constraint u. Then for some lower bound constraint l, the term above is too big for (l,u) ) Don’t have to iterate over the upper bounds

  34. The Omega Test Pugh’s algorithm: First Formulation Algorithm Check (S, xk) Precondition: Fourier Motzkin on (S,xk) said yes, Omega Test on (S,xk) said no Let m be the most negative coefficient of xk, among all upper bounds. Let it occur in i ai’xi¸ 0 for each lower bound l of xk in S for j = 0 to (|mak| - |m| - ak) b à Test (S [ { i  k akai’xi = j + I  k maixi }) if (b=true) {Conclude S has solutions; exit} end if end for S à S [ {i  k akai’xi¸ (|mak| - |m| - ak +1) + I  k ak’aixi} end for Conclude S has no solution

  35. The Omega Test Pugh’s algorithm: Pugh’s Formulation Algorithm Check (S, xk) Precondition: Fourier Motzkin on (S,xk) said yes, Omega Test on (S,xk) said no Let m be the most negative coefficient of xk, among all upper bounds. for each lower bound l of xk in S for j = 0 to b(|mak| - |m| - ak)/|m|c b à Test (S [ { akxk = j + I  k -aixi }) if (b=true) {Conclude S has solutions; exit} end if end for S à S [ {akxk¸ 1 + b(|mak| - |m| - ak +1)/|m|c + I  k-aixi} end for Conclude S has no solution

  36. The Omega Test Pragmatics: Choosing variables to Eliminate • If possible perform exact elimination • Then no iteration is needed • Else choose variable with smallest coefficients • This makes iterations smaller

  37. The Omega Test: Extensions • Finding all solutions • Simplification of linear programs Essential idea: Do not terminate after one solution

  38. Going Further: The 2 Variable Per Constraint problem • At most 2 variables per constraint • Efficient Algorithms known – O(mnlog n), n=number of variables, m=number of constraints • Work by: Charles Nelson Simon, King, Howe

More Related