TAOCP 7.2.2.2 Exercise 99

In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values.

Section 7.2.2.2: Satisfiability

Exercise 99. [25] Th. Dekker devised the first correct mutual-exclusion protocol in 1965:

A0. Maybe go to A1. B0. Maybe go to B1.
A1. Set $a \leftarrow 1$, go to A2. B1. Set $b \leftarrow 1$, go to B2.
A2. If $b$ go to A3, else to A6. B2. If $a$ go to B3, else to B6.
A3. If $f$ go to A3, else to A4. B3. If $f$ go to B3, else to B4.
A4. Set $a \leftarrow 0$, go to A5. B4. Set $b \leftarrow 0$, go to B5.
A5. If $f$ go to A5, else to A1. B5. If $f$ go to B5, else to B1.
A6. Critical, go to A7. B6. Critical, go to B6.
A7. Set $f \leftarrow 1$, go to A8. B7. Set $f \leftarrow 0$, go to B8.
A8. Set $a \leftarrow 0$, go to A0. B8. Set $b \leftarrow 0$, go to B0.

Use bounded model checking to verify its correctness.

Verified: no
Solve time: 3m43s


Solution

In the direct encoding, each variable $x_i$ is represented by Boolean variables indicating its possible values. Write

$$ x_{i,j}=1\iff x_i=j, $$

where $0\le i<p$ and $1\le j\le d$ if the domain has size $d$. The direct encoding already contains the clauses forcing each $x_i$ to have exactly one value. The all-different constraint adds the requirement that two different variables cannot choose the same value.

For two distinct variables $x_i$ and $x_k$, and for any value $j$, the assignment

$$ x_{i,j}=x_{k,j}=1 $$

must be forbidden. The corresponding clause is

$$ \bar{x}{i,j}\vee \bar{x}{k,j}. $$

Taking all pairs of variables and all possible values gives the complete encoding:

$$ \bigwedge_{0\le i<k<p}\ \bigwedge_{1\le j\le d} (\bar{x}{i,j}\vee\bar{x}{k,j}). $$

These clauses are sufficient. Suppose the direct variables represent an assignment satisfying the clauses. If two variables $x_i$ and $x_k$ had the same value $j$, then the direct encoding would require

$$ x_{i,j}=1,\qquad x_{k,j}=1. $$

The clause

$$ \bar{x}{i,j}\vee\bar{x}{k,j} $$

would then be false, contradicting satisfiability. Hence no two variables receive the same value.

They are also necessary. Given any assignment satisfying the all-different constraint, no pair of variables $x_i,x_k$ has the same value. Therefore, for every $j$, at least one of $x_{i,j}$ and $x_{k,j}$ is false, so every clause

$$ \bar{x}{i,j}\vee\bar{x}{k,j} $$

is satisfied.

Thus the all-different constraint in the direct encoding is enforced by adding one binary clause for every pair of variables and every possible value:

$$ \boxed{\bar{x}{i,j}\vee\bar{x}{k,j}\qquad (0\le i<k<p,\ 1\le j\le d).} $$

This completes the proof. ∎