<p>Let $m$ be the number of pigeons and $n$ be the number of holes.  Let the propositional variables $B_{i,0}$ ... $B_{i,log(n)}$ encode the binary representation of $j-1$ if the $i$th pigeon is put into the $j$th hole. (Example, if pigeon 1 were placed in hole 10, $j - 1 = 9$, which is binary 1001.  So $B_{1,3}$ = true, $B_{1,2}$ = false, $B_{1,1}$ = false and $B_{1,0}$ = true.)</p>

<p>Enforce a particular ordering of the pigeons in the holes by requiring that the hole encoded by the $B_{i}$ variables is less than that of $B_{i+1}$.  The encodings are compared as you would expect:</p>

<p>$B_{i,log(n)}$ &lt; $B_{i+1,log(n)}$<br>
OR<br>
$B_{i,log(n)}$ = $B_{i+1,log(n)}$ AND $B_{i,log(n)-1}$ &lt; $B_{i+1,log(n)-1}$<br>
OR<br>
$B_{i,log(n)}$ = $B_{i+1,log(n)}$ AND $B_{i,log(n)-1}$ = $B_{i+1,log(n)-1}$ AND $B_{i,log(n)-2}$ &lt; $B_{i+1,log(n)-2}$<br>
OR<br>
...  </p>

<p>... following the pattern of allowing the most significant bits to be equivalent as long as the next bit to the right is less than that of the next pigeon.  There will be $O(log(n))$ conjunctions per comparator and $O(m)$ comparators, giving the expected $O(m * log(n))$ additional clauses.</p>

<p>The $B$ variable values must be implied by the $X_{i,j}$ values.  Each $B_{i,*}$ bit is implied by any one of a particular set of the $X_{i,j}$ variables being set.  Example: assuming $n = 16$, you would have:</p>

<p>$ExactlyOne(X_{1,9}, X_{1,10}, X_{1,11}, X_{1,12}, X_{1,13}, X_{1,14}, X_{1,15}, X_{1,16}, \overline{B_{1,3}})$</p>

<p>which forces $B_{1,3}$ true if pigeon 1 is placed in any of holes 9-16.  Otherwise $B_{1,3}$ is set false to satisfy the clause.  These clauses set the remaining $B_{i}$ bits.</p>

<p>$ExactlyOne(X_{1,5}, X_{1,6}, X_{1,7}, X_{1,8}, X_{1,13}, X_{1,14}, X_{1,15}, X_{1,16}, \overline{B_{1,2}})$
$ExactlyOne(X_{1,3}, X_{1,4}, X_{1,7}, X_{1,8}, X_{1,11}, X_{1,12}, X_{1,15}, X_{1,16}, \overline{B_{1,1}})$
$ExactlyOne(X_{1,2}, X_{1,4}, X_{1,6}, X_{1,8}, X_{1,10}, X_{1,12}, X_{1,14}, X_{1,16}, \overline{B_{1,0}})$</p>

<p>There will be $log(n)$ of these clauses for each pigeon.  Since there are $m$ pigeons, $m * log(n)$ clauses are added.</p>

CC BY-SA 3.0
2013-04-05T03:17:37.397Z
Thanks for your response! But aren't extra clauses required to enforce the binary encoding itself? Using your example with pigeon 1 being placed in hole 10, I think clauses are required to compel $X_{1,10} \to B_{1,3} \land \overline{B_{1,2}} \land \overline{B_{1,1}} \land B_{1,0}$. This expands to $log(n)$ clauses in CNF. And we need one for each $X_{i,j}$, resulting in $m*n$ growth again.
Andrew Lamoureux
CC BY-SA 3.0
2013-04-05T03:26:30.157Z
I'll edit the answer to address this.
Kyle Jones
CC BY-SA 3.0
2013-04-05T13:50:13.633Z
Using $ExactlyOne()$ to "compress" the verbose "if pigeon goes here, bits must be this" statements is just brilliant! Since this constraint is the subject of their paper, there's no doubt that your solution is what was omitted. Thanks Kyle!
Andrew Lamoureux
CC BY-SA 3.0
2013-04-04T22:14:54.350Z
2013-04-05T04:29:12.543Z
2013-04-05T04:29:12.543Z
Kyle Jones
<p>In the paper &quot;Efficient CNF Encoding for Selecting 1 from N Objects&quot;, the authors introduce their &quot;commander variable&quot; technique for encoding the constraint, and then talk about the pigeonhole problem.</p>
<p>Since my error may exist in lower-level understanding, let me declare what I think I know before posing the question:</p>
<blockquote>
<p>Let <span class="math-container">$m$</span> and <span class="math-container">$n$</span> be the number of pigeons and holes. The naive encoding uses a propositional variable <span class="math-container">$X_{i,j}$</span> that is true when the <span class="math-container">$i'th$</span> pigeon is to be put in the <span class="math-container">$j'th$</span> hole. The clause <span class="math-container">$ExactlyOne(X_{1,1}, X_{1,2}, ..., X_{1,n})$</span> enforces that pigeon 1 must occupy exactly one hole; identical clauses are added for the other pigeons. The clause <span class="math-container">$AtMostOne(X_{1,1}, X_{2,1}, ..., X_{m,1})$</span> enforces that no more than one pigeon occupies hole 1; identical clauses are added for the remaining holes.</p>
<p>When there are more pigeons than holes (m &gt; n), the problem is unsolvable (obvious to humans) but the SAT solver doesn't &quot;see&quot; this fact. When it can't find a way to place pigeons <span class="math-container">$1,2,3,..,m$</span> it will search an attempt with pigeons <span class="math-container">$2,1,3,...,m$</span>. It doesn't understand that the order of the pigeons is irrelevant. The paper, among others, calls this symmetry.</p>
<p>Instances where <span class="math-container">$m=n+1$</span> are used as a strenuous test of a SAT solver's ability to detect unsatisfiability.</p>
</blockquote>
<p>The paper proposes to break the symmetry by enforcing order on pigeons. Pigeon <span class="math-container">$i$</span> must be placed in a hole in front of the hole of pigeon <span class="math-container">$i+1$</span> (i.e., the pigeon in hole <span class="math-container">$j$</span> must have a smaller number than of the pigeon in hole <span class="math-container">$j+1$</span>). It then disappointingly says, &quot;Due to space limitations, we do not explicitly describe in detail the canonical-ordering encoding, but the number of clauses generated is of order <span class="math-container">$O(n*log(n))$</span>&quot;.</p>
<p>So my question is: what did they do to get these results?</p>
<p>I want to treat the variables <span class="math-container">$\{X_{1,1}, X_{2,1}, ..., X_{m,1}\}$</span> as string of bits that, numerically, identifies the choice of which pigeon went into hole 1, and so on. Follow this with <span class="math-container">$n-1$</span> comparators to enforce the paper's suggestion. My naive comparator construction, however, requires m clauses, one for each bit (of increasingly ugly size). Help! :)</p>

<cc.complexity-theory><sat><proof-complexity>
How do I use canonical ordering to reduce symmetry in the SAT encoding of the pigeonhole problem?
Andrew Lamoureux
# How do I use canonical ordering to reduce symmetry in the SAT encoding of the pigeonhole problem?

(Asked by: username_0 on 2013-04-03)

In the paper "Efficient CNF Encoding for Selecting 1 from N Objects", the authors introduce their "commander variable" technique for encoding the constraint, and then talk about the pigeonhole problem.

Since my error may exist in lower-level understanding, let me declare what I think I know before posing the question:

> Let $m$ and $n$ be the number of pigeons and holes. The naive encoding uses a propositional variable $X\_{i,j}$ that is true when the $i'th$ pigeon is to be put in the $j'th$ hole. The clause $ExactlyOne(X\_{1,1}, X\_{1,2}, ..., X\_{1,n})$ enforces that pigeon 1 must occupy exactly one hole; identical clauses are added for the other pigeons. The clause $AtMostOne(X\_{1,1}, X\_{2,1}, ..., X\_{m,1})$ enforces that no more than one pigeon occupies hole 1; identical clauses are added for the remaining holes.
>
> When there are more pigeons than holes (m > n), the problem is unsolvable (obvious to humans) but the SAT solver doesn't "see" this fact. When it can't find a way to place pigeons $1,2,3,..,m$ it will search an attempt with pigeons $2,1,3,...,m$. It doesn't understand that the order of the pigeons is irrelevant. The paper, among others, calls this symmetry.
>
> Instances where $m=n+1$ are used as a strenuous test of a SAT solver's ability to detect unsatisfiability.

The paper proposes to break the symmetry by enforcing order on pigeons. Pigeon $i$ must be placed in a hole in front of the hole of pigeon $i+1$ (i.e., the pigeon in hole $j$ must have a smaller number than of the pigeon in hole $j+1$). It then disappointingly says, "Due to space limitations, we do not explicitly describe in detail the canonical-ordering encoding, but the number of clauses generated is of order $O(n\*log(n))$".

So my question is: what did they do to get these results?

I want to treat the variables $\{X\_{1,1}, X\_{2,1}, ..., X\_{m,1}\}$ as string of bits that, numerically, identifies the choice of which pigeon went into hole 1, and so on. Follow this with $n-1$ comparators to enforce the paper's suggestion. My naive comparator construction, however, requires m clauses, one for each bit (of increasingly ugly size). Help! :)

**Tags:** cc.complexity-theory, sat, proof-complexity


---

## 1 answers

### Answer by username_1 on 2013-04-04. Score: 7 | Accepted answer

Let $m$ be the number of pigeons and $n$ be the number of holes. Let the propositional variables $B\_{i,0}$ ... $B\_{i,log(n)}$ encode the binary representation of $j-1$ if the $i$th pigeon is put into the $j$th hole. (Example, if pigeon 1 were placed in hole 10, $j - 1 = 9$, which is binary 1001. So $B\_{1,3}$ = true, $B\_{1,2}$ = false, $B\_{1,1}$ = false and $B\_{1,0}$ = true.)

Enforce a particular ordering of the pigeons in the holes by requiring that the hole encoded by the $B\_{i}$ variables is less than that of $B\_{i+1}$. The encodings are compared as you would expect:

$B\_{i,log(n)}$ < $B\_{i+1,log(n)}$  
OR  
$B\_{i,log(n)}$ = $B\_{i+1,log(n)}$ AND $B\_{i,log(n)-1}$ < $B\_{i+1,log(n)-1}$  
OR  
$B\_{i,log(n)}$ = $B\_{i+1,log(n)}$ AND $B\_{i,log(n)-1}$ = $B\_{i+1,log(n)-1}$ AND $B\_{i,log(n)-2}$ < $B\_{i+1,log(n)-2}$  
OR  
...

... following the pattern of allowing the most significant bits to be equivalent as long as the next bit to the right is less than that of the next pigeon. There will be $O(log(n))$ conjunctions per comparator and $O(m)$ comparators, giving the expected $O(m \* log(n))$ additional clauses.

The $B$ variable values must be implied by the $X\_{i,j}$ values. Each $B\_{i,\*}$ bit is implied by any one of a particular set of the $X\_{i,j}$ variables being set. Example: assuming $n = 16$, you would have:

$ExactlyOne(X\_{1,9}, X\_{1,10}, X\_{1,11}, X\_{1,12}, X\_{1,13}, X\_{1,14}, X\_{1,15}, X\_{1,16}, \overline{B\_{1,3}})$

which forces $B\_{1,3}$ true if pigeon 1 is placed in any of holes 9-16. Otherwise $B\_{1,3}$ is set false to satisfy the clause. These clauses set the remaining $B\_{i}$ bits.

$ExactlyOne(X\_{1,5}, X\_{1,6}, X\_{1,7}, X\_{1,8}, X\_{1,13}, X\_{1,14}, X\_{1,15}, X\_{1,16}, \overline{B\_{1,2}})$
$ExactlyOne(X\_{1,3}, X\_{1,4}, X\_{1,7}, X\_{1,8}, X\_{1,11}, X\_{1,12}, X\_{1,15}, X\_{1,16}, \overline{B\_{1,1}})$
$ExactlyOne(X\_{1,2}, X\_{1,4}, X\_{1,6}, X\_{1,8}, X\_{1,10}, X\_{1,12}, X\_{1,14}, X\_{1,16}, \overline{B\_{1,0}})$

There will be $log(n)$ of these clauses for each pigeon. Since there are $m$ pigeons, $m \* log(n)$ clauses are added.

> **Comments:**
> **username_0**: Thanks for your response! But aren't extra clauses required to enforce the binary encoding itself? Using your example with pigeon 1 being placed in hole 10, I think clauses are required to compel $X_{1,10} \to B_{1,3} \land \overline{B_{1,2}} \land \overline{B_{1,1}} \land B_{1,0}$. This expands to $log(n)$ clauses in CNF. And we need one for each $X_{i,j}$, resulting in $m*n$ growth again.  
> **username_1**: I'll edit the answer to address this.  
> **username_0**: Using $ExactlyOne()$ to "compress" the verbose "if pigeon goes here, bits must be this" statements is just brilliant! Since this constraint is the subject of their paper, there's no doubt that your solution is what was omitted. Thanks Kyle!  

---

