Bradley, Manna. The Calculus of Computation, Springer, 2007
.pdf190 |
7 Quantified Linear Arithmetic |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
a1 |
|
|
|
|
a2 |
|
|
|
|
|
|
(a) |
|
• |
|
|
• |
|
|
• |
|
|
|
• |
|
◦ |
|
|
◦ |
|
◦ |
|
|
|
|||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||||||||||||
|
|
|
|
|
|
|
b |
|
|
|
|
|
|
|
|
|
a1 |
|
|
|
|
a2 |
|
|
|
|
||||
|
(b) |
|
◦ |
|
|
• |
|
| |
• |
|
|
|
• |
|
◦ |
|
◦ |
|
◦ |
|
|
|||||||||
|
|
|
|
|
|
|
|
|
|
|||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
a1 |
|
|
b a2 |
|
|
|
|
|||
|
(c) |
|
|
|
◦ |
|
|
◦ |
|
|
◦ |
|
|
|
◦ |
|
◦ |
|
◦ |
|◦ |
|
|||||||||
|
|
|
|
|
|
|
|
|
|
|
|
Fig. 7.1. (a) Left infinite projection (b) δ-interval (c) false
However, according to the periodicity rule, there exists a satisfying integer n′ within the δ-interval to the right of b .
Figure 7.1 illustrates several situations when a, b, c, and d terms are constant. Circles represent points that satisfy the divides constraints; solid circles in particular represent satisfying points. Figure 7.1(a) illustrates a formula x < a1 x < a2 δ | x: each left-pointing triangle represents a x < ai literal. The left infinite projection is satisfied. Figure 7.1(b) illustrates an additional x > b literal; now, the δ-interval following the right-pointing triangle at b is searched. It contains a satisfying point. Finally, b > a1 in Figure 7.1(c), so the δ-interval does not contain a satisfying point.
c
Example 7.7. Consider ΣZ -formula
x. 3x − 2y + 1 > −y 2x − 6 < z 4 | 5x + 1 . |
|
| |
{z } |
|
F [x] |
After Step 3, we have |
|
x. 2x < z + 6 y − 1 < 3x 4 | 5x + 1 . |
|
| |
{z } |
F3[x]
Collecting coe cients of x in Step 4, we find
δ′ = lcm{2, 3, 5} = 30 .
Multiplying when necessary, we rewrite the formula so that 30 is the coe cient of every occurrence of x:
x. 30x < 15z + 90 10y − 10 < 30x 24 | 30x + 6 .
Replacing 30x with fresh x′ and conjoining a divides atom completes Step 4:
x′. x′ < 15z + 90 10y − 10 < x′ 24 | x′ + 6 30 | x′ . |
|
| |
{z } |
F4[x′]
For Step 5, construct the left infinite projection
F−∞[x] : 24 | x′ + 6 30 | x′ ,
7.2 Quantifier Elimination over Integers |
191 |
which simplifies to . Compute
δ = lcm{24, 30} = 120
and
B = {10y − 10} .
Then replacing x′ |
by 10y − 10 + j in F4[x′] produces |
|
||||||||||||
|
j=1 |
|
24 |
|
10y |
|
10 + j + 6 |
|
30 |
−10y |
10 +−j |
|||
|
120 |
|
|
|
| |
− |
|
|
|
|
| |
− |
|
|
|
_ |
|
|
|
|
10y |
10 + j |
|||||||
|
F5 : |
10y − 10 + j < 15z + 90 |
|
10 < 10y |
||||||||||
which simplifies to |
|
|
|
|
|
30 10y + j 10 . |
|
|||||||
|
F5 : j=1 |
|
24 10y + j 4 |
|
||||||||||
|
120 |
|
|
|
| |
|
|
− |
|
| |
|
− |
|
|
|
_ |
|
|
|
|
|
|
|||||||
|
|
10y + j < 15z + 100 |
0 < j |
|
|
|
||||||||
5 |
|
|
|
|
|
c |
|
|
|
|
|
|
|
|
F |
is quantifier-free and TZ |
-equivalent to |
x. F [x]. |
|
|
Example 7.8. Consider again the formula defining the set of even integers:
x. 2x = y .
| {z }
F [x]
Rewriting according to Steps 2 and 3 produces
x. y − 1 < 2x 2x < y + 1 .
Then
δ′ = lcm{2, 2} = 2 ,
so Step 4 completes with
x′. y − 1 < x′ x′ < y + 1 2 | x′ . |
|
| |
{z } |
F4[x′]
Computing the left infinite projection F−∞ produces , as F4[x′] contains a
(B)literal as a conjunct. However,
δ= lcm{2} = 2
and
B = {y − 1} ,
so
192 |
7 Quantified Linear Arithmetic |
|
|
|
2 |
|
|
F5 : |
(y − 1 < y − 1 + j y − 1 + j < y + 1 2 | y − 1 + j) . |
|
|
|
j=1 |
|
|
Simplifying, we find |
|
|
|
|
2 |
|
|
F5 : |
(0 < j j < 2 2 | y + j − 1) , |
|
|
|
j=1 |
|
|
and then |
|
|
|
F5 : |
2 | y , |
|
|
which is quantifier-free and TZ-equivalent to x. F [x]. |
|
||
Example 7.9. Consider the formula |
|
||
|
|
c |
|
x. (3x + 1 < 10 7x − 6 > 7) 2 | x . |
|
||
|
F [x] |
|
|
|
| {z } |
|
|
Rewriting to isolate x terms produces |
|
||
x. (3x < 9 13 < 7x) 2 | x , |
|
||
so |
|
|
|
δ′ = lcm{3, 7} = 21 . |
|
|
|
After multiplying coe cients by proper constants, |
|
||
x. (21x < 63 39 < 21x) 42 | 21x , |
|
||
we replace 21x by x′: |
|
|
|
x′. (x′ < 63 39 < x′) 42 | x′ 21 | x′ . |
|
||
|
F4 [x′] |
|
|
|
| |
{z } |
|
Then
F−∞[x′] : ( ) 42 | x′ 21 | x′ , or, simplifying,
F−∞[x′] : 42 | x′ 21 | x′ .
Finally,
δ = lcm{21, 42} = 42
7.2 Quantifier Elimination over Integers |
193 |
and
B = {39} ,
so
|
42 |
|
(42 | j 21 | j) |
F5 : |
j=1 |
42 |
|
|
((39 + j < 63 39 < 39 + j) 42 | 39 + j 21 | 39 + j) . |
|
j=1 |
Since 42 | 42 and 21 | 42, the left main disjunct simplifies to , so that x. F [x]
c |
|
|
c Z |
|
|
|
|
|
|
|
|
is TZ-equivalent to . Thus, F is TZ |
-valid. |
|
|
|
|
|
|
||||
|
|
|
Z-c |
|
|
|
x. F [x] in which F is quantifier- |
||||
Theorem 7.10 (Correct). Given Σ -formula |
|
||||||||||
free, Cooper’s method returns a T equivalent quantifier-free formula. |
|
||||||||||
Proof. |
|
|
the first four steps produce formula F |
|
|||||||
|
The transformations of |
c |
|
|
|
|
|
|
4 |
. By |
|
x. F [x] |
x. F4[x] . c |
|
|
|
|
|
|
|
|
|
|
inspection, we assert that in TZ |
|
|
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
c |
|
|
|
δ |
δ |
|
|
4 |
|
|
5 |
|
|
The focus of the proof is to prove that |
x. F [x] |
F |
|
in TZ: |
|
||||||
x. F4[x] F−∞[j] |
|
_ |
F4[b + j] . |
|
|
|
|||||
|
|
j=1 |
j=1 b B |
|
|
|
|
|
|
|
We accomplish the proof in two steps.
1.F5 x. F4[x]: We assume the existence of an interpretation I such that I |= F5 and prove that I |= x. F4[x].
2.x. F4[x] F5: We assume the existence of an interpretation I such that I |= x. F4[x] and prove that I |= F5.
Assume then that I |= F5, so that one of the disjuncts of F5 is true under I. If one of the second set of disjuncts is true, say F4[b + j ], then
I {x 7→b + j } |= F4[x]
I |= x. F4[x] .
Otherwise, one of the first set of disjuncts is true, so for some j [1, δ], I {x 7→j } |= F−∞[x]. By construction of F−∞, there is some λ > 0 such that I {x 7→j − λδ} |= F4[x]. That is, there is some j − λδ that is so small that the inequality literals of F4 evaluate under I {x 7→j − λδ} exactly as in the construction of F−∞. Thus, I |= x. F4[x] in this case as well.
For the other direction, assume that I |= x. F4[x]. Thus, some n Z exists such that I {x 7→n} |= F4[x]. If for some b B and j [1, δ],
194 7 Quantified Linear Arithmetic
I |= n = b + j , then I |= F4[b + j ]. As F4[b + j ] is a disjunct of F5,
I |= F5.
Otherwise, consider whether I {x 7→n − δ} |= F4[x]. If not, then one of the (B) literals, say b < x for some b B, of F4 becomes false under I in the transition from n to n − δ. But then I |= n = b + j for some j [1, δ], contradicting our assumption that n is not equal to some b + j . Hence, it must be the case that I {x 7→n − δ} |= F4[x].
By induction using this argument, we find that I {x 7→n − λδ} |= F4[x] for all λ > 0. For some λ, n − λδ becomes so small that
I {x 7→n − λδ} |= F4[x] ↔ F−∞[x] , so
I {x 7→n − λδ} |= F−∞[x] .
That is, n − λδ is so small that the inequality literals of F4 evaluate under I {x 7→n − λδ} exactly as in the construction of F−∞. Now, since F−∞
contains only divides literals, we can choose a µ such that n |
− |
λδ + µδ |
|
[1, δ]. |
Let j = n − λδ + µδ. Then I |= F−∞[j ], so that I |= F5. |
|
|
7.2.3 A Symmetric Elimination
The construction in Step 5 was biased to the left. We can just as easily define a right elimination. Construct the right infinite projection F+∞[x′] from F4[x′] by replacing
(A) literals x′ < a by
and
(B) literals b < x′ by .
The idea is that very large numbers (the right side of the “number line”) satisfy (B) literals but not (A) literals.
Then define δ as before, but now define A as the set of a terms appearing in (A) literals. Construct
δ |
δ |
_ |
F5 : F+∞[−j] |
|
|
|
F4[a − j] . |
|
j=1 |
j=1 a A |
Now, instead of choosing the left or right elimination (corresponding to the left or right infinite projections, respectively) arbitrarily, choose the elimination according to the number of (A) and (B) literals. If there are fewer (A) literals than (B) literals, choose the right elimination; otherwise, choose the left elimination. This heuristic minimizes the number of disjuncts in the resulting formula F5.
|
7.2 Quantifier Elimination over Integers |
195 |
Example 7.11. In the formula |
|
|
F : x. (x < 13 x > 15) |
x < y , |
|
there are two (A) literals but |
only one (B) literal. Hence, choose the left |
|
infinite projection to produce fewer disjuncts. |
|
7.2.4 Eliminating Blocks of Quantifiers
Consider a formula with a block of quantifiers: x1. · · · xn. F [x1, . . . , xn], where F is quantifier-free. Eliminating xn produces a formula of the form
x1. · · · xn−1.
G1 |
: |
δ |
|
|
δ |
_ |
|
|
|
|
|||
F−∞[x1 |
, . . . , xn−1, j] |
|
F4[x1, . . . , xn−1, b + j] . |
|||
|
|
|
||||
|
|
j=1 |
|
|
j=1 b B |
Disjunction and existential quantification commute, so we can rewrite G1 as
Wδ
j=1 x1. · · · xn−1. F−∞[x1, . . . , xn−1, j]
G2 : |
δ |
_ |
|
||
|
x1. · · · xn−1. F4[x1, . . . , xn−1, b + j] |
j=1 b B
and continue the elimination on each disjunct.
This optimization can be taken one step further. Rather than expanding the disjuncts over the iterator j, treat j as a free variable during the subsequent eliminations. Then only 1 + |B| formulae need be examined during the next
phase: the formula x1. · · · xn−1. F−∞[x1, . . . , xn−1, j] and, for each b B, the formula x1. · · · xn−1. F4[x1, . . . , xn−1, b + j].
Example 7.12. Consider the formula
y. x. x < −2 1 − 5y < x 1 + y < 13x . |
|||
| |
F [{z |
] |
} |
|
x,y |
|
|
At Step 3,
δ′ = lcm{1, 13} = 13 ,
producing
y. x. 13x < −26 13 − 65y < 13x 1 + y < 13x
and then
y. x′. x′ < −26 13 − 65y < x′ 1 + y < x′ 13 | x′ .
196 7 Quantified Linear Arithmetic
With δ = lcm{13} = 13, A = {−26}, and B = {13 − 65y, 1 + y}, choose the right elimination to form:
y. |
13 |
26 j < 26 13 − 65y < −26 − j . |
|
j=1 |
|||
|
− 1−+ y <−−26 − j 13 | − 26 − j |
F+∞ simplifies to since F is a conjunction of both (A) and (B) literals. Now, instead of applying elimination to the entire subformula within the quantifier y, commute the quantifier and the disjunctions:
|
13 |
|
|
G : |
y. j > 0 39 + j < 65y y < −27 − j 13 | − j − 26 . |
|
|
|
j=1 |
|
|
Treating j as a free variable, apply QE to the subformula |
|
||
H : y. j > 0 39 + j < 65y y < −27 − j 13 | − j − 26 |
|
||
as usual. Then simplify to produce |
|
||
|
65 |
|
|
H′ : |
(k < −66j − 1794 13 | − j − 26 65 | 39 + j + k) , |
|
|
|
k=1 |
|
|
and replace H with H′ in G to produce the final formula |
|
||
13 |
65 |
|
|
|
(k < −66j − 1794 13 | − j − 26 65 | 39 + j + k) . |
|
|
j=1 k=1 |
|
|
|
This formula is TZ-equivalent to |
y, x. F [x, y]. |
|
|
|
c |
|
|
7.2.5 Solving Divides Constraints
Consider a formula of the form G : x1. · · · xn. F [x1, . . . , xn] without free
variables. Applying Cooper’s method with the block elimination optimization |
||
produces a quantifier-free TZ -equivalent formula of the form |
||
|
|
c |
δ1 |
· · · |
δn |
G′ : |
F ′[j1, . . . , jn] , |
|
j1 =1 |
|
jn =1 |
also without free variables. Expanding this formula by attempting every possible combination of values for j1, . . . , jn produces δ1 × δ2 × · · ·× δn disjuncts. This naive expansion is prohibitively expensive on even small problems.
Notice, however, that Step 4 introduces many divisibility literals as conjuncts. F5 has the form
7.2 Quantifier Elimination over Integers |
197 |
F5 : |
1 |
· · · |
n |
F ′′ |
i |
ki | ti[j1, . . . , jn]! , |
|
δ1 |
|
δ |
|
^ |
|
|
j =1 |
|
jn =1 |
|
|
where the ti are terms containing only constants and the ji iterators. Cooper realized that the conjuncts
^
D : ki | ti[j1, . . . , jn]
i
can be solved to reduce significantly the number of disjuncts to consider. There are two steps to solving divides constraints.
Step 1: Triangulate the Constraints
The following theorem provides a means for reducing the number of literals that contain some ji. It applies Euclid’s algorithm for computing the greatest common divisor (GCD) d of two integers m and n. Euclid’s algorithm also returns two integers p and q such that pm + qn = d.
Theorem 7.13. Consider two divisibility constraints
F : m | ax + b n | αx + β ,
where m, n Z+, a, α Z \ {0}, and b, β are terms not containing x. Let d, p, q = gcd(an, αm) be such that d is the GCD of an and αm, and p and q obey pan + qαm = d. Then F is satisfiable i
G : mn | dx + bpn + βqm d | αb − aβ
is satisfiable.
While both of the literals of F contain x, only one of the literals of G contains x. Therefore, we can apply this theorem to triangulate a set S of divisibility constraints. Let be a linear ordering of j1, . . . , jn. S is in triangular form if for each ji, at most one constraint of S contains ji as the least (according to ) free variable.
The triangularization algorithm proceeds iteratively. On one iteration, perform the following steps:
1. Choose from S two constraints
m | aji + b and n | αji + β
such that there is no jk ji that occurs in at least two divisibility constraints of S.
2. Apply Theorem 7.13 to produce the new constraints
mn | dji + bpn + βqm and d | αb − aβ .
Replace the original constraints with these constraints in S.
198 7 Quantified Linear Arithmetic
Example 7.14. Consider the divisibility constraints of Example 7.12:
13 | − j − 26 65 | 39 + j + k .
Fix the variable order j k. According to this order, only one constraint should have an occurrence of j, so apply Theorem 7.13:
m | aj + b |
n | αj + |
β |
|
|
|
|
|
13 | −j + −26 65 | j + k + 39 |
|
|
|
||||
Compute |
|
|
|
|
|
|
|
d, p, q = gcd(an, αm) |
so that |
|
pan + qαm = d |
|
|||
13, 0, 1 = gcd(−65, 13) |
0(−65) + 1(13) = 13 |
|
|||||
|
|
|
|||||
and construct |
|
|
|
|
|
|
|
mn | dj + |
bpn |
+ |
βqm |
|
d | αb − |
aβ |
|
845 | 13j + (−26)(0)(65) + (k + 39)13 |
13 | −26 − (−1)(k + 39) |
||||||
or, simplifying, |
|
|
|
|
|
|
|
845 | 13j + 13k + 507 |
13 | k + 13 . |
|
|
|
As desired, only one constraint has an occurrence of j. Additionally, the simplest constraint contains only k.
Step 2: Solve the Constraints
To solve the triangulated system of constraints S, consider the following theorem.
Theorem 7.15. Consider divisibility constraint
F : m | ax + b ,
for m Z+, a Z\{0}, and b a term not containing x. Let d, p, q = gcd(a, m) be such that d is the GCD of a and m, and p and q obey pa + qm = d. F is satisfiable i d | b. If it is satisfiable, its solutions are
pb |
|
λm |
for λ Z . |
x = − d |
+ |
d |
With S in triangular form, we need only solve the system recursively:
1. |
If S is empty, generate a disjunct according to the current values of |
|
j1, . . . , jn. |
2. |
Otherwise, choose from S a constraint |
F : m | aji + b
such that b is an integer. Apply Theorem 7.15 to F .
7.2 Quantifier Elimination over Integers |
199 |
3.If F is unsatisfiable, return.
4.Otherwise, instantiate the remaining constraints of S with each solution to ji within the range [1, δi], and recursively solve.
Example 7.16. Consider the divisibility constraints of Example 7.12:
13 | − j − 26 65 | 39 + j + k .
The system is already in triangular form for the variable order k j. To solve the first constraint
m |
| aj + |
b |
compute |
d, p, q = gcd(a, m) |
|||||
13 |
| −j + −26 |
|
|
|
1, −1, 0 = gcd(−1, 13) . |
||||
Does 1 | − 26? Yes, so the solutions are given by |
|||||||||
j = |
( 1) |
−26 |
+ λ 13 |
= |
− |
26 + 13λ for λ |
|
Z . |
|
|
|
− − |
1 |
1 |
|
|
|
Since j [1, 13], only λ = 3 is relevant, providing the solution j = 13. After substituting j = 13 into the second constraint, to solve
m |
| ak + b |
compute d, p, q |
= gcd(a, m) |
65 |
| k + 52 |
1, 1, 0 |
= gcd(1, 65) . |
Does 1 | 52? Yes, so the solutions are given by |
|||
|
52 |
65 |
for λ Z . |
k = −(1) 1 + λ 1 = −52 + 65λ |
Since k [1, 65], only λ = 1 is relevant, providing the solution k = 13. j = 13, k = 13 is the only solution to the divisibility constraints 13 | − j − 26 65 | 39 + j + k.
However, the additional conjunct
(k < −66j − 1794){j 7→13, k 7→13}
c
is not true, so the formula of Example 7.12 is TZ-equivalent to and is thus
c
TZ-unsatisfiable.
Alternatively, we could have enumerated all 13 × 65 = 845 possible disjuncts to discover that none of them simplifies to . In 844 of these disjuncts, at least one of the divisibility constraints is .
Solve the triangulated system of Example 7.14 with variable order j k, and verify that the solution is the same. The variable order used for triangulating the constraint system does not a ect the solutions.
Solving divisibility constraints significantly improves the performance of QE on purely existential and purely universal formulae. What about formulae