It isn’t that they can’t see the solution.
It is that they can’t see the problem.
— G. K. CHESTERTON, The Scandal of Father Brown (1935)
Notes on the Exercises
1. A moderately easy problem for a mathematically inclined reader.
2. They help teach you how to ask good questions.
3. See H. Poincaré, Rendiconti del Circolo Matematico di Palermo 18 (1904), 45–110; R. H. Bing, Annals of Math. (2) 68 (1958), 17–37; G. Perelman, arXiv:math/0211159 [math. DG ] (2002), 39 pages; 0303109 and 0307245 [math. DG ] (2003), 22+7 pages.
Mathematical Preliminaries Redux
1. (a) A beats B in 5+0+5+5+0+5 cases out of 36; B beats C in 4+2+4+4+2+4; C beats A in 2+2+2+6+2+6.
(b) The unique solution, without going to more than six spots per face, is
(c) A = { F m −2 × 1, F _m −1 × 4}, B = { F m__ × 3}, _C = { F m −1 × 2, F m −2 × 5} makes Pr ( C > A ) \= F m − 2 F m + 1 / F m 2 ; and we have F m −2 F m +1 \= F m −1 F m − (−1) m . [Similarly, with n faces and A = {⌊ n / ϕ 2 ⌋ × 1, ⌈ n / ϕ ⌉ × 4}, etc., the probabilities are 1/ ϕ −O(1/ n ). See R. P. Savage, Jr., AMM 101 (1994), 429–436. Additional properties of nontransitive dice have been explored by J. Buhler, R. Graham, and A. Hales, AMM 125 (2018), 387–399; M. Purcell, AMM 130 (2023), 421–436.]
2. Let Pr( A > B ) = 𝓐, Pr( B > C ) = 𝓑, Pr( C > A ) = 𝓒. We can assume that no x appears on more than one die; if it did, we could replace it by x + in A and x − in C (for small enough ∊) without decreasing 𝓐, 𝓑, or 𝓒. So we can list the face elements in nondecreasing order and replace each one by the name of its die; for example, the previous answer (b) yields CBBBAAAAACCCCCBBBA . Clearly AB, BC , and CA are never consecutive in an optimal arrangement of this kind: BA is always better than AB .
Suppose the sequence is C c 1 B b 1 A a 1 ... C c k B b k A a k where c i > 0 for 1 ≤ i ≤ k and b i , a i > 0 for 1 ≤ i < k . Let α i = a i /( a 1 + ··· + a k ), β i = b i /( b 1 + ··· + b k ), γ i = c i /( c 1 + ··· + c k ); then 𝓐 = α 1 β 1 + α 2 ( β 1 + β 2 )+ ···, 𝓑 = β 1 γ 1 + β 2 ( γ 1 + γ 2 )+ ···, 𝓒 = γ 2 α 1 + γ 3 ( α 1 + α 2 )+ ···. We will show that min(𝓐, 𝓑, 𝓒) ≤ 1/ ϕ when the α ’s, β ’s, and γ ’s are nonnegative real numbers; then it is < 1/ ϕ when they are rational.
The key idea is that we can assume k ≤ 2 and α 2 = 0. Otherwise the following transformation leads to a shorter array without decreasing 𝓐, 𝓑, or 𝓒:
γ 2 ′ \= λ γ 2 , γ 1 ′ \= γ 1 + γ 2 − γ 2 ′ , β 2 ′ \= λ β 2 , β 1 ′ \= β 1 + β 2 − β 2 ′ , α 1 ′ \= α 1 / λ , α 2 ′ \= α 1 + α 2 − α 1 ′ .
Indeed, 𝓐′ = 𝓐, 𝓒′ = 𝓒, and 𝓑′ − 𝓑 = (1 − λ )( β 1 − λβ 2 ) γ 2 , and we can choose λ thus:
Case 1: β 1 ≥ β 2 . Choose λ = α 1 /( α 1 + α 2 ), making α 2 ′ \= 0 .
Case 2: β 1 < β 2 and γ 1 / γ 2 ≤ β 1 / β 2 . Choose λ = 1 + γ 1 / γ 2 , making γ 1 ′ \= 0 .
Case 3: β 1 < β 2 and γ 1 / γ 2 > β 1 / β 2 . Choose λ = 1 + β 1 / β 2 , making β 1 ′ \= 0 .
Finally, then, 𝓐 = β 1 , 𝓑 = 1 − β 1 γ 2 , 𝓒 = γ 2 ; they can’t all be greater than 1/ ϕ .
[Similarly, with n dice, the asymptotic optimum probability p n satisfies p n \= α 2 ( n ) \= 1 − α 1 ( n − 1 ) α 2 ( n ) \= ⋅ ⋅ ⋅ \= 1 − α 1 ( 2 ) α 2 ( 3 ) \= α 1 ( 2 ) . One can show that f n (1 − p n ) = 0, where f n +1 ( x ) = f n ( x )− xf n −1 ( x ), f 0 ( x ) = 1, f 1 ( x ) = 1− x . Then f n ( x 2 ) is expressible as the Chebyshev polynomial x n + 1 U n + 1 ( 1 2 x ) ; and we have p n = 1−1/(4 cos 2 π /( n +2)). See Z. Usiskin, Annals of Mathematical Statistics 35 (1964), 857–862; S. Trybu la, Zastosowania Matematyki 8 (1965), 143–156; A. Komisarski, AMM 128 (2021), 423–434.]
3. Brute force (namely a program) finds eight solutions, of which the simplest is
all with respective probabilities 17 27 , 16 27 , 16 27 . [If
is also allowed, the unique solution
has the property that every roll has exactly one die below the average and two above, with each of A, B, C equally likely to be below; hence all three probabilities are 2/3. See J. Moraleda and D. G. Stork, College Mathematics Journal 43 (2012), 152–159.]
4. (a) The permutation (1 2 3 4)(5 6) takes A → B → C → D → A . So B versus C is like A versus B , etc. Also Pr( A beats C ) = Pr( C beats A ) = Pr( B beats D ) = Pr( D beats B ) \= 288 720 ; Pr( A and C tie) = Pr( B and D tie) \= 144 720 .
(b) Assume by symmetry the players are A, B, C . Then the bingoers are ( A, B, C, AB, AC, BC, ABC ) with respective probabilities (168, 216, 168, 48, 72, 36, 12)/720.
(c) It’s ( A, AB, AC, ABC, ABCD ) with probabilities (120, 24, 48, 12, 0)/720.
5. (a) If A k = 1001 with probability .99, otherwise A k = 0, but B k = 1000 always, then P 1000 = .99 1000 ≈ .000043. (This example gives the smallest possible P 1000 , because Pr ( ( A 1 − B 1 ) + ⋅ ⋅ ⋅ + ( A n − B n ) > 0 ≥ Pr ( [ A 1 > B 1 ] ... [ A n > B n ] ) \= P 1 n . )
(b) Let E = q 0 + q 2 + q 4 + ··· ≈ 0.67915 be the probability that B = 0. Then Pr ( A > B ) \= Σ k \= 0 ∞ q 2 k ( E + Σ j \= 0 k − 1 q 2 j + 1 ) ≈ .47402 ; Pr ( A < B ) \= Σ k \= 0 ∞ q 2 k + 1 ( 1 − E + Σ j \= 0 k q 2 j ) ≈ .30807 ; and Pr( A = B ) = Pr( A = B = 0) = E (1 − E ) ≈ .21790 is also the probability that AB > 0.
(c) During the first n k rounds, the probability that either Alice or Bob has scored more than m k is at most n k ( q k +1 + q k +2 + ··· ) = O (2 − k ); and the probability that neither has ever scored m k is (1 − q k ) nk < exp(− q k n k ) = exp(−2 k / D ). Also m k > n k m k −1 when k > 1. Thus Alice “ quite surely” wins when k is even, but loses when k is odd, as k → ∞. [ The American Statistician 43 (1989), 277–278.]
6. The probability that X j = 1 is clearly p 1 = 1/( n −1); hence X j = 0 with probability p 0 = ( n − 2)/( n − 1). And the probability that X i = X j = 1 when i < j is p 1 2 . Thus (see exercise 20 ), ( X i , X j ) will equal (0, 1), (1, 0), or (0, 0) with the correct probabilities p 0 p 1 , p 1 p 0 , p 0 p 0 . But X i = X j = X k = 1 with probability 0 when i < j < k .
For 3-wise independence let Pr( X 1 ... X n = x 1 ... x n ) = a x 1+···+ xn /( n −2) 3 , where a 0 \= 2 ( n − 2 3 ) , a 1 \= ( n − 2 2 ) , a 3 = 1, otherwise a j = 0.
7. Let f m ( n ) \= Σ j \= 0 m ( n j ) ( − 1 ) j ( n + 1 − m ) m − j , and define probabilities ia a j f k−j ( n − j ) as in answer 6 . (In partiular, we have f 0 ( n ) = 1, f 1 ( n ) = 0, f 2 ( n ) \= ( n − 1 2 ) , f 3 ( n ) \= 2 ( n − 2 3 ) , f 4 ( n ) \= 3 ( n − 3 4 ) + ( n − 3 2 ) 2 .) This definition is valid if we can prove that f m ( n ) ≥ 0 for n ≥ m , because of the identity Σ j ( n j ) f m − j ( n − j ) \= ( n + 1 − m ) m .
To prove that inequality, Schulte-Geers notes (see CMath (5.19)) that f m ( n ) \= Σ k \= 0 m ( m − n k ) ( n − m ) m − k \= Σ k \= 0 m ( n − m − 1 + k k ) ( − 1 ) k ( n − m ) m − k ; these terms pair up nicely to yield Σ k \= 0 m − 1 k ( n − m − 1 + k k + 1 ) ( n − m ) m − k − 1 [ k e v e n ] + ( n − 1 m ) [ m even ] .
8. If 0 < k < n , the probability that k of the components have any particular setting is 1/2 k , because the remaining components have even parity as often as odd parity. So there’s ( n − 1)-wise independence, but not n -wise.
9. Give probability 1/2 to 0 ... 0 and 1 ... 1; all other vectors have probability 0.
10. If n > p we have X p +1 \= X 1 , so there’s no independence. Otherwise, if m < n ≤ p , there’s m -wise independence because any m vectors (1, j ,..., j m −1 ) are linearly independent modulo p (they’re columns of Vandermonde’s matrix, exercise 1.2.3–37); but the X ’s are dependent ( m + 1)-wise, because a polynomial of degree m cannot have m + 1 different roots. If m ≥ n and n ≤ p there is complete independence.
Instead of working mod p, we could use any finite field in this construction.
11. We can assume that n = 1, because ( X 1 + ··· + X n )/ n and ( X n +1 + ··· + X 2 n )/ n are independent random variables with the same discrete distribution. Then Pr ( | X 1 + X 2 − 2 α | ≤ 2| X 1 − α |) ≥ Pr(| X 1 − α| + | X 2 − α | ≤ 2| X 1 − α |) = Pr(| X 2 − α| ≤ | X 1 − α |) = (1 + Pr( X 1 = X 2 ))/2 > 1/2. [This exercise was suggested by T. M. Cover.]
12. Let w = Pr( A and B ), x \= Pr ( A and B ¯ ) , y = Pr( Ā and B ), z \= Pr ( A ¯ and B ¯ ) . All five statements are equivalent to wz > xy , or to | w x y z | > 0 , or to “ A and B are strictly positively correlated” (see exercise 61 ). [This exercise was suggested by E. Georgiadis.]
13. False in many cases. For example, take Pr ( A ¯ and B ¯ and C ¯ ) \= Pr ( A ¯ and B and C ¯ ) \= 0 , Pr( A and B and C ) = 2/7, and all other joint probabilities 1/7.
14. Induction on n . [ Philosophical Transactions 53 (1763), 370–418, proof of Prop. 6.]
15. If Pr( C ) > 0, this is the chain rule, conditional on C . But if Pr( C ) = 0, it’s false by our conventions, unless A and B are independent.
16. If and only if Pr ( A ¯ ∩ B ∩ C ) \= 0 ≠ Pr ( B ) or Pr ( A ¯ ∩ C ) \= 0
17. 4/51, because four of the cards other than Q ♠ are aces.
18. Since ( M − X )( X − m ) ≥ 0, we have ( M E X ) − (E X 2 ) + ( m E X ) − mM ≥ 0. [See C. Davis and R. Bhatia, AMM 107 (2000), 353–357, for generalizations.]
19. (a) The binary values of Pr( X n = 1) = E X n for n = 0, 1, 2, ... , are respectively (.0101010101010101 ... ) 2 , (.0011001100110011 ... ) 2 , (.0000111100001111 ... ) 2 , ... ; thus they’re the complemented reflections of the “ magic masks” 7.1.3–(47). The answer is therefore (2 2 n − 1)/(2 2 n + 1 − 1) = 1/(2 2 n + 1).
(b) Pr ( X 0 X 1 ... X n − 1 \= x 0 x 1 ... x n − 1 ) \= 2 ( x ¯ n − 1 ... x ¯ n − 1 ... x ¯ 1 x ¯ 0 ) 2 / ( 2 2 n − 1 ) can be “read off” from the magic masks by AND ing and complementing. [See E. Lukacs, Characteristic Functions (1960), 119, for related theory.]
(c) The infinite sum S is well defined because Pr( S = ∞) = 0. Its expectation E S \= Σ n \= 0 ∞ 1 / ( 2 2 n + 1 ) ≈ 0.59606 corresponds to the case z = 1/2 in answer 7.1.3– 41( c ). By independence, var ( S ) \= Σ n \= 0 ∞ var ( X n ) \= Σ n \= 0 ∞ 2 2 n / ( 2 2 n + 1 ) 2 ≈ 0.44148 .
(d) The parity number E R = (.0110100110010110 ... ) 2 has the decimal value
0.41245 40336 40107 59778 33613 68258 45528 30895−,
and can be shown to equal 1 2 − 1 4 P where P \= Π k \= 0 ∞ ( 1 − 1 / 2 2 k ) [R. W. Gosper and R. Schroeppel, MIT AI Laboratory Memo 239 (29 February 1972), Hack 122], which is transcendental [K. Mahler, Mathematische Annalen 101 (1929), 342–366; 103 (1930), 532]. (Furthermore it turns out that 1 / P − 1 / 2 \= Σ k \= 0 ∞ 1 / Π j \= 0 k − 1 ( 2 2 j − 1 ) .) Since R is binary, var( R ) = (E R )(1 − E R ) ≈ 0.242336.
(e) Zero (because π is irrational, hence p 0 + p 1 + ··· = ∞). However, if we ask the analogous question for Euler’s constant γ instead of π , nobody knows the answer.
(f) E Y n = 2E X n ; in fact, Pr( Y 0 Y 1 Y 2 ... = x 0 x 1 x 2 ... ), for any infinite string x 0 x 1 x 2 ... , is equal to 2 Pr( X 0 X 1 X 2 ... = x 0 x 1 x 2 ... ) mod 1, because we shift the binary representation one place to the left (and drop any carry). Thus in particular, E Y m Y n \= 2 E X m X n \= 1 2 E Y m E Y n when m ≠ n ; Y m and Y n are negatively correlated because covar ( Y m , Y n ) \= − 1 2 E Y m E Y n .
(g) Clearly E T = 2E S . Also E T 2 = 2E S 2 , because E Y m Y n = 2E X m X n for all m and n . So var( T ) = 2(var( S )+(E S ) 2 ) − (2 E S ) 2 = 2 var( S ) − 2(E S ) 2 ≈ 0.17237.
20. Let p j = E X j . We must prove, for example, that E( X 1 (1 − X 2 )(1 − X 3 ) X 4 ) = p 1 (1 − p 2 )(1 − p 3 ) p 4 when k ≥ 4. But this is E( X 1 X 4 − X 1 X 2 X 4 − X 1 X 3 X 4 + X 1 X 2 X 3 X 4 ) = p 1 p 4 − p 1 p 2 p 4 − p 1 p 3 p 4 + p 1 p 2 p 3 p 4 .
21. From the previous exercise we know that they can’t both be binary. Let X be binary and Y ternary, taking each of the values (0, 0), (0, 2), (1, 0), (1, 1), (1, 2) with probability 1/5. Then E XY = E X = 3/5 and E Y = 1; Pr( X = 0) Pr( Y = 1) = 2/25 ≠ 0.
22. By (8) we have Pr( A 1 ∪ ··· ∪ A n ) = E[ A 1 ∪ ··· ∪ A n ] = E max([ A 1 ],..., [ A n ]) ≤ E([ A 1 ]+ ··· +[ A n ]) = E[ A 1 ]+ ··· +E[ A n ] = Pr( A 1 )+ ··· +Pr( A n ).
23. The hinted probability is Pr( X s = 0 and X 1 + ··· + X s −1 \= s − r), so it equals ( s − 1 s − r ) p s − r ( 1 − p ) r . To get B m,n ( p ), sum it for r = n − m and n − m ≤ s ≤ n . [For an algebraic rather than probabilistic/combinatorial proof, see CMath , exercise 8.17.]
24. (a) The derivative of B m , n ( x ) \= Σ k \= 0 m ( n k ) x k ( 1 − x ) n − k is
B m , n ′ ( x ) \= Σ k \= 1 m ( n k ) k x k − 1 ( 1 − x ) n − k − Σ k \= 0 m ( n k ) ( n − k ) x k ( 1 − x ) n − 1 − k \= n ( Σ k \= 0 m − 1 ( n − 1 k ) x k ( 1 − x ) n − 1 − k − Σ k \= 0 m ( n − 1 k ) x k ( 1 − x ) n − 1 − k ) \= n ( n − 1 m ) x m ( 1 − x ) n − 1 − m .
[See Karl Pearson, Biometrika 16 (1924), 202–203.]
(b) The hint, which says that ∫ 0 a / ( a + b + 1 ) x a ( 1 − x ) b d x < ∫ a / ( a + b + 1 ) 1 x a ( 1 − x ) b d x when 0 ≤ a ≤ b , will prove that 1 − B m,n ( m / n ) < B m,n ( m / n ). If a > 0 it suffices to show that ∫ 0 a / ( a + b ) x a ( 1 − x ) b d x ≤ ∫ a / ( a + b ) 1 x a ( 1 − x ) b d x , because we have ∫ 0 a / ( a + b + 1 ) < ∫ 0 a / ( a + b ) ≤ ∫ a / ( a + b ) 1 < ∫ a / ( a + b + 1 ) 1 . Let x = ( a −∊)/( a + b ), and observe that ( a −∊) a ( b +∊) b is less than or equal to ( a + ∊) a ( b − ∊) b for 0 ≤ ∊ ≤ a , because the quantity
( a − ∈ a + ∈ ) a \= e a ( ln ( 1 − ∈ / a ) − ln ( 1 + ∈ / a ) ) \= exp ( − 2 ∈ ( 1 + ∈ 2 3 a 2 + ∈ 4 5 a 4 + ⋅ ⋅ ⋅ ) )
is nondecreasing when a increases.
(c) Let t k \= ( n k ) m k ( n − m ) n − k . When m ≥ n /2 we can show that 1 − B m , n ( m / n ) \= Σ k > m t k / n n < B m , n ( m / n ) \= Σ k \= 0 m t k / n n , because t m + d < t m +1− d for 1 ≤ d ≤ n − m . For if r d_ \= _t m + d / t m +1− d , we have r 1 = m /( m + 1) < 1; also
r d + 1 r d \= ( n − m + d ) ( n − m − d ) m 2 ( m + 1 + d ) ( m + 1 − d ) ( n − m ) 2 < 1 ,
because (( m +1) 2 − d 2 )( n − m ) 2 − (( n − m ) 2 − d 2 ) m 2 = (2 m +1)( n − m ) 2 +(2 m − n ) nd 2 .
[Peter Neumann proved in Wissenschaftliche Zeitschrift der Technischen Universit¨at Dresden 15 (1966), 223–226, that m is the median. The argument in part (c) is due to Nick Lord, in The Mathematical Gazette 94 (2010), 331–332. See also S. Janson, Statistics and Probability Letters 171 (2021) 109020, 10 pages.]
25. (a) ( ( n k ) ) − ( ( n k + 1 ) ) is ∑ p I q j ( q t /( n − k ) − p t /( k +1)), summed over all partitions of {1,..., n } into disjoint sets I ∪ J ∪ { t }, where | I | = k , | J | = n − k − 1, p I = ∏ i∊I p i , q J = ∏ j∊J q j . And q t /( n − k ) − p t /( k +1) ≥ 0 ⇔ p t ≤ ( k +1)/( n + 1).
(b) Given p 1 , ... , p n −1 , the quantity ( ( n k ) ) is maximized when p n = p , by (a). The same argument applies symmetrically to all indices j .
26. The inequality is equivalent to r n , k 2 ≥ r n , k − 1 r n , k + 1 , which was stated without proof on pages 242–245 of Newton’s Arithmetica Universalis (1707), then finally proved by Sylvester many years later [ Proc. London Math. Soc. 1 (1865), 1–16]. We have nr n,k = kp n r n −1 , k_ −1 +( _n − k ) q n r n −1 , k_ ; hence n 2 ( r n , k 2 − r n , k − 1 r n , k + 1 ) \= ( p n r n − 1 , k − 1 − q n r n − 1 , k ) 2 + ( k 2 − 1 ) p n 2 A + ( k − 1 ) ( n − 1 − k ) p n q n B + ( ( n − k ) 2 − 1 ) q n 2 C , where A \= r n − 1 , k − 1 2 − r n − 1 , k − 2 r n − 1 , k , B \= r n − 1 , k − 1 r n − 1 , k − r n − 1 , k − 2 r n − 1 , k + 1 and C \= r n − 1 , k 2 − r n − 1 , k − 1 r n − 1 , k + 1 are nonnegative, by induction on _n .
27. Σ k \= 0 m ( ( n k ) ) \= Σ k \= 0 m ( ( n − m − 1 + k k ) ) ( 1 − p n − m + k ) , by the same argument as before.
28. (a) ( ( n k ) ) \= ( ( n − 2 k ) ) A + ( ( n − 2 k − 1 ) ) B + ( ( n − 2 k − 2 ) ) C and E g ( X ) \= Σ k \= 0 n − 2 ( ( n − 2 k ) ) h k , where A = (1 − p n −1 )(1 − p n ), C = p n −1 p n , B = 1 − A − C , and h k = Ag ( k )+ Bg ( k +1)+ Cg ( k + 2). If the p j ’s aren’t all equal, we may assume that p n −1 < p < p n . Setting p n − 1 ′ \= p n − 1 + ∈ and p n ′ \= p n − ∈ , where ∊ = min( p n − p , p − p n −1 ), changes A, B, C to A ′ = A + δ , B ′ = B − 2 δ , C ′ = C + δ , where δ = ( p n − p )( p − p n −1 ); hence h k changes to h k ′ \= h k + δ ( g ( k ) − 2 g ( k + 1 ) + g ( k + 2 ) ) . Convex functions satisfy g ( k ) − 2 g ( k + 1) + g ( k + 2) ≥ 0, by (19) with x = k and y = k + 2; hence we can permute the p ’s and repeat this transformation until p j = p for 1 ≤ j ≤ n .
(b) Suppose E g ( X ) is maximum, and that r of the p ’s are 0 and s of them are 1. Let a satisfy ( n − r − s ) a + s = np and assume that 0 < p n −1 < a < p n < 1. As in part (a) we can write E g ( X ) = αA + βB + γC for some coefficients α, β, γ .
If α −2 β + γ > 0, the transformation in (a) (but with a in place of p ) would increase E g ( X ). And if α − 2 β + γ < 0, we could increase it with a similar transformation, using δ = − min( p n −1 , 1 − p n ). Therefore α − 2 β + γ = 0; and we can repeat the transformation of (a) until every p j is 0, 1, or a .
(c) Since Σ k \= 0 m ( ( n k ) ) \= 0 when s > m , we may assume that s ≤ m , hence r + s < n . For this function g ( k ) = [0 ≤ k ≤ m ] we have α − 2 β + γ \= ( ( n − 2 m ) ) − ( ( n − 2 m − 1 ) ) . This difference cannot be positive if the choice of { p 1 ,..., p n } is optimum; in particular we cannot have s = m . If r > 0 we can make p n −1 \= 0 and p n = a , so that ( ( n − 2 m ) ) \= ( n − r − s − 1 m − s ) a m − s ( 1 − a ) n − r − 1 − m and ( ( n − 2 m − 1 ) ) \= ( n − r − s − 1 m − 1 − s ) a m − 1 − s ( 1 − a ) n − r − m . But then the ratio ( ( n − 2 m ) ) / ( ( n − 2 m − 1 ) ) \= ( n − r − m ) a / ( ( m − s ) ( 1 − a ) ) exceeds 1; hence r = 0.
Similarly s > 0 we can set ( p n −1 , p n ) = ( a , 1), getting the ratio ( ( n − 2 m ) ) / ( ( n − 2 m − 1 ) ) \= ( n − r − m ) a / ( ( m − s + 1 ) ( 1 − a ) ) ≥ 1 . In this case ( ( n − 2 m ) ) \= ( ( n − 2 m − 1 ) ) if and only if np = m + 1; we can transform without changing E g ( X ), until s = 0 and each p j = p .
[ Reference: Annals of Mathematical Statistics 27 (1956), 713–721. The coefficients ( ( n k ) ) also have many other important properties; see exercise 7.2.1.5–63 and the survey by J. Pitman in J. Combinatorial Theory A77 (1997), 279–303.]
29. The result is obvious when m = 0 or n ; and there’s a direct proof when m = n − 1: B n −1, n ( p ) = 1 − p n ≥ (1 − p ) n /((1 − p ) n + p ) because p − np n + ( n − 1) p n +1 \= p (1 − p )(1 + p + ··· + p n −1 − p n −1 n ) ≥ 0. The result is also clear when p = 0 or 1.
If p = ( m + 1)/ n we have R m,n ( p ) = ((1 − p )( m + 1)/((1 − p ) m + 1)) n − m \= (( n − m − 1)/( n − m )) n − m . So if m > 0 and p ^ \= m / ( n − 1 ) , we can apply exercise 28(c) with p 1 \= ⋅ ⋅ ⋅ \= p n − 1 \= p ^ and p n = 1:
B m , n ( p ) ≥ Σ k \= 0 m ( ( n k ) ) \= Σ k \= 0 m ( n − 1 k − 1 ) p ^ k − 1 ( 1 − p ^ ) n − k \= B m − 1 , n − 1 ( p ^ ) .
When 1 ≤ m < n − 1, let Q m,n ( p ) = B m,n ( p ) − R m,n ( p ). The derivative
Q m , n ′ ( p ) \= ( n − m ) ( n m ) ( 1 − p ) n − m − 1 ( A − F ( p ) ) / ( ( 1 − p ) m + 1 ) n − m + 1 ,
where A \= ( m + 1 ) n − m / ( n m ) > 1 and F ( p ) = p m ((1 − p ) m +1) n − m +1 , begins positive at p = 0, eventually becomes negative but then is positive again at p = 1. (Notice that F (0) = 0, and F ( p ) increases dramatically until p = ( m +1)/( n + 1); then it decreases to F (1) = 1.) The facts that Q m , n ( m + 1 n ) ≥ 0 \= Q m , n ( 0 ) \= Q m , n ( 1 ) now complete the proof, because Q m , n ′ ( p ) changes sign only once in [ 0.. m + 1 n ] . [ Annals of Mathematical Statistics 36 (1965), 1272–1278.]
30. (a) Pr( X k = 0) = n /( n + 1); hence p = n n /( n +1) n > 1/ e ≈ 0.368.
(b) (Solution by J. H. Elton.) Let p km = Pr( X k = m ). Assume that these probabilities are fixed for 1 ≤ k < n , and let x m = p nm . Then x 0 = x 2 + 2 x 3 + 3 x 4 +··· ; we want to minimize p \= Σ m \= 1 ∞ ( A m + ( m − 1 ) A 0 ) x m in nonnegative variables x 1 , x 2 , ... , where A m = Pr( X 1 +···+ X n −1 ≤ n − m ), subject to the condition Σ m \= 1 ∞ m x m \= 1 . Since all coefficients of p are nonnegative, the minimum is achieved when all x m for m ≥ 1 are zero except for one value m = m n , which minimizes ( A m +( m − 1) A 0 )/ m . And m n ≤ n + 1, because A m = 0 whenever m > n . Similarly m 1 , ... , m n −1 also exist.
(c) (Solution by E. Schulte-Geers.) Letting m 1 = ··· = m n = t ≤ n + 1, we want to minimize B ⌊ n / t ⌋, n (1/ t ). The inequality of Samuels in exercise 29 implies that
B m , n ( p ) ≥ ( 1 − 1 f ( m , n , p ) + 1 ) n for p ≤ m + 1 n , where f ( m , n , p ) \= ( m + 1 ) ( 1 − p ) n ( n − m ) p ,
because we can set x = ((1 − p ) m +1)/((1 − p )( m + 1)) in the arithmetic–geometric mean inequality x n − m ≤ (( n − m ) x + m ) n / n n . Now 1/ t ≤ (⌊ n / t ⌋ + 1)/( n + 1) and f (⌊ n / t ⌋, n , 1/ t ) ≥ n ; hence B ⌊ n/t ⌋ ,n (1/ t ) ≥ n n /( n +1) n .
[Peter Winkler called this the “ gumball machine problem” in CACM 52 , 8 (August 2009), 104–105. J. H. Elton has verified that the joint distributions in (a) are optimum when n ≤ 20; see arXiv:0908.3528 [math.PR] (2009), 7 pages. Do those distributions in fact minimize p for all n ? Uriel Feige has conjectured more generally that we have Pr( X 1 + ··· + X n < n + 1/( e −1)) ≥ 1/ e whenever X 1 , ... , X n are independent nonnegative random variables with E X k ≤ 1; see SICOMP 35 (2006), 964–984.]
31. This result is immediate because Pr( f ([ A 1 ],..., [ A n ])) = E f ([ A 1 ],..., [ A n ]). But a more detailed, lower-level proof will be helpful with respect to exercise 32 .
Suppose, for example, that n = 4. The reliability polynomial is the sum of the reliability polynomials for the minterms of f ; so it suffices to show that the result is true for functions like x 1 ∧ x ¯ 2 ∧ x ¯ 3 ∧ x 4 \= x 1 ( 1 − x 2 ) ( 1 − x 3 ) x 4 . And it’s clear that Pr ( A 1 ∩ A ¯ 2 ∩ A ¯ 3 ∩ A 4 ) \= Pr ( A 1 ∩ A ¯ 2 ∩ A 4 ) − Pr ( A 1 ∩ A ¯ 2 ∩ A 3 ∩ A 4 ) \= π 14 − π 124 − π 134 + π 1234 . (See exercise 7.1.1–12; also recall the inclusion-exclusion principle.)
32. The 2 n minterm probabilities in the previous answer must all be nonnegative, and they must sum to 1. We’ve already stipulated that π ∅ = 1, so the sum-to-1 condition is automatically satisfied. (The condition stated in the exercise when I ⊆ J is necessary but not sufficient; for example, π 12 must be ≥ π 1 + π 2 − 1.)
33. The three events ( X, Y ) = (1, 0), (0, 1), (1, 1) occur with probabilities p, q, r , respectively. The value of E( X | Y ) is 1, r /( q + r ), r /( q + r ) in those cases. Hence the answer is pz + ( q + r ) z r /( q+r ). (This example demonstrates why univariate generating functions are not used in the study of conditional random variables such as E( X | Y ). But we do have the simple formula E ( X | Y \= k ) \= ( [ z k ] ∂ ∂ w G ( 1 , z ) ) / ( [ z k ] G ( 1 , z ) ) .)
34. The right-hand side is
Σ w E ( X | Y ) Pr ( w ) \= Σ w Pr ( w ) Σ w ′ X ( w ′ ) Pr ( w ′ ) [ Y ( w ′ ) \= Y ( w ) ] / Pr ( Y \= Y ( w ) ) \= Σ w Pr ( w ) Σ w ′ X ( w ′ ) Pr ( w ′ ) [ Y ( w ′ ) \= Y ( w ) ] / Pr ( Y \= Y ( w ′ ) ) \= Σ w ′ X ( w ′ ) Pr ( w ′ ) Σ w Pr ( w ) [ Y ( w ) \= Y ( w ′ ) ] / Pr ( Y \= Y ( w ′ ) ) .
35. Part (b) is false. If, for instance, X and Y are independent random bits and Z = X , we have E ( X | Y ) \= 1 2 and E ( 1 2 | Z ) \= 1 2 ≠ X \= E ( X | Z ) . The correct formula instead of (b) is
E ( E ( X | Y , Z ) | Z ) \= E ( X | Z ) . ( * )
This is (12) in the probability spaces conditioned by Z , and it is the crucial identity that underlies exercise 91 . Part (a) is true because it is the case Y = Z of (∗).
36. (a) f(X ); (b) E( f(Y ) g ( X )), generalizing (12). Proof: E( f ( Y )E( g(X ) | Y )) = Σ y f ( y )E( g ( X ) | Y = y ) Pr( Y = y ) = Σ x,y f(y)g(x )Pr( X = x, Y = y ) = E( f(Y)g(X )).
37. If we’re given the values of X 1 , ... , X k_ −1 , the value of _X _k is equally likely to be any of the _n + 1 − k values in {1,..., n }\{ X 1 ,..., X k_ −1 }. Hence its average value is (1 + ··· + _n − X 1 −···− X k_ −1 )/( _n + 1 − k ). We conclude that E( X k_ | _X 1 ,..., X k_ −1 ) = ( _n(n + 1)/2 − X 1 −···− X k_ −1 )/( _n + 1 − k ). [Incidentally, the sequence Z 0 , Z 1 , ... , defined by Z j_ \= ( _n + j ) X 1 +( n + j − 2) X 2 + ··· + ( n − j ) X j_ +1 − ( _j + 1) n ( n + 1)/2 for 0 ≤ j < n and Z j_ \= _Z n −1 for j ≥ n , is therefore a martingale.]
38. Let t m,n be the number of restricted growth strings of length m + n that begin with 01 ... ( m −1). (This is the number of set partitions of {1,..., m+n } in which each of {1,..., m } appears in a different block.) The generating function Σ n ≥0 t m,n z n / n ! turns out to be exp( e z − 1 + mz ); hence t m , n \= Σ k ϖ k ( n k ) m n − k .
Suppose M = max( X 1 ,..., X k_ −1 ) + 1. Then Pr( _X _k \= _j ) = t M,n − k / t M,n +1− k for 0 ≤ j < M , and t M +1 ,n − k / t M,n +1− k for j = M . Hence E ( X k | X 0 , ... , X k − 1 ) \= ( ( m 2 ) t M , n − k + M t M + 1 , n − k ) / t M , n + 1 − k .
39. (a) Since E( K | N = n ) = pn we have E( K | N ) = pN .
(b) Hence E K = E(E( K | N )) = E pN = pμ .
(c) Let p n k \= Pr ( N \= n , K \= k ) \= ( e − μ μ n / n ! ) × ( n k ) p k ( 1 − p ) n − k \= ( e − μ μ k p k / k ! ) × f ( n − k ) , where f(n ) = (1 − p ) n μ n / n !. Then E( N | K = k ) = Σ n np nk /Σ n p nk . Since nf ( n − k ) = kf ( n − k )+( n − k ) f ( n − k ) and nf(n ) = (1 − p )μ f(n − 1), the answer is k + (1 − p )μ; hence E( N | K ) = K + (1 − p )μ. [G. Grimmett and D. Stirzaker, Probability and Random Processes (Oxford, 1982), §3.7.]
40. If p = Pr( X > m ), clearly E X ≤ (1 − p ) m + pM . [We also get this result from (15), by taking S = { x | x ≤ m }, f(x) = M − x , s = M − m .]
41. (a) Convex when a ≥ 1 or a = 0; otherwise neither convex nor concave. (However, x a is concave when 0 < a < 1 and convex when a < 0, if we consider only positive values of x .) (b) Convex when n is even or n = 1; otherwise neither convex nor concave. (This function is ∫ 0 x t n − 1 e x − t d t / ( n − 1 ) ! , according to 1.2.11.3–(5); so f ″( x )/ x > 0 when n ≥ 3 is odd.) (c) Convex. (In fact f(|x|) is convex whenever f(z) has a power series with nonnegative coefficients, convergent for all z. ) (d) Convex, provided of course that we allow f to be infinite in the definition (19).
42. We can show by induction on n that f ( p 1 x 1 +···+ p n x n ) ≤ p 1 f ( x 1 )+···+ p n f(x n ), when p 1 , ... , p n ≥ 0 and p 1 + ··· + p n \= 1, as in exercise 6.2.2–36. The general result follows by taking limits as n → ∞. [The quantity p 1 x 1 + ··· + p n x n is called a “ convex combination” of { x 1 ,..., x n }; similarly, E X is a convex combination of X values. Jensen actually began his study by assuming only the case p \= q \= 1 2 of (19).]
43. f (E X ) = f (E(E( X | Y ))) ≤ E( f (E( X | Y ) )) ≤ E ( E f(X) | Y ) = E f(X ). [S. M. Ross, Probability Models for Computer Science (2002), Lemma 3.2.1.]
44. The function f(xy) is convex in y for any fixed x . Therefore g(y) = E f(Xy ) is convex in y : It’s a convex combination of convex functions. Also g(y) ≥ f (E Xy ) = f (0) = g (0) by (20). Hence 0 ≤ a ≤ b implies g (0) ≤ g(a) ≤ g(b) by convexity of g . [S. Boyd and L. Vandenberghe, Convex Optimization (2004), exercise 3.10.]
45. Pr( X > 0) = Pr(| X | ≥ 1); set m = 1 in (16).
46. E X 2 ≥ (E X ) 2 in any probability distribution, by Jensen’s inequality, because squaring is convex. We can also prove it directly, since E X 2 − (E X ) 2 = E( X − E X ) 2 .
47. We always have Y ≥ X and Y 2 ≤ X 2 . (Consequently (22) yields Pr( X > 0) = Pr( Y > 0) ≥ (E Y ) 2 /(E Y 2 ) ≥ (E X ) 2 /(E X 2 ) when E X ≥ 0.)
48. Pr ( a − X 1 − ⋅ ⋅ ⋅ − X n > 0 ) ≥ a 2 / ( a 2 + σ 1 2 + ... + σ n 2 ) , by exercise 47 . [This inequality was also known to Chebyshev; see J. Math. Pures et Appl. (2) 19 (1874), 157–160. In the special case n = 1 it is equivalent to “Cantelli’s inequality,”
Pr ( X ≥ E X + a ) ≤ var ( X ) / ( var ( X ) + a 2 ) , for a ≥ 0 ;
see Atti del Congresso Internazionale dei Matematici 6 (Bologna: 1928), 47–59, §6–§7.]
49. Pr( X = 0) = 1−Pr( X > 0) ≤ (E X 2 −(E X ) 2 )/ E X 2 ≤ (E X 2 −(E X ) 2 )/(E X ) 2 = (E X 2 )/(E X ) 2 − 1. [Some authors call this inequality the “ second moment principle,” but it is strictly weaker than (22).]
50. (a) Let Y j_ \= _X _j / _X if X j_ > 0, otherwise _Y _j \= 0. Then _Y 1 + ··· + Y m \= [ X > 0]. Hence Pr ( X > 0 ) \= Σ j \= 1 m E Y j ; and E Y j = E( X j / X | X j >0). Pr( X j >0). [This identity, which requires only that X j_ ≥ 0, is elementary yet nonlinear, so it apparently lay undiscovered for many years. See D. Aldous, _Discrete Math. 76 (1989), 168.]
(b) Since X j_ ∊ {0, 1}, we have Pr( _X _j > 0) = E X j__ \= _p _j ; and E( _X _j /X | _X _j > 0) = E( _X _j /X | X j \=1) = E(1 /X | X j \= 1) ≥ 1 / E( _X | X j \=1).
(c) Pr ( X J \= 1 ) \= Σ j \= 1 m Pr ( J \= j and X j \= 1 ) \= Σ j \= 1 m p j / m \= E X / m . Hence Pr( J = j | X j_ \= 1) = Pr( _J = j and X j_ \= 1) / Pr( X j \= 1) = ( _p _j /m ) / (E _X/m ) = p _j / E _X .
(d) Since J is independent we have t j_ \= E( _X | J = j and X j_ \= 1) = E( _X | X j \= 1).
(e) The right side is ( E X ) Σ j \= 1 m ( p j / E X ) / t j ≥ ( E X ) / Σ j \= 1 m ( p j / E X ) t j .
51. If g ( q 1 ,...,q m ) = 1 − f ( p 1 ,...,p m ) is the dual of f , where q j_ \= 1 − _p _j , a lower bound on _g gives an upper bound on f . For example, when f is x 1 x 2 x 3 ∨ x 2 x 3 x 4 ∨ x 4 x 5 , f ¯ is x ¯ 1 x ¯ 4 ∨ x ¯ 2 x ¯ 4 ∨ x ¯ 3 x ¯ 4 ∨ x ¯ 2 x ¯ 5 ∨ x ¯ 3 x ¯ 5 . So the inequality (24) gives g ( q 1 ,...,q 5 ) ≥ q 1 q 4 / (1 + q 2 + q 3 + q 2 q 5 + q 3 q 5 ) + q 2 q 4 / ( q 1 + 1 + q 3 + q 5 + q 3 q 5 ) + q 3 q 4 / ( q 1 + q 2 + 1 + q 2 q 5 + q 5 )+ q 2 q 5 / ( q 1 q 4 + q 4 + q 3 q 4 + 1 + q 3 ) + q 3 q 5 / ( q 1 q 4 + q 2 q 4 + q 4 + q 2 + 1). In particular, g ( . 1 ,...,. 1) > 0.039 and f (.9 ,...,. 9) < 0.961.
52. ( n k ) p k / Σ j \= 0 k ( k j ) ( n − k j ) p j .
53. f ( p 1 ,...,p 6 ) ≥ p 1 p 2 (1− p 3 ) / (1+ p 4 p 5 (1− p 6 ))+···+ p 6 p 1 (1− p 2 ) / (1+ p 3 p 4 (1− p 5 )). Monotonicity is not required when applying this method, nor need the implicants be prime. The result is exact when the implicants are disjoint.
54. (a) Pr ( X > 0 ) ≤ E X \= ( n 3 ) p 3 , because E X uvw \= p 3 for all u < v < w .
(b) Pr( X > 0) ≥ (E X ) 2 / (E X 2 ), where the numerator is the square of (a) and the denominator can be shown to be ( n 3 ) p 3 + 12 ( n 4 ) p 5 + 30 ( n 5 ) p 6 + 20 ( n 6 ) p 6 . For example, the expansion of X 2 contains 12 terms of the form X uvw X uvw ′ with u < v < w < w ′, and each of those terms has expected value p 5 .
55. A BDD for the corresponding Boolean function of ( 10 2 ) \= 45 variables has about 1.4 million nodes, and allows us to evaluate the true probability (1 − p ) 45 G ( p/ (1 − p )) exactly, where G ( z ) is the corresponding generating function (see exercise 7.1.4–25). The results are: (a) 30 / 37 ≈ .811 < 35165158461687 / 2 45 ≈ .999 < 15; (b) 10 / 109 ≈ .092 < 4180246784470862526910349589019919032987399 / (4 × 10 43 ) ≈ .105 < .12.
56. The upper bound is μ = λ 3 / 6; the lower bound divides this by 1 + μ . [The exact asymptotic value can be obtained using the principle of inclusion and exclusion and its “bracketing” property, as in Eq. 7.2.1.4–(48); the result is 1 − e −μ . See P. Erdős and A. Rényi, Magyar Tudományos Akadémia Mat. Kut. Int. Közl. 5 (1960), 17–61, §3.]
57. To compute E( X | X uvw \= 1) we sum Pr( X u ′ v ′ w ′ | X uvw \= 1) over all ( n 3 ) choices of u ′ < v ′ < w ′. If { u ′ ,v ′ ,w ′}∩{ u, v, w } has t elements, this probability is p 3− t ( t −1)/2 ; and there are ( 3 t ) ( n − 3 3 − t ) such cases. Consequently we get
Pr ( X > 0 ) ≥ ( n 3 ) p 3 / ( ( n − 3 3 ) p 3 + 3 ( n − 3 2 ) p 3 + 3 ( n − 3 1 ) p 2 + ( n − 3 0 ) p 0 ) .
[In this problem the lower bound turns out to be the same using either inequality; but the derivation here was easier.]
58. Pr ( X > 0 ) ≤ ( n k ) p k ( k − 1 ) / 2 . The lower bound, using the conditional expectation inequality as in the previous answer, divides this by Σ t \= 0 k ( k t ) ( n − k k − t ) p k ( k − 1 ) / 2 − t ( t − 1 ) / 2 .
59. (a) It suffices to prove that a 0 b 1 + a 1 b 0 ≤ c 0 d 1 + c 1 d 0 . The key observation is that c 1 d 0 ( c 0 d 1 + c 1 d 0 − a 0 b 1 − a 1 b 0 ) = ( c 1 d 0 − a 0 b 1 )( c 1 d 0 − a 1 b 0 )+( c 0 c 1 d 0 d 1 − a 0 a 1 b 0 b 1 ). Thus the result holds when c 1 d 0 ≠ 0; and if c 1 d 0 = 0 we have a 0 b 1 + a 1 b 0 = 0.
All four hypotheses hold with equality when a 0 = b 0 = d 0 = 0 and the other variables are 1, yet the conclusion is that 1 ≤ 2. Conversely, when b 1 = c 1 = 2 and the other variables are 1, we have a 1 b 0 < c 1 d 0 but conclude only that 6 ≤ 6.
(b) Let A l = Σ { a 2 j + l | 0 ≤ j < 2 n −1 } for l = 0 and l = 1, and define B l , C l , D l Similarly from b 2 j + l , c 2 j + l , d 2 j + l . The hypotheses for j mod 2 = l and k mod 2 = m prove that A l B m ≤ C l | m D l&m , by induction on n . Hence, by part (a), we have the desired inequality ( A 0 + A 1 )( B 0 + B 1 ) ≤ ( C 0 + C 1 )( D 0 + D 1 ). [This result is due to R. Ahlswede and D. E. Daykin, Zeitschrift für Wahrscheinlichkeitstheorie und verwandte Gebiete 43 (1978), 183–185, who stated it in the language of the next exercise.]
(c) Now let A n = a 0 + ··· + a 2 n −1 , and define B n , C n , D n similarly. If A ∞ B ∞ > C ∞ D ∞ , we’ll have A n B n > C ∞ D ∞ for some n . But C ∞ D ∞ ≥ C n D n , contra (b).
[In fact much more is true: We have Σ vj+vk=n a j b k ≤ Σ vj+vk=n c j d k , for all n . See A. Björner, Combinatorica 31 (2011), 151–164; D. Christofides, arXiv:0909.5137 [math.CO] (2009), 6 pages.]
60. (a) We can consider each set to be a subset of the nonnegative integers. Let α ¯ ( S ) \= α ( S ) [ S ∈ F ] , β ¯ ( S ) \= β ( S ) [ S ∈ G ] , γ ¯ ( S ) \= γ ( S ) [ S ∈ F ⊔ G ] , δ ¯ ( S ) \= δ ( S ) [ S ∈ F ⊓ G ] ; then α ¯ ( ℘ ) \= α ( F ) , β ¯ ( ℘ ) \= β ( G ) , γ ¯ ( ℘ ) \= γ ( F ⊔ G ) , and δ ¯ ( ℘ ) \= δ ( F ⊓ G ) , where ℘ is the family of all possible sub sets. Since any set S of nonnegative integers can be encoded in the usual way as the binary number s = Σ j∊S 2 j , the desired result follows from the four functions theorem if we let a s \= α ¯ ( S ) , b s \= β ¯ ( S ) , c s \= γ ¯ ( S ) , d s \= δ ¯ ( S ) .
(b) Let α( S ) = β ( S ) = γ ( S ) = δ( S ) = 1 for all sets ( S ).
61. (a) In the hinted case we can let α( S ) = f ( S )μ( S ), β( S ) = g ( S )μ( S ), γ( S ) = f ( S ) g ( S )μ( S ), δ( S ) = μ( S ); the four functions theorem yields the result. The general case follows because we have E ( f g ) − E ( f ) E ( g ) \= E ( f ^ g ^ ) − E ( f ^ ) E ( g ^ ) , where f ^ ( S ) \= f ( S ) − f ( ∅ ) and g ^ ( S ) \= g ( S ) − g ( ∅ ) . [See Commun. Math. Physics 22 (1971), 89–103.]
(b) Changing f ( S ) to θf ( S ) and g ( S ) to ϕg ( S ) changes E( fg ) − E( f )E( g ) to θ ϕ (E( fg ) − E( f )E( g )), for all real numbers θ and ϕ .
(c) If S and T are supported, then R = S ∩ T and U = S ∪ T are supported. Furthermore we can write S = R ∪ { s 1 ,..., s k } and T = R ∪ { t 1 ,..., t l } whre the sets S i = R ∪ { s 1 ,..., s i } and T j = R ∪ { t 1 ,..., t j } are supported, as are their unions U i,j = S i ∪ T j , for 0 ≤ i ≤ k and 0 ≤ j ≤ l . By (iii) we know that μ ( U i +1, j )/ μ ( U i,j ) ≤ μ ( U i +1, j +1 )/ μ ( U i,j+1 ) when 0 ≤ i < k and 0 ≤ j < l . Multiplying these inequalities for 0 ≤ i < k , we obtain μ ( U k,l )/ μ ( U 0,j ) ≤ μ ( U k,j+1 )/ μ ( U 0,j+1 ). Hence μ ( S )/ μ ( R ) = μ ( U k,0 )/ μ ( U 0,0 ) ≤ μ ( U k,l )/ μ ( U 0,l ) = μ ( U )/ μ ( T ).
(d) In fact, equality holds, because [ j ∊ S ] + [ j ∊ T ] = [ j ∊ S ∪ T ] + [ j ∊ S ∩ T ]. [ Note: Random variables with this distribution are often confusingly called “ Poisson trials,” a term that conflicts with the (quite different) Poisson distribution of exercise 39 .]
(e) Choose c in the following examples so that Σ S μ ( S ) = 1. In each case the supported sets are subsets of U = {1,..., m }. (i) Let μ ( S ) = cr 1 r 2 ··· r | S | , where 0 < r 1 ≤ ··· ≤ r m . (ii) Let μ ( S ) = cp j when S = {1,..., j } and 1 ≤ j ≤ m , otherwise μ ( S ) = 0. (If p 1 = ··· = p m in this case, the FKG inequality reduces to Chebyshev’s monotonic inequality of exercise 1.2.3–31.) (iii) Let
μ ( S ) = c μ_ 1 ( _S ∩ U 1 ) μ 2 ( S ∩ U 2 )... μ k ( S ∩ U k ),
where each μ j_ is a distribution on the subsets of _U j ⊆ U that satisfies (**). The subuniverses U 1 , . . . , U k needn’t be disjoint. (iv) Let μ ( S ) = ce − f(S ) , where f is a submodular set function on the supported subsets of U : f(S ∪ T ) + f(S ∩ T ) ≤ f(S ) + f(T ) whenever f(S) and f(T) are defined. (See Section 7.6.)
62. A Boolean function is essentially a set function whose values are 0 or 1. In general, under the Bernoulli distribution or any other distribution that satisfies the condition of exercise 61 , the FKG inequality implies that any monotone increasing Boolean function is positively correlated with any other monotone increasing Boolean function, but negatively correlated with any monotone decreasing Boolean function. In this case, f is monotone increasing but g is monotone decreasing: Adding an edge doesn’t disconnect a graph; deleting an edge doesn’t invalidate a 4-coloring.
(Notice that when f is a Boolean function, E f is the probability that f is true under the given distribution. The fact that covar( f, g ) ≤ 0 in such a case is equivalent to saying that the conditional probability Pr( f | g ) is ≤ Pr( f ).)
63. If ω is the event ‘ Z 0 = a and Z 1 = b ’, we have Z 0 ( ω ) = a and E( Z 1 | Z 0 )( ω ) = ( p a 1 + 2 p a 2 ) / ( p a 0 + p a 1 + p a 2 ). Hence p 01 = p 02 = p 20 = p 21 = 0, and p 10 = p 12 . Those conditions are necessary and sufficient for E( Z 1 | Z 0 ) = Z 0 .
64. (a) No. Consider the probability space consisting of just three events ( Z 0 ,Z 1 ,Z 2 ) = (0, 0, −2), (1, 0, 2), (1, 2, 2), each with probability 1/3. Call those events a , b , c . Then E( Z 1 | Z 0 )( a ) = 0 = Z 0 ( a ); E ( Z 1 | Z 0 ) ( b , c ) \= 1 2 ( 0 + 2 ) \= Z 0 ( b , c ) ; E ( Z 2 | Z 1 ) ( a , b ) \= 1 2 ( − 2 + 2 ) \= Z 1 ( a , b ) ; E( Z 2 | Z 1 )( c ) = 2 = Z 1 ( c ). But E( Z 2 | Z 0 , Z 1 )( a ) = −2 ≠ Z 1 ( a ).
(b) Yes. We have Σ z n +1 ( z n +1 − z n ) Pr( Z 0 = z 0 ,...,Z n +1 = z n +1 ) = 0 for all fixed ( z 0 ,...,z n ). Sum these to get Σ z n +1 ( z n +1 − z n )Pr( Z n \= z n ,Z n +1 = z n +1 ) = 0.
65. Observe first that E( Z n +1 | Z 0 ,...,Z k_ ) = E(E( _Z n +1 | Z 0 ,...,Z n ) | Z 0 ,...,Z k_ ) = E( _Z n | Z 0 ,...,Z k_ ) whenever _k < n . Thus E( Z m ( n +1) | Z 0 ,...,Z m ( n ) ) = Z m ( n ) for all n ≥ 0. Hence E( Z m ( n +1) | Z m (0) ,...,Z m ( n ) ) = Z m ( n ) , as in the previous exercise.
66. We need to specify the joint distribution of { Z 0 ,...,Z n }, and it’s not difficult to see that there is only one solution. Let p ( σ 1 ,...,σ n ) = Pr( Z 1 = σ 1 ,...,Z n \= σ n n ) when σ 1 , ... , σ n are each ±1. The martingale law p ( σ 1 ... σ n 1 ) ( n + 1 ) − p ( σ 1 ... σ n 1 ¯ ) ( n + 1 ) \= σ n p ( σ 1 ... σ n ) n \= σ n ( p ( σ 1 ... σ n 1 ) + p ( σ 1 ... σ n 1 ¯ ) ) n gives p ( σ 1 ...σ n +1 ) /p ( σ 1 ...σ n ) = (1 + 2 n [ σ n σ n +1 > 0]) / (2 n + 2). Hence we find that Pr ( Z 1 \= z 1 , ... , Z n \= z n ) \= ( Π k \= 1 n − 1 ( 1 + 2 k [ z k z k + 1 > 0 ] ) ) / ( 2 n n ! ) . When n = 3, for example, the eight possible cases z 1 z 2 z 3 \= 123 , 12 3 ¯ , ... , 1 ¯ 2 ¯ 3 ¯ occur with probabilities (15, 3, 1, 5, 5, 1, 3, 15) / 48.
67. (a) You “always” (with probability 1) make 2 n +1 − (1 + 2 + ··· +2 n ) = 1 dollar.
(b) Your total payments are X = X 0 + X 1 + ··· dollars, where X n \= 2 n with probability 2 − n , otherwise X n \= 0. So E X n \= 1, and E X = E X 0 + E X 1 + ··· = ∞.
(c) Let 〈 T n 〉 be a sequence of uniformly random bits; and define the fair sequence Y n \= ( − 1 ) T n 2 n T 0 ... T n − 1 , or Y n \= 0 if there is no n th bet. Then Z n \= Y 0 + ··· + Y n .
[The famous adventurer Casanova lost a fortune in 1754 using this strategy, which he called “the martingale” in his autobiography Histoire de ma vie . A similar betting scheme had been proposed by Nicolas Bernoulli (see P. R. de Montmort, Essay d’Analyse sur les Jeux de Hazard , second edition (1713), page 402); and the perplexities of (a) and (b) were studied by his cousin Daniel Bernoulli, whose important paper in Commentarii Academiæ Scientiarum Imperialis Petropolitanæ 5 (1731), 175–192, has caused this scenario to become known as the St. Petersburg paradox.]
68. (a) Now Z n \= Y 1 + ··· + Y n , where Y n \= ( − 1 ) T n [ N ≥ n ] . Again Pr( Z N \= 1) = 1.
(b) The generating function g ( z ) equals z (1 + g ( z ) 2 ) / 2, since he must win $2 if the first bet loses. Hence g ( z ) \= ( 1 − 1 − z 2 ) / z ; and the desired probability is [ z n ] g ( z ) = C ( n − 1) / 2 [ n odd] / 2 n , where C k is the Catalan number ( 2 k k ) / ( k + 1 ) .
(c) Pr ( N ≥ n ) \= [ z n ] ( 1 − z g ( z ) ) / ( 1 − z ) \= [ z n ] ( 1 + z ) / 1 − z 2 \= ( 2 ⌊ n / 2 ⌋ ⌊ n / 2 ⌋ ) / 2 ⌊ n / 2 ⌋ .
(d) E N = g ′(1) = ∞. (It’s also Σ n \= 1 ∞ Pr ( N ≥ n ) , where Pr ( N ≥ n ) ∼ 1 / π n .)
(e) Let p m \= Pr( Z n ≥ − m ) for all n ≥ 0. Clearly p 0 = 1 / 2 and p m \= (1 + p m − 1 p m ) / 2 for m > 0; this recurrence has the solution p m \= ( m + 1) / ( m + 2). So the answer is 1 / (( m + 1)( m + 2)); it’s another probability distribution with infinite mean.
(f) The generating function g m ( z ) for the number of times − m is hit satisfies g 0 ( z ) = z /(2− z ), g m ( z ) = (1+ g m −1 ( z ) g m ( z ))/2 for m > 0. So g m ( z ) = h m ( z )/ h m +1 ( z ) for m ≥ 0, where h m ( z ) = 2 m − (2 m − 1) z , and g m ′ ( 1 ) \= 2 . [A distribution with finite mean! See W. Feller, An Intro. to Probability Theory 2 , second edition (1971), XII.2.]
69. Each permutation of n elements corresponds to a configuration of n + 1 balls in the urn. For Method 1, the number of corresponding “red balls” is the position of element 1; for Method 2, it is the value in position 1. For example, we’d put 3 1 2 4 into node (2, 3) with respect to Method 1 but into (3, 2) with respect to Method 2. (In fact, Methods 1 and 2 construct permutations that are inverses of each other.)
70. Start with the permutation 1 2 ... ( c − 1) at the root, and use Method 1 of the previous exercise to generate all n !/( c −1)! permutations in which these elements retain that order. A permutation with j in position P j_ for 1 ≤ _j < c stands for P j_ − _P _j −1 balls of color _j , where P 0 = 0 and P c \= n + 1; for example, if c = 3, the permutation 3 1 4 2 would correspond to node (2, 2, 1). The resulting tuples ( A 1 ,..., A c )/( n + 1) then form a martingale for n = c , c +1, ... , uniformly distributed (for each n ) among all ( n c − 1 ) compositions of n + 1 into c positive parts.
[We can also use this setup to deal with Pólya’s two-color model when there are r red balls and b black balls at the beginning: Imagine r + b colors, then identify the first r of them with red. This model was first studied by D. Blackwell and D. Kendall, J. Applied Probability 1 (1964), 284–296.]
71. If m = r ′ − r and n = b ′ − b we must move m times to the right and n times to the left; there are ( m + n n ) such paths. Every path occurs with the same probability, because the numerators of the fractions are r ⋅ ( r + 1 ) ⋅ ... ⋅ ( r ′ − 1 ) ⋅ b ⋅ ( b + 1 ) ⋅ ... ⋅ ( b ′ − 1 ) \= r m ¯ b n ¯ in some order, and the denominators are ( r + b ) ⋅ ( r + b + 1 ) ⋅ ... ⋅ ( r ′ + b ′ − 1 ) \= ( r + b ) m + n ¯ .
The answer, ( m + n n ) r m ¯ b n ¯ / ( r + b ) m + n ¯ , reduces to 1/( r ′ + b ′ − 1) when r = b = 1.
72. Since all paths to ( r, b ) have the same probability, this expected value is the same as E( X 1 X 2 ... X m ), which is obviously 1/( m +1). (Thus the X ’s are very highly correlated: This expected value would be 1/2 m if they were independent. Notice that the probability of an event such as ( X 2 = 1, X 5 = 0, X 6 = 1) is E( X 2 (1 − X 5 ) X 6 ) = 1/3 − 1/4.)
[The far-reaching ramifications of such exchangeable random variables are surveyed in O. Kallenberg’s book Probabilistic Symmetries and Invariance Principles (2005).]
73. f ( r , n ) \= r ( n + 1 r ) Σ k ( r − 1 k ) ( − 1 ) k q n + 1 − r + k , where q k = a k /( k +1), by induction on r.
74. Node ( r, n + 2 − r) on level n is reached with probability 〈 n r − 1 〉 / n ! , proportional to an Eulerian number (see Section 5.1.3). (Indeed, we can associate the permutations of {1, ..., n +1} that have exactly r runs with this node, using Method 1 as in exercise 69 .)
Reference: Communications on Pure and Applied Mathematics 2 (1949), 59–70.
75. As before, let R n \= X 0 +···+ X n be the number of red balls at level n . Now we have E( X n_ +1 | _X 0 ,..., X n ) = 1 − R n /( n + 2). Hence E( R n +1 | R n ) = ( n +1) R n /( n + 2) + 1, and the definition Z n \= ( n +1) R n − ( n + 2)( n +1)/2 is a natural choice.
76. No. For example, let Z 0 = X , Z 0 ′ \= Y , and Z 1 \= Z 1 ′ \= X + Y , where X and Y are independent with E X = E Y = 0. Then E( Z 1 | Z 0 ) = Z 0 and E ( Z 1 ′ | Z 0 ′ ) \= Z 0 ′ , but E ( Z 1 + Z 1 ′ | Z 0 Z 0 ′ ) \= 2 ( Z 0 + Z 0 ′ ) . (On the other hand, if 〈 Z n 〉 and 〈 Z n ′ 〉 are both martingales with respect to some common sequence 〈 X n 〉, then 〈 Z n + Z n ′ 〉 is also.)
77. E( Z n +1 | Z 0 ,..., Z n ) = E(E( Z n +1 | Z 0 ,..., Z n , X 0 ,..., X n ) | Z 0 ,..., Z n ) , which equals E(E( Z n +1 | X 0 ,..., X n ) | Z 0 ,..., Z n ) because Z n is a function of X 0 , ... , X n ; and that equals E( Z n | Z 0 ,..., Z n ) = Z n . (Furthermore 〈 Z n 〉 is a martingale with respect to, say, a constant sequence. But not with respect to every sequence.)
A similar proof shows that any sequence 〈 Y n 〉 that is fair with respect to 〈 X n 〉 is also fair with respect to itself.
78. E( Z n +1 | V 0 ,..., V n ) = E( Z n V n +1 | V 0 ,..., V n ) = Z n .
The converse holds with V 0 = Z 0 and V n \= Z n / Z n −1 for n > 0, provided that Z n −1 = 0 implies Z n \= 0, and that we define V n \= 1 when that happens.
79. Z n \= V 0 V 1 ... V n , where V 0 = 1 and each V n for n > 0 is independently equal to q/p (with probability p ) or to p/q (with probability q ). Since E V n \= q + p = 1, 〈 V n 〉 is multiplicatively fair. [See A. de Moivre, The Doctrine of Chances (1718), 102–154.]
80. (a) True; in fact E( f n ( Y 0 ... Y n −1 ) Y n ) = 0 for any function f n .
(b) False: For example, let Y 5 = ±1 if Y 3 > 0, otherwise Y 5 = 0. (Hence permutations of a fair sequence needn’t be fair. The statement is, however, true if the Y ’s are independent with mean zero.)
(c) False if n 1 = 0 and m = 1 (or if m = 0); otherwise true. (Sequences that satisfy E(( Y n 1 − E Y n 1 ) ... ( Y n m − E Y n m )) = E( Y n 1 − E Y n 1 ) ... E( Y n m − E Y n m ) are called totally uncorrelated . Such sequences, with E Y n \= 0 for all n , are not always fair; but fair sequences are always totally uncorrelated.)
81. Assuming that X 0 , ... , X n can be deduced from Z 0 , ... , Z n , we have a n X n + b n X n −1 = Z n \= E( Z n +1 | Z 0 ,..., Z n ) = E( a n +1 X n +1 + b n +1 X n | X 0 ,..., X n ) = a n +1 ( X n + X n −1 )+ b n +1 X n for n ≥ 1. Hence a n +1 = b n , b n +1 = a n − a n +1 = b n − 1 − b n ; and we have a n \= F − n −1 , b n \= F − n −2 by induction, verifying the assumption.
[See J. B. MacQueen, Annals of Probability 1 (1973), 263–271.]
82. (a) Z n \= A n / C n , where A n \= 4 − X 1 − ··· − X n is the number of aces and C n is the number of cards remaining after you’ve seen n cards. Hence E Z n +1 = ( A n / C n )( A n −1)/( C n −1)+(1− A n / C n ) A n /( C n −1) = A n / C n . (In every generalization of Pólya’s urn for which the n th step adds k n balls of the chosen color, the ratio red/(red + black) is always a martingale, even when k n is negative, as long as enough balls of the chosen color remain. This exercise represents the case k n \= −1.)
(b) This is the optional stopping principle in a bounded-time martingale.
(c) Z N \= A N / C N is the probability that an ace will be next. [“Ace Now” is a variant of R. Connelly’s game “ Say Red”; see Pallbearers Review 9 (1974), 702.]
83. Z n \= Σ k \= 1 n ( X n − E X n ) is a martingale, for which we can study the bounded stopping rules N n ′ ( x 0 , ... , x n − 1 ) \= [ n < m ] ⋅ N n ( x 0 , ... , x n − 1 ) for any m . But Svante Janson suggests a direct computation, beginning with the formula S N \= Σ n \= 1 ∞ X n [ N ≥ n ] where N might be ∞: We have E( X n [ N ≥ n ]) = (E X n )(E[ N ≥ n ]), because [ N ≥ n ] is a function of { X 0 ,..., X n −1 }, hence independent of X n . And since X n ≥ 0, we have E S N \= Σ n \= 1 ∞ E ( X n [ N ≥ n ] ) \= Σ n \= 1 ∞ ( E X n ) E [ N ≥ n ] \= Σ n \= 1 ∞ E ( ( E X n ) [ N ≥ n ] ) \= E Σ n \= 1 ∞ ( E X n ) [ N ≥ n ] which is E Σ n \= 1 N E X n . (The equation might be ‘∞ = ∞’.)
[ Wald’s original papers, in Annals of Mathematical Statistics 15 (1944), 283–296, 16 (1945), 287–293, solved a somewhat different problem and proved more.]
84. (a) We have f ( Z n ) = f(E(Z n +1 | Z 0 ,..., Z n )) ≤ E( f(Z n +1 ) | Z 0 ,..., Z n ) by Jensen’s inequality. And the latter is E( f(Z n +1 ) | f(Z 0 ),..., f(Z n )) as in answer 77 . [Incidentally, D. Gilat has shown that every nonnegative submartingale is 〈|Z n |〉 for some martingale 〈 Z n 〉; see Annals of Probability 5 (1977), 475–481.]
(b) Again we get a submartingale, provided that we also have f(x) ≤ f(y) for a ≤ x ≤ y ≤ b . [J. L. Doob, Stochastic Processes (1953), 295–296.]
85. Since 〈 B n /( R n + B n ) = 1 − R n /( R n + B n )〉 is a martingale by (27), and since f(x) = 1/ x is convex for positive x , 〈( R n + B n )/ B n 〉 = 〈 R n / B n + 1〉 is a submartingale by exercise 84 . (A direct proof could also be given.)
86. The rule N n +1 ( Z 0 ,..., Z n ) = [max( Z 0 ,..., Z n ) < x and n + 1 < m ] is bounded. If max( Z 0 ,..., Z m −1 ) < x then we have Z N < x , where N is defined by (31); similarly, if max( Z 0 ,..., Z m −1 ) ≥ x then Z N ≥ x . Hence Pr(max( Z 0 ,..., Z n ) ≥ x ) ≤ (E Z N )/ x by Markov’s inequality; and E Z N ≤ E Z n in a submartingale.
87. This is the probability that Z n becomes 3/4, which also is Pr(max( Z 0 ,..., Z n ) ≥ 3/4 ) . But E Z n \= 1/2 for all n , hence (33) tells us that it is at most (1/2)/(3/4) = 2/3.
(The exact value can be calculated as in the following exercise. It turns out to be Σ k \= 0 ∞ 2 ( 4 k + 2 ) ( 4 k + 3 ) \= 1 2 H 3 / 4 − 1 2 H 1 / 2 + 1 3 \= 1 4 π − 1 2 ln 2 ≈ .439 .)
88. (a) We have S > 1/2 if and only if there comes a time when there are more red balls than black balls. Since that happens if and only if the process passes through one of the nodes (2, 1), (3, 2), (4, 3), ... , the desired probability is p 1 + p 2 + ··· , where p k_ is the probability that node ( _k + 1, k ) is hit before any of ( j + 1, j ) for j < k .
All paths from the root to ( k + 1, k ) are equally likely, and the paths that meet our restrictions are equivalent to the paths in 7.2.1.6–(28). Thus we can use Eq. 7.2.1.6–(23) to show that p k_ \= 1/(2 _k − 1) − 1/(2 k ); and 1 − 1/2 + 1/3 − 1/4 + ··· = ln 2.
(b, c) If p k_ is the probability of hitting node (( _t − 1) k +1, k ) before any previous (( t − 1) j +1, j ), a similar calculation using the t -ary ballot numbers C p q ( t ) yields p k_ \= ( _t − 1)(1/( tk − 1) − 1/( tk )). Then Σ k \= 1 ∞ p k \= 1 − ( 1 − 1 / t ) H 1 − 1 / t (see Appendix A ).
Notes: We have Pr( S = 1/2) = 1 − ln 2, since S is always ≥ 1/2. But we cannot claim that Pr( S ≥ 2/3) is the sum of cases that pass through (2, 1), (4, 2), (6, 3), etc., because the supremum might be 2/3 even though the value 2/3 is never reached. Those cases occur with probability π / 27 hence Pr ( S \= 2 / 3 ) ≥ 2 π / 27 − ln3 ≈ .111 . A determination of the exact value of Pr( S = 2/3) is beyond the scope of this book, because we’ve avoided the complications of measure theory by defining probability only in discrete spaces; we can’t consider a limiting quantity such as S to be a random variable, by our definitions! But we can assign a probability to the event that max( Z 0 , Z 1 ,..., Z n ) > x , for any given n and x , and we can reason about the limits of such probabilities.
With the help of deeper methods, E. Schulte-Geers and W. Stadje have proved that the supremum is reached within n steps, a.s. Hence Pr ( S \= 2 / 3 ) \= 2 π / 27 − ln3 ; indeed, Pr( S is rational) = 1, since only rationals are reached; and Pr( S = ( t − 1)/ t ) = (2−3/ t ) H 1−1 /t −(1−2/ t ) H 1−2 /t −( t −2)/( t −1). [ J. Applied Prob. 52 (2015), 180–190.]
89. Set Y n \= c n ( X n − p n ), a n \= − c n p n , b n \= c n (1 − p n ). (Incidentally, when c 1 = ··· = c n \= 1, exercise 1.2.10–22 gives an upper bound that has quite a different form.)
90. (a) Apply Markov’s inequality to Pr ( e ( Y 1 + ... + Y n ) t ≥ e t x ) .
(b) e yt ≤ e − pt ( q − y ) + e qt ( y + p ) = e f(t) + ye g(t) because the function e yt is convex.
(c) We have f ′( t ) = − p + pe t /( q + pe t ) and f ″( t ) = pqe t /( q + pe t ) 2 ; hence f (0) = f ′(0) = 0. And f ″( t ) ≤ 1/4, because the geometric mean of q and pe t , ( pqe t ) 1/2 , is less than or equal to the arithmetic mean, ( q + pe t )/2.
(d) Set c = b − a, p = − a/c , q = b/c , Y = Y/c , t = ct , h(t) = e g(ct) / c .
(e) In E ( ( e c 1 2 t 2 / 4 + Y 1 h 1 ( t ) ) ... ( e c n 2 t 2 / 4 + Y n h n ( t ) ) ) the terms involving h k_ ( _t ) all drop out, because 〈 Y n 〉 is fair. So we’re left with the constant term, e c t 2 / 4 .
(f) Let t = 2 x/c , to make ct 2 /4 − xt = − x 2 / c .
91. E( Z n +1 | X 0 ,..., X n ) = E (E( Q | X 0 ,..., X n , X n +1 ) | X 0 ,..., X n ), and this is equal to E( Q | X 0 ,..., X n ) by formula (∗) in answer 35 . Apply exercise 77 .
92. Q 0 = E X m \= 1/2. If n < m we have Q n \= E( X m | X 0 ,..., X n ), which is the same as E( X n +1 | X 0 ,..., X n ) (see exercise 72 ); and this is (1 + X 1 + ··· + X n )/( n + 2), which is the same as Z n in (27). If n ≥ m , however, we have Q n \= X m .
93. Everything goes through exactly as before, except that we must replace the quantity ( m − 1) t / m t −1 by the generalized expected value, which is Σ k \= 1 m Π n \= 1 t ( 1 − p n k ) .
94. If the X ’s are dependent, the Doob martingale still is well defined; but when we write its fair sequence as an average of Δ( x 1 ,..., x t ) there is no longer a nice formula such as (40). In any formula for Δ that has the form Σ x p x ( Q ( ... x n ... ) − Q ( ... x ... )), Pr( X n = x n , X n+1 , ... )/(Pr( X n = x n ) Pr( X n+1 = x n+1 , ... )) must equal Σ x p x , so it must be independent of x n . Thus (41) can’t be used.
95. False; the probability of only one red ball at level n is 1/( n +1) = Ω( n −1 ). But there are a.s. more than 100 red balls, because that happens with probability ( n −99)/( n +1).
96. Exercise 1.2.10–21, with ∊n equal to the bound on | X − n /2|, tells us that (i) is q.s. and that (i), (ii), (iii) are a.s. To prove that (iv) isn’t a.s., we can use Stirling’s approximation to show that ( n n / 2 ± k ) / 2 n is ⊖( n −1/2 when k \= n ; consequently Pr ( | X | < n ) \= ⊖ ( 1 ) . A similar calculation shows that (ii) isn’t q.s.
97. We need to show only that a single bin q.s. receives that many. The probability generating function for the number of items H that appear in any particular bin is G(z) = (( n − 1 + z)/n ) N , where N = ⌊ n 1+δ ⌋ . If r \= 1 2 n δ , we have
Pr ( H ≤ r ) ≤ ( 1 2 ) − r G ( 1 2 ) \= 2 r ( 1 − 1 2 n ) ⌊ 2 n r ⌋ ≤ 2 r ( 1 − 1 2 n ) 2 n r − 1 ≤ 2 r + 1 e − r ,
by 1.2.10–(24). And if r = 2 n δ we have
Pr ( H ≥ r ) ≤ 2 − r G ( 2 ) \= 2 − r ( 1 + 1 n ) ⌊ n r / 2 ⌋ ≤ 2 − r ( 1 + 1 n ) n r / 2 ≤ 2 − r e r / 2 ,
by 1.2.10–(25). Both are exponentially small. [See Knuth, Motwani, and Pittel, Random Structures & Algorithms 1 (1990), 1–14, Lemma 1.]
98. Let E n \= E R , where R is the number of reduction steps; and suppose F(n) = k with probability p k_ , where Σ k \= 1 n p k \= 1 and Σ k \= 1 n k p k \= g ≥ g n . (The values of _p 1 , ... , p n , and g might be different, in general, every time we compute F (n ).)
Let Σ a b \= Σ j \= a b 1 / g j . Clearly E 0 = 0. And if n > 0, we have by induction
E n \= 1 + Σ k \= 1 n p k E n − k ≤ 1 + Σ k \= 1 n p k Σ 1 n − k \= 1 + Σ k \= 1 n p k ( Σ 1 n − Σ 1 n − Σ n − k + 1 n ) \= Σ 1 n + 1 − Σ k \= 1 n p k Σ n − k + 1 n ≤ Σ 1 n + 1 − Σ k \= 1 n p k k g n ≤ Σ 1 n .
[See R. M. Karp, E. Upfal, and A. Wigderson, J. Comp. and Syst. Sci. 36 (1988), 252.]
99. The same proof would work, provided that induction could be justified, if we were to do the sums from k = −∞ to n and define Σ a b \= − Σ j \= b + 1 a − 1 1 / g j when a > b . (For example, that definition gives − Σ n + 3 n \= 1 / g n + 1 + 1 / g n + 2 ≤ 2 / g n .)
And in fact it does become a proof, by induction on m , that we have E m , n ≤ Σ 1 n for all m, n ≥ 0, where E m,n \= E min( m, R ). Indeed, we have E 0 ,n = E m +1 , 0 = 0; and E m + 1 , n \= 1 + Σ k \= − ∞ n p k E m , n − k when n > 0. [This problem is exercise 1.6 in Randomized Algorithms by Motwani and Raghavan (1995). Svante Janson observes that the random variable Z m \= Σ 1 X m + min ( m , R ) is a supermartingale, where X m is the value of X after m iterations, as a consequence of this proof.]
100. (a) Σ k \= 1 m k p k ≤ Emin ( m , T ) \= p 1 + 2 p 2 + ⋅ ⋅ ⋅ + m p m + m p m + 1 + ⋅ ⋅ ⋅ + m p ∞ ≤ E T .
(b) E min( m , T ) ≥ mp ∞ for all m . (We assume that ∞· p = ( p > 0? ∞: 0).)
101. (Solution by Svante Janson.) If 0 < t < min( p 1 ,..., p m ) = p , we have E e t X \= ∏ k \= 1 m E e t X k \= ∏ k \= 1 m p k / ( e − t − 1 + p k ) < ∏ k \= 1 m p k / ( p k − t ) , because e − t −1 > − t . Set t = θ/μ , and note that p k ln ( 1 − t / p k ) ≥ p ln ( 1 − t / p ) ≥ 1 μ ln ( 1 − t μ ) \= t θ ln ( 1 − θ ) . By 1.2.10– (25), therefore, Pr ( X ≥ r μ ) ≤ e − r t μ ∏ k \= 1 m p k / ( p k − t ) \= exp ( − r θ − Σ k \= 1 m ln ( 1 − t / p k ) ) ≤ exp ( − r θ − Σ k \= 1 m ( t / p k ) ( ln ( 1 − θ ) ) / θ ) \= exp ( − r θ − ln ( 1 − θ ) ) . Choose θ = ( r − 1)/ r to get the desired bound re 1− r . (The bound is nearly sharp when m = 1 and p is small, since Pr( X ≥ r/p ) = (1 − p ) ⌈ r/p ⌉−1 ≈ e − r .)
102. Applying exercise 101 with μ ≤ s 1 + ··· + s m and r = ln n gives probability O ( n −1 log n ) that ( s 1 + ··· + s m ) r trials aren’t enough. And if r = f(n )ln n , where f(n) is any increasing function that is unbounded as n → ∞, the probability that s _k r trials don’t obtain coupon _k is superpolynomially small. So is the probability that any one of a polynomial number of such failures will occur.
103. (a) The recurrence p o ij \= [ i=j ], p ( n + 1 ) i j \= Σ k \= 0 2 p n i k ( [ f 0 ( k ) \= j ] + [ f 1 ( k ) \= j ] ) / 2 leads to generating functions g i j \= Σ n \= 0 ∞ p n i j z n that satisfy g i0 = [ i=0 ]+( g i0 + g i 1 ) z /2, g i1 = [ i=1 ]+( g i0 + g i 2 ) z /2, g i2 = [ i=2 ]+( g i1 + g i 2 ) z /2. From the solution g i_ 0 = _A+B+C , g i_ 1 = _A−2B , g i_ 2 = _A+B−C , A \= 1 3 / ( 1 − z ) , B \= 1 6 ( 1 − 3 [ i \= 1 ] ) ( 1 + z / 2 ) , and C \= 1 2 ( [ i \= 0 ] − [ i \= 2 ] ) / ( 1 − z / 2 ) , we conclude that the probability is 1 3 + O ( 2 − n ) ; in fact it is always either ⌊2 n /3⌋/2 n or ⌈2 n /3⌉/2 n . The former occurs if and only if i ≠ j and n is even, or i + j = 2 and n is odd.
(b) Letting g 012 \= z 2 ( g 001 + g 112 ) , g 001 \= z 2 ( [ j \= 0 ] + g 011 ) , etc., yields the generating function g 012 = ([ j ≠ 1] + [ j = 1] z ) z 2 /(4 − z 2 ). Hence each j occurs with probability 1/3, and the generating function for N is z 2 /(2− z ); mean = 3, variance = 2.
(c) Now g 001 \= z 2 ( [ j \= 0 ] + g 012 ) , etc.; the output is never 1; 0 and 2 are equally likely; and N has the same distribution as before.
(d) Functional composition isn’t commutative, so the stopping criterion is different: In the second case, 111 cannot occur unless the previous step had 000 or 222. The crucial difference is that, without stopping, process (b) becomes fixed at coalescence; process (c) continues to change a 0 a 1 a 2 as n increases (although all three remain equal).
(e) If T is even, sub( T ) returns (−1, 0, 1, 2) with probability (2, (2 T − 1)/3, (2 T − 4)/3, (2 T − 1)/3)/2 T . Thus the supposed alternative to (b) will output 0 with probability 1 4 + 5 32 + 85 4096 + ⋅ ⋅ ⋅ \= 1 3 Σ k \= 1 ∞ 2 k + 1 ( 2 2 k − 1 ) / 2 2 k + 1 ≈ 0.427 , not 1/3.
(f) Change sub( T ) to use consistent bits X T , X T −1 , ... , X 1 instead of generating new random bits X each time; then the method of (b) is faithfully simulated. (The necessary consistency can be achieved by carefully resetting the seed of a suitable random number generator at appropriate times.)
[The technique of (f) is called “coupling from the past” in a monotone Monte Carlo simulation. It can be used to generate uniformly random objects of many important kinds, and it runs substantially faster than method (b) when there are thousands or millions of possible states instead of just three. See J. G. Propp and D. B. Wilson, Random Structures & Algorithms 9 (1996), 223–252.]
104. Let q = 1 − p . The probability of output (0, 1, 2) in (b) is ( q 2 , pq , p 2 )/(1 − pq ); in (c) it is ( q 2 (1 + p ), 0, p 2 (1 + q ))/(1 − pq ). In both cases N has generating function (1− pq (2− z )) z 2 /(1− pqz 2 ), mean 3/(1 − pq ) − 1, variance (5 − 2 pq ) pq /(1 − pq ) 2 .
105. We have g 0 = 1 and g a \= z ( g a −1 + g a +1 )/2 for 0 < a < n /2.
If n = 2 m is even, let g a \= z a t m−a / t m for 0 ≤ a ≤ m . The polynomials t k defined by t 0 = t 1 = 1, t k +1 \= 2 t k − z 2 t k −1 fill the bill, because they make g m \= zg m −1 . The generating function T w \= ∑ m \= 0 ∞ t m w m \= 1 - w / 1 - 2 w + w 2 z 2 now shows, after differentiation by z , that we have t m ' 1 \= - m m - 1 and t m '' ( 1 ) \= ( m 2 - 5 m + 3 ) m ( m - 1 ) / 3 ; hence t m '' 1 + t m ' 1 - t m ' 1 2 \= 2 3 m 2 - m 4 . The mean and variance, given a , are therefore a − ( m − a )( m − a − 1) + m ( m − 1) = a ( n − a ) and 2 3 m - a 2 - m - a 4 - m 2 + m 4 \= 1 3 n - a 2 + a 2 - 2 a n - a , respectively.
When n = 2 m − 1 we can write g a \= z a u m−a / u m for 0 ≤ a ≤ m , with u m +1 \= 2 u m − z 2 u m − 1 . In this case we want u 0 = 1 and u 1 = z , so that g m \= g m −1 . From U w \= ∑ m \= 0 ∞ u m w m \= 1 + z - 2 w / 1 - 2 w + w 2 z 2 we deduce u m ' 1 \= - m m - 2 and u m '' 1 \= m m - 1 m 2 - 7 m + 7 / 3 . It follows that, also in this case, the mean number of steps in the walk is a ( n − a ) and the variance is 1 3 n - a 2 + a 2 - 2 a n - a .
[The polynomials t m and u m in this analysis are disguised relatives of the classical Chebyshev polynomials defined by T m cos θ \= cos m θ , U m cos θ \= sin m + 1 θ / sin θ . Let us also write V m cos θ \= cos m - 1 2 θ / cos 1 2 θ . Then V m ( x ) = (2 − 1 /x ) T m ( x )+ (1 /x − 1) U m ( x ); and we have t m \= z m T m (1 /z ), u m \= z m V m (1 /z ).]
106. Before coalescing, the array a 0 a 1 ... a d −1 always has the form a r ( a +1) ... ( b −1) b s for some 0 ≤ a < b < d , r > 0, and s > 0, where r + s + b − a = d + 1. Initially a = 0, b = d − 1, r = s = 1. The behavior of the algorithm while r + s = t is like a random walk on the t - cycle, as in the previous exercise, starting at a = 1. Let G t be the generating function for that problem, which has mean t − 1 and variance 2 3 t . Then this problem has the generating function G 2 G 3 ... G d ; so its mean is ∑ k \= 2 d k - 1 \= 2 d , and the variance is ∑ k \= 2 d 2 3 k \= 2 4 d + 1 .
107. (a) If the probabilities can be renumbered so that p 1 ≤ q 1 and p 2 ≤ q 2 , the five events of Ω can have probabilities p 1 , p 2 , q 1 − p 1 , q 2 − p 2 , and q 3 , because p 3 = ( q 1 − p 1 )+ ( q 2 − p 2 )+ q 3 . But if that doesn’t work, we can suppose that p 1 < q 1 ≤ q 2 ≤ q 3 < p 2 ≤ p 3 . Then p 1 , q 1 − p 1 , p 1 + p 2 − q 1 , p 3 − q 3 , and q 3 are nonnegative.
(b) Give Ω’s events the probabilities 1 12 , 2 12 , 3 12 , 6 12 .
(c) For example, let p 1 \= 1 9 , p 2 \= p 3 \= 4 9 , q 1 \= q 2 \= q 3 \= 1 3 .
108. Let p k \= Pr′( X = k ) and q k \= Pr″( Y = k ). The set ∪ n ∑ k ≤ n p k , ∑ k ≤ n q k divides the unit interval [0 .. 1) into countably many sub intervals, which we take as the set Ω of atomic events ω . Let X ( ω ) = n if and only if ω ⊆ [ ∑ k < n p k . . ∑ k ≤ n p k ) ; a similar definition works for Y ( ω ). And X ( ω ) ≤ Y ( ω ) for all ω .
109. (a) We’re given that p 1 + p 3 ≤ q 1 + q 3 , p 2 + p 3 ≤ q 2 + q 3 , and p 3 ≤ q 3 . (Also that 0 ≤ 0 and p 1 + p 2 + p 3 ≤ q 1 + q 2 + q 3 ; but those inequalities always hold.) We must find a coupling with p 12 = p 21 = p 31 = p 32 = 0, because 1 ⊀ 2 , 2 ⊀ 1 , 3 ⊀ 1 , and 3 ⊀ 2 . In the previous problem we were given that p 2 + p 3 ≤ q 2 + q 3 and p 3 ≤ q 3 , and we had to find a coupling with p 21 = p 31 = p 32 = 0.
(b) Let A ↑ = { x | x ⪰ a for some a ∈ A } and B ↓ = { x | x ⪯ b for some b ∈ B }. We’re given that Pr′( X ∈ A ↑ ) ≤ Pr″( Y ∈ A ↑ ) for all A . Let A = {1 ,..., n }\ B ↓ , so that Pr′( X ∈ B ↓ ) = 1 − Pr′( X ∈ A ). The result follows because A = A ↑ .
(c) Remove all arcs x i → x j from the network when i ⊀ j . Then a blocking pair ( I, J ) has the property that i j implies i ∈ I or j ∈ J . Let A = { x | x ⪯ a for some a ∉ J } and B = {1 ,..., n }\ A . Then A ⊆ I , B ⊆ J , and B = B ↓ . Hence Σ i∈ I p i + Σ j∈ J q j ≥ Σ i∈A p i + Σ j∈B q j ≥ Σ i∈A q i + Σ j∈B q j \= 1.
[See K. Nawrotzki, Mathematische Nachrichten 24 (1962), 193–200; V. Strassen, Annals of Mathematical Statistics 36 (1965), 423–439.]
110. (a) The result is trivial if r = 1. Otherwise consider the probability distributions p k ' \= p k r k / 1 - r and q k ' \= q k r k / 1 - r ; use the coupling p i j \= 1 - r p i ' q j ' + r j i \= j . [See W. Doeblin, Revue mathématique de l’Union Interbalkanique 2 (1938), 77–105; R. L. Dobrushin, Teoriya Veroyatnosteĭ i ee
15 (1970), 469–497.]
(b) Yes, because the ( p ′, q ′) distribution satisfies the hypotheses of that exercise.
111. (a) Here are the 60 triples 1 π 3 π 4 π , with the minima in bold type:
1 34 1 63 1 23 1 26 1 42 1 42 1 53 1 45 1 63 1 54 2 45 2 34 5 3 4 56 3 6 2 3 5 2 6 63 2 65 2 5 3 4 64 3
3 56 6 4 5 2 46 2 34 4 3 5 46 3 5 2 4 4 2 3 64 2 53 2 46 1 35 1 36 1 64 1 25 1 23 1 34 1 53 1 32 1 42 1
5 1 2 4 1 2 4 1 5 3 1 5 3 1 6 6 1 5 2 1 6 2 1 6 4 1 5 3 1 6 6 2 3 5 2 6 65 2 45 2 56 4 3 54 4 65 3 64 2 56 2 65
(b) Both S A and S B lie in A ∪ B . Each element of A ∪ B is equally likely to have the minimum value aπ ; exactly | A ∩ B | of those elements have that value as their sketch.
(c) | A ∩ B ∩ C | / | A ∪ B ∪ C |.
Notes: The ratio | A ∩ B | / | A ∪ B | is a useful measure of similarity, called the “ Jaccard index” because Paul Jaccard used it to compare different Swiss ecological sites according to the sets of plant species seen at each place [ Bulletin de la Société Vaudoise des Sciences Naturelles 37 (1901), 249]. It is commonly used today to rank the similarity between web pages, based on a certain set of words in each page.
Minwise independence was introduced by Andrei Broder for that application in 1997, using n = 2 64 and a method of identifying roughly 1000 words A on a typical web page. By calculating, say, independent sketches S 1 ( A ), ... , S 100 ( A ) for each page, the number of j such that S j ( A ) = S j ( B ) gives a highly reliable and quickly computable estimate of the Jaccard index. A perfectly minwise independent family is impossible in practice when n is huge, but the associated theory has led to approximate “minhash” algorithms that work well. See A. Z. Broder, M. Charikar, A. M. Frieze, and M. Mitzenmacher, J. Computer and System Sciences 60 (2000), 630–659. See also the related, independent work by K. Mulmuley, Algorithmica 16 (1996), 450–463.
112. (a) Such a rule breaks ties properly, provided that the number of π with ∞’s in B is a multiple of n − m . Each B can have its own rule.
(b) In fact we can produce families whose permutations are all obtained from N/n = d “seeds” by cyclic shifts, as in exercise 111 . Begin with m = 1 and a table of N = lcm(1, 2, ..., n ) partial permutations whose entries π ij for 1 ≤ i ≤ N and 1 ≤ j ≤ n are entirely blank, except that π ij \= 1 for each pair ij with ( j − 1) d < i ≤ jd and 1 ≤ j ≤ n . When n = 4, for instance, the initial tableau
1 ⊔⊔⊔ 1 ⊔⊔⊔ 1 ⊔⊔⊔ ⊔ 1 ⊔⊔ ⊔ 1 ⊔⊔ ⊔ 1 ⊔⊔ ⊔⊔ 1 ⊔ ⊔⊔ 1 ⊔ ⊔⊔ 1 ⊔ ⊔⊔⊔ 1 ⊔⊔⊔ 1 ⊔⊔⊔ 1
represents N = 12 truncated permutations with m = 1. We’ll insert some 2s next.
Let A be a subset of size n − m that is all blank, in some π . Each A occurs equally often (as in uniform probing, Section 6.4); so the number of such π is N / n - m n . Fortunately this is a multiple of n − m , because exercise 1.2.6–48 tells us that N / n - m n - m n \= N ∑ k \= 0 m - 1 k k m / n - m + k .
Take n − m such π and insert m +1 into different positions within them. Then find another such A , if possible, and repeat the process until no blank subsets of size n − m remain. Then set m ← m + 1, and continue in the same way until m = n .
It’s not hard to see that the insertions can be done so that π j , π d + j , ... , π ( n − 1) d + j are maintained as cyclic shifts of each other. When n = 4 the 2s are essentially forced:
12 ⊔⊔ 1 ⊔ 2 ⊔ 1 ⊔⊔ 2 ⊔ 12 ⊔ ⊔ 1 ⊔ 2 21 ⊔⊔ ⊔⊔ 12 2 ⊔ 1 ⊔ ⊔ 21 ⊔ 2 ⊔⊔ 1 ⊔ 2 ⊔ 1 ⊔⊔ 21
But then there are two ways to fill the two cases with A = {3 , 4}:
123 ⊔ 1 ⊔ 2 ⊔ 13 ⊔ 2 ⊔ 123 ⊔ 1 ⊔ 2 21 ⊔ 3 3 ⊔ 12 2 ⊔ 1 ⊔ ⊔ 213 23 ⊔ 1 ⊔ 2 ⊔ 1 3 ⊔ 21
12 ⊔ 3 1 ⊔ 2 ⊔ 13 ⊔ 2 312 ⊔ ⊔ 1 ⊔ 2 213 ⊔ ⊔ 312 2 ⊔ 1 ⊔ ⊔ 213 2 ⊔ 31 ⊔ 2 ⊔ 1 3 ⊔ 21
Adopting the first of these leads to two ways to fill A = {2, 4}:
123 ⊔ 132 ⊔ 13 ⊔ 2 ⊔ 123 ⊔ 132 21 ⊔ 3 3 ⊔ 12 2 ⊔ 13 ⊔ 213 23 ⊔ 1 32 ⊔ 1 3 ⊔ 21
123 ⊔ 1 ⊔ 23 13 ⊔ 2 ⊔ 123 31 ⊔ 2 21 ⊔ 3 3 ⊔ 12 231 ⊔ ⊔ 213 23 ⊔ 1 ⊔ 231 3 ⊔ 21
Here A is a cyclic shift of itself, but consistent placement is always possible.
[See Yoshinori Takei, Toshiya Itoh, and Takahiro Shinozaki, IEICE Transactions on Fundamentals E83-A (2000), 646–655, 747–755.]
113. (a) The probability is zero if l ≥ k or r > n − k . Otherwise the result follows if we can prove it in the “complete” case when l = k − 1 and r = n − k , because we can sum the probabilities of complete cases over all ways to specify which of the unconstrained elements are < k and which are > k .
To prove the complete case, we may assume that a i \= i , b = k , and c j \= k + j for 1 ≤ i ≤ l = k − 1 and 1 ≤ j ≤ r = n − k . The probability can be computed via the principle of inclusion and exclusion, because we know Pr(min a∈A aπ \= kπ ) = 1/( n − k + t ) = P B whenever A = { k ,..., n } ∪ B and B consists of t elements less than k . For example, if k = 4 the probability that 4 π = 4 and {1 π, 2 π, 3 π } = {1 , 2 , 3} is P ∅ − P {1} − P {2} − P {3} + P {1, 2} + P {1, 3} + P {2,3} − P {1,2,3} ; each of those probabilities is correct for truly random π .
(b) This event is the disjoint union of complete events of type (a). [See A. Z. Broder and M. Mitzenmacher, Random Structures & Algorithms 18 (2001), 18–30.]
Notes: The function ψ ( n ) = ln(lcm(1, 2, ..., n )) = Σ p k ≤ n [ p prime] ln p was introduced by P. L. Chebyshev [see J. de mathématiques pures et appliquées 17 (1852), 366–390], who proved that it is Θ( n ). Refinements by Ch.-J. de la Vallée Poussin [ Annales de la Société Scientifique de Bruxelles 20 (1896), 183–256] showed that in fact ψ ( n ) = n + O ( ne − C log n ) for some positive constant C . Thus lcm(1, 2, ..., n ) grows roughly as e n , and we cannot hope to generate a list of minwise independent permutations when n is large; the length of such a list is 232,792,560 already for 19 ≤ n ≤ 22.
114. First assume that | S j | = d j + 1 for all j , and let g j ( x ) = ∏ s∈S j ( x − s ). We can replace x j d j + 1 by x j d j + 1 - g j x j , without changing the value of f ( x 1 ,..., x n ) when x j ∈ S j . Doing this repeatedly until every term of f has degree ≤ d j in each variable x j will produce a polynomial that has at least one nonroot in S 1 × … × S n , according to exercise 4.6.1–16. [See N. Alon, Combinatorics, Probab. and Comput. 8 (1999), 7–29.]
Now in general, if there were at most | S 1 |+…+| S n |−( d 1 +…+ d n + n ) nonroots, we could eliminate them one (or more) at a time, by removing an element from any S j for which | S j | ≥ d j + 1. Contradiction.
(This inequality also implies stronger lower bounds when the sets S j are large. If, for example, d 1 = … = d n \= d and if each | S j | ≥ s , where s = d + 1 + ⌈ d /( n − 1)⌉, we can decrease each | S j | to s and increase the right-hand side. For further asymptotic improvements see Béla Bollobás, Extremal Graph Theory (1978), §6.2 and §6.3.)
115. Representing the vertex in row x and column y by ( x, y ), if all points could be covered we’d have f x , y \= ∏ j \= 1 p x - a j ∏ j \= 1 q y - b j ∏ j \= 1 r x + y + c j x - y + d j \= 0 , for all 1 ≤ x ≤ m and 1 ≤ y ≤ n and for some choices of a j , b j , c j , d j . But f has degree p + q +2 r = m + n − 2, and the coefficient of x m -1 y n -1 is ± r / 2 r ≠ 0 .
116. Let g v \= Σ{ x e | v ∈ e } for each vertex v , including x e twice if e is a loop from υ to itself. Apply the nullstellensatz with f \= ∏ v 1 - g v p - 1 - ∏ e 1 - x e and with each S j \= {0, 1}, using mod p arithmetic. This polynomial has degree m , the number of edges and variables, because the first product has degree ( p − 1) n < m ; and the coefficient of ∏ e x e is (−1) m ≠ 0. Hence there is a solution x that makes f ( x ) nonzero. The subgraph consisting of all edges with x e \= 1 in this solution is nonempty and satisfies the desired condition, because g v ( x ) mod p = 0 for all υ .
(This proof works also if we consider that a loop contributes just 1 to the degree. See N. Alon, S. Friedland, and G. Kalai, J. Combinatorial Theory B37 (1984), 79–91.)
117. If ω = e 2πi/m , we have Eω jX \= ∑ k \= 0 n k n p k ( 1 - p ) n - k ω j k \= ( ω j p + 1 - p ) n . Also | ω j p + 1 − p | 2 = p 2 + 1− p 2 + p (1− p )( ω j + ω −j \= 1 −4 p (1− p sin 2 (π j / m ). Now sin πt ≥ 2 t for 0 ≤ t ≤ 1/2. Hence, if 0 ≤ j ≤ m /2 we have | ω j p + 1 − p | 2 ≤ 1 − 16 p (1 − p ) j 2 /m 2 ≤ exp(−16 p (1 − p ) j 2 /m 2 ); if m/ 2 ≤ j ≤ m we have sin( πj/m ) = sin( π ( m − j ) /m ). Thus ∑ j \= 1 m - 1 | Eω j X | ≤ 2 ∑ j \= 1 m - 1 exp - 8 p 1 - p j 2 n / m 2 .
The result follows, since Pr X mod m \= r \= 1 m ∑ j \= 0 m - 1 ω - j r E ω j X . [S. Janson and D. E. Knuth, Random Structures & Algorithms 10 (1997), 130–131.]
118. Indeed, (22) with Y = X − x yields more (when we also apply exercise 47 ):
Pr( X ≥ x ) ≥ Pr( X > x ) ≥ ( E X − x ) 2 E ( X − x ) 2 \= ( E X − x ) 2 E X 2 − x ( 2 E X − x ) ≥ ( E X − x ) 2 E X 2 − x E X ≥ ( E X − x ) 2 E ( X 2 − x ) 2 .
(The attribution of this result to Paley and Zygmund is somewhat dubious. They did, however, write an important series of papers [ Proc. Cambridge Philosophical Society 26 (1930), 337–357, 458–474; 28 (1932), 190–205] in which a related inequality appeared in the proof of Lemma 19.)
119. Let f ( x, t ) = Pr( U ≤ V ≤ W and V ≤ (1 − t ) U + tW ), g ( x, t ) = Pr( U ≤ W ≤ V and W ≤ (1 − t ) U + tV ), h ( x, t ) = Pr( W ≤ U ≤ V and U ≤ (1 − t ) W + tV ). We want to prove that f ( x, t ) + g ( x, t ) + h ( x, t ) = t . Notice that, if U ¯ \= 1 − U , V ¯ \= 1 − V , W ¯ \= 1 − W , we have Pr( W ≤ U ≤ V and U ≥ ( 1 − t ) W + t V ) \= Pr( V ≤ U ¯ ≤ W ¯ and U ¯ ≤ t V ¯ + 1 ( 1 − t ) W ¯ ) . Hence x 2 - h ( x , t ) \= f ( 1 - x , 1 - t ) , and we may assume that t ≤ x .
Clearly g ( x , t ) \= ∫ 0 x d u x ∫ x 1 d v 1 - x t ( v - u ) \= t 2 . And t ≤ x implies that
f ( x , t ) \= ∫ ( x − t ) / ( 1 − t ) x d u x ∫ x ( 1 − t ) u + t d v 1 − x ( v − ( 1 − t ) u ) / t ) \= t 2 ( 1 − x ) 2 / ( 6 ( 1 − t ) x ) ; h ( x , t ) \= ∫ x 1 d v 1 − x ( ∫ 0 v t d u x u + ∫ v t x d u x t 1 − t ( v − u ) ) \= t 2 − f ( x , t ) .
Instead of this elaborate calculation, Tamás Terpai has found a much simpler proof: Let A = min( U, V, W ), M = UV W , and Z = max( U, V, W ). Then the conditional distribution of M , given A and Z , is a mixture of three distributions: Either A = U , Z = V , and M is uniform in [ A..Z ]; or A = U , Z = W , and M is uniform in [ x..Z ]; or A = W , Z = V , and M is uniform in [ A..x ]. (These three cases occur with respective probabilities ( Z − A, Z − x, x − A ) / (2 Z − 2 A ), but we don’t need to know that detail.) The overall distribution of M , being an average of conditional uniform distributions over all A ≤ x and Z ≥ x , is therefore uniform.
[See S. Volkov, Random Struct. & Algorithms 43 (2013), 115–130, Theorem 5.]
120. See J. Jabbour-Hattab, Random Structures & Algorithms 19 (2001), 112–127.
121. (a) D ( y ∥ x ) \= 1 5 lg 6 5 + 2 15 lg 4 5 ≈ .0097 ; D ( x ∥ y ) \= 1 6 lg 5 6 + 1 6 lg 5 4 ≈ .0098 .
(b) We have E( ρ ( X ) lg ρ ( X )) ≥ (E ρ ( X )) lg E ρ ( X ) by Jensen’s inequality (20); and E ρ ( X ) = Σ t y ( t ) = 1, so the logarithm evaluates to 0.
The question about zero is the hard part of this exercise. We need to observe that the function f ( x ) = x lg x is strictly convex, in the sense that equality holds in (19) only when x = y . Thus we have (E Z )lgE Z = E( Z lg Z ) for a positive random variable Z only when Z is constant. Consequently D ( y || x ) = 0 if and only if x ( t ) = y ( t ) for all t .
(c) Let x ^ ( t ) \= x ( t ) / p and y ^ ( t ) \= y ( t ) / q be the distributions of X and Y within T . Then 0 ≤ D ( y ^ ∥ x ^ ) \= ∑ t ∈ T y ^ ( t ) lg ( y ^ ( t ) / x ^ ( t ) ) \= E ( lg ρ ( Y ) | Y ∈ T ) + lg ( p / q ) .
(d) D ( y || x ) = (Elg m ) − H Y \= lg m − H Y . (Hence, by (b), the maximum entropy of any such random variable Y is lg m , attainable only with the uniform distribution. Intuitively, H Y is the number of bits that we learn when Y is revealed.)
(e) I X,Y \= − H Z −Σ u,v z ( u, v )(lg x ( u )+lg y ( v )) = − H Z + Σ u x ( u )lg(1 /x ( u )) + Σ v y ( v ) lg(1/ y ( v )), because Σ v z ( u, v ) = x ( u ) and Σ u z ( u, v ) = y ( v ).
(f) Conditioning I X,Z \= H X + H Z − H X,Z on Y gives 0 ≤ I ( X,Z )| Y \= H X|Y + H Z|Y − H (X,Z)| Y \= H X|Y + ( H Y,Z − H Y ) − ( H X,Y,Z − H Y ).
122. (a) D ( y ∥ x ) \= ∑ t \= 0 ∞ ( 3 t / 4 t + 1 ) lg ( 3 t / 2 t + 1 ) \= lg 27 16 ≈ 0 . 755 ; D ( x ∥ y ) \= lg 4 3 ≈ 0 . 415 .
(b) Let q = 1 − p and t \= p n + u n . Then we have
y t \= e - u 2 / 2 p q 2 π p q n exp u 2 q - u 2 p + u 3 6 p 2 - u 3 6 q 2 1 n + O ( 1 n ) ; ln ρ t \= - u 2 2 q - 1 2 ln q + u 2 q - u 3 6 q 2 1 n + O 1 n .
By restricting | u | ≤ n ∈ and trading tails (see 7.2.1.5–(20)), we obtain
D ( y ∥ x ) \= 1 2 π p q n ∞ - ∞ e - u 2 / ( 2 p q ) ( - u 2 2 q ln 2 - 1 2 lg q ) d u n + O ( 1 n ) \= 1 2 ln 2 ( ln 1 1 - p - p ) + O ( 1 n ) .
In this case D ( x || y ) is trivially ∞, because x ( n +1) > 0 but y ( n +1) = 0.
123. Since p k +1 \= p k y ( t ) /z k ( t ) we have ρ ( t ) = (1 − p k ) p k +1 / ( p k (1 − p k +1 )). [This relation was the original motivation that led S. Kullback and R. A. Leibler to define D ( y || x ), in Annals of Mathematical Statistics 22 (1951), 79–86.]
124. Let m \= c 2 2 D y ∥ x and g ( t ) = f ( t )[ ρ ( t ) ≤ m ]; thus g ( t ) = f ( t ) except with probability Δ c . We have | E ( f )− E n ( f )| = ( E ( f )− E ( g ) ) + | E ( g )− E n ( g )|+ ( E n ( f )− E n ( g ) ) . The Cauchy– Schwarz inequality (exercise 1.2.3–30) implies that the first and last are bounded by ∥ f ∥ ∆ c , because f ( t ) − g ( t ) = f ( t )[ ρ ( t ) >m ].
Now var( ρ ( X ) g ( X )) ≤ E( ρ ( X ) 2 g ( X ) 2 ) ≤ m E( ρ ( X ) f ( X ) 2 ) = m E( f ( Y ) 2 ) = m f 2 . Hence ( E ( g ) − E n ( g )) 2 = var E n ( g ) = var( ρ ( X ) g ( X )) /n ≤ || f || 2 / c 2 .
Consider now the case c < 1. From Markov’s inequality we have Pr( ρ ( X ) > m ) ≤ (E ρ ( X ))/ m = 1/ m . Also E( ρ ( X )[ ρ ( X ) ≤ m ]) = E[ ρ ( Y ) ≤ m ] = 1 − Δ c . Consequently Pr( E n (1) ≥ a ) ≤ Pr(max 1≤k≤n ρ ( X k ) > m ) + Pr ( ∑ k \= 1 n ρ ( X k ) [ ρ ( X k ) ≤ m ] ≥ n a ) ≤ n / m + E ( ∑ k \= 1 n ρ ( X k ) [ ρ ( X k ) ≤ m ] ) / ( n a ) \= c 2 + ( 1 - ∆ c ) / a .
[S. Chatterjee and P. Diaconis, Annals of Applied Prob. 28 (2018), 1099–1135.]
125. (a) From a n 2 \= a n - 1 a n + 1 we deduce that a n \= cx n for some c ≥ 0 and x ≥ 0.
(b) It remains log-convex ⇔ ca 1 ≥ a 0 2 ; it remains log-concave ⇔ ca 1 ≤ a 0 2 . (The latter condition always holds in the important case c = 0.)
(c) If a m−1 a n +1 > 0 we have a m /a m−1 ≥ a m + 1 /a m ≥ … ≥ a n + 1 /a n , because there are no internal zeros. (And the analogous result holds for log-convexity.)
(d) If xz ≥ y 2 and XZ ≥ Y 2 and x, y, z, X, Y, Z > 0, we have ( x + X )( z + Z ) − ( y + Y ) 2 ≥ ( x + X )( y 2 /x + Y 2 /X ) − ( y + Y ) 2 = ( x/X )( Y − Xy/x ) 2 ≥ 0. [L. L. Liu and Y. Wang, Advances in Applied Mathematics 39 (2007), 455.]
(e) Let c n \= ∑ k ( n k ) a k b n - k . Clearly c 1 2 ≤ c 0 c 2 . And c n \= ∑ k k n - 1 a n - 1 - k b k + 1 + ∑ k k n - 1 a k + 1 b n - 1 - k , so we can apply (c) and induction on n to the shifted sequences. [H. Davenport and G. Pólya, Canadian Journal of Mathematics 1 (1949), 2–3.]
(f) Yes: Let a k \= b k \= 0 when k < 0, and c n \= Σ k a k b n−k . Then we have
c n 2 - c n - 1 c n + 1 \= ∑ 0 ≤ j ≤ k ( a j a k - a j - 1 a k + 1 ) ( b n - j b n - k - b n + 1 - j b n - 1 - k ) ,
which is a special case of the Binet– Cauchy identity (exercise 1.2.3–46) with m = 2.
(g) Yes, but a more intricate proof seems to be needed. We have c n \= t 00 , c n +1 \= t 01 + t 10 , and c n +2 = t 02 + 2 t 11 + t 20 , where t i j \= ∑ k k n a k + i b n - k + j ; hence c n + 1 2 - c n c n + 2 \= ( t 01 2 - t 00 t 02 ) + ( t 10 2 - t 00 t 20 ) + 2 ( t 01 t 10 - t 00 t 11 ) . We will show that each of these parenthesized terms is nonnegative.
Let b j ' \= j n b j . Then the sequence 〈 b j ' 〉 is log-concave; and t i 0 is the ( n + i )th term of the sequence ∑ k a k b n - k ' , which is log-concave by (f). Therefore t 10 2 ≥ t 00 t 20 . A similar argument shows that t 01 2 ≥ t 00 t 02 . Finally, Binet–Cauchy gives the identity
t 01 t 10 - t 00 t 11 \= ∑ p < q ( n p ) ( n q ) ( a p + 1 a q - a p a q + 1 ) ( b n - p b n - q + 1 - b n - p + 1 b n - q )
from the matrix product T = AXB , where A i j \= a i + j , X i j \= ( j n ) [ i + j \= n ] , B i j \= b i + j . [D. W. Walkup, Journal of Applied Probability 13 (1976), 79–80.]
126. The stated probability is p m \= ( n m ) m m ( n - m ) n - m / n n . We have p m /p m +1 = f m /f n − m − 1 , where f m \= ( m/ ( m + 1)) m . Since f 0 ≥ f 1 > … , the minimum occurs when m = ⌊ n/ 2⌋. And p ⌊ n / 2 ⌋ \= ( 1 + O ( 1 / n ) ) / π n / 2 , by exercise 1.2.11.2–9.
127. (a) Random binary vectors have Pr( X 1 + … + X n ≤ θn ) ≤ x − θn ((1 + x )/2) n for 0 < x ≤ 1, by the tail inequality 1.2.10–(24). Set x = θ/ (1 − θ ) and multiply by 2 n .
(b) We have lg θ n n \= H θ n - lg 2 π θ ( 1 - θ ) n + O ( 1 / n ) by 1.2.11.2–(18).
(c) Let p m′ m″ \= Pr( x ⊕ X ′ ⊕ X ″ is sparse and νX ′ = m ′, νX ′ = m ′). We will prove that each p m′ m″ is exponentially small, using several instructive methods.
First, let ∈ = θ (1 − 2 θ )/3. We can assume that ( θ − ∈ ) n < m ′, m ″ ≤ θn , because Pr v X ' ≤ ( θ - ∈ ) n \= O ( n 2 H θ - ∈ - H θ n ) is exponentially small.
Second, let Y ′ and Y ″ be random binary vectors whose bits are independently 1 with probabilities m ′ /n and m ″ /n . Each bit of x ⊕ Y ′ ⊕ Y ″ is 1 with probability m ′ /n (1 − m ″ /n )+(1 − m ′ /n ) m ″ /n ≥ 2( θ − )(1 − θ ) ≥ θ + ∈ when x has a 0 bit, or ( m ′ /n )( m ″ /n ) + (1 − m ″ /n )(1 − m ′ /n ) ≥ ( θ − ∈ ) 2 + (1 − θ ) 2 ≥ θ + when x has a 1 bit. Therefore, by the tail inequality, we have Pr( x ⊕ Y ′ ⊕ Y ″ is sparse) ≤ α n , where α = (1+ /θ ) θ (1 − /(1 − θ )) 1−θ . This is exponentially small, since α < 1.
Finally, let Z ′ and Z ″ be independent random bit vectors with νZ ′ = m ′ and νZ ″ = m ″. Then p m ' m ″ \= m n , m ″ n / S n , θ 2 P m ' m ″ , where P m ′m″ is the probability that x ⊕ Z ′ ⊕ Z ″ is sparse. Then Pr( x ⊕ Y ′ ⊕ Y ″ is sparse) ≥ Pr( x ⊕ Y ′ ⊕ Y ″ is sparse and νY ″ = m ′ and νY ′ = m ′) = Ω( P m ′m″ / n ) by exercise 126 . (Study this!)
[V. Guruswami, J. Håstad, and S. Kopparty, IEEE Trans. IT-57 (2011), 718–725, used this result to prove the existence of efficient linear list-decodable codes.]
128. (a) Pr k pings \= k n 1 n k 1 - 1 n n - k is binomial, hence Pr 1 ping \= 1 - 1 n n - 1 .
(b) It waits T rounds, where Pr( T = k ) = (1 − p ) k−1 p has the geometric distribution with p \= 1 n 1 - 1 n n - 1 . Hence, for example by exercise 3.4.1–17, we have E T \= 1 / p \= n n / ( n - 1 ) n - 1 \= ( n - 1 ) exp n ln ( 1 / ( 1 - 1 / n ) ) - e n - 1 2 e + O ( 1 / n ) . (The standard deviation, e n - 1 2 e - 1 2 + O ( 1 / n ) , is approximately the same as the mean.)
(c) The hint suggests that we study the “coupon collector’s distribution”: If each box of cereal randomly contains one of n different coupons, how many boxes must we buy before we’ve got every coupon? The generating function for this distribution is
C z \= n z n n - 1 z n - z … z n - n - 1 z \= n n / z - 0 n - 1 n / z - 1 … 1 n / z - n - 1 \= n n / z - 1 , because the time to acquire the next coupon, after we’ve already got k of them, is a geometric distribution with generating function ( n − k ) z/ ( n − kz ).
Let B be the number of boxes purchased. The upper tail inequality 1.2.10–(25) tells us that Pr( B ≥ (1 + ∈) n ln n) ≤ ( n/ ( n − 1/2)) −(1+ ∈ ) n ln n C ( n /( n − 1/2)), which is
e 1 + ∈ n ln n ln 1 - 1 / 2 n n n - 1 / 2 \= e - 1 + ∈ 2 ln n + O log n n 4 n n 2 n \= π n - ∈ / 2 1 + O log n n
by exercise 1.2.6–47. Thus B is a.s. less than (1 + ∈ ) n ln n .
Now let S be the number of successful accesses in r = ⌊(1 + ∈ ) en ln n ⌋ rounds. Then S is equivalent to r tosses of a biased coin for which the probability of success is p \= 1 - 1 n n - 1 \= 1 / e + O 1 / n , by (a). So S has the binomial distribution, and Pr( S ≤ (1 − ∈/2) rp ) ≤ e −∈ 2 rp /8 by exercise 1.2.10–22(b). This argument proves that S is q.s. greater than (1 − ∈ /2) rp = (1 + ∈/2 − ∈ 2 /2) n ln n + O (log n ).
Consequently S attempts at coupon collecting will a.s. succeed.
(d) An argument similar to (c) applies, with ∈ ↦ − ∈ and n − 1/2 ↦ n + 1/2.
[This exercise is based on a protocol analyzed in Jon Kleinberg and Éva Tardos’s book Algorithm Design (Addison–Wesley, 2006), §13.1. See Uriel Feige and Jan Vondrák, Theory of Computing 6 (2010), 247–290, §3.1, for optimum contention resolution with a related (but different) model.]
129. The hint follows because | cot πz | ≤ ( e π +1)/( e π −1) and | r ( z )| = O (1 /M 2 )onthe path of integration. The function π cot πz has no finite singularities except for simple poles at k for all integers k . Furthermore its residue is 1 at each of its poles. Therefore ∑ k \= - ∞ ∞ r k + ∑ j \= 1 t (Residue of r ( z ) π cot πz at z j ) = lim M→∞ O (1 /M ) = 0.
Let the sums be S 1 , S 2 , S 3 , S 4 . We have S 1 = π 2 /4, because the residue of (cot πz )/(2 z − 1) 2 at 1/2 is − π/ 4. And S 2 = π coth π , because the residue of (cot πz )/( z 2 +1) at ± i is −(coth π )/2. Similarly, the residue of (cot πz )/( z 2 + z +1) at - 1 ± i 3 / 2 is − α , where α \= tanh 3 π / 2 / 3 ; hence S 3 = 2 πα . Finally, the residues of (cot πz ) /( ( z 2 + z + 1)(2 z − 1)) at its poles are 2 7 α 1 ± i 3 / 2 and 0; hence S 4 \= - 2 7 S 3 . (With hindsight, we can explain this “coincidence” by noting that 7 / k 2 + k + 1 2 k - 1 \= 4 2 k - 1 - 2 k + 3 k 2 + k + 1 and that ∑ k \= - n n + 1 1 2 k - 1 \= ∑ k \= - n n - 1 2 k + 1 k 2 + k + 1 \= 0 .)
130. (a) Clearly E X 2 \= 1 π ∫ - ∞ ∞ t 2 d t / 1 + t 2 > 2 π ∫ 1 ∞ d t , so E X 2 = ∞. But E X \= 1 π ∫ - ∞ ∞ t d t / ( 1 + t 2 ) \= 1 2 π ln ( 1 + ∞ 2 ) - ln ( 1 + ( ∞ 2 ) ) \= ∞ - ∞ is undefined. Thus X has no mean (although it does have the median value 0).
(b) 1/2, 2/3, and 5/6, because Pr | X | ≤ x \= 1 π ∫ - x x d t 1 + t 2 \= 2 π arctan x when x ≥ 0.
(c) This follows directly from the fact that Pr( X ≤ x ) = (arctan x ) /π +1/2.
(d) In step P4 of Algorithm 3.4.1P, V 1 /V 2 is a random tangent, so it is a Cauchy deviate. Furthermore, by the theory underlying that algorithm, V 1 /V 2 is the ratio of independent normal deviates; thus, Z ← X/Y is Cauchy whenever X and Y are independently normal. The Cauchy distribution is also Student’s t distribution with 1 degree of freedom; Section 3.4.1’s recipe for generating it is to compute Z ← X/ | Y |.
(e) We have z ≤ Z ≤ z + dz ⇔ ( z − qY ) /p ≤ X ≤ ( z + dz − qY ) /p . Hence
Pr ( z ≤ Z + d z and y ≤ Y ≤ y + d y ) \= 1 π d z p 1 ( 1 + ( z - q y / p 2 ) ) 1 π d y 1 + y 2 ,
and we want to integrate this for −∞ < y < ∞. The integrand has poles at y = ± i and y = ( z ± ip ) /q , and it is O (1 /M 4 ) when | y | = M . So we can integrate on a semicircular path, y = t for − M ≤ t ≤ M followed by y = Me it for 0 ≤ t ≤ π , obtaining
∞ - ∞ d y ( p 2 + ( z - q y ) 2 ) ( 1 + y 2 ) \= 2 πi ( ( Residue at i ) + ( Residue at z + p i q ) ) \= 1 p ( 1 + z 2 ) .
Thus Pr ( z ≤ Z ≤ z + d z ) \= 1 π d z / ( 1 + z 2 ) as desired.
It follows by induction (see answer 42 ) that any convex combination of independent Cauchy deviates is a Cauchy deviate . In particular, the average of n independent Cauchy deviates is no more concentrated than a single deviate is; the “ law of large numbers” doesn’t always hold. [S. D. Poisson proved this special case in Connaissance des Tems pour l’an 1827 (1824), 273–302. The distribution is named after A. L. Cauchy, not Poisson, because Cauchy clarified matters by publishing seven notes about it ― one note per week! ― in Comptes Rendus Acad. Sci. 37 (Paris, 1853), 64–68, ... , 381–385.]
(f) By (e), c · X is | c 1 | + … + | c n | = || c || 1 times a Cauchy deviate. [This fact has important applications to dimension reduction and data streams; see P. Indyk, JACM 53 (2006), 307–323.]
(g) If t ≥ 0 we get e −t , using the residue of e itz /(1 + z 2 ) at z = i and the semicircular path of part (e), because the integrand is O (1 /M 2 ) when | z | = M . If t ≤ 0 we can integrate in the opposite direction, getting e + t . Hence the answer is e −| t | .
131. (a) By exercise 129 , c = 1/( π coth π ). [Notice that coth π ≈ 1.0037 is nearly 1.]
(b) When n ≠ 0, the method of exercise 129 tells us, somewhat surprisingly, that ∑ k \= - ∞ ∞ 1 / 1 + k 2 1 + n - k 2 \= 2 π coth π / n 2 + 4 . Thus Pr( X + Y = n ) = 2 c/ ( n 2 + 4). When n is even, this is exactly 1 2 Pr 2 Z \= n .
When n = 0, there’s a double pole and the calculations are trickier. We can more easily compute Pr ( X + Y ≠ 0 ) \= ∑ n \= 1 ∞ 4 c n 2 + 4 \= c ( π coth 2 π - 1 2 ) ≈ . 837717 . Thus Pr( X + Y = 0) ≈ .162283.
132. (a) k K n - k N - K / n N . [Hence the probability generating function g ( z ) \= Σ k p k z k is a hypergeometric function, ( n N - K ) F ( N - K − n + 1 - K , - N | z ) / ( n N ) ; see Eq. 1.2.6–(39).]
(b) g ′(1) = nK/N ; {⌊(( n + 1)( K +1) − 1)/( N +2)⌋ , ⌊( n + 1)( K + 1))/( N +2)⌋}; n ( N − n )( N − K )/( N 3 − N 2 ). (Note that g ″(1) = n ( n − 1) K ( K − 1)/( N ( N − 1)).)
(c) Let Q = X 1 + … + X n and Z m \= E( Q | X 1 ,...,X m ). Then we have Z m \= ( K − X 1 −‧‧‧− X m )( n − m )/( N − m )+ X 1 + ‧‧‧ + X m . The associated fair sequence is Y m \= Z m − Z m − 1 = Δ m ( X 1 + ‧‧‧ + X m − 1 − K ) + c m X m for 1 ≤ m ≤ n , where c m \= ( N − n )/( N − m ) and Δ m = c m − c m − 1 . Since Y m changes by at most c m when { X 1 ,..., X m −1 } are given and X m varies, (37) tells us that Pr( Q ≥ nK/N + x ) = Pr( Z n − Z 0 ≥ x ) = Pr( Y 1 + … + Y n ≥ x ) ≤ e − 2 x 2 / ( c 1 2 + ⋅ ⋅ ⋅ + c n 2 ) ≤ e − 2 x 2 / n .
133. (a) By induction on m : Suppose m > 1 and no t rows are shattered. Discard duplicate columns, and let 2 b of the remaining ones have a “mate” whose bit in the bottom row is complemented. Let a of them have no mate. Then the first m − 1 rows contain a + b ≤ f ( m − 1, t ) distinct columns, by induction; and b ≤ f ( m − 1, t − 1). Hence there are a + 2 b ≤ f ( m − 1, t )+ f ( m − 1, t − 1) = f ( m, t ) distinct columns.
(b) For example, let the columns be all length- m vectors that have at most t −1 1s.
[N. Sauer, Journal of Combinatorial Theory A13 (1972), 145–147.]
134. (a) Use Chebyshev’s inequality (18), because the variance is p j (1 − p j ) ≤ 1/4.
(b) Consider the m 2 m equally likely ways we could have gotten two samples ( χ , χ ′) from the same 2 m atomic events. If A j occurs K = M j ( χ )+ M j ( χ ′) times,
Pr ( E j ^ ( χ , χ ' ) > ∈ ) \= Pr ( ∑ { ( k K ) ( m - k 2 m - k ) / ( m 2 m ) | | k - K / 2 | > ∈ m } ) ≤ 2 e - 2 ( ∈ m ) 2 / m .
(c) Δ 2 m ( A ) Pr E ^ j χ , χ ' > ∈ / 2 ≥ Pr max j E ^ j χ , χ ' ≥ ∈ / 2 and E ( χ ) > ∊ ) ≥ Pr ( E j (χ′) ≤ ∊/2 and E j (χ) > ∊ and E ( χ ) > ∈ ) ≥ 1 2 Pr ( E j ( χ ) > ∈ and E ( χ ) > ∊ ). [ Teoriya Veroyatnosteĭ i ee Primeneniîa 16 (1971), 264–279.]
135. (Notice that the smallest non -Baxter permutations are 3142 and its inverse, 2413.)
If P is a Baxter permutation, so are P R = p n ... p 1 and P C \= p ¯ 1 ... p ¯ n , where x ¯ \= n + 1 − x . So is the permutation P \ n obtained by deleting n ; and so are the permutations P \ x obtained by deleting x and subtracting 1 from each element that exceeds x , if x = p n or x = 1 or x = p 1 . (Consider, for example, deleting n from P − .)
Let’s look at the n +1 permutations obtained by inserting n +1 into an n -element Baxter permutation. For example, when n = 8 and P = 21836745 the nine extensions are 921836745, 291836745, 219836745, 218936745, 218396745, 218369745, 218367945, 218367495, 218367459. Only four of these fail Baxter’s property, namely 291836745, 218396745, 218369745, and 218367495; and we soon discover the general rule: n + 1 can be Baxterly inserted if and only if it’s placed just before a left-to-right maximum, or just after a right-to-left maximum. (In our example, the left-to-right maxima are 2 and 8; the right-to-left maxima are 5, 7, and 8.)
Let B n ( i, j, k ) be the number of ( n +1)-element Baxter permutations with exactly i + 1 left-to-right maxima, j + 1 left-to-right minima, k ascents, and n − k descents. Such permutations correspond to floorplans with n + 1 rooms, i + 1 rooms touching the bottom of the frame, j + 1 rooms touching the left of the frame, k + 2 vertical bounds, and n − k + 2 horizontal bounds (see exercise 7.2.2.1–372 ). The reasoning above yields an interesting recurrence for nonnegative i , j , k , n :
B 0 ( i , j , k ) \= [ i \= j \= k \= 0 ] , B n + 1 ( i + 1 , j + 1 , k ) \= Σ i ′ > i B n ( i ' , j , k ) + Σ j ′ > j B n ( i , j ' , k - 1 ) ;
and the solution for i + j ≤ n can be expressed as a determinant of binomial coefficients:
B n ( i , j , k ) \= det ( ( n − j − 1 k − 1 ) ( n k − 1 ) ( n - i - 1 n - k + 1 ) ( n − j − 1 k ) ( n k ) ( n − i − n − k ) ( n − j − 1 k + 1 ) ( n k + 1 ) ( n − i − 1 n − k − 1 ) ) , unless { i \= 0 and j \= n or i \= n and j \= 0 .
Summing on i and j now gives the simpler formula
b n ( k ) \= t n + 1 ( k + 1 ) / t n + 1 ( 1 ) , w h e r e t n ( k ) \= ( n k − 1 ) ( n k ) ( n k + 1 ) , ,
for the number of n -element Baxter permutations with exactly k ascents.
Since the terms with k ≈ n/ 2 dominate the sum b n \= Σ k b n ( k ), we obtain the asymptotic value
b n \= 8 n + 2 12 π n 4 1 - 22 3 n + O n - 2 ,
due to A. M. Odlyzko. [See G. Baxter, Proc. American Math. Soc. 15 (1964), 851– 855; F. R. K. Chung, R. L. Graham, V. E. Hoggatt, Jr., and M. Kleiman, Journal of Combinatorial Theory A24 (1978), 382–394; W. M. Boyce, Houston J. Math. 7 (1981), 175–189; S. Dulucq and O. Guibert, Discrete Math. 180 (1998), 143–156.] R. L. Ollerton has found the recurrence ( n + 2)( n + 3) b n \= (7 n 2 + 7 n − 2) b n − 1 + 8( n − 1)( n − 2) b n − 2 , with b 0 = 1, as well as the closed form b n \= F 2 , 3 1 - n , - n , - 1 - n | - 1 .
The initial terms are ( b 0 , b 1 , ... ) = (1, 1, 2, 6, 22, 92, 422, 2074, 10754, 58202, ...).
136. It’s true if y ≤ x + 1 2 , because f ( x + t ) − f ( x ) increases from f ( t ) to − f (1 − t ) as x increases from 0 to 1 − t . But it fails when x < 1 2 and y = 1.
137. (a) The sets U \= x | Pr X ≤ x ≥ 1 2 and L \= x | Pr X < x ≤ 1 2 are intervals. Let m \= inf U and m \= sup L ; then U ∩ L \= m . . m . Since the distribution function Pr( X ≤ x ) is right-continuous, m − ∈ U ; similarly, m − ∈ L , because Pr( X<x ) is left-continuous. Also m ≤ m ; for if m < x < m then Pr ( X ≤ x ) < 1 2 < Pr ( X < x ) .
(b) If m < m then Pr X ≤ m ≤ Pr X < m \= 1 - Pr X ≥ m ≤ 1 2 ≤ Pr X ≤ m .
(c) Pr X ≤ y ≥ 1 2 implies y ≥ m ; Pr( X < x ) ≤ 1 2 implies x ≤ m ; so it’s true if m \= m . But we might have x > m or y < m .
(d) Suppose m ∊ med X and c < m . (A similar argument applies when c > m .) Let Δ x = | x − c |−| x − m |. If x ≥ m we have Δ x = m − c . If x < m we have ∆ x \= c - m + 2 x - ˙ c ; hence E(Δ X | X < m ) ≥ c − m . Therefore E(Δ X ) ≥ ( c − m ) Pr( X<m )+ ( m − c )Pr( X ≥ m ) = ( m − c ) (2 Pr( X ≥ m ) − 1) ≥ 0. Equality holds if and only if Pr X ≥ m \= 1 2 and Pr( c<X <m ) = 0; the latter is the same as Pr( X ≤ c ) = Pr( X<m ). [See M. Mitzenmacher and E. Upfal, Probability and Computing (2017), Theorem 3.9.]
(e) True by Cantelli’s inequality, answer 48 : If m ≥ μ then 1 2 ≤ Pr ( X ≥ m ) ≤ σ 2 / ( σ 2 + ( m − μ ) 2 ) . If 1 2 ≤ Pr ( − X ≥ − m ) ≤ σ 2 / ( σ 2 + ( μ − m ) 2 ) .
(f) Call f a “C-function” if I t \= { x | f ( x ) ≤ t } is connected and closed for all t . Every convex f is a C-function; for if a ∊ I t and b ∊ I t , we have pa +(1 − p ) b ∊ I t for 0 ≤ p ≤ 1; also I t is closed because f is continuous. (There also are rather wild C-functions, such as f x \= x < 0 ? 3 : x < 1 ? 2 - x : x ≤ 2 ? x - 1 : x ≤ 3 ? x : x . .
Given a C-function f and a random variable X , let med X \= m . . m and med f X \= M . . M . If M ≤ M ≤ M , then I M is a closed interval and Pr( X ∊ I M ) = Pr( f ( X )≤ M ) ≥ 1 2 . Thus by (c), either f m ≤ M or f m ≤ M . (For example, if f ( x ) = − x we have m \= - M and m \= - M .) [See M. Merkle, Statistics & Probability Letters 71 (2005), 277–281.]
138. Working in the slices of probability space where Y is constant, we have (by definition) var( X | Y ) = E( X 2 | Y ) − (E( X | Y )) 2 and var(E( X | Y )) = E(E( X | Y )) 2 − (E(E( X | Y ))) 2 . Hence E(var( X | Y )) = E(E( X 2 | Y )) − E(E( X | Y )) 2 . The complicated term E(E( X | Y )) 2 fortuitously cancels out, giving var(E( X | Y )) + E(var( X | Y )) = E(E( X 2 | Y )) − (E(E( X | Y ))) 2 = E X 2 − (E X ) 2 . [See CMath , pages 423–425.]
139. Let x ( z ) = Σ k Pr( X n \= k ) z k , g n ( w, z ) = Σ j,k Pr( R n \= j, S n \= k ) w j z k , h n ( w, z ) = Σ j,k Pr S n + \= j , S n \= k w j z k ; these generating functions involve negative values of k , so we treat them as “formal series.” We shall prove that g = h , where
g \= ∑ n \= 0 ∞ g n w , z t n and h \= exp ∑ n \= 1 ∞ h n w , z t n n ;
that will suffice because g n ( w, z ) = r n ( wz, z −1 ) and h n w , z \= s n + w z + s n - z - 1 - 1 .
Let X be the operation that multiplies a formal series by x ( z ), and let P be the operation that replaces w j z k by w max( j, k) z k . Notice that h n ( w, z ) = P ( x ( z ) n ); furthermore we have g 0 ( w, z ) = 1, g n ( w, z ) = PXg n − 1 for n > 0. It follows that g is the unique formal series that satisfies g = 1 + tP Xg . To finish the proof, we have 1 - t X h \= exp 1 - P ln 1 - t x z \= 1 + ∑ n \= 1 ∞ 1 - P ln 1 - t x z n / n ! ; hence h − tP Xh = P ( (1 − tX ) h) = 1. [J. G. Wendel, Proc. Amer. Math. Soc. 9 (1958), 905–908.]
140. (a) Let q = 1 − p . The expected number of marked elements that remain a max is ∑ k k n p k q n - k H k \= H n + ln p + O q n / n , by Theorem 1.2.7A. To this we add ∑ m \= 1 n t m , where t m \= Pr( x m unmarked and still a max) \= ∑ j , k j m - 1 k n - m p j + k q n - j - k / j j + k . (For example, t 1 = q ; t 2 = q 2 + ( q − q n )/( n − 1); t m \= t n + 1− m .) The identity ∑ k k n p k q n - k / j k + j \= 1 - ∑ k \= 0 j \= 1 k n + j p k q n + j - k / p j j n + j shows that, for fixed m , t m \= ∑ j \= 0 m - 1 q m - j m - 1 j / n - m + j j + O q n / n . Summing on m , and trading tails, yields t 1 + … + t n \= 2 q/p + O ( q n /n ). [For this result, as well as those of parts (b) and (c), see C. Banderier, R. Beier, and K. Mehlhorn, LNCS 2747 (2003), 198–207.]
(b) Say m \= n . If a of the first m elements are marked, and b of the last n − m , the probability that all a leave the first m positions is q \= b a / a + b a > b - a / b a ; and in this case λ ( X ) ≥ m − a . We q.s. have a ≤ 3 4 m and b ≥ 1 4 n + m ; consequently q ≥ exp( a ln(1 − a/b )) ≥ exp(− a 2 /( b − a )) ≥ exp(−9/4) and λ ( X ) \= Ω ( n ) .
(c) Let m \= 8 n / p ln n and ignore all x k with k ≤ m or x k ≥ n − m ; at most 2 m maxs are ignored. At most about ln pn of the marked elements are maxs. And if x k is neither ignored nor marked, it’s a max with probability O (1 /n ); the reason is that q.s. at most 2 pn are marked, of which ≥ pm/ 2 precede x k and ≥ pm/ 2 exceed x k .
(d) If x ¯ k > x ¯ k + 1 , swapping x ¯ k ↔ x ¯ k + 1 and δ k ↔ δ k + 1 doesn’t decrease E λ ( X ).
(e) Let m \= ∈ n and ∆ k \= x ¯ k - x ¯ k - m , where x ¯ k \= 0 for k < 0. If x k is a max then either (*) ∈ < Δ k + δ k or (**) ∈ ≥ Δ k + δ k > max{ δ k −1 ,..., δ k− m }. One can show that Pr(*) ≤ Pr(**); hence Pr( x k is a max) ≤ Δ k /(2 ∈ )+1/( m +1)+1 /k . Sum on k .
See V. Damerow, B. Manthey, F. Meyer auf der Heide, H. Räcke, C. Scheideler, C. Sohler, and T. Tantau, ACM Transactions on Algorithms 8 (2012), 30:1–30:28, where a matching lower bound is also proved. Similarly, if each δ k is a normal deviate with standard deviation σ , they showed that E λ X \= O log n 1 + σ - 1 log n .
141. We can assume that p 1 + … + p n \= 1. Then e ln(E X) ≥ e E ln X (ln is concave).
142. (a) Let p j \= Pr(| X |= x j ). Since every term in the difference M q M t - M r M s \= ∑ j < k p j p k x j q x k q x k s - q - x j s - q x k r - q - x j r - q is nonnegative, we have M q M t ≥ M r M s .
(b) The hint gives M s / M r M r / s - r ≥ x 1 p 1 x 1 r ⋯ x n p n x n r . Similarly, but reversing the inequality because q < r , M q / M r M r / q - r ≤ x 1 p 1 x 1 r ⋯ x n p n x n r . Take the M r th root.
(c) The “fact” follows when ( q, r, s ) = (0 , 1 /p, 1) in (b). Let c \= 1 / ∑ b k q , and set p k \= c b k q , x k \= a k q / b k q ; then M 1/ p \= c Σ a k b k , M 1 \= c ∑ a k p . (When 0 < p < 1 and q < 0, the same relation holds but with ≤ changed to ≥ and b k \= 0 forbidden.)
(d) | E X Y | ≤ E ( | X | | Y | ) \= ∑ i , j p i j 1 / p + 1 / q x i y j ≤ ( E | X | p ) 1 / p ( E | Y | q ) 1 / q , where p ij \= Pr(| X |= x i and | Y |= y j ) is the joint distribution of | X | and | Y |.
Historical notes: This inequality and Jensen’s inequality evolved in concert. The fact that E | X | r ≤ (E | X |) r for 0 < r < 1, while E | X | r ≥ (E | X |) r for other values of r , was already implicit on page 155 of Reynaud and Duhamel’s Problèmes et développemens (Paris, 1823). Rogers published his contributions in Messenger of Math. 17 (1887), 145–150 (with a few typographic errors). That inspired O. Höder [ Göttinger Nachrichten (1889), 38–47] to prove (20) for all f with f ″( x ) ≥ 0, obtaining Rogers’s identities as corollaries. Many related results are detailed in Hardy, Littlewood, and Pólya’s book Inequalities (1934), Chapter 2. For example, if p j ,a ij ≥ 0 for 1 ≤ i ≤ m and 1 ≤ j ≤ n , with Σ p j \= 1, their Theorem 11 states that
∑ i \= 1 m ( Π j \= 1 n a i j p j ) ≤ Π j \= 1 n ( ∑ i \= 1 m a i j ) p j . [ The case n \= 2 , p 1 \= 1 p , p 2 \= 1 q , is ( c ) . ]
143. Let M = (E(| X | + | Y |) p ) 1/ p \= (Σ i,j ( p ij ( x i + y j ) p )) 1/ p , with the p ij of answer 142(d) . Then we have M = Σ( x )+Σ( y ), where Σ( x ) = Σ i,j p ij x i ( x i + y j ) p −1 /M p −1 \= ∑ i , j p i j 1 / p x i p i j 1 / p x i + y i p - 1 / M p - 1 ≤ ∑ i , j p i j x i p 1 / p ∑ i j p i j x i + y j p 1 / q / M p - 1 \= E | X | p 1 / p . Add Σ( y ). [H. Minkowski, Geometrie der Zahlen (Leipzig, 1896), §40(I).]
144. (a) By convexity, | x | p = | E( x + Y )| p ≤ E | x + Y | p for any x . Take E of both sides.
(b) By (a), E | X | p = E | X + | p ≤ E | X + − X − | p .
(c) The hint follows because (1 + x ) p + (1 − x ) p − 2 x p ≥ 2 for 0 ≤ x ≤ 1. Consequently E | X | p + E | Y | p ≤ E | X + Y | p when E | X + Y | p = E | X − Y | p . Now use induction on n . [See J. A. Clarkson, Trans. Amer. Math. Soc. 40 (1936), 396–414.]
(d) E | X 1 | p + … + E | X n | p ≤ E | X 1 sym | p + … + E | X 1 sym + … + X n sym | p \= E | X 1 + … + X n + - X 1 - + … + X n - | p ≤ E 2 p - 1 | X 1 + + … + X n + | p + E 2 p - 1 | - ( X 1 - + … + X n - ) | p \= 2 p E | X 1 + … + X n | p . [See A. Gut, Probability: A Graduate Course (Springer, 2013), Theorem 3.6.1. We’ve used the fact that | x + y | p ≤ 2 p −1 (| x | p + | y | p ), which actually holds for p ≥ 1 because the mapping x ↦ | x | p is convex.]
145. We have a 1 2 + ⋯ + a n 2 m \= ∑ k 1 , … , k n c k 1 , … k n a 1 2 k 1 … a n 2 k n by the multinomial theorem, Eq. 1.2.6−(42), where; c k 1 , … k n \= k 1 , … , k n m ; E ( ( a 1 X 1 + ⋅ ⋅ ⋅ + a n X n ) 2 m ) \= ∑ k 1 , … , k n c ' ( k 1 , … k n ) a 1 k 1 … a n k n , where c ' k 1 , … , k n \= k 1 , … , k n 2 m when each k j is even, otherwise c ′( k 1 ,..., k n ) = 0. And c ′(2 k 1 ,...,2 k n ) /c ( k 1 ,..., k n ) = (2 m − 1)!!/ ∏ j \= 1 m 2 k j - 1 !!. [A. Khintchine, Math. Zeitschrift 18 (1923), 109–116. More generally, ( a 1 2 + … + a n 2 ) p / 2 ≤ E | a 1 X 1 + … + a n X n | p ≤ 2 p / 2 π - 1 / 2 Γ ( p + 1 2 ) ( a 1 2 + … + a n 2 ) p / 2 , for all p ≥ 2; see U. Haagerup, Studia Mathematica 70 (1981–1982), 231–283.]
146. For every binary vector t = t 1 ... t n let T n t \= ∑ k \= 1 n - 1 t k X k . Also let ∑ k \= 1 n X k , S n sym \= ∑ k \= 1 n X k sym , T n sym t \= ∑ k \= 1 n - 1 t k X k sym . By exercise 144 we have
2 − 2 m E T n ( t ) 2 m ≤ 2 − 2 m E T n sym ( t ) 2 m \= 2 − 2 m E ( S n sym ) 2 m ≤ E S n 2 m ≤ E ( T n sym ) 2 m \= E T n sym ( t ) 2 m ≤ 2 2 m E T n ( t ) 2 m
for all t , because S n sym and T n sym t have the same distribution. Exercise 145 tells us that
∑ k \= 1 n x k 2 m ≤ 1 2 n ∑ t ∑ k \= 1 n - 1 t k x k 2 m ≤ 2 m - 1 ! ! ∑ k \= 1 n x k 2 m
for all sequences x 1 ...x n of atomic values. So the result follows by applying E. [ Fundamenta Mathematicæ 29 (1937), 60–90; Studia Mathematica 7 (1938), 104–120.]
147. This is an application of the previous several exercises; see A. Gut, Probability (2013), Theorem 3.9.1. [H. P. Rosenthal, Israel J. Mathematics 8 (1970), 273–303.]
As to volume 4, well, I’m making progress but it is the toughest of the lot.
— DONALD E. KNUTH, letter to Michael F. Yoder (19 November 1973)
Section 7.2.2
1. Although many formulations are possible, the following may be the nicest: (i) D k is arbitrary (but hopefully finite), and P l is always true. (ii) D k \= {1, 2,..., n } and P l \= ‘ x j ≠ x k for 1 ≤ j < k ≤ l ’. (iii) For combinations of n things from N , D k \= {1,..., N + 1 − k } and P l \= ‘ x 1 > ··· > x l ’. (iv) D k \= {0, 1,..., ⌊ n/k ⌋}; P l \= ‘ x 1 ≥ ··· ≥ x l and n − ( n − l ) x l ≤ x 1 + ··· + x l ≤ n ’. (v) For restricted growth strings, D k \= {0,..., k −1} and P l \= ‘ x j +1 ≤ 1+max( x 1 ,..., x j ) for 1 ≤ j < l ’. (vi) For indices of left parentheses (see 7.2.1.6 (8)), D k \= {1,...,2 k − 1} and P l \= ‘ x 1 < ··· < x l ’.
2. True. (If not, set D 1 ← D 1 ∩ { x | P 1 ( x )}.)
3. Let D k \= {1,...,max degree on level k − 1}, and let P l ( x 1 ,..., x l ) = ‘ x 1 . ··· . x l is a label in T ’s Dewey decimal notation’ (see Section 2.3).
4. We can restrict D 1 to {1, 2, 3, 4}, because the reflection (9− x 1 ) ... (9− x 8 ) of every solution x 1 ... x 8 is also a solution. (H. C. Schumacher made this observation in a letter to C. F. Gauss, 24 September 1850.) Notice that Fig. 68 is left-right symmetric.
5. try ( l ) = “If l > n , visit x 1 ... x n . Otherwise, for x l ← min D l , min D l + 1, ... , max D l , if P l ( x 1 ,..., x l ) call try ( l + 1).”
This formulation is elegant, and fine for simple problems. But it doesn’t give any clue about why the method is called “backtrack”! Nor does it yield efficient code for important problems whose inner loop is performed billions of times. We will see that the key to efficient backtracking is to provide good ways to update and downdate the data structures that speed up the testing of property P l . The overhead of recursion can get in the way, and the actual iterative structure of Algorithm B isn’t difficult to grasp.
6. Excluding cases with j = r or k = r from (3) yields respectively (312, 396, 430, 458, 458, 430, 396, 312) solutions. (With column r also omitted there are just (40, 46, 42, 80, 80, 42, 46, 40).)
7. Yes, almost surely for all n > 16. One such is x 1 x 2 ... x 17 = 2 17 12 10 7 14 3 5 9 13 15 4 11 8 6 1 16. [See Proc. Edinburgh Math. Soc. 8 (1890), 43 and Fig. 52.] Preuβer and Engelhardt found 34,651,355,392 solutions when n = 27.
8. Yes: (42736815, 42736851); also therefore (57263148, 57263184).
9. Yes, at least when m = 4; e.g., x 1 ... x 16 = 5 8 13 16 3 7 15 11 6 2 10 14 1 4 9 12. There are no solutions when m = 5, but 7 10 13 20 17 24 3 6 23 11 16 21 4 9 14 2 19 22 1 8 5 12 15 18 works for m = 6. (Are there solutions for all even m ≥ 4? C. F. de Jaenisch, Traité des applications de l’analyse mathématique au jeu des échecs 2 (1862), 132 133, noted that all 8-queen solutions have four of each color. He proved that the number of white queens must be even, because Σ k \= 1 4 m ( x k + k ) is even.)
10. Let bit vectors a l , b l , c l represent the “useful” elements of the sets in (6), with a l \= ∑{2 x −1 | x ∈ A l }, b l \= ∑{2 x −1 | x ∈ B l ∩ [1 .. n ]}, c l \= ∑{2 x −1 | x ∈ C l ∩ [1 .. n ]}. Then step W2 sets bit vector s l ← μ & a ¯ l & b ¯ l & c ¯ l , where μ is the mask 2 n − 1.
In step W3 we can set t ← s l & (− s l ), a l +1 ← a l + t , b l +1 ← ( b l + t ) ≫ 1, c l +1 ← (( c l + t ) ≪ 1) & μ ; and it’s also convenient to set s l ← s l − t at this time, instead of deferring this change to step W4.
(There’s no need to store x l in memory, or even to compute x l in step W3 as an integer in [1 .. n ], because x l can be deduced from a l+1 − a l when a solution is found.)
11. (a) Only when n = 1, because reflected queens can capture each other.
(b) Queens not in the center must appear in groups of four.
(c) The four queens occupy the same rows, columns, and diagonals in both cases.
(d) In each solution counted by c n we can independently tilt (or not) each of the ⌊ n /4⌋ groups of four. [ Mathematische Unterhaltungen und Spiele 1 , second edition (Leipzig: Teubner, 1910), 249–258.]
12. With distinct x k , Σ k \= 1 n ( x k + k ) \= 2 ( n + 1 2 ) ≡ 0 (modulo n ). If the ( x k + k ) mod n are also distinct, the same sum is also ≡ ( n + 1 2 ) . But that’s impossible when n is even.
Now suppose further that the numbers ( x k − k ) mod n are distinct. Then we have Σ k \= 1 n ( x k + k ) 2 ≡ Σ k \= 1 n ( x k − k ) 2 ≡ Σ k \= 1 n k 2 \= n ( n + 1 ) ( 2 n + 1 ) / 6 . And we also have Σ k \= 1 n ( x k + k ) 2 + Σ k \= 1 n ( x k − k ) 2 \= 4 n ( n + 1 ) ( 2 n + 1 ) / 6 ≡ 2 n / 3 , which is impossible when n is a multiple of 3. [See W. Ahrens, Mathematische Unterhaltungen und Spiele 2 , second edition (1918), 364–366, where G. Pólya cites a more general result of A. Hurwitz that applies to wraparound diagonals of other slopes.]
Conversely, if n isn’t divisible by 2 or 3, we can let x n \= n and x k \= (2 k ) mod n for 1 ≤ k ≤ n . [The rule x k \= (3 k ) mod n also works. See Édouard Lucas, Récréations Mathématiques 1 (1882), 84–86.]
13. The ( n + 1) queens problem clearly has a solution with a queen in a corner if and only if the n queens problem has a solution with a queen-free main diagonal. Hence by the previous answer there’s always a solution when n mod 6 ∈ {0, 1, 4, 5}.
Another nice solution was found by J. Franel [L’ Intermédiaire des Mathématiciens 1 (1894), 140–141] when n mod 6 ∈ {2, 4}: Let x k \= ( n /2 + 2 k − 3[2 k ≤ n ]) mod n + 1, for 1 ≤ k ≤ n . With this setup we find that x k − x j \= ±( k − j ) and 1 ≤ j < k ≤ n implies (1 or 3)( k − j ) + (0 or 3) ≡ 0 (modulo n ); hence k − j = n − (1 or 3). But the values of x 1 , x 2 , x 3 , x n − 2 , x n − 1 , x n give no attacking queens except when n = 2.
Franel’s solution has empty diagonals, so it provides solutions also for n mod 6 ∈ {3, 5}. We conclude that only n = 2 and n = 3 are impossible.
[A more complicated construction for all n > 3 had been given earlier by E. Pauls, in Deutsche Schachzeitung 29 (1874), 129–134, 257–267. Pauls also explained how to find all solutions, in principle, by building the tree level by level ( not backtracking).]
14. For 1 ≤ j ≤ n , let x 1 ( j ) … x m ( j ) be a solution for m queens, and let y 1 . . . y n be a solution for n toroidal queens. Then X ( i − 1 ) n + j \= ( x i ( j ) − 1 ) n + y j (for 1 ≤ i ≤ m and 1 ≤ j ≤ n ) is a solution for mn queens. [I. Rivin, I. Vardi, and P. Zimmermann, AMM 101 (1994), 629–639, Theorem 2.]
15. More precisely, there’s a constant σ = e 1− α such that, for any fixed ϵ with 0 < ϵ < σ , Q ( n )/ n ! is q.s. between ((1 − ϵ ) σ ) n and ((1 + ϵ ) σ ) n . In fact, a subtle analysis [ Advances in Math . 427 (2023), 109127:1–83] shows that the average of all solutions approaches a fascinating probability distribution. P. Nobel, A. Agrawal, and S. Boyd have computed α accurately [ Optimization Letters 17 (2023), 1229–1240].
16. Let the queen in row k be in cell k . Then we have a “relaxation” of the n queens problem, with | x k − x j | becoming just x k − x j in (3); so we can ignore the b vector in Algorithm B * or in exercise 10 . We get
n \= 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 H ( n ) \= 1 1 1 3 7 23 83 405 2113 12657 82297 596483 4698655 40071743 367854835
[N. J. Cavenagh and I. M. Wanless, Discr. Appl. Math . 158 (2010), 136.146, Table 2 .]
17. It fails spectacularly in step L5. The minus signs, which mark decisions that were previously forced, are crucial tags for backtracking.
18. x 4 … x 8 \= 2 ¯ 1 ¯ 0 4 ¯ 0 , p 0 … p 4 = 33300, and y 1 y 2 y 3 = 130. (If x i ≤ 0 the algorithm will never look at y i ; hence the current state of y 4 … y 8 is irrelevant. But y 4 y 5 happens to be 20, because of past history; y 6 , y 7 , and y 8 haven’t yet been touched.)
19. We could say D l is {− n ,...,−2, −1, 1, 2,..., n }, or { k | k ≠ 0 and 2 − l ≤ k ≤ 2 n − l − 1}, or anything in between. (But this observation isn’t very useful.)
20. First we add a Boolean array a 1 ... a n , where a k means “ k has appeared,” as in Algorithm B *. It’s 0 ... 0 in step L1; we set a k ← 1 in step L3, a k ← 0 in step L5.
The loop in step L2 becomes “while x l < 0, go to L5 if l ≥ n − 1 and a 2 n − l −1 \= 0, otherwise set l ← l + 1.” After finding l + k + 1 ≤ 2 n in L3, and before testing x l + k +1 for 0, insert this: “If l ≥ n − 1 and a 2 n − l −1 \= 0, while l + k + 1 ≠ 2 n set j ← k , k ← p k .”
21. (a) In any solution x k \= n ⇔ x k + n + 1 \= − n ⇔ x n − k D \= n .
(b) x k \= n − 1 for some k ≤ n /2 if and only if x k D \= n − 1 for some k > n /2.
(c) Let n ′ = n − [ n is even]. Change ‘ l ≥ n − 1 and a 2 n − l −1 \= 0’ in the modified step L2 to ‘( l = ⌊ n /2⌋ and a n ′ \= 0) or ( l ≥ n − 1 and a 2 n − l −1 \= 0)’. Insert the following before the other insertion into step L3: “If l = ⌊ n /2⌋ and a n ′ \= 0, while k ≠ n ′ set j ← k , k ← p k .” And in step L5 — this subtle detail is needed when n is even — go to L5 instead of L4 if l = ⌊ n /2⌋ and k = n ′.
22. The solutions 1 1 ¯ and 21 1 ¯ 2 ¯ for n = 1 and n = 2 are self-dual; the solutions for n = 4 and n = 5 are 431 1 ¯ 2 3 ¯ 4 ¯ 2 ¯ , 245 2 ¯ 31 1 ¯ 4 ¯ 3 ¯ 5 ¯ , 451 1 ¯ 23 4 ¯ 2 ¯ 5 ¯ 3 ¯ , and their duals. The total number of solutions for n = 1, 2, ... is 1, 1, 0, 2, 4, 20, 0, 156, 516, 2008, 0, 52536, 297800, 1767792, 0, 75678864, ... ; there are none when n mod 4 = 3, by a parity argument.
Algorithm L needs only obvious changes. To compute solutions by a streamlined method like exercise 21 , use n ′ = n − (0, 1, 2, 0) and substitute ‘ l = ⌊ n /4⌋ + (0, 1, 2, 1)’ for ‘ l = ⌊ n /2⌋’, when n mod 4 = (0, 1, 2, 3); also replace ‘ l ≥ n − 1 and a 2 n − l −1 \= 0’ by ‘ l ≥ ⌈ n /2⌉ and a ⌊(4 n +2−2 l )/3⌋ \= 0’. The case n = 15 is proved impossible with 397 million nodes and 9.93 gigamems.
23. slums → sluff , slump , slurs , slurp , or sluts ; ( slums , total ) → ( slams , tonal ).
24. Build the list of 5-letter words and the trie of 6-letter words in step B1; also set a 01 a 02 a 03 a 04 a 05 ← 00000. Use min D l \= 1 in step B2 and max D l \= 5757 in step B4. To test P l in step B3, if word x l is c 1 c 2 c 3 c 4 c 5 , form a l 1 ... a l 5 , where a lk \= trie [ a ( l −1) k , c k ] for 1 ≤ k ≤ 5; but jump to B4 if any a lk is zero.
25. There are 5 × 26 singly linked lists, accessed from pointers h kc , all initially zero. The x th word c x 1 c x 2 c x 3 c x 4 c x 5 , for 1 ≤ x ≤ 5757, belongs to 5 lists and has five pointers l x 1 l x 2 l x 3 l x 4 l x 5 . To insert it, set l xk ← h kc xk , h kc xk ← x , and s kc xk ← s kc xk + 1, for 1 ≤ k ≤ 5. (Thus s kc will be the length of the list accessed from h kc .)
We can store a “signature” Σ c \= 1 26 2 c − 1 [ t r i e [ a , c ] ≠ 0 ] with each node a of the trie. For example, the signature for node 260 is 2 0 + 2 4 + 2 8 + 2 14 + 2 17 + 2 20 + 2 24 = # 1124111 , according to (11); here A ↔ 1, ... , Z ↔ 26.
The process of running through all x that match a given signature y with respect to position z , as needed in steps B2 and B4, now takes the following form: (i) Set i ← 0. (ii) While 2 i & y = 0, set i ← i + 1. (iii) Set x ← h z ( i +1) ; go to (vi) if x = 0. (iv) Visit x . (v) Set x ← l xz ; go to (iv) if x ≠ 0. (vi) Set i ← i + 1; go to (ii) if 2 i ≤ y .
Let trie [ a , 0] be the signature of node a . We choose z and y = trie [ a ( l −1) z , 0] in step B2 so that the number of nodes to visit, Σ c \= 1 26 s z c [ 2 c − 1 & y ≠ 0 ] , is minimum for 1 ≤ z ≤ 5. For example, when l = 3, x 1 = 1446, and x 2 = 185 as in (10), that sum for z = 1 is s 11 + s 15 + s 19 + s 1(15) + s 1(18) + s 1(21) + s 1(25) = 296 + 129 + 74 + 108 + 268 + 75 + 47 = 997; and the sums for z = 2, 3, 4, 5 are 4722, 1370, 5057, and 1646. Hence we choose z = 1 and y = # 1124111 ; only 997 words, not 5757, need be tested for x 3 .
The values y l and z l are maintained for use in backtracking. (In practice we keep x , y , and z in registers during most of the computation. Then we set x l ← x , y l ← y , z l ← z before increasing l ← l + 1 in step B3; and we set x ← x l , y ← y l , z ← z l in step B5. We also keep i in a register, while traversing the sublists as above; this value is restored in step B5 by setting it to the z th letter of word x , decreased by ’A’ .)
26. Here are the author’s favorite 5 × 7 and 5 × 8, and the only 5 × 9’s:
|
|
|
|
No 5 × 10 word rectangles exist, according to our ground rules.
27. (1, 15727, 8072679, 630967290, 90962081, 625415) and (15727.0, 4321.6, 1749.7, 450.4, 286.0). Total time ≈ 18.3 teramems.
28. Build a separate trie for the m -letter words; but instead of having trie nodes of size 26 as in (11), it’s better to convert this trie into a compressed representation that omits the zeros. For example, the compressed representation of the node for prefix ‘ CORNE ’ in (12) consists of five consecutively stored pairs of entries (‘ T ’, 5013), (‘ R ’, 171), (‘ L ’, 9602), (‘ D ’, 3878), (‘ A ’, 3879), followed by (0, 0). Similarly, each shorter prefix with c descendants is represented by c consecutive pairs (character, link), followed by (0, 0) to mark the end of the node. Steps B3 and B4 are now very convenient.
Level l corresponds to row i l \= 1 + ( l − 1) mod m and column j l \= 1 + ⌊( l − 1)/ m ⌋. For backtracking we store the n -trie pointer a i l ,j l as before, together with an index x l into the compressed m -trie.
This method was used by M. D. McIlroy in 1975 (see answer 32 ). It finds all 5 × 6 word rectangles in just 400 gigamems; and its running time for “transposed” 6 × 5 rectangles turns out to be slightly less (380 gigamems). Notice that only one mem is needed to access each (character, link) pair in the compressed trie.
29. Yes, exactly 1618 of the 625415 solutions have repeated words. For example:
|
|
|
|
|
30. The use of a single compressed trie both horizontally and vertically leads to a very pretty algorithm, which needs only 120 M μ to find all 541,968 solutions. De Morgan’s example isn’t among them, because the proper name ‘ ELLEN ’ doesn’t qualify as a word by our conventions. But some of the squares might be “meaningful,” at least poetically:
|
|
|
|
|
|
Just six of the solutions belong to the restricted vocabulary WORDS (500); three of them actually belong to WORDS (372), namely **ASS|*IGHT|AGREE|SHEEP|STEPS , where *** is either CLL or GLL or GRR . (And *** = GRL gives an unsymmetric 5 × 5 in WORDS (372). There are (1787056 − 541968)/2 = 622544 unsymmetric squares in WORDS (5757).)
31. Yes, 27 of them. The search is greatly facilitated by noting that the NE-to-SW diagonal word must be one of the 18 palindromes in WORDS (5757). ‘ SCABS|CANAL|ANGLE|BALED|SLEDS ’, which belongs to WORDS (3025), has the most common words. [See the end of Chapter 18 in Babbage’s Passages from The Life of a Philosopher (London, 1864).]
32. There are (717, 120386, 2784632, 6571160, 1117161, 13077, 6) of sizes 2 × 2, ... , 8 × 8, and none larger than this. Each of these runs needed fewer than 6 gigamems of computation. Example solutions with words as common as possible are
with the following numeric ranks of “minimax rarity” within their lists: TO = 2, SEE = 25, AREA = 86, ERROR = 438, ESTEEM = 1607, TREBLES = 5696, ETERNISE = 23623.
[ Word squares go back thousands of years; ‘ SATOR|AREPO|TENET|OPERA|ROTAS ’, a famous 5 × 5 example that is found in many places including the ruins of Pompeii, actually has fourfold symmetry. But 6 × 6 squares appear to have been unknown until William Winthrop, the U.S. consul in Malta(!), published ‘ CIRCLE|ICARUS| RAREST|CREATE|LUSTRE|ESTEEM ’ in Notes & Queries (2) 8 (2 July 1859), page 8, claiming to have thereby “squared the circle.” (If he had been told not to use a proper name like Icarus, he could have said ‘ CIRCLE|INURES|RUDEST|CREASE|LESSER|ESTERS ’.)]
The conclusion to be drawn about exercises of this kind is that four letters are nothing at all; that five letters are so easy that nothing is worth notice unless the combination have meaning; that six letters, done in any way, are respectable; and that seven letters would be a triumph.
— AUGUSTUS DE MORGAN, in Notes & Queries (3 September 1859)
Henry Dudeney constructed several 7×7 examples and used them in clever puzzles, beginning with ‘ PALATED|ANEMONE|LEVANTS|AMASSES|TONSIRE|ENTERER|DESSERT ’[ The Weekly Dispatch (25 October and 8 November 1896)] and ‘ BOASTER|OBSCENE|ASSERTS|SCEPTRE|TERTIAN|ENTRANT|RESENTS ’ [ The Weekly Dispatch (21 November and 5 December 1897)]. Years later he was particularly pleased to have found ‘ NESTLES|ENTRANT| STRANGE|TRAITOR|LANTERN|ENGORGE|STERNER ’ [ Strand 55 (1918), 488; 56 (1919), 74; The World’s Best Word Puzzles (1925), Puzzles 142 and 145]. M. Douglas McIlroy was the first to apply computers to this task [ Word Ways 8 (1975), 195–197], discovering 52 examples such as ‘ WRESTLE|RENEWAL|ENPLANE|SELFDOM|TWADDLE|LANOLIN|ELEMENT ’. Then he turned to the more difficult problem of double word squares , which are un-symmetric and contain 2 n distinct words: He presented 117 double squares, such as ‘ REPAST|AVESTA|CIRCUS|INSECT|SCONCE|MENTOR ’, in Word Ways 9 (1976), 80–84. (His experiments allowed proper names, but avoided plurals and other derived word forms.)
For an excellent history of word squares and word cubes, chronicling the subsequent computer developments as well as extensive searches for 10 × 10 examples using vast dictionaries, see Ross Eckler, Making the Alphabet Dance (New York: St. Martin’s Griffin, 1997), 188–203; Tribute to a Mathemagician (A K Peters, 2005), 85–91.
33. Working from bottom to top and right to left is equivalent to working from top to bottom and left to right on the word reversals . This idea does make the tries smaller; but unfortunately it makes the programs slower. For example, the 6×5 computation of answer 28 involves a 6347-node trie for the 6-letter words and a 63060-node compressed trie for the 5-letter words. Those sizes go down to 5188 and 56064, respectively, when we reverse the words; but the running time goes up from 380 G μ to 825 G μ .
34. Leave out face and (of course) dada ; the remaining eleven are fine.
35. Keep tables p i , p i j ′ , p i j k " , s i , s i j ′ , s i j k " , for 0 ≤ i, j, k < m , each capable of storing a ternary digit, and initially zero. Also keep a table x 0 , x 1 , ... of tentatively accepted words. Begin with g ← 0. Then for each input w j \= abcd , where 0 ≤ a, b, c, d < m , set x g ← abcd and also do the following: Set p a ← p a + ˙ 1 , p a b ′ ← p a b ′ + ˙ 1 , p a b c " ← p a b c " + ˙ 1 , s d ← s d + ˙ 1 , s c d ′ ← s c d ′ + ˙ 1 , s b c d " ← s b c d " + ˙ 1 , where x + ˙ y \= min ( 2 , x + y ) ) denotes saturating ternary addition. Then if s a ′ p b ′ c ′ d ′ " + s a ′ b ′ " p d ′ \= 0 for all x k \= a ′ b ′ c ′ d ′, where 0 ≤ k ≤ g , set g ← g +1. Otherwise reject w j and set p a ← p a −1, p a b ′ ← p a b ′ − 1 , p a b c " ← p a b c " − 1 , s d ← s d − 1, s c d ′ ← s c d ′ − 1 , s b c d " ← s b c d " − 1 .
36. (a) The word bc appears in message abcd if and only if a → b , b → c , and c → d .
(b) For 0 ≤ k < r , put vertex v into class k if the longest path from v has length k . Given any such partition, we can include all arcs from class k to class j < k without increasing the path lengths. So it’s a question of finding the maximum of Σ 0≤j<k<r p j p k subject to p 0 + p 1 + ... + p r − 1 = m . The values p j \= ⌊( m + j ) /r ⌋ achieve this (see exercise 7.2.1.4–68(a)). When r = 3 the maximum simplifies to ⌊ m 2 / 3 ⌋.
37. (a) The factors of the period, 15 926 535 89 79 323 8314, begin at the respective boundary points 3, 5, 8, 11, 13, 15, 18 (and then 3 + 19 = 22, etc.). Thus round 1 retains boundaries 5, 8, and 15. The second-round substrings y 0 = 926, y 1 = 5358979, y 2 = 323831415 have different lengths, so lexicographic comparison is unnecessary; the answer is y 2 y 0 y 1 = x 15 ...x 33 .
(b) Each substring consists of at least three substrings of the previous round.
(c) Let a 0 = 0, b 0 = 1, a e +1 = a e a e b e , b e +1 = b e a e b e ; use a e or b e when n = 3 e .
(d) We use an auxiliary subroutine ‘less( i )’, which returns [ y i − 1 <y i ], given i > 0: If b i − b i −1 ≠ b i +1 − b i , return [ b i − b i −1 <b i +1 − b i ]. Otherwise, for j = 0, 1, ... , while b i + j < b i +1 , if x b i −1 + j ≠ x b i + j return [ x b i −1 + j <x b i + j ]. Otherwise return 0.
The tricky part of the algorithm is to discard initial factors that aren’t periodic. The secret is to let i 0 be the smallest index such that y i −3 ≥ y i −2 < y i −1 ; then we can be sure that a factor begins with y i .
O1. [Initialize.] Set x j ← x j − n for n ≤ j < 2 n , b j ← j for 0 ≤ j < 2 n , and t ← n .
O2. [Begin a round.] Set t ′ ← 0. Find the smallest i > 0 such that less( i ) = 0. Then find the smallest j ≥ i + 2 such that less( j − 1) = 1 and j ≤ t + 2. (If no such j exists, report an error: The input x was equal to one of its cyclic shifts.) Set i ← i 0 ← j mod t . (Now a dip of the period begins at i 0 .)
O3. [Find the next factor.] Find the smallest j ≥ i + 2 such that less( j − 1) = 1. If j − i is even, go to O5.
O4. [Retain a boundary.] If i < t , set b t ′ ′ ← b i ; otherwise set b k ′ ← b k − 1 ′ for t ′ ≥ k > 0 and b 0 ′ ← b i − t . Finally set t ′ ← t ′ +1.
O5. [Done with round?] If j < i 0 + t , set i ← j and return to O3. Otherwise, if t ′ = 1, terminate; σx begins at item x b 0 ′ . Otherwise set t ← t ′, b k ← b k ′ for 0 ≤ k < t , and b k ← b k − t + n for k ≥ t while b k − t < 2 n . Return to O2.
(e) Say that a “ superdip” is a dip of odd length followed by zero or more dips of even length. Any infinite sequence y that begins with an odd-length dip has a unique factorization into superdips. Those superdips can, in turn, be regarded as atomic elements of a higher-level string that can be factored into dips. The result σx of Algorithm O is an infinite periodic sequence that allows repeated factorization into infinite periodic sequences of superdips at higher and higher levels, until becoming constant.
Notice that the first dip of σx ends at position i 0 in the algorithm, because its length isn’t 2. Therefore we can prove the commafree property by observing that, if codeword σx ″ appears within the concatenation σx σx ′ of two codewords, its superdip factors are also superdip factors of those codewords. This yields a contradiction if any of σx , σx ′,or σx ″ is a superdip. Otherwise the same observation applies to the superdip factors at the next level. [ Eastman’s original algorithm was essentially the same, but presented in a more complicated way; see IEEE Trans. IT-11 (1965), 263–267. R. A. Scholtz subsequently discovered an interesting and totally different way to define the set of codewords produced by Algorithm O, in IEEE Trans. IT-15 (1969), 300–306.]
38. Let f k ( m ) be the number of dips of length k for which m > z 1 and z k < m . The number of such sequences with z k −1 \= j is ( m − j − 1 ) ( m − j + k − 3 k − 2 ) \= ( k − 1 ) ( m − j + k − 3 k − 1 ) ; summing for 0 ≤ j < m gives f k ( m ) \= ( k − 1 ) ( m + k − 2 k ) . Thus F m ( z ) \= Σ k \= 0 ∞ f k ( m ) z k \= ( m z − 1 ) / ( 1 − z ) m . (The fact that f 0 ( m ) = −1 in these formulas turns out to be useful!)
Algorithm O finishes in one round if and only if some cyclic shift of x is a superdip. The number of aperiodic x that finish in one round is therefore n [ z n ] G m ( z ), where
G m ( z ) \= F m ( − z ) − F m ( z ) F m ( − z ) + F m ( z ) \= ( 1 + m z ) ( 1 − z ) m − ( 1 − m z ) ( 1 + z ) m ( 1 + m z ) ( 1 − z ) m + ( 1 − m z ) ( 1 + z ) m .
To get the stated probability, divide by Σ d \ n μ ( d ) m n/d , the number of aperiodic x . (See Eq. 7.2.1.1–(60). For n = 3, 5, 7, 9 these probabilities are 1, 1, 1, and 1 − 3 / ( m 3 − 1 3 ) .)
39. If so, it couldn’t have 0011, 0110, 1100, or 1001.
40. That section considered such representations of stacks and queues, but not of unordered sets, because large blocks of sequential memory were either nonexistent or ultra-expensive in olden days. Linked lists were the only decent option for families of variable-size sets, because they could more readily fit in a limited high-speed memory.
41. (a) The blue word x with α = d (namely 1101) appears in its P2 list at location 5e .
(b) The P3 list for words of the form 010∗ is empty. (Both 0100 and 0101 are red.)
42. (a) The S2 list of 0010 has become closed (hence 0110 and 1110 are hidden).
(b) Word 1101 moved to the former position of 1001 in its S1 list, when 1001 became red. (Previously 1011 had moved to the former position of 0001.)
43. In this case, which of course happens rarely, it’s safe to set all elements of STAMP to zero and set σ ← 1. (Do not be tempted to save one line of code by setting all STAMP elements to −1 and leaving σ = 0. That might fail when σ reaches the value −1!)
44. (a) Set r ← 5. Then for k ← 0, 1, ... , f − 1, set t ← FREE[ k ] , j ← MEM[CLOFF + 4 t + m 4 ] − ( CLOFF +4 t ), and if j < r set r ← j , c ← t ; break out of the loop if r = 0.
(b) If r > 0 set x ← MEM[CLOFF +4 cl ( ALF[ x ] ) ] .
(c) If r > 1 set q ← 0, p ′ ← MEM[PP] , and p ← POISON . While p < p ′ do the following steps: Set y ← MEM[ p ] , z ← MEM[ p +1 ] , y ′ ← MEM[ y + m 4 ] , and z ′ ← MEM[ z + m 4 ] . (Here y and z point to the heads of prefix or suffix lists; y ′ and z ′ point to the tails.) If y = y ′ or z = z ′, delete entry p from the poison list; this means, as in (18), to set p ′ ← p ′−2, and if p ≠ p ′ to store( p, MEM[ p ′ ] ) and store( p +1 , MEM[ p ′ +1 ] ). Otherwise set p ← p +2; if y ′ − y ≥ z ′ − z and y ′ − y > q , set q ← y ′ − y and x ← MEM[ z ] ; if y ′ − y < z ′ − z and z ′ − z > q , set q ← z ′ − z and x ← MEM[ y ] . Finally, after p has become equal to p ′, store( PP ,p ′) and set c ← cl ( ALF[ x ] ). (Experiments show that this “max kill” strategy for r > 1 slightly outperforms a selection strategy based on r alone.)
45. (a) First there’s a routine rem( α, δ, o ) that removes an item from a list, following the protocol (21): Set p ← δ + o and q ← MEM[ p + m 4 ] − 1. If q ≥ p (meaning that list p isn’t closed or being killed), store( p + m 4 ,q ), set t ← MEM[ α + o − m 4 ] ; and if t ≠ q also set y ← MEM[ q ] , store( t, y ), and store( ALF[ y ] + o − m 4 ,t ).
Now, to redden x we set α ← ALF[ x ] , store( α, RED ); then rem( α, p 1 ( α ) , P1OFF ), rem( α, p 2 ( α ) , P2OFF ), ... , rem( α, s 3 ( α ) , S3OFF ), and rem( α, 4 cl ( α ) , CLOFF ).
(b) A simple routine close( δ, o ) closes list δ + o : Set p ← δ + o and q ← MEM[ p + m 4 ] ; if q ≠ p − 1, store( p + m 4 ,p − 1).
Now, to green x we set α ← ALF[ x ] , store( α, GREEN ); then close( p 1 ( α ) , P1OFF ), close( p 2 ( α ) , P2OFF ), ... , close( s 3 ( α ) , S3OFF ), and close(4 cl ( α ) , CLOFF ). Finally, for p ≤ r < q (using the p and q that were just set within ‘close’), if MEM[ r ] ≠ x redden MEM[ r ] .
(c) First set p ′ ← MEM[PP] +6, and store( p ′ −6 ,p 1 ( α )+ S1OFF ), store( p ′ −5 ,s 3 ( α )+ P3OFF ), store( p ′ − 4 ,p 2 ( α )+ S2OFF ), store( p ′ − 3 ,s 2 ( α )+ P2OFF ), store( p ′ − 2 ,p 3 ( α )+ S3OFF ), store( p ′ − 1 ,s 1 ( α )+ P1OFF ); this adds the three poison items (27).
Then set p ← POISON and do the following while p < p ′: Set y , z , y ′, z ′ as in answer 44(c) , and delete poison entry p if y = y ′ or z = z ′. Otherwise if y ′ < y and z ′ < z , go to C5 (a poisoned suffix-prefix pair is present). Otherwise if y ′ > y and z ′ > z , set p ← p + 2. Otherwise if y ′ < y and z ′ > z , store( z + m 4 ,z ), redden MEM[ r ] for z ≤ r < z ′, and delete poison entry p . Otherwise (namely if y ′ > y and z ′ < z ), store( y + m 4 ,y ), redden MEM[ r ] for y ≤ r < y ′, and delete poison entry p .
Finally, after p has become equal to p ′, store( PP ,p ′).
46. Exercise 37 exhibits such codes explicitly for all odd n . The earliest papers on the subject gave solutions for n = 2, 4, 6, 8. Yoji Niho subsequently found a code for n = 10 but was unable to resolve the case n = 12 [ IEEE Trans. IT-19 (1973), 580–581].
This problem can readily be encoded in CNF and given to a SAT solver. The case n = 10 involves 990 variables and 8.6 million clauses, and is solved by Algorithm 7.2.2.2C in 10.5 gigamems. The case n = 12 involves 4020 variables and 175 million clauses. After being split into seven independent subproblems (by appending mutually exclusive unit clauses), it was proved unsatisfiable by that algorithm after about 86 teramems of computation.
So the answer is “No.” But we can come close: Aaron Windsor used a SAT solver in 2021 to discover a binary commafree code for n = 12 that contains a representative of every cycle class except [000011001011].
47. (a) There are 28 commafree binary codes of size 3 and length 4; Algorithm C produces half of them, because it assumes that cycle class [0001] is represented by 0001 or 0010. They form eight equivalence classes, two of which are symmetric under the operation of complementation-and-reflection; representatives are {0001 , 0011 , 0111} and {0010 , 0011 , 1011}. The other six are represented by {0001 , 0110 , 0111 or 1110}, {0001 , 1001 , 1011 or 1101}, {0001 , 1100 , 1101}, {0010 , 0011 , 1101}.
(b) Algorithm C produces half of the 144 solutions, which form twelve equivalence classes. Eight are represented by {0001, 0002, 1001, 1002, 1102, 2001, 2002, 2011, 2012, 2102, 2112, 2122 or 2212} and ({0102 , 1011 , 1012} or {2010 , 1101 , 2101}) and ({1202 , 2202 , 2111} or {2021 , 2022 , 1112}); four are represented by {0001, 0020, 0021, 0022, 1001, 1020, 1021, 1022, 1121 or 1211, 1201, 1202, 1221, 2001, 2201, 2202} and ({1011 , 1012 , 2221} or {1101 , 2101 , 1222}).
(c) Algorithm C yields half of the 2304 solutions, which form 48 equivalence classes. Twelve classes have unique representatives that omit cycle classes [0123], [0103], [1213], one such being the code {0010, 0020, 0030, 0110, 0112, 0113, 0120, 0121, 0122, 0130, 0131, 0132, 0133, 0210, 0212, 0213, 0220, 0222, 0230, 0310, 0312, 0313, 0320, 0322, 0330, 0332, 0333, 1110, 1112, 1113, 2010, 2030, 2110, 2112, 2113, 2210, 2212, 2213, 2230, 2310, 2312, 2313, 2320, 2322, 2330, 2332, 2333, 3110, 3112, 3113, 3210, 3212, 3213, 3230, 3310, 3312, 3313}. The others each have two representatives that omit classes [0123], [0103], [0121], one such pair being the code {0001, 0002, 0003, 0201, 0203, 1001, 1002, 1003, 1011, 1013, 1021, 1022, 1023, 1031, 1032, 1033, 1201, 1203, 1211, 1213, 1221, 1223, 1231, 1232, 1233, 1311, 1321, 1323, 1331, 2001, 2002, 2003, 2021, 2022, 2023, 2201, 2203, 2221, 2223, 3001, 3002, 3003, 3011, 3013, 3021, 3022, 3023, 3031, 3032, 3033, 3201, 3203, 3221, 3223, 3321, 3323, 3331} and its isomorphic image under reflection and (01)(23).
48. Algorithm C isn’t fast enough to solve this problem. But Aaron Windsor used a SAT solver in 2021 to find such a code of size 139 = (5 4 − 5 2 ) / 4 − 11, and to prove that no such code of size 140 exists. (He also found, rather quickly, that an optimum ternary commafree code for n = 6 contains (3 6 − 3 3 − 3 2 +3 1 ) / 6 − 3 = 113 codewords.) See Journal of Automated Reasoning 67 (2023), 12:1–12:10.
49. The 3-bit sequences 101, 111, 110 were rejected before seeing 000. In general, to make a uniformly random choice from q possibilities, the text suggests looking at the next t = ⌈lg q ⌉ bits b 1 ...b t . If ( b 1 ...b t ) 2 < q , we use choice ( b 1 ...b t ) 2 + 1; otherwise we reject b 1 ...b t and try again. [This simple method is optimum when q ≤ 4, and the best possible running time for other values of q uses more than half as many bits. But a better scheme is available for q = 5, using only 3 1 3 bits per choice instead of 4 4 5 ; and for q = 6, one random bit reduces to the case q = 3. See D. E. Knuth and A. C. Yao, Algorithms and Complexity , edited by J. F. Traub (Academic Press, 1976), 357–428, §2.]
50. It’s the number of nodes on level l + 1 (depth l ) of the search tree. (Hence we can estimate the profile. Notice that D = D 1 ...D l −1 in step E2 of Algorithm E .)
51. Z 0 = C (), Z l +1 \= c () + D 1 c ( X 1 )+ D 1 D 2 c ( X 1 X 2 )+ ... + D 1 ...D l c ( X 1 ...X l )+ D 1 ...D l +1 C ( X 1 ...X l +1 ).
52. (a) True: The generating function is z ( z +1) ... ( z + n − 1) /n !; see Eq. 1.2.10–(9).
(b) For instance, suppose Y 1 Y 2 ...Y l = 1457 and n = 9. Alice’s probability is 1 1 1 2 2 3 1 4 1 5 5 6 1 7 7 8 8 9 \= 1 3 1 4 1 6 1 9 . Elmo obtains X 1 X 2 ...X l = 7541 with probability 1 9 1 6 1 4 1 3 .
(c) The upper tail inequality (see exercise 1.2.10–22 with μ = H n ) tells us that Pr (l ≥ (ln n )(ln ln n ) ) ≤ exp(−(ln n )(ln ln n )(ln ln ln n )+ O (ln n )(ln ln n )).
(d) If k ≤ n/ 3 we have Σ j \= 0 k ( n j ) ≤ 2 ( n k ) . By exercise 1.2.6–67, the number of nodes on the first (ln n )(ln ln n ) levels is therefore at most 2 (ne/ ((ln n )(ln ln n )) ) (ln n )(ln ln n ) .
53. The key idea is to introduce recursive formulas analogous to (29):
m ( x 1 … x l ) \= c ( x 1 … x l ) + min ( m ( x 1 … x l x l + 1 ( 1 ) ) d , … , m ( x 1 … x l x l + 1 ( d ) ) d ) ; M ( x 1 … x l ) \= c ( x 1 … x l ) + max ( M ( x 1 … x l x l + 1 ( 1 ) ) d , … , M ( x 1 … x l x l + 1 ( d ) ) d ) ; C ^ ( x 1 … x l ) \= c ( x 1 … x l ) 2 + Σ i \= 1 d ( C ^ ( x 1 … x l x l + 1 ( i ) ) d + 2 c ( x 1 … x l ) C ( x 1 … x l x l + 1 ( i ) ) ) .
They can be computed via auxiliary arrays MIN , MAX , KIDS , COST , and CHAT as follows:
At the beginning of step B2, set MIN[ l ] ← ∞, MAX[ l ] ← KIDS[ l ] ← COST[ l ] ← CHAT[ l ] ← 0. Set KIDS[ l ] ← KIDS[ l ] + 1 just before l ← l + 1 in step B3.
At the beginning of step B5, set m ← c ( x 1 ...x l −1 ) + KIDS[ l ] × MIN[ l ] , M ← c ( x 1 ...x l −1 ) + KIDS[ l ] × MAX[ l ] , C ← c ( x 1 ...x l −1 ) + COST[ l ] , Ĉ ← c ( x 1 ...x l −1 ) 2 + KIDS[ l ] × CHAT[ l ] + 2 × COST[ l ] . Then, after l ← l − 1 is positive, set MIN[ l ] ← min (m, MIN[ l ] ) , MAX[ l ] ← max (M, MAX[ l ] ) , COST[ l ] ← COST[ l ] + C , CHAT[ l ] ← CHAT[ l ] + Ĉ . But when l reaches zero in step B5, return the values m , M , C , Ĉ − C 2 .
54. Let p ( i ) = pX 1 ... X l −1 ( y i ), and simply set D ← D/p ( I ) instead of D ← Dd . Then node x 1 ...x l is reached with probability Π ( x 1 ...x l ) = p ( x 1 ) p x 1 ( x 2 ) ... p x 1 ... x l ( x l ), and c ( x 1 ... x l ) has weight 1 /Π ( x 1 ...x l ) in S ; the proof of Theorem E goes through as before. Notice that p ( I ) is the a posteriori probability of having taken branch I .
(The formulas of answer 53 should now use ‘ /p ( i )’ instead of ‘ d ’; and that algorithm should be modified appropriately, no longer needing the KIDS array.)
55. Let pX 1 ... X l −1 ( y i ) = C ( x 1 ...x l −1 y i ) /(C ( x 1 ...x l −1 ) − c ( x 1 ...x l −1 ) ) . (Of course we generally need to know the cost of the tree before we know the exact values of these ideal probabilities, so we cannot achieve zero variance in practice. But the form of this solution shows what kinds of bias are likely to reduce the variance.)
56. The effects of lookahead, dynamic ordering, and reversible memory are all captured easily by a well-designed cost function at each node. But there’s a fundamental difference in step C2, because different codeword classes can be selected for branching at the same node (that is, with the same ancestors x 1 ...x l −1 ) after C5 has undone the effects of a prior choice. The level l never surpasses L + 1, but in fact the search tree involves hidden levels of branching that are implicitly combined into single nodes.
Thus it’s best to view Algorithm C ’s search tree as a sequence of binary branches: Should x be one of the codewords or not? (At least this is true when the “max kill” strategy of answer 44 has selected the branching variable x . But if r > 1 and the poison list is empty, an r -way branch is reasonable (or an ( r + 1)-way branch when the slack is positive), because r will be reduced by 1 and the same class c will be chosen after x has been explored.)
If x has been selected because it kills many other potential codewords, we probably should bias the branch probability as in exercise 54 , giving smaller weight to the “yes” branch because the branch that includes x is less likely to lead to a large subtree.
57. Let p k = 1 /D ( k ) be the probability that Algorithm E terminates at the k th leaf. Then Σ k \= 1 M ( 1 / M ) lg ( 1 / ( M p k ) ) is the Kullback–Leibler divergence D ( q || p ), where q is the uniform distribution (see exercise MPR–121). Hence 1 M Σ k \= 1 M lg D ( k ) ≥ lg M . (The result of this exercise is essentially true in any probability distribution.)
58. Let ∞ be any convenient value ≥ n . When vertex v becomes part of the path we will perform a two-phase algorithm. The first phase identifies all “tarnished” vertices, whose DIST must change; these are the vertices u from which every shortest path to t passes through v . It also forms a queue of “resource” vertices, which are untarnished but adjacent to tarnished ones. The second phase updates the DIST s of all tarnished vertices that are still connected to t . Each vertex has LINK and STAMP fields in addition to DIST .
For the first phase, set d ← DIST( v ) , DIST( v ) ← ∞+1, R ← Λ, T ← v , LINK( v ) ← Λ, then do the following while T ≠ Λ: (∗) Set u ← T , T ← S ← Λ. For each w −−− u , if DIST( w ) < d do nothing ( u = v ); if DIST( w ) ≥ ∞ do nothing ( w is gone or already known to be tarnished); if DIST( w ) = d , make w a resource (see below); otherwise DIST( w ) = d +1. If w has no neighbor at distance d , w is tarnished: Set LINK( w ) ← T , DIST( w ) ← ∞, T ← w . Otherwise make w a resource (see below), and set u ← LINK( u ) ; return to (*) if u ≠ Λ, otherwise append S to R (see below) and set d ← d + 1.
The queue of resources will start at R . We will stamp each resource with v so that nothing is added twice to that queue. To make w a resource when DIST( w ) = d , do the following (unless u = v or STAMP( w ) = v ): Set STAMP( w ) ← v ; if R = Λ, set R ← RT ← w ; otherwise set LINK(RT) ← w and RT ← w . To make w a resource when DIST( w ) = d + 1 and u ≠ v and STAMP( w ) ≠ v , put it first on stack S as follows: Set STAMP( w ) ← v ; if S = Λ, set S ← SB ← w ; otherwise set LINK( w ) ← S , S ← w .
Finally, when u = Λ, we append S to R : Nothing needs to be done if S = Λ. Otherwise, if R = Λ, set R ← S and RT ← SB ; but if R ≠ Λ, set LINK(RT) ← S and RT ← SB . (These shenanigans keep the resource queue in order by DIST .)
Phase 2 operates as follows: Nothing needs to be done if R = Λ. Otherwise we set LINK(RT) ← Λ, S ← Λ, and do the following while R ≠ Λ or S ≠ Λ: (i) If S = Λ, set d ← DIST(R) . Otherwise set u ← S , d ← DIST( u ) , S ← Λ; while u ≠ Λ, update the neighbors of u and set u ← LINK( u ) . (ii) While R ≠ Λ and DIST(R) = d , set u ← R , R ← LINK( u ) , and update the neighbors of u . In both cases “update the neighbors of u ” means to look at all w −−− u , and if DIST( w ) = ∞ to set DIST( w ) ← d + 1, LINK( w ) ← S , and S ← w . (It works, although S does double duty!)
59. (a) Compute the generating function g ( z ) (see exercise 7.1.4–209) and then g ′(1).
(b) Let ( A, B, C ) denote paths that touch (center, NE corner, SW corner). Recursively compute eight counts ( c 0 ,...,c 7 ) at each node, where c j counts paths π with j = 4[ π ∈ A ] + 2[ π ∈ B ] + [ π ∈ C ]. At the sink node
we have c 0 = 1, c 1 = ... = c 7 = 0. Other nodes have the form x = ( ē ? x l : x h ) where e is an edge. Two edges go across the center and affect A ; three edges affect each of B and C . Say that those edges have types 4, 2, 1, respectively; other edges have type 0. Suppose the counts for x l and x h are ( c 0 ′ , … , c 7 ′ ) and ( c 0 " , … , c 7 " ) , and e has type t . Then count c j for node x is c j ′ + [ t \= 0 ] c j " + [ t & j ≠ 0 ] ( c j " + c j − t " ) .
(This procedure yields the following exact “ Venn diagram” set counts at the root: c 0 | \= | A ¯ ∩ B ¯ ∩ C ¯ | \= 7653685384889019648091604 ; c 1 \= c 2 \= | A ¯ ∩ B ¯ ∩ C | \= | A ¯ ∩ B ∩ C ¯ | \= 7755019053779199171839134 ; c 3 \= | A ¯ ∩ B ∩ C | \= | 7857706970503366819944024 ; c 4 \= | A ∩ B ¯ ∩ C ¯ | \= 4888524166534573765995071 ; c 5 \= c 6 \= | A ∩ B ¯ ∩ C | \= A ∩ B ∩ C ¯ | \= 4949318991771252110605148 ; c 7 \= | A ∩ B ∩ C | \= 5010950157283718807987280 .)
60. Yes, the paths are less chaotic and the estimates are better:
61. (a) Let x k be the number of nodes at distance k − 1 from the root.
(b) Let Q n ( m ) \= P n ( 1 ) + … + P n ( m ) . Then we have the joint recurrence P 1 ( m ) \= 1 , P n + 1 ( m ) \= Q n ( 2 m ) ; in particular, Q 1 ( m ) \= m . And for n ≥ 2, we have Q n ( m ) \= Σ k \= 1 n a n k ( m k ) for certain constants a nk that can be computed as follows: Set t k ` ← P n ( k ) for 1 ≤ k ≤ n . Then for k = 2, ... , n set t n ← t n − t n −1 , ... , t k ← t k − t k −1 . Finally a nk ← t k for 1 ≤ k ≤ n . For example, a 21 = a 22 = 2; a 31 = 6, a 32 = 14, a 33 = 8. The numbers P n ( m ) have O ( n 2 + n log m ) bits, so this method needs O ( n 5 ) bit operations to compute P n .
(c) P n ( m ) corresponds to random paths with X 1 = m , D k = 2 X k , X k +1 \= ⌈2 U k X k ⌉, where each U k is an independent uniform deviate. Therefore P n ( m ) \= E ( D 1 … D n − 1 ) is the number of nodes on level n of an infinite tree. We have X k +1 ≥ 2 k U 1 ...U k m , by induction; hence P n ( m ) ≥ E ( 2 ( n 2 ) U 1 n − 2 U 2 n − 3 … U n − 2 m n − 1 1 ) \= 2 ( n 3 ) m n − 1 / ( n − 1 ) ! .
[M. Cook and M. Kleber have discussed similar sequences in Electronic Journal of Combinatorics 7 (2000), #R44, 1–16. See also K. Mahler’s asymptotic formula for binary partitions, in J. London Math. Society 15 (1940), 115–123, which shows that lg P n \= ( n 2 ) − lg ( n − 1 ) ! + ( lg n 2 ) + O ( 1 ) .]
62. Random trials indicate that the expected number of 2-regular graphs is ≈ 3 . 115, and that the number of disjoint pairs is (0, 1, ... , 9, and ≥ 10) approximately (74.4, 4.3, 8.7, 1.3, 6.2, 0.2, 1.5, 0.1, 2.0, 0.0, and 12.2) percent of the time. If the cubes are restricted to cases where each color occurs at least five times, these numbers change to ≈ 4 . 89 and (37.3, 6.6, 17.5, 4.1, 16.3, 0.9, 5.3, 0.3, 6.7, 0.2, 5.0).
However, the concept of “unique solution” is tricky, because a 2-regular graph with k cycles yields 2 k ways to position the cubes. Let’s say that a set of cubes has a strongly unique solution if (i) it has a unique disjoint pair of 2-regular graphs, and furthermore (ii) both elements of that pair are n -cycles. Such sets occur with probability only about 0.3% in the first case, and 0.4% in the second.
[N. T. Gridgeman, in Mathematics Magazine 44 (1971), 243–252, showed that puzzles with four cubes and four colors have exactly 434 “types” of solutions.]
63. It’s easy to find such examples at random, as in the second part of the previous answer, since strongly unique sets occur about 0.5% of the time (and weakly unique sets occur with probability ≈ 8 . 4%). For example, the pairs of opposite faces might be (12 , 13 , 34), (02 , 03 , 14), (01 , 14 , 24), (04 , 13 , 23), (01 , 12 , 34).
(Incidentally, if we require each color to occur exactly six times, every set of cubes that has at least one solution will have at least three solutions, because the “hidden” pairs can be chosen in three ways.)
64. Each of these cubes can be placed in 16 different ways that contribute legitimate letters to all four of the visible words. (A cube whose faces contain only letters in {C , H , I , N , O , U , X , Z} can be placed in 24 ways. A cube with a pattern like
cannot be placed at all.) We can restrict the first cube to just two placements; thus there are 2 · 16 · 16 · 16 · 16 = 131072 ways to place those cubes without changing their order. Of these, only 6144 are “compatible,” in the sense that no right-side-up-only letter appears together with an upside-down-only letter in the same word.
The 6144 compatible placements can then each be reordered in 5! = 120 ways. One of them, whose words before reordering are GRHTI , NCICY ,
, OUNNI , leads to the unique solution. (There’s a partial solution with three words out of four. There also are 39 ways to get two valid words, including one that has UNTIL adjacent to HOURS , and several with SYRUP opposite ECHOS .)
65. E. Robertson and I. Munro, in Utilitas Mathematica 13 (1978), 99–116, have reduced the exact cover problem to this problem.
66. Call the rays N, NE, E, SE, S, SW, W, NW; call the disks 1, 2, 3, 4 from inside to outside. We can keep disk 1 fixed. The sum of rays N, S, E, W must be 48. It is 16 (on disk 1) plus 13 or 10 (on disk 2) plus 8 or 13 (on disk 3) plus 11 or 14. So it is attained either as shown, or after rotating disks 2 and 4 clockwise by 45 ° . (Or we could rotate any disk by a multiple of 90 ° , since that keeps the desired sum invariant.)
Next, with optional 90 ° rotations, we must make the sum of rays N + S equal to 24. In the first solution above it is 9 plus (6 or 7) plus (4 or 4) plus (7 or 4), hence never 24. But in the other solution it’s 9 plus (4 or 6) plus (4 or 4) plus (5 or 9); hence we must rotate disk 2 clockwise by 90 ° , and possibly also disk 3. However, 90 ° rotation of disk 3 would make the NE + SW sum equal to 25, so we musn’t move it.
Finally, to get NE’s sum to be 12, via optional rotations by 180 ° , we have 1 plus (2 or 5) plus (1 or 5) plus (3 or 4); we must shift disks 3 and 4. Hurrah: That makes all eight rays correct. Factoring twice has reduced 8 3 trials to 2 3 +2 3 +2 3 .
[See George W. Ernst and Michael M. Goldstein, JACM 29 (1982), 1–23. Such puzzles go back to the 1800s; three early examples are illustrated on page 28 of Slocum and Botermans’s New Book of Puzzles (1992). One of them, with six rings and six rays, factors from 6 5 trials to 2 5 +3 5 . A five-ray puzzle would have defeated factorization.]
67. Call the cards 1 5 2 5 , 5 1 1 3 , ... , 3 7 5 5 . The key observation is that all 12 sums must be odd, so we can first solve the problem mod 2. For this purpose we may call the cards 1 1 0 1 , 1 1 1 1 , ... , 1 1 1 1 ; only three cards now change under rotation, namely 1 1 0 1 , 0 1 0 0 , and 1 1 0 0 (which are the mod 2 images of 1 5 2 5 , 4 5 4 2 , and 7 3 8 4 ).
A second observation is that each solution gives 6 × 6 × 2 others, by permuting rows and/or columns and/or by rotating all nine cards. Hence we can assume that the upper left card is 0 0 1 1 ( 8 4 7 3 ). Then 0 1 0 0 ( 4 5 4 2 ) must be in the first column, possibly rotated to 0 0 0 1 ( 4 2 4 5 ), to preserve parity in the left two black sums. We can assume that it’s in row 2. In fact, after retreating from 13 mod 2 to 13, we see that it must be rotated. Hence the bottom left card must be either 4 7 2 5 , 7 7 5 5 , or 3 7 5 5 .
Similarly we see that 1 1 0 1 ( 1 5 2 5 ) must be in the first row, possibly rotated to 0 1 1 1 ( 2 5 1 5 ); we can put it in column 2. It must be rotated, and the top right card must be 3 4 5 4 or 3 7 5 5 . This leaves just six scenarios to consider, and we soon obtain the solution: 8 4 7 3 , 2 5 1 5 , 3 4 5 4 ; 4 2 4 5 , 2 5 4 7 , 7 4 5 2 ; 7 7 5 5 , 1 3 5 1 , 5 5 3 7 .
68. In general, let’s say that a vertex labeling of a digraph is stable if v ’s label is the number of distinct labels among { w | v −−→ w }, for all v . We wish to find all stable labelings that extend a given partial labeling. We may assume that no vertex is a sink.
Let Λ( v ) be a set of digits that includes every label that v could possibly have, in a solution to this extension problem. Initially, Λ( v ) = { d } if v ’s label is supposed to be d ; otherwise Λ( v ) = {1 ,...,d + ( v )}. These sets are conveniently represented as the binary numbers L ( v ) = {2 k –1 | k ∈ Λ( v )}. Our goal is to reduce each L ( v ) to a 1-bit number. A nice backtrack routine called “refine( v )” proves to be helpful in this regard.
Let v 0 = v and let v 1 , ... , v n be v ’fs successors. Let a j = L ( v j ). Following the outline of Algorithm B , we let x l ⊆ a l be a 1-bit number, accepted in step B3 only if 2 νs l –1 ⊆ g l , where s l = x 1 | ... | x l and where the goal sets g l are defined by g n = a 0 , g l = ( g l +1 | g l +1 ≫ 1) & (2 l – 1). We start with all b j → 0; then when visiting a solution x 1 . . . x n , we set b j → b j | x j for 1 ≤ j ≤ n , and b 0 ≠ b 0 | 2 νs n –1 . After finding all solutions we’ll have b j ⊆ a j for all j ; and whenever b j ≠ a j we can reduce L ( v j ) → b j .
Operate in rounds, where all vertices are refined in round 1; subsequent rounds refine only the vertices whose parameters a j have changed. In each round we first refine the vertices with smallest product ( νa 1 ) ... ( νa n ), because they have the fewest potential solutions x 1 ... x n . This method isn’t guaranteed to succeed; but fortunately it does solve the stated problem, after 301 refinements in 6 rounds. [Such “ Japanese arrow puzzles” were introduced by Masanori Natsuhara on page 75 of Puzuraa 128 (July 1992).]
69. (The main point is that the 33rd digit of π is zero.) On 14 March 2023, Germán González-Morris rose to this challenge by promulgating the puzzle shown here, which actually exhibits 35 of the requested digits(!). (The answer can be found in Appendix E .)
Is it possible that there might also be a puzzle of this kind whose empty boxes are symmetrically located about the center, as they are in exercise 68 ?
70. An extremely instructive analysis [ Combinatorics, Probability and Computing 23 (2014), 725–748] leads to the recurrences P m = (5 + 9 z ) P m −2 − 4 P m −4 , Q m = (5 + 9 z ) Q m −2 − 4 Q m −4 , for m ≥ 6, where the initial values are ( P 2 ,P 3 ,P 4 ,P 5 ) = (1 , 1+ z, 1+3 z, 1+10 z +9 z 2 ); ( Q 2 ,Q 3 ,Q 4 ,Q 5 ) = (1 − 4 z, 1 − 9 z − 6 z 2 , 1 − 19 z − 18 z 2 , 1 − 36 z − 99 z 2 − 54 z 3 ). The denominator Q m ( z ) has all real roots, exactly one of which is positive, namely 1 /ρ m .
71. Suppose there are n questions, whose answers each lie in a given set S . A student supplies an answer list α = a 1 ...a n , with each a j ∈ S ; a grader supplies a Boolean vector β = x 1 ...x n . There is a Boolean function f js ( α, β ) for each j ∈ {1 ,...,n } and each s ∈ S . A graded answer list ( α, β ) is valid if and only if F ( α, β ) is true, where
F ( α , β ) \= F ( a 1 … a n , x 1 … x n ) \= Λ j \= 1 n Λ s ∈ S ( [ a j \= s ] ⇒ x j ≡ f j s ( α , β ) ) .
The maximum score is the largest value of x 1 + ··· + x n over all graded answer lists ( α, β ) that are valid. A perfect score is achieved if and only if F ( α, 1 ... 1) holds.
Thus, in the warmup problem we have n = 2, S = {A , B}; f 1A = [ a 2 =B]; f 1B = [ a 1 =A]; f 2A = x 1 ; f 2 B \= x ¯ 2 ⊕ [ a 1 \= A ] .. The four possible answer lists are:
A A : F \= ( x 1 ≡ [ A \= B ] ) ∧ ( x 2 ≡ x 1 ) A B : F \= ( x 1 ≡ [ B \= B ] ) ∧ ( x 2 ≡ x ¯ 2 ⊕ [ A \= A ] ) B A : F \= ( x 1 ≡ [ B \= A ] ) ∧ ( x 2 ≡ x 1 ) B B : F \= ( x 1 ≡ [ B \= A ] ) ∧ ( x 2 ≡ x ¯ 2 ⊕ [ B \= A ] )
Thus AA and BA must be graded 00; AB can be graded either 10 or 11; and BB has no valid grading. Only AB can achieve the maximum score, 2; but 2 isn’t guaranteed.
In Table 666 we have, for example, f 1C = [ a 2 ≠ = A] ∧ [ a 3 = A]; f 4D = [ a 1 = D] ∧ [ a 15 = D]; f 12A = [Σ A − 1 = Σ B ], where Σ s = Σ 1≤ j ≤20 [ a j = s ]. It’s amusing to note that f 14E = [{Σ A ,..., Σ E } = {2 , 3 , 4 , 5 , 6}].
The other cases are similar (although often more complicated) Boolean functions — except for 20D and 20E, which are discussed further in exercise 72 .
Notice that an answer list that contains both 10E and 17E must be discarded: It can’t be graded, because 10E says ‘ x 10 ≡ x ¯ 17 ’ while 17E says ‘ x 17 ≡ x 10 ’.
By suitable backtrack programming, we can prove first that no perfect score is possible. Indeed, if we consider the answers in the order (3, 15, 20, 19, 2, 1, 17, 10, 5, 4, 16, 11, 13, 14, 7, 18, 6, 8, 12, 9), many cases can quickly be ruled out. For example, suppose a 3 = C. Then we must have a 1 ≠ a 2 ≠ ··· = a 16 ≠ a 17 = a 18 ≠ a 19 ≠ a 20 , and early cutoffs are often possible. (We might reach a node where the remaining choices for answers 5 , 6 , 7 , 8 , 9 are respectively {C , D}, {A , C}, {B , D}, {A , B , E}, {B , C , D}, say. Then if answer 8 is forced to be B, answer 7 can only be D; hence answer 6 is also forced to be A. Also answer 9 can no longer be B.) An instructive little propagation algorithm will make such deductions nicely at every node of the search tree. On the other hand, difficult questions like 7, 8, 9, are best not handled with complicated mechanisms; it’s better just to wait until all twenty answers have been tentatively selected, and to check such hard cases only when the checking is easy and fast. In this way the author’s program showed the impossibility of a perfect score by exploring just 52859 nodes, after only 3.4 megamems of computation.
The next task was to try for score 19 by asserting that only x j is false. This turned out to be impossible for 1 ≤ j ≤ 18, based on very little computation whatsoever (especially, of course, when j = 6). The hardest case, j = 15, needed just 56 nodes and fewer than 5 kilomems. But then, ta da, three solutions were found: One for j = 19 (185 kilonodes, 11 megamems) and two for j = 20 (131 kilonodes, 8 megamems), namely
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 D C E A B E B C E A B E A E D B D A b B ; ( i ) A E D C A B C D C A C E D B C A D A A c ; ( ii ) D C E A B A D C D A E D A E D B D B B e . ( iii )
(The incorrect answers are shown here as lowercase letters. The first two solutions establish the truth of 20B and the falsity of 20E.)
72. Now there’s only one list of answers with score ≥ 19, namely (iii). But that is paradoxical — because it claims 20E is false; hence the maximum score cannot be 19!
Paradoxical situations are indeed possible when the global function F of answer 71 is used recursively within one or more of the local functions f js . Let’s explore a bit of recursive territory by considering the following two-question, two-letter example:
1. (A) Answer 1 is incorrect. | (B) Answer 2 is incorrect. |
2. (A) Some answers can’t be graded consistently. | (B) No answers achieve a perfect score. |
Here we have f 1 A \= x ¯ 1 ; f 1 B \= x ¯ 2 ; f 2A = ∃ a 1 ∃ a 2 ∀ x 1 ∀ x 2 ¬ F ( a 1 a 2 , x 1 x 2 ); f 2B = ∀ a 1 ∀ a 2 ¬ F ( a 1 a 2 , 11). ( Formulas quantified by ∃ a or ∀ a expand into | S | terms, while ∃ x or ∀ x expand into two; for example, ∃ a ∀ xg ( a, x ) = ( g (A , 0)∧ g (A , 1) ) ∨ (g (B , 0)∧ g (B , 1)) when S = {A , B}.) Sometimes the expansion is undefined, because it has more than one “fixed point”; but in this case there’s no problem because f 2A is true: Answer AA can’t be graded, since 1A implies x 1 ≡ x ¯ 1 . Also f 2B is true, because both BA and BB imply x 1 ≡ x ¯ 2 . Thus we get the maximum score 1 with either BA or BB and grades 01.
On the other hand the simple one-question, one-letter questionnaire ‘ 1. (A) The maximum score is 1’ has an indeterminate maximum score. For in this case f 1A = F (A , 1). We find that if F (A , 1) = 0, only (A , 0) is a valid grading, so the only possible score is 0; similarly, if F (A , 1) = 1, the only possible score is 1.
OK, suppose that the maximum score for the modified Table 666 is m . We know that m < 19; hence (iii) isn’t a valid grading. It follows that 20E is true, which means that every valid graded list of score m has x 20 false . And we can conclude that m = 18, because of the following two solutions (which are the only possibilities with 20C false):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 B A d A B E D C D A E D A E D E D B E c A E D C A B C D C A C E D B a C D A A c
But wait. If m = 18, we can score 18 with 20A true and two errors, using (say)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 D e D A B E D e C A E D A E D B D C C A
or 47 other answer lists. This contradicts m = 18, because x 20 is true.
End of story? No. This argument has implicitly been predicated on the assumption that 20D is false. What if m is indeterminate? Then a new solution arises
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 D C E A B E D C E A E B A E D B D A d D
of score 19. With (iii) it yields m = 19! If m is determinate, we’ve shown that m cannot actually be defined consistently; but if m is indeterminate, it’s definitely 19.
Question 20 was designed to create difficulties. [:-)]
— DONALD R. WOODS (2001)
73. The 29 words spark , often , lucky , other , month , ought , names , water , games , offer , lying , opens , magic , brick , lamps , empty , organ , noise , after , raise , drink , draft , backs , among , under , match , earth , roofs , topic yield this: “The success or failure of backtrack often depends on the skill and ingenuity of the programmer. ... Backtrack programming (as many other types of programming) is somewhat of an art.” — Solomon W. Golomb, Leonard D. Baumert.
That solution can be found interactively, using inspired guesses based on a knowledge of English and its common two-letter and three-letter words. But could a computer that knows common English words discover it without understanding their meanings?
We can formulate that question as follows: Let w 1 , ... , w 29 be the unknown words from WORDS (1000), and let q 1 , ... , q 29 be the unknown words of the quotation. (By coincidence there happen to be just 29 of each.) We can restrict the q ’s to words that appear, say, 32 times or more in the British National Corpus. That gives respectively (85, 562, 1863, 3199, 4650, 5631, 5417, 4724, 3657, 2448) choices for words of (2, 3, ... , 11) letters; in particular, we allow 3199 possibilities for the five-letter words q 7 , q 11 , q 21 , q 22 , because they aren’t required to lie in WORDS (1000). Is there a unique combination of words w i and q j that meets the given anacrostic constraints?
This is a challenging problem, whose answer turns out (surprisingly?) to be no . In fact, here is the first solution found by the author’s machine(!): “The success or failure of backtrack often depends on roe skill and ingenuity at the programmer. ... Backtrack programming (as lacy offal types of programming) as somewhat al an art.” (The OSPD4 includes ‘al’ as the name of the Indian mulberry tree; the BNC has ‘al’ 3515 times, mostly in unsuitable contexts, but that corpus is a blunt instrument.) Altogether 720 solutions satisfy the stated constraints; they differ from the “truth” only in words of at most five letters.
Anacrostic puzzles, which are also known by other names such as double-crostics, were invented in 1933 by E. S. Kingsley. See E. S. Spiegelthal, Proceedings of the Eastern Joint Computer Conference 18 (1960), 39–56, for an interesting early attempt to solve them — without backtracking — on an IBM 704 computer.
74. Instead of considering 1000 possibilities for 131 132 133 134 135 , it suffices to consider the 43 pairs xy such that cxyab is in WORDS (1000) and abc is a common three-letter word. (Of these pairs ab , ag , ... , ve , only ar leads to a solution. And indeed, the 720 solutions factor into three sets of 240, corresponding to choosing earth , harsh , or large as the keyword for 131 132 133 134 135 .) Similar reductions, but not so dramatic, occur with respect to 137 139 , 118 119 , 46 48 , and 32 35 .
75. The following algorithm uses an integer utility field TAG( u ) in the representation of each vertex u , representing the number of times u has been “ tagged.” The operations “tag u ” and “untag u ” stand respectively for TAG( u ) ← TAG( u ) + 1 and TAG( u ) ← TAG( u ) −1. Vertices shown as ‘⊙’ in the 21 examples have a nonzero TAG field, indicating that the algorithm has decided not to include them in this particular H .
State variables v l (a vertex), i l (an index), and a l (an arc) are used at level l for 0 ≤ l < n . We assume that n > 1.
R1. [Initialize.] Set TAG( u ) ← 0 for all vertices u . Then set v 0 ← v , i ← i 0 ← 0, a ← a 0 ← ARCS( v ) , TAG( v ) ← 1, l ← 1, and go to R4.
R2. [Enter level l .] (At this point i = i l −1 , v = v i , and a = a l −1 is an arc from v to v l −1 .) If l = n , visit the solution v 0 v 1 ...v n −1 and set l ← n − 1.
R3. [Advance a .] Set a ← NEXT( a ) , the next neighbor of v .
R4. [Done with level?] If a ≠ Λ, go to R5. Otherwise if i = l − 1, go to R6. Otherwise set i ← i +1, v ← v i , a ← ARCS( v ) .
R5. [Try a .] Set u ← TIP( a ) and tag u . If TAG( u ) > 1, return to R3. Otherwise set i l ← i , a l ← a , v l ← u , l ← l + 1, and go to R2.
R6. [Backtrack.] Set l ← l − 1, and stop if l = 0. Otherwise set i ← i l , v ← v i . Untag all neighbors of v k , for l ≥ k > i . Then set a ← NEXT( a l ) ; while a ≠ Λ, untag TIP( a ) and set a ← NEXT( a ) . Finally set a ← a l and return to R3.
This instructive algorithm differs subtly from the conventional structure of Algorithm B . Notice in particular that TIP( a l ) is not untagged in step R6; that vertex won’t be untagged and chosen again until some previous decision has been reconsidered.
76. Let G have N vertices. For 1 ≤ k ≤ N , perform Algorithm R on the k th vertex v of G , except that step R1 should tag the first k − 1 vertices so that they are excluded. (You’ll need to make it work when n = 1. A tricky shortcut can be used: If we untag all neighbors of v = v 0 after Algorithm R stops, the net effect will be to tag only v .)
The n -omino placement counts 1, 4, 22, 113, 571, 2816, 13616, 64678, 302574 are computed almost instantly, for small n . (Larger n are discussed in Section 7.2.3.)
77. (a) All but the 13th and 18th, which require an upward or leftward step.
(b) True. If u ∈ H and u ≠ v , let p u be any node of H that’s one step closer to v .
(c) Again true: The oriented spanning trees are also ordinary spanning trees.
(d) The same algorithm works, except that step R4 must return to itself after setting a ← ARCS( v ) . (We can no longer be sure that ARCS( v ) ≠ Λ.)
78. Extend Algorithm R to terminate immediately if WT( v ) ≥ U , otherwise to visit the singleton solution v . Also set w ← WT( v ) in step R1. Replace steps R2 and R5 by
R2 ′ . [Enter level l ]. If w ≥ L , visit the solution v 0 v 1 ...v l −1 .
R5 ′ . [Try a .] Set u ← TIP( a ) and tag u . If TAG( u ) > 1 or w + WT( u ) ≥ U , return to R3. Otherwise set i l ← i , a l ← a , v l ← u , w ← w + WT( u ) , l ← l + 1, and go to R2.
In step R6, set w ← w − WT( v l ) just before setting i ← i l .
79. (a) (0 ,j ) and (1 ,j ) for j ≥ 44; (2 ,j ) for j ≥ 32; (4 ,j ), (8 ,j ), (10 ,j ) for j < 12.
(b) True, each of the Boolean functions r i,j is clearly monotone.
(c) The “couplers” can be simulated by playing s j ∗ and g j ∗ instead of s j and g j (as if the organist had assistants). Therefore the problem can be factored into independent subproblems for the Pedal, Swell, and Great separately: Let there be P n , S n , G n playable sounds on the Pedal, Swell, and Great, and define P ( z ) = Σ n P n z n , S ( z ) = Σ n S n z n , G ( z ) = Σ n G n z n ; then Q ( z ) = Σ n Q n z n is the convolution P ( z ) S ( z ) G ( z ).
(d) p 0 = p 12 = c 0 = c 1 = c 15 = 1 gives (0 , 0), (0 , 12), (0 , 24), (1 , 0), (1 , 12); s 0 = s 19 = s 28 = c 3 = c 4 = 1 gives (the beautiful) (3 , 0), (3 , 19), (3 , 28), (4 , 19), (4 , 28); etc.
(e) It’s unplayable if and only if i ∈ {2 , 14 , 15} or i ′ ∈ {0 , 1 , 2 , 14 , 15} or ( i ≠ i ′ and either 3 ≤ i, i ′ ≤ 8 or 9 ≤ i, i ′ ≤ 15).
(f) Q 1 = 812 − 112 = 700, because we can’t have (14 ,j ) or (15 ,j ) without (13 ,j ).
(g) Q 811 = 12 sounds lack only one pipe: With all inputs 1 except p j , for 12 ≤ j < 24, only r 2 ,j is 0. (Thankfully there isn’t enough wind pressure to actually play this.)
(h) Brute-force backtrack programs can be written, using the monotonicity property (b) for cutoffs, in order to check small values and to list the actual sounds. But the best way to compute P n , S n , G n , and Q n is to use generating functions.
For example, let G ( z ) = G 0 ( z ) + G 1 ( z ) + ... + G 63 ( z ), where G k ( z ) for k = ( c 14 c 13 c 12 c 11 c 10 c 9 ) 2 enumerates the sounds for a given setting of console switches, excluding sounds already enumerated by G j ( z ) for j < k . Then G 0 ( z ) = 1; G k ( z ) = 0 if c 13 c 14 = 1; otherwise G k ( z ) = f ( c 9 + c 11 + c 12 + c 13 + 3 c 14 ) when c 10 = 0, and G k ( z ) = g ( c 9 +1+ c 11 + c 12 + c 13 +3 c 14 , 1+ c 11 + c 12 + c 13 +3 c 14 ) when c 10 = 1, where
f ( n ) \= ( 1 + z n ) 56 − 1 , g ( m , n ) \= ( 1 + z n ) 12 ( ( 1 + z m ) 44 − 1 ) .
Thus G ( z ) = 1 + 268 z + 8146 z 2 + 139452 z 3 + ... + 178087336020 z 10 + ... +12 z 374 + z 380 .
Similarly, with S ( z ) \= Σ k \= 0 63 S k ( z ) and k = ( c 8 c 7 c 6 c 5 c 4 c 3 ) 2 , we have S 0 ( z ) = 1; S 32 ( z ) = (1 + z ) 44 − 1; otherwise S k ( z ) = f ( c 3 + c 5 + c 6 + c 7 ) when c 4 = c 8 = 0, S k ( z ) = g(c 3 + c 4 + c 5 + c 6 + c 7 + c 8 , max( c 3 ,c 4 ) + c 5 + c 6 + c 7 ) when c 4 + c 8 > 0. Thus S ( z ) = 1 + 312 z + 9312 z 2 + 155720 z 3 + ... + 180657383126 z 10 + ... +12 z 308 + z 312 . [Curiously we have S n > G n for 1 ≤ n ≤ 107.]
The generating functions for P ( z ) \= Σ k \= 0 31 P k ( z ) , with k = ( c 16 c 15 c 2 c 1 c 0 ) 2 , are trickier. Let h ( w, z ) = (1+3 wz 2 +2 w 2 z 3 + w 2 z 4 + w 3 z 4 ) 8 ( (1+2 wz 2 + w 2 z 3 ) 4 −1 ) . Then P 31 ( z ) = h ( z, z 2 ), and there are three main cases when 0 < k < 31: If c 0 c 15 = c 1 c 16 = 0, then P k ( z ) = (1+ z c 15 + c 16 ) 32 − (1 + z c 15 + c 16 ) 20 if c 0 + c 1 + c 2 = 0, otherwise P k ( z ) = (1 + z c 0 + c 1 + c 2 + c 15 + c 16 ) 32 − 1. If c 0 = c 15 , c 1 = c 16 , c 2 = 0, then P k ( z ) = q ( z c 0 + c 1 ),
q ( z ) \= ( 1 + 3 z 2 + 2 z 3 + z 4 ) 8 ( 1 + 2 z 2 + z 3 ) 4 − 2 ( 1 + 2 z 2 + z 3 ) 8 ( 1 + z 2 ) 4 + ( 1 + z 2 ) 8 .
Otherwise we have P k ( z ) = h ( z c 0 + c 1 + c 2 + c 15 + c 16 −2 ,z ). Thus P ( z ) = 1+120 z +2336 z 2 + 22848 z 3 + ... + 324113168 z 10 + ... +8 z 119 + z 120 . And Q ( z ) = 1 + 700 z + 173010 z 2 + 18838948 z 3 + 1054376915 z 4 + 38386611728 z 5 + 1039287557076 z 6 + 22560539157160 z 7 + 410723052356833 z 8 + 6457608682396156 z 9 + 89490036797524716 z 10 + ... +12 z 811 + z 812 . So ( Q 2 / ( 812 2 ) , … , Q 10 / ( 812 10 ) ≈ ( .5 , .2 , .06 , .01 , .003 , .0005 , .00009 , .00002 , .000003 ) .
Dr Pell was wont to say, that in the Resolution of Questiones, the main matter is the well stating them: which requires a good mother-witt & Logick: as well as Algebra: for let the Question be but well-stated, and it will worke of it selfe: . . . By this way, an man cannot intangle his notions, & make a false Steppe.
— JOHN AUBREY, An Idea of Education of Young Gentlemen (c. 1684)
Section 7.2.2.1
1. (a) Note first that Algorithm 6.2.2T has its own LLINK and RLINK fields, for left and right children; they shouldn’t be confused with the links of the doubly linked list. After all deletions are done, LLINK ( k ) will be the largest search-tree ancestor of k that’s less than k ; RLINK ( k ) will be the smallest ancestor of k that’s greater than k ; but if there’s no such ancestor, the link will be 0. (For example, in Fig. 10 of Section 6.2.2, RLINK(LEO) would be PISCES and LLINK(AQUARIUS) would be the list head.)
(b) There are C n \= ( 2 n n ) 1 n + 1 classes (the Catalan number), one for each binary tree.
(c) The size of each class is the number of topological sortings of the partial order generated by the relations k ≺ LLINK ( k ), k ≺ RLINK ( k ). And this number equals 1 only in the 2 n −1 “ degenerate” trees of height n (see exercise 6.2.2–5).
2. (a) (Solution by X. Lou.) We can prove that LLINK ( a k ) = a k − 1 and RLINK ( a k ) = ( a k + 1) mod ( n + 1) when a k is undeleted; hence that undeletion sets RLINK ( a k − 1) and LLINK (( a k + 1) mod ( n + 1)) to the correct value a k . (If a k − 1 wasn’t deleted before a k , LLINK ( a k ) never changed. Otherwise LLINK ( a k ) became a k − 1 when a k − 1 was undeleted, by induction on k . A similar argument works for RLINK .) Notice that each LLINK and RLINK is reset exactly once, except that LLINK (1) and RLINK ( n ) remain 0.
(Programmers are advised to use this amazing fact only with great care, because the lists are malformed during the process and fully reconstructed only at the end.)
(b) No. For example, delete 1, 2, 3; then undelete 1, 3, 2.
(c) Yes. The argument of (a) applies to each maximal interval of affected elements.
3. (a) ( x 1 ,..., x 6 ) = (1, 0, 0, 1, 1, 0). (In general the solutions to linear equations won’t always be 0 or 1. For example, the equations x 1 + x 2 = x 2 + x 3 = x 1 + x 3 = 1 imply that x 1 \= x 2 \= x 3 \= 1 2 ; hence the corresponding exact cover problem is unsolvable.)
(b) In practice, m is much larger than n . Example (5) is just a “toy problem”! The best we can hope to achieve from n simultaneous equations is to express n of the variables in terms of the other m − n ; that leaves 2 m − n cases to try.
4. If G is bipartite, the exact covers are the ways to choose the vertices of one part. (Hence there are 2 k solutions, if G has k components.) Otherwise there are no solutions. ( Algorithm X will discover that fact quickly, although Algorithm 7B is faster.)
5. Given a hypergraph, find a set of vertices that hits each hyperedge exactly once. (In an ordinary graph this is the scenario of exercise 4 .)
Similarly, the so-called hitting set problem is dual to the vertex cover problem.
6. The header nodes, numbered 1 through N , are followed by L ordinary nodes and M + 1 spacers; hence the final node Z is number L + M + N + 1. (There also are N + 1 records for the horizontal list of items; those “records” aren’t true “nodes.”)
7. Node 23 is a spacer; ‘−4’ indicates that it follows the 4th option. (Any nonpositive number would work, but this convention aids debugging.) Option 5 ends at node 25.
8. ( Secondary items, which are introduced in the text after (24), are also handled by the steps below. Such items should occur after all of the primary items have been listed on the first line, and separated from them by some distinguishing mark.)
I1. [Read the first line.] Set N 1 ← −1, i ← 0. Then, for each item name α on the first line, set i ← i + 1, NAME ( i ) ← α , LLINK ( i ) ← i − 1, RLINK ( i − 1) ← i . If α names the first secondary item, also set N 1 ← i − 1. (In practice α is limited to at most 8 characters, say. One should report an error if α = NAME ( j ) for some j < i .)
I2. [Finish the horizontal list.] Set N ← i . If N 1 < 0 (there were no secondary items), set N 1 ← N . Then set LLINK ( N + 1) ← N , RLINK ( N ) ← N + 1, LLINK ( N 1 + 1) ← N + 1, RLINK ( N + 1) ← N 1 + 1, LLINK (0) ← N 1 , RLINK ( N 1 ) ← 0. (The active secondary items, if any, are accessible from record N + 1.)
I3. [Prepare for options.] Set LEN ( i ) ← 0 and ULINK ( i ) ← DLINK ( i ) ← i for 1 ≤ i ≤ N . (These are the header nodes for the N item lists, which are initially empty.) Then set M ← 0, p ← N + 1, TOP ( p ) ← 0. (Node p is the first spacer.)
I4. [Read an option.] Terminate with Z ← p if no input remains. Otherwise let the next line of input contain the item names α 1 ... α k , and do the following for 1 ≤ j ≤ k : Use an algorithm from Chapter 6 to find the index i j for which NAME ( i j ) = α j . (Report an error if unsuccessful. Complain also if an item name appears more than once in the same option, because a duplicate might make Algorithm X fail spectacularly.) Set LEN ( i j ) ← LEN ( i j ) + 1, q ← ULINK ( i j ), ULINK ( p + j ) ← q , DLINK ( q ) ← p + j , DLINK ( p + j ) ← i j , ULINK ( i j ) ← p + j , TOP ( p + j ) ← i j .
I5. [Finish an option.] Set M ← M +1, DLINK ( p ) ← p + k , p ← p + k +1, TOP ( p ) ← − M , ULINK ( p ) ← p − k , and return to step I4. (Node p is the next spacer.)
9. Set θ ← ∞, p ← RLINK (0). While p ≠ 0, do the following: Set λ ← LEN ( p ); if λ<θ set θ ← λ , i ← p ; and set p ← RLINK ( p ). (We could exit the loop immediately if θ = 0.)
10. If LEN ( p ) > 1 and NAME ( p ) doesn’t begin with ‘#’, set λ ← M + LEN ( p ) instead of LEN ( p ). (Similarly, the “ nonsharp preference” heuristic favors nonsharp items.)
11. Item a is selected at level 0, trying option x 0 = 12, ‘ a d g ’, and leading to (7). Then item b is selected at level 1, trying x 1 = 16, ‘ b c f ’. Hence, when the remaining item e is selected at level 2, it has no options in its list, and backtracking becomes necessary. Here are the current memory contents — substantially changed from Table 1 :
i : | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| — |
|
|
|
|
|
|
|
| 0 | 0 | 0 | 0 | 3 | 0 | 5 | 6 |
| 0 | 2 | 3 | 5 | 5 | 0 | 0 | 0 |
x : | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| — | 2 | 1 | 1 | 1 | 0 | 0 | 1 |
| — | 20 | 16 | 9 | 27 | 5 | 6 | 25 |
| — | 12 | 16 | 9 | 27 | 5 | 6 | 25 |
x : | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 0 | 3 | 5 | —1 | 1 | 4 | 7 | —2 |
| — | 3 | 5 | 9 | 1 | 4 | 7 | 12 |
| 10 | 3 | 5 | 14 | 20 | 21 | 25 | 18 |
x : | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 2 | 3 | 6 | —3 | 1 | 4 | 6 | —4 |
| 2 | 9 | 6 | 16 | 12 | 4 | 18 | 20 |
| 2 | 3 | 6 | 22 | 1 | 27 | 6 | 25 |
x : | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
|
| 2 | 7 | —5 | 4 | 5 | 7 | —6 |
|
| 16 | 7 | 24 | 4 | 10 | 25 | 27 |
|
| 2 | 7 | 29 | 4 | 5 | 7 | — |
|
12. Report that x is out of range if x ≤ N or x > Z or TOP ( x ) ≤ 0. Otherwise set q ← x and do “print ‘ NAME(TOP ( q ))’ and set q ← q + 1; if TOP ( q ) ≤ 0 set q ← ULINK ( q )” until q = x . Then set i ← TOP ( x ), q ← DLINK ( i ), and k ← 1. While q ≠ x and q ≠ i , set q ← DLINK ( q ) and k ← k + 1. If q ≠ i , report that the option containing x is ‘ k of LEN ( i )’ in item i ’s list; otherwise report that it’s not in that list.
[ Algorithm C extends Algorithm X to colors. If COLOR ( q ) ≠ 0, also print ‘: c ’ where c = COLOR ( q ) if COLOR ( q ) > 0, otherwise c = COLOR ( TOP ( q )).]
13. For 0 ≤ j < l , node x j is part of an option in the solution. By setting r ← x j and then r ← r + 1 until TOP ( r ) < 0, we’ll know exactly what that option is: It’s option number − TOP ( r ), which begins at node ULINK ( r ). (Many applications of Algorithm X have a custom-made output routine, to convert x 0 ... x l −1 into an appropriate format — presenting it directly as a sudoku solution or a box packing, etc.)
Exercise 12 explains how to provide further information, not only identifying the option of x j but also showing its position in the search tree.
14. (a) The options are ‘ S j M k ’, for all 0 ≤ j, k < n except j = k or j = ( k + 1) mod n .
(b) There are ( u 3 ,..., u 10 ) = (1, 2, 13, 80, 579, 4738, 43387, 439792) solutions. The running time for n = 10 is about 180 (or 275) mems per solution with (or without) MRV.
[This problem has a rich history: E. Lucas presented and named it in his Théorie des Nombres (1891), 215, 491–495. An equivalent problem had, however, already been posed by P. G. Tait, and solved by A. Cayley and T. Muir; see Trans. Royal Soc. Edinburgh 28 (1877), 159, and Proc. Royal Soc. Edinburgh 9 (1878), 338–342, 382– 391, 11 (1880), 187–190. In particular, Muir found the recurrence relation
( n − 1 ) u n + 1 \= ( n 2 − 1 ) u n + ( n + 1 ) u n − 1 + ( − 1 ) n ⋅ 4 , for n > 1.
Clearly u 2 = 0; a careful consideration of initial values shows that the choices u 0 = 1 and u 1 = −1 give mathematically clean expressions, such as the explicit formula
u n \= Σ k \= 0 n ( − 1 ) k 2 n 2 n − k ( 2 n − k k ) ( n − k ) ! .
(See J. Touchard, Comptes Rendus Acad. Sci. 198 (Paris, 1934), 631–633; I. Kaplansky, Bull. Amer. Math. Soc. 49 (1943), 784–785.) The k th term of this formula can also be written n ! Σ j ( − 1 ) j + k 2 k − 2 j / ( ( k − 2 j ) ! j ! ( n − 1 ) j ¯ ) ; hence we have the curious identity
u n n ! \= Σ j \= 0 n / 2 ( − 1 ) j j ! T n − 2 j ( n − 1 ) j ¯ \= T n − T n − 1 n − 1 + T n − 2 / 2 ! ( n − 1 ) ( n − 2 ) − T n − 3 / 3 ! ( n − 1 ) ( n − 2 ) ( n − 3 ) + ⋅ ⋅ ⋅ ,
where T n \= Σ k \= 0 n ( − 2 ) k / k ! is the sum of the first n + 1 terms of the power series for e −2 . The ménage numbers therefore satisfy the interesting asymptotic formula
u n \= n ! e 2 \= ( 1 − 1 n − 1 + 1 / 2 ! ( n − 1 ) ( n − 2 ) + ⋅ ⋅ ⋅ + ( − 1 ) k / k ! ( n − 1 ) ⋅ ⋅ ⋅ ( n − k ) + O ( n − k − 1 ) )
for all fixed k ≥ 0, discovered by I. Kaplansky and J. Riordan [ Scripta Mathematica 12 (1946), 113–124]. In fact, M. Wyman and L. Moser proved that the sum of this series for 0 ≤ k < n differs from u n by less than 1/2 [ Canadian J. Mathematics 10 (1958), 468–480]. Among many other things, they also found a (complicated) expression for the exponential generating function ∑ n u n z n / n !. The ordinary generating function ∑ n u n z n has the surprisingly nice form ((1 − z )/(1 + z )) F ( z /(1 + z ) 2 ), where F ( z ) = ∑ n ≥0 n ! z n ; see P. Flajolet and R. Sedgewick, Analytic Combinatorics (2009), 368–372.]
15. Omit the options with i = n − [ n even] and j > n /2.
(Other solutions are possible. For example, we could omit the options with i = 1 and j ≥ n ; that would omit n − 1 options instead of only ⌊ n /2⌋. However, the suggested rule turns out to make Algorithm X run about 10% faster.)
16. The two solutions are ‘ r 1 c 2 a 3 b −1 ’ ‘ r 2 c 4 a 6 b −2 ’ ‘ r 3 c 1 a 4 b 2 ’ ‘ r 4 c 3 a 7 b 1 ’ ‘ a 2 ’ ‘ a 5 ’ ‘ a 8 ’ ‘ b −3 ’ ‘ b 0 ’ ‘ b 3 ’; ‘ r 1 c 3 a 4 b −2 ’ ‘ r 2 c 1 a 3 b 1 ’ ‘ r 3 c 4 a 7 b −1 ’ ‘ r 4 c 2 a 6 b 2 ’ ‘ a 2 ’ ‘ a 5 ’ ‘ a 8 ’ ‘ b −3 ’ ‘ b 0 ’ ‘ b 3 ’. At the top levels, the MRV heuristic causes Algorithm X to branch first on the slack variables a 2 , a 8 , b −3 , and b 3 , which each have at most two possibilities. (And that’s actually a pretty strange way to tackle the four queens problem!)
17. Branch first on r 3 , which has four options. If ‘ r 3 c 1 a 4 b 2 ’, there’s just one option for c 2 , then c 3 , then r 2 , so we get the first solution: ‘ r 3 c 1 a 4 b 2 ’ ‘ r 1 c 2 a 3 b −1 ’ ‘ r 4 c 3 a 7 b 1 ’ ‘ r 2 c 4 a 6 b −2 ’. If ‘ r 3 c 2 a 5 b 1 ’, c 3 is forced, then r 2 can’t be covered. If ‘ r 3 c 3 a 6 b 0 ’, r 2 is forced, then c 2 can’t be covered. If ‘ r 3 c 4 a 7 b −1 ’, we cruise to the second solution: ‘ r 3 c 4 a 7 b −1 ’ ‘ r 1 c 3 a 4 b −2 ’ ‘ r 2 c 1 a 3 b 1 ’ ‘ r 4 c 2 a 6 b 2 ’. (And that’s a good way.)
18. ‘ c e ’ ‘ a d f ’ ‘ b g ’ (as before) and ‘ b c f ’ ‘ a d g ’ (new).
19. When all primary items have been covered in step X2, accept a solution only if LEN ( i ) = 0 for all of the active secondary items, namely the items accessible from RLINK ( N + 1). [This algorithm is called the “ second death” method, because it checks that all of the purely secondary options have been killed off by primary covering.]
20. For 1 ≤ k < m , set t ← k & (− k ); include secondary item y k in option α j for k ≤ j < min( m, k + t ) and in option β j for k − t ≤ j < k .
Equivalently, to set up option α j , include a and set t ← j ; while t > 0, include y t and set t ← t & ( t − 1). To set up option β j , include b and set t ← −1 − j ; while t > − m , include y − t and set t ← t & ( t − 1).
If j > k , options α j and β k both contain y j &−2 ⌊lg( j &~ k )⌋ .
21. The options α j i will contain the primary item a i . Simply do k − 1 pairwise orderings, with secondary items y k i to ensure that j k ≤ j k +1 . If m is a power of 2, it turns out that the options for 1 < i < k each have exactly lg m secondary items. For example, if m = 4 and k > 2, the options α j 2 are ‘ a 2 y 1 1 y 2 1 ’, ‘ a 2 y 2 1 y 1 2 ’, ‘ a 2 y 3 1 y 2 2 ’, ‘ a 2 y 3 2 y 2 2 ’.
(The author attempted to knock out options for α i ′ with i ′ < i − 1 or i ′ > i + 1, by adding additional secondary items, but that turned out to be a bad idea.)
Of course, this method doesn’t compete with the lightning-quick methods for combination generation in Section 7.2.1.3. For instance, when m = 20 and k = 8 it needs 1.1 G μ to crank out the ( 27 8 ) \= 2220075 coverings, about 500 mems per solution.
22. (a) Let n ′ = ⌊ n /2⌋ + 1. By rotation/reflection we can assume that the queen in column n ′ (the middle column) is in row i and the queen in row n ′ is in column j , where 1 ≤ i < j < n ′. We obtain a suitable exact cover problem by leaving out the options o ( i, j ) = ‘ r i c j a i + j b i − j ’ for i = j or i + j = n + 1; also omit o ( i, j ) for i > j when j = n ′; j > i when i = n ′; and ( i, j ) = ( n ′ − 1, n ′) or ( n ′, 1). Then include secondary items to force the pairwise ordering of α k \= o ( k + 1, n ′) and β k \= o ( n ′, k + 2), for 0 ≤ k < m = n ′ − 2.
(b) Now we assume a queen in ( j, j ), where 1 ≤ j < n ′, and that the queen in row n is closer to the bottom right corner than the queen in column n . So we omit options o ( i, j ) for i + j = n + 1 or i = j ≥ n ′ or ( i, j ) = ( n , 2) or ( i, j ) = ( n −1, n ); we make item b 0 primary; and we let α k \= o ( n, n − k − 1), β k \= o ( n − k − 2, n ) for 0 ≤ k < m = n − 3.
(c) This time we want queens in ( i, i ) and ( j, n + 1 − j ) where 1 ≤ i < j < n ′. We promote a n +1 and b 0 to primary; omit o ( i, j ) when i = j ≥ n ′ − 1 or i = n + 1 − j ≥ n ′ or ( i, j ) = (1, n ); and let α k \= o ( k + 1, k + 1), β k \= o ( k + 2, n − k − 1) for 0 ≤ k < m = n ′ − 2.
In case (a) there are (0, 0, 1, 8, 260, 9709, 371590) solutions for n = (5, 7,..., 17); Algorithm X handles n = 17 in 3.4 G μ . [In case (b) there are (0, 0, 1, 4, 14, 21, 109, 500, 2453, 14498, 89639, 568849) for n = (5, 6,..., 16); and n = 16 costs 6.0 G μ . In case (c), similarly, there are (1, 0, 3, 6, 24, 68, 191, 1180, 5944, 29761, 171778, 1220908) solutions; n = 16 costs 5.5 G μ .]
23. (a) Consider the queens in column a of row 1, row b of column n , column c ¯ of row n , and row d ¯ of column 1, where x ¯ \= n + 1 − x . (These four queens are distinct, because no queen is in a corner. Notice also that neither a ¯ nor b ¯ nor c ¯ nor d ¯ can equal a .) Repeated rotations and/or reflections will change these numbers from ( a, b, c, d ) to
( b , c , d , a ) , ( c , d , a , b ) , ( d , a , b , c ) , ( d ¯ , c ¯ , b ¯ , a ¯ ) , ( c ¯ , b ¯ , a ¯ , d ¯ ) , ( b ¯ , a ¯ , d ¯ , c ¯ ) , ( a ¯ , d ¯ , c ¯ , b ¯ ) .
Those eight 4-tuples are usually distinct, and in such cases we can save a factor of 8 by eliminating all but one of them. There always is a solution with a ≤ b , c , d > a ¯ ; and those inequalities can be enforced by doing three simultaneous pairwise comparisons, between the options for row 1 and the respective options for column n , row n , and column 1. For example, the options that correspond to a = 1 when n = 16 are ‘ r 1 c 2 a 3 b −1 ’; ‘ r 2 c 16 a 18 b −14 x 1 x 2 x 4 ’; ‘ r 15 c 16 a 31 b −1 x 1 x 2 x 4 ’; ‘ r 16 c 2 a 18 b 14 y 1 y 2 y 4 ’; ‘ r 16 c 14 a 30 b 2 y 1 y 2 y 4 ’; ‘ r 2 c 1 a 3 b 1 z 1 z 2 z 4 ’; ‘ r 15 c 1 a 16 b 14 z 1 z 2 z 4 ’. (Here m = n /2 − 1 = 7.)
With this change, the number of solutions for n = 16 drops from 454376 to 64374 (ratio ≈ 7.06), and the running time drops from 4.3 G μ to 1.2 G μ (ratio ≈ 3.58).
[The author experimented with further restrictions, so that solutions were allowed only if (i) a < b , c , d ; (ii) a = b < c , d ; (iii) a = b = c < d ; (iv) a = b = c = d ; (v) a = c < b , d . Five options were given for each value of a < n /2 − 1, and m was 6 instead of 7. The number of solutions decreased to 59648; but the running time increased to 1.9 G μ . Thus a point of diminishing returns had been reached. (A completely canonical reduction would have produced 57188 solutions, with considerable difficulty.)]
(b) This case is almost identical to (a), because the queen in the center vacates all other diagonal cells. Requiring a ≤ b , c , d > a ¯ reduces the number of solutions for n = 17 from 4067152 to 577732 (ratio ≈ 7.04), and run time to 3.2 G μ (ratio ≈ 4.50).
24. We simply combine compatible options into (a) pairs, (b) quadruplets, and force a queen in the center when n is odd. For example, when n = 4 we replace (23) by (a) ‘ r 1 c 2 a 3 b −1 r 4 c 3 a 7 b 1 ’; ‘ r 1 c 3 a 4 b −2 r 4 c 2 a 6 b 2 ’; ‘ r 2 c 1 a 3 b 1 r 3 c 4 a 7 b −1 ’; ‘ r 2 c 4 a 6 b −2 r 3 c 1 a 4 b 2 ’; (b) ‘ r 1 c 2 a 3 b −1 r 2 c 4 a 6 b −2 r 4 c 3 a 7 b 1 r 3 c 1 a 4 b 2 ’; ‘ r 2 c 1 a 3 b 1 r 3 c 4 a 7 b −1 r 1 c 3 a 4 b −2 r 4 c 2 a 6 b 2 ’. The options when n = 5 are (a) ‘ r 1 c 2 a 3 b −1 r 5 c 4 a 9 b 1 ’; ‘ r 1 c 4 a 5 b −3 r 5 c 2 a 7 b 3 ’; ‘ r 2 c 1 a 3 b 1 r 4 c 5 a 9 b −1 ’; ‘ r 2 c 5 a 7 b −3 r 4 c 1 a 5 b 3 ’; ‘ r 3 c 3 a 6 b 0 ’; (b) ‘ r 1 c 2 a 3 b −1 r 2 c 5 a 7 b −3 r 5 c 4 a 9 b 1 r 4 c 1 a 5 b 3 ’; ‘ r 2 c 1 a 3 b 1 r 1 c 4 a 5 b −3 r 4 c 5 a 9 b −1 r 5 c 2 a 7 b 3 ’; ‘ r 3 c 3 a 6 b 0 ’.
An n -queen solution is either asymmetric (changed by 180 ° rotation) or singly symmetric (changed by 90 ° rotation but not 180 ° ) or doubly symmetric (unchanged by 90 ° rotation). Let Q a ( n ), Q s ( n ), Q d ( n ) be the number of such solutions that are essentially different; then Q ( n ) = 8 Q a ( n ) + 4 Q s ( n ) + 2 Q d ( n ) when n > 1. Furthermore there are 4 Q s ( n ) + 2 Q d ( n ) solutions to (a) and 2 Q d ( n ) solutions to (b). Hence we can determine the individual values just by counting solutions, and we obtain these results for small n :
n \= 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Q a ( n ) \= 0 1 0 4 11 42 89 329 1765 9197 45647 284743 1846189 11975869 Q s ( n ) \= 0 0 1 2 1 4 3 12 18 32 105 310 734 2006 Q d ( n ) \= 1 1 0 0 0 0 0 0 4 4 0 0 32 64
We can reduce the solutions to (a) by a factor of 2, by simply eliminating the options that contain { r 1 , c k } for k ≥ ⌈ n /2⌉. We can reduce the solutions to (b) by a factor of 2⌊ n /4⌋, by simply eliminating the options that contain { r j , c k } for j < ⌈ n /2⌉ and k ≥ ⌈ n /2⌉. With these simplifications, the computation of Q d (16) needs only 70 K μ ; and then the computation of Q s (16) needs only 5 M μ . Only 20 M μ are needed to determine that Q d (32) = 2 7 · 1589.
25. With 64 items, one for each cell of the chessboard, let there be 92 options, one for each of the 92 solutions to the eight queens problem (see Fig. 68 ). Every option names eight of the 64 items; so an 8-coloring is equivalent to solving this exact cover problem. Algorithm X needs only 25 kilomems and a 7-node search tree to show that such a mission is impossible. [In fact no seven solutions can be disjoint, because each solution touches at least three of the twenty cells 13, 14, 15, 16, 22, 27, 31, 38, 41, 48, 51, 58, 61, 68, 72, 77, 83, 84, 85, 86. See Thorold Gosset, Messenger of Mathematics 44 (1914), 48. However, Henry E. Dudeney found the illustrated way to occupy all but two cells, in Tit-Bits 32 (11 September 1897), 439; 33 (2 October 1897), 3.]
12345678 |
78563412 |
46718235 |
23854167 |
84236751 |
51672384 |
67481523 |
512784 |
26. This is an exact cover problem with 92 + 312 + 396 + ··· + 312 = 3284 options (see exercise 7.2.2–6 ). Algorithm X needs about 32 megamems to find the solution shown, and about 1.3 T μ to find all 11,092 of them.
07348652 |
18650437 |
75421860 |
26835071 |
34072186 |
52183704 |
80564213 |
61207345 |
27. Let u jh and d jh be secondary items for 1 ≤ j ≤ 2 n and 1 ≤ h ≤ ⌊ n /2⌋. Insert the gadget
u j 1 u j 2 ⋅ ⋅ ⋅ u j ⌈ i / 2 ⌉ u ( j + 1 ) ⌈ i / 2 ⌉ ⋅ ⋅ ⋅ u k ⌈ i / 2 ⌉ ⋅ ⋅ ⋅ u k 2 u k 1
into each option (16); also append similar options, but with ‘ u ’ changed to ‘ d ’, except when i = n . [Solutions whose planar graph “splits” will be obtained more than once. One such example is 12 10 8 6 4 11 9 7 5 4 6 8 10 12 5 7 9 11 3 1 2 1 3 2.]
28. (a) Denoting that formula by ρ ( c 0 , t 0 ; ... ; c l , t l ), notice that if c j ′ \= t j + 1 − c j we have ρ ( c 0 , t 0 ; … ; c l , t l ) + ρ ( c 0 ′ , t 0 ; … ; c l ′ , t l ) \= 1 . Consequently the completion ratio is 1/2 if and only if c j ′ \= c j for all j , namely when t j \= 2 c j − 1.
(b) The ratio ρ ( c 0 , t 0 ; ... ; c l , t l ) never has an odd denominator, because p / q + p ′/ q ′ has an even denominator whenever q and p ′ are odd and q ′ is even. But we can get arbitrarily close to 1/3, since ρ (2, 4; ... ;2, 4) = 1/3 + 1/(24 · 4 l ).
29. If T has only a root node, let there be one column, no rows. Otherwise let T have d ≥ 1 subtrees T 1 , ... , T d , and assume that we’ve constructed matrices with rows R j and columns C j for each T j . Let C = C 1 ⋃ ··· ⋃ C d . The matrix for T is obtained by appending three new columns {0, 1, 2} and the following new rows: (i) ‘0 1 2 and all columns of C \ C j ’, for 1 ≤ j ≤ d ; (ii) ‘ j and all columns of C ’, for j ∈ {0, 1}. The matrix for the example tree has 15 columns and 14 rows.
011111000000000 |
101111000000000 |
110111000000000 |
111100000000000 |
111010000000000 |
000000011111000 |
000000101111000 |
000000110111000 |
000000111100000 |
000000111010000 |
000000111111111 |
111111000000111 |
111111111111100 |
111111111111010 |
30. Yes, assuming that duplicate options are permitted. Use the previous construction; but if T is just a root node marked as a solution, let there be no rows and no columns. (Without duplicate options, no two solution nodes can be siblings.)
31. (a) In step I4 of answer 8 , insert p + j into the r th position of the list for i j , instead of at the bottom, where r is uniform between 1 and LEN ( i j ).
(b) In answer 9 , when λ < θ also set r ← 1; when λ = θ , set r ← r + 1, and change i ← p with probability 1/ r .
32. (a) No. Otherwise there would be an option with no primary items.
(b) Yes, but only if there are two options with the same primary items.
(c) Yes, but only if there are two options whose union is also an option, when restricted to primary items.
(d) The number of places, j , where x = 1 and x ′ = 0 must be the same as the number where x = 0 and x ′ = 1. For if A has exactly k primary items in every option, exactly jk primary items are being covered in different ways.
(e) Again distances must be even, because every solution also solves the restricted problem, which is uniform. (Consequently it makes sense to speak of the semidistance d ( x, x ′)/2 between solutions of a quasi-uniform exact covering problem. The semidistance in a polyform packing problem is the number of pieces that are packed differently.)
33. (Solution by N. Posting.) Add a new row at the bottom of A , all 1s. This ( m +1)× n matrix A ′ has one solution that chooses only the last row. All other solutions choose rows that solve A. (Another construction, which adds a new column, can be used if the all-1s row is already present.)
34. (Solution by T. Matsui.) Assume that all 1s in column 1 appear in the first t rows, where t > 3. Add two new columns at the left, and two new rows 1100 ... 0, 1010 ... 0 of length n + 2 at the bottom. For 1 ≤ k ≤ t , if row k was 1 α k , replace it by 010 α k if k ≤ t /2, 001 α k if k > t /2. Insert 00 at the left of the remaining rows t + 1 through m .
This construction can be repeated (with suitable row and column permutations) until no column sum exceeds 3. If the original column sums were ( c 1 ,..., c n ), the new A ′ has 2 T more rows and 2 T more columns than A did, where T \= Σ j \= 1 n ( c j ∸ 3 ) .
One consequence is that the exact cover problem is NP-complete even when restricted to cases where all row and column sums are at most 3.
Notice, however, that this construction is not useful in practice, because it disguises the structure of A : It essentially destroys the minimum remaining values heuristic, because all columns whose sum is 2 look equally good to the solver!
35. Take a matrix with column sums ( c 1 ,..., c n ), all ≤ 3, and extend it with three columns of 0s at the right. Then add the following four rows: ( x 1 ,..., x n , 0, 1, 1), ( y 1 ,..., y n , 1, 0, 1), ( z 1 ,..., z n , 1, 1, 0), and (0,...,0, 1, 1, 1), where x j \= [ c j < 3], y j \= [ c j < 2], z j \= [ c j < 1]. The bottom row must be chosen in any solution.
36. The following modifications (which work also with Algorithm C ) will find all solutions in lexicographic order; we can terminate early if we want only the first one.
Set LL ← 0 in step X1. (We will use the MRV heuristic, but only on levels > LL .)
If RLINK (0) = 0 and l = LL + 1 in step X2, visit the current solution as usual. Otherwise, however, set LL ← LL + 1 and do the following while l > LL (because the current solution was not found lexicographically): Set l ← l − 1, i ← TOP ( x l ); uncover the items ≠ i in the option that contains x l (as in X6); uncover i (as in X7).
In step X3, if l = LL simply set i ← RLINK (0). Otherwise use exercise 9 , say.
If l < LL after setting l ← l − 1 in step X8, set LL ← l .
To get the lexicographically smallest solution to the n queens problem, make sure that the first n items are r 1 , r 2 , ... , r n . (The other primary items, c j , can follow in any order.) The first solution for n = 32, found after 4.2 G μ , has queens in columns 1, 3, 5, 2, 4, 9, 11, 13, 15, 6, 18, 24, 26, 30, 25, 31, 28, 32, 27, 29, 16, 19, 10, 8, 17, 12, 21, 7, 14, 23, 20, 22. (Without MRV the computation would have taken 35.6 G μ .)
[The analogous problem for n = 48 is already quite difficult; that case was first solved by Wolfram Schubert. The best results currently known for large n have been obtained via sophisticated methods of integer programming: In November 2017, Matteo Fischetti and Domenico Salvagnin were the first to solve the case n = 56 and many larger cases, although n = 62 was still unsolved; see arXiv:1907.08246 [cs.DS] (2019), 14 pages. See also OEIS A141843 for the latest developments.]
37. (a) Let a i,j \= 0 if i ≤ 0 or j ≤ 0; otherwise
a i , j \= mex ( { a i , j − k | k > 0 } ∪ { a i − k , j | k > 0 } ∪ { a i − k , j − k | k > 0 } ∪ { a i + k , j − k | k > 0 } )
where ‘mex’ is defined in exercise 7.1.3–8. It is not difficult to verify that a i,q i \= 1 and that each of the sequences 〈 a i,n 〉, 〈 a n,j 〉 for n ≥ 1 is a permutation of the positive integers. (See OEIS A065188 and Alec Jones’s A269526.)
(b) The following exercise gives strong empirical evidence for this conjecture. And in the full plane, the analogous spiral sequence can be analyzed: See F. M. Dekking, J. Shallit, and N. J. A. Sloane, Electronic J. Combinatorics 27 (2020), #P1.52, 1–27.
38. The following method, inspired by Eq. 7.2.2–(6) and the previous exercise, uses binary vectors a , b , c , where c has both positive and negative subscripts.
G1. [Initialize.] Set r ← 0, s ← 1, t ← 0, n ← 0. (We’ve computed q k for 1 ≤ k ≤ n .)
G2. [Try for q n ≤ n .] (At this point a k \= 1 for 1 ≤ k < s and a s \= 0; also c k \= 1 for − r < k ≤ t and c − r \= c t +1 \= 0; each vector contains n 1s.) Set n ← n + 1, k ← s .
G3. [Found?] If k > n − r go to G4. Otherwise if a k \= b k + n \= c k − n \= 0, go to G5. Otherwise set k ← k + 1 and repeat this step.
G4. [Make q n > n .] Set t ← t + 1, q n ← n + t , a n + t ← b 2 n + t ← c t ← 1, and return to G2.
G5. [Make q n ≤ n .] Set q n ← k , a k ← b k + n ← c k − n ← 1. If k = s , set s ← s + 1 repeatedly until a s \= 0. If k = n − r , set r ← r + 1 repeatedly until c − r \= 0. Return to G2.
In step G2 we have s ≈ n − r ≈ t ≈ n / ϕ ; hence the running time is extremely short. Empirically, in fact, the calculation of q n requires at most 19 accesses to the bit vectors (averaging about 5.726 accesses), for each n . Agreement with exercise 37 is very close:
( q 999999997 , ... , q 1000000004 ) \= ( 618033989 , 1618033985 , 618033988 , ) 1618033988 , 1618033990 , 1618033992 , 1618033994 , 618033991 ) .
Moreover, it’s likely that q n ∈ [ n / ϕ − 3 . . n / ϕ + 5] ⋃ [ nϕ − 2 .. nϕ + 1] for all n .
39. (a) With probability (1 − p ) n , no items will be selected; in such cases we must restart the clause generator, because options can’t be empty. Ten random trials with m = 500, n = 100, and p = .05 gave respectively (444, 51, 138, 29, 0, 227, 26, 108, 2, 84) solutions, costing about 100 megamems per solution.
Although the exercise did not call for a mathematical analysis, we can derive a formula for the expected number of solutions by computing the probability that a given subset of the options is an exact cover, then summing over all subsets. If the subset has k items, and if each item in each option were present with probability p , this probability would be ( kp (1 − p ) k −1 ) n . However, we’ve excluded empty options; the true probability f ( n, p, k ) turns out to be k ! { n k } ( p ( 1 − p ) k − 1 ) n / ( 1 − ( 1 − p ) n ) k . The sum Σ k { m k } f ( n , p , k ) , when ( m, n, p ) = (500, 100, .05), is approximately 3736.96 with the incorrect formula and 297.041 with the correct one.
[In unpublished notes, Robin Pemantle and Boris Pittel have independently derived asymptotic results for m = αn and p = r / n , for fixed α and r as n → ∞. The behavior of Algorithm X with this random model is not easy to analyze, but an analysis may be within reach because of the recursive structure.]
(b) This case has completely different behavior. In the first place, n must obviously be a multiple of r . In the second place, we’ll need more options to get even one solution when n = 100 and r = 5, because conveniently small options don’t exist.
Proof: The total number of set partitions into twenty subsets of size 5 is P = 100!/(20! · 5! 20 ) ≈ 10 98 ; the total number of possible options is N \= ( 100 5 ) \= 75287520 . The probability that any particular set partition occurs as a solution is the probability that twenty given options occur in a random sample of m , with replacement, namely g ( N , m , 20 ) \= Σ k ( 20 k ) ( − 1 ) k ( N − k ) m / N m \= Σ t { m t } t ! ( N − 20 t − 20 ) / N m . If m isn’t extremely large, this is almost the same as the probability without replacement, namely ( N − 20 m − 20 ) / ( N m ) ≈ ( m / N ) 20 . The expected number of solutions when m = (500, 1000, 1500), respectively, is P g ( N, m , 20) ≈ (.000002, 2.41, 8500).
40. Set f m ← 0 and f k −1 ← f k | r k for m ≥ k > 1. The bits of u k represent items that are being changed for the last time.
Let u k \= u ′ + u ″, where u ′ = u k & p . If u k ≠ 0 at the beginning of step N4, we compress the database as follows: For N ≥ j ≥ 1, if s j & u ′ ≠ u ′, delete ( s j , c j ); otherwise if s j & u ″ ≠ 0, delete ( s j , c j ) and insert ( ( s j & u ¯ k ) | u ′ , c j ) .
To delete ( s j , c j ), set ( s j , c j ) ← ( s N , c N ) and N ← N − 1.
When this improved algorithm terminates in step N2, we always have N ≤ 1. Furthermore, if we let p k \= r 1 | ··· | r k −1 , the size of N never exceeds 2 ν k , where ν k \= ν 〈 p k r k f k 〉 is the size of the “ frontier” (see exercise 7.1.4–55).
[In the special case of n queens, represented as an exact cover problem as in (23), this algorithm is due to I. Rivin, R. Zabih, and J. Lamping, Inf. Proc. Letters 41 (1992), 253–256. They proved that the frontier for n queens never has more than 3 n items.]
41. The author has had reasonably good results using a triply linked binary search tree for the database, with randomized search keys. (Beware: The swapping algorithm used for deletion was difficult to get right.) This implementation was, however, limited to exact cover problems whose matrix has at most 64 columns; hence it could do n queens via (23) only when n < 12. When n = 11 its database reached a maximum size of 75,009, and its running time was about 25 megamems. But Algorithm X was noticeably better: It needed only about 12.5 M μ to find all Q (11) = 2680 solutions.
In theory, this method will need only about 2 3 n steps as n → ∞, times a small polynomial function of n . A backtracking algorithm such as Algorithm X , which enumerates each solution explicitly, will probably run asymptotically slower (see exercise 7.2.2–15 ). But in practice, a breadth-first approach needs too much space.
On the other hand, this method did beat Algorithm X on the n queen bees problem of exercise 7.2.2–16 : When n = 11 its database grew to 364,864 entries; it computed H (11) = 596,483 in just 30 M μ , while Algorithm X needed 440 M μ .
42. The set of solutions for s j can be represented as a regular expression α j instead of by its size, c j . Instead of inserting ( s j + t, c j ) in step N3, insert α j k . If inserting ( s, α ), when ( s i , α i ) is already present with s i \= s , change α i ← α i ∪ α . [Alternatively, if only one solution is desired, we could attach a single solution to each s j in the database.]
43. Let i = ( i 1 i 0 ) 3 and j = ( j 1 j 0 ) 3 ; then cell ( i, j ) belongs to box ( i 1 j 1 ) 3 . Mathematically, it’s cleaner to consider the matrices a i j ′ \= a i j − 1 , b i j ′ \= b i j − 1 , c i j ′ \= c i j − 1 , which are the “ multiplication tables” of interesting binary operators on {0,...,8}. We have a i j ′ \= ( ( i 0 i 1 ) 3 + j ) mod 9; b i j ′ \= ( ( i 0 + j 1 ) mod 3, ( i 1 + j 0 ) mod 3) 3 ; and c i j ′ \= ( ( i 0 + i 1 + j 1 ) mod 3, ( i 0 − i 1 + j 0 ) mod 3) 3 . (Furthermore the latter two operators are “ isotopic”: c i j ′ \= b ( i π ) ( j π − ) ′ π , when ( i 1 , i 0 ) 3 π \= ( i 1 , ( i 0 + i 1 ) mod 3) 3 .)
[A pattern like (28c) appeared in a Paris newspaper of 1895, in connection with magic squares. But no properties of its 3×3 subsquares were mentioned; it was a sudoku solution purely by coincidence. See C. Boyer, Math. Intelligencer 29 , 2 (2007), 63.]
44. No. The 33rd digit is 0. [A sudoku whose clues are π ’s first 32 digits was first constructed by Johan de Ruiter in 2007; see [www.puzzlepicnic.com/puzzle?346](http://www.puzzlepicnic.com/puzzle?346) . Furthermore, π ’s first 22 digits can actually be arranged in a circle to give a uniquely solvable sudoku, if we also require the elements of both main diagonals to be distinct! See Aad Thoen and Aad van de Wetering, Exotische Sudoku’s (2016), 144.]
45. Step X3 chooses p 44 , p 84 , p 74 , p 24 , p 54 , p 14 , p 82 , p 42 , p 31 , p 32 , p 40 , p 45 , p 46 , p 50 , p 72 , p 60 , p 00 , p 62 , p 61 , p 65 , p 35 , p 67 , p 70 , p 71 , p 75 , p 83 , p 13 , p 03 , p 18 , p 16 , p 07 , p 01 , p 05 , p 15 , p 21 , p 25 , p 76 , p 36 , p 33 , p 37 , p 27 , p 28 , p 53 , p 56 , p 06 , p 08 , p 58 , p 77 , p 88 , in that order.
46. The lists for items p 44 , p 84 , r 33 , r 44 , r 48 , r 52 , r 59 , r 86 , r 88 , c 22 , c 43 , b 07 , b 32 , b 39 , b 43 , b 54 , and b 58 have length 1 when Algorithm X begins to tackle puzzle (29a). Step X3 will branch on whichever item was placed first in step X1. (The author’s sudoku setup program puts p before r before c before b in that step.)
47. r 13 , c 03 , b 03 , b 24 , b 49 , b 69 . The latter three were hidden already in (32).
48. In case (a) we list the available columns; in case (b) we list the available rows:
(Notice that “hidden” singles and pairs, etc., become “ naked” in this representation. Similar plots, which relate boxes to values, are also possible; but they’re trickier, because boxes aren’t orthogonal to rows or columns.)
49. (a) For columns, remove all items r ik and b xk , as well as c jk with j ≠ j 0 ; let u j — v k when an option contains ‘ p ij 0 c j 0 k ’. For boxes, remove all r ik , c jk , and b xk with x ≠ x 0 ; let u j — v k when an option contains ‘ p (3 ⌊ x 0 /3 ⌋ + ⌊ j /3⌋)(3( x mod 3)+( j mod 3)) b x 0 k ’.
(b) The n − q non -neighbors of a hidden q -tuple (e.g., { u 3 , u 8 , u 1 }) are “naked.”
(c) By (b) it suffices to list the naked ones (and only those for which q < r ). Let’s denote the option in (30) by ijk . In row 4 we find the naked pair { u 3 , u 8 }, hence we can delete options 411, 417, 421, 427, 471; also the naked triple { u 1 , u 3 , u 8 }, so we can also delete option 424. There’s no nakedness in the columns. The naked triple { u 0 , u 3 , u 6 } in box 4 allows deletion of options 341, 346, 347, 351, 356, 357.
(d) Let u i — v j if there’s an option that contains ‘ r ik 0 c jk 0 ’. When k 0 = 9 there’s a naked pair { u 1 , u 5 }, so we can delete options 079 and 279.
[Many other reductions have been proposed. For example, (33) has a “ pointing pair” in box 4: Since ‘4’ and ‘8’ must occupy that box in row 3, we can remove options 314, 324, 328, 364, 368, 378. Classic references are the early tutorials by W. Gould, The Times Su Doku Book 1 (2005); M. Mepham, Solving Sudoku (2005). A comprehensive theory, applicable also to many other problems, has been developed by D. Berthier, Pattern-Based Constraint Satisfaction and Logic Puzzles (2012).]
50. Such a puzzle must add a 7 or 8 in one of 18 places, because (29c) has just 2 solutions. So there are 36 of them (18 isomorphic pairs).
51. We can solve this problem with Algorithm M , using options (30) with k ≠ 8 and giving multiplicity 2 to each of the items r i 7 , c j 7 , b x 7 . There are six solutions, all of which extend the partial solution shown. Only one yields a sudoku square when we change half of the 7s to 8s.
52. (Solution by F. Stappers.) Puzzles claiming to be “the world’s hardest sudoku” keep appearing in online forums. Rated by search tree size with Algorithm X , the toughest among nearly 27,000 such extreme puzzles is shown here in a canonical form. (It’s number 6539 in a list available from [sites.google.com/site/sudoeleven/](http://sites.google.com/site/sudoeleven/) (2011).) Its randomized search tree sizes are 24400±1900 — astonishingly high for sudoku; and its mean running time is about 12 M μ .)
53. (a) Every shidoku solution is equivalent to one of the two special solutions A or B below (which incidentally have respectively 32 and 16 automorphisms, in the sense of exercise 114 ). We can’t uniquely specify either solution unless we have at least one clue in each of the regions { A , B , C , D } of C .
(b) Only 4 4 = 256 sets of four clues meet the conditions of (a), for each of A and B ; we can test them all. Reducing by the automorphisms leaves two for A and eleven for B :
(There also are 22 essentially different shidoku puzzles with five irredundant clues, and a unique puzzle with six. The latter, which is solved by A , is shown above at the bottom left; it cannot omit a clue without having an empty region in either C or C T . These results were discovered by Ed Russell in 2006.)
54. For example, removing clues one at a time shows that only 10 of the 32 givens are actually essential. The best strategy for finding all minimal X is probably to examine candidate sets in order of decreasing cardinality: Suppose W ⊆ X , and suppose that previous tests have shown that the solution is unique, given X , but not given X \ w for any w ∈ W . Thus X is minimal if W = X . Otherwise let X \ W = { x 1 ,..., x t }, and test X \ x i for each i . Suppose the solution turns out to be unique if and only if i > p . Then we schedule the t − p candidate pairs ( W ⋃ { x 1 ,..., x p }, X \ x i ), p < i ≤ t , for processing in the next round. With suitable caching of previous results, we can avoid testing the same subset of clues more than once. Furthermore we can readily modify Algorithm X so that it backtracks immediately after discovering a single unwanted solution.
All 777 minimal subsets were found in this manner, involving 15441 invocations of Algorithm X , but needing a total of only about 1.5 gigamems of computation. Altogether (1, 22, 200, 978, 2780, 4609, 4249, 1950, 373, 22) candidate pairs were examined in rounds (32, 31, ... , 23); and exactly (8, 154, 387, 206, 22) solutions were found of sizes (27, 26, 25, 24, 23). The lexicographically last 23-clue subset, which is illustrated below, turns out to be a fairly tough puzzle, with 220 nodes in its search tree.
(Let f ( x 1 ,..., x 32 ) be the monotone Boolean function ‘[the solution is unique, given the clues with x j \= 1]’. This problem essentially asks for f ’s prime implicants.)
55. If only one of those nine appearances has been specified, the other eight can always be permuted into another solution. And the entire diagram can be partitioned into nine disjoint sets of nine, all with the same property, thus requiring at least 2 · 9 clues.
This argument proves that all 18-clue characterizations must have a very special form. The interesting solution above makes a particularly satisfying puzzle. (The author found it with the help of a SAT solver; see Section 7.2.2.2 .)
The same argument shows that (28b) needs at least 18 clues. But this time the corresponding SAT instance is unsatisfiable. Moreover, any 19-clue solution must have three clues in just one critical group of nine; the associated SAT instance, which insists on having at least one clue in each of the 2043 subsets of at most 18 cells that can be rearranged into new solutions, also is unsatisfiable. (Proved in 177 M μ .) But hurrah, the special structure does lead to 20-clue examples, like the one above.
(The constructions for (28b) apply also to (28c), via the isotopism in answer 43 .)
56. (We assume that a decent sudoku problem has only one solution.) An example with 40 irredundant clues, shown here, was first discovered by Mladen Dobrichev in 2014, after examining a huge number of cases. (Incidentally, the solution to this problem has no automorphisms.) An example with 41 irredundant clues would be a big surprise.
57. There are only 2 · 3! · 3! · 3! · 3! = 2592 possibilities for each box. So we can set up an exact cover problem with 9 · 2592 options, each of which names a box, nine row-column pairs, three horizontal trios, and three vertical trios. We can assume by symmetry that there’s only one option for box 0, namely ‘ b 0 r 01 c 01 r 04 c 14 r 07 c 27 r 18 c 08 r 12 c 12 r 15 c 25 r 26 c 06 r 29 c 19 r 23 c 23 h 147 h 258 h 369 v 168 v 249 v 357 ’. Furthermore row 0 can be restricted to 1472AB3CD , where { A , C } = { 5 , 6 } and { B , D } = { 8 , 9 }. That reduces the number of options to 16417; and Algorithm X quickly ((58+54)M μ ) finds 864 solutions.
Such solutions were first discovered by A. Thoen and A. van de Wetering; see Thoen’s book Sudoku Patterns (2019), §2.7. All 864 are isomorphic under sudoku-solution-preserving permutations of rows and columns. One of the nicest is
58. Use the standard 729 sudoku options (30); but also include queen items ‘ a ( i + j ) k ′ b ( i + j ) k ′ ’ in option ( i, j, k ) when k ≤ 7. Furthermore, in order to avoid getting each solution 7! 2! = 10080 times, force row 0 by adding a new primary item ‘*’ and new secondary items ‘* j ’ for 0 ≤ j < 9, together with 20 options ‘* * 0 : f (0, p, q ) ... * 8 : f (8, p, q )’ for 0 ≤ p < q < 9, p + q < 9, where f ( j, p, q ) = ( j = p ? 8: j = q ? 9: 1 + j − [ j > p ] − [ j > q ]). Include ‘* j : k ’ in option (0, j, k ). There are only four solutions, found in 3 G μ , centrally symmetric and reducing under transposition to only two. (See Appendix E , and Thoen’s book Sudoku Patterns (2019), §3.4.)
59. When p s precede r s precede c s precede b s in X1, the tree sizes are 1105, 910, 122.
60. Using the options (30), items r ik and c jk should be secondary when row i or column j contains fewer than 6 cells. The puzzles are fun to solve by hand; but in a pinch, Algorithm X will traverse search trees of sizes 23, 26, and 16 to find the answers:
[These are the first of 26 elegant puzzles announced by Serhiy and Peter Grabarchuk on Martin Gardner’s 100th birthday (21 October 2014) and posted at [puzzlium.com](http://puzzlium.com) .]
61. Exactly 1315 of the ( 25 5 ) \= 53130 ways to retain five clues result in a unique solution, and 175 of them involve all five digits. The lexicographically first is Fig. A–2(a) .
62. Follow the hint; the undesired straight n -ominoes can be rejected easily in step R2 by examining v n −1 and v 0 . This quickly produces (16, 105, 561, 2804, 13602) box options, for n = (3, 4, 5, 6, 7), which can be fed to Algorithm X to get jigsaw patterns.
There are no patterns for n = 3. But n = 4 has 33 patterns, which divide into eight equivalence classes under rotation and/or reflection:
(The number of symmetries is shown below each arrangement; notice that 8/1 + 8/1 + 8/2 + 8/2 + 8/2 + 8/4 + 8/4 + 8/8 = 33.) Similarly, n = 5 has 266 equivalence classes, representing 256 · (8/1) + 7 · (8/2) + 3 · (8/4) = 2082 total patterns; n = 6 has 40237 classes, representing 39791 · (8/1) + 439 · (8/2) + 7 · (8/4) = 320098 patterns in all.
The computation gets more serious in the case n = 7, when Algorithm X needs about 1.9 T μ to generate the 132,418,528 jigsaw patterns. These patterns include 16,550,986 classes with no symmetry, and 2660 with one nontrivial symmetry. The latter break down into 2265 that are symmetric under 180 ° rotation, 354 that are symmetric under horizontal reflection, and 41 that are symmetric under diagonal reflection. Here are some typical symmetric examples:
(It’s not difficult to generate all of the symmetric solutions for slightly higher values of n ; three of the classes for n = 8, shown above, have more than 2 symmetries. And the case n = 9 contains two patterns with 8-fold symmetry besides the standard sudoku boxes: See Fig. A–2(b) and (c) , where the latter might be called windmill sudoku! For complete counts for n = 8 and n = 9, with straight n -ominoes allowed, see Bob Harris’s preprint “Counting nonomino tilings,” presented at G4G9 in 2010.)
Fig. A–2. Jigsaw sudoku patterns.
63. A simple modification of exercise 7.2.2–76 will generate the 3173 boxes that have the desired rainbow property. An exact cover problem, given those 3173 options, shows (after 1.2 G μ of computation) that the boxes can be packed in 98556 ways. If we restrict the options to the 3164 that aren’t sudoku boxes, the number of packings goes down to 42669, of which 24533 are faultfree. Figure A–2(d) is a faultfree example.
64. (a) When n = 4, one of the eight classes in answer 62 (the 2nd) has no solutions; another (the 5th) is clueless. When n = 5, eight of the 266 classes have no solution; six are clueless. When n = 6, 1966 of 40237 are vacuous and 28 are clueless.
(Maxime’s original puzzle appeared in the newsletter of Chicago Area Mensa [ ChiMe MM , 3 (March 2000), 15]. Algorithm X solves it with a 40-node search tree. But the tree size would have been 215 if he’d put ABCDEF in the next row down!)
(b) (Solution by Bob Harris, [www.bumblebeagle.org/dusumoh/proof/](http://www.bumblebeagle.org/dusumoh/proof/) , 2006.) The clueless jigsaw for n = 4 generalizes to all larger n , as illustrated here for n = 7: First a = 3 ; hence b = 3 ; ... ; hence f = 3 . Then g = 4 ; hence h = 4 ; ... ; hence l = 4 . And so on. Finally we know where to place the 2 ’s and the 1 ’s. (This proof shows that, for odd n > 3, there’s always an n × n jigsaw sudoku whose clues lie entirely on the main diagonal. Is there also a general construction that works for even values of n ? An 8 × 8 example appears in exercise 65 .)
65. (The author designed these puzzles with the aid of exercises 62 and 64 . Similar puzzles have been contrived by J. Henle, Math. Intelligencer 38 , 1 (2016), 76–77.)
66. (Puzzles like this might be too difficult for humans, but not for Algorithm C .) Extend the 729 options (30) by adding ‘ ij : k ’, where ij is a new secondary item for 0 ≤ i, j < 9. Also add eighteen new primary items k for 1 ≤ k ≤ 9 and s j for 0 ≤ j < 9, where k represents card k and s j represents a slot in the 3×3 array. Each item k has nine options, for the nine slots in which it might be placed; for example, the options for item 2 are ‘2 s 0 00:2 11:3 22:4 20:1’, ‘2 s 1 03:2 14:3 25:4 23:1’, ... , ‘2 s 8 66:2 77:3 88:4 86:1’.
There are 9! ways to place the cards in slots; but only 9!/(3! 3!) = 10080 are actually different, because the rows and columns can be permuted independently without changing the number of sudoku solutions. Suppose card c j goes into slot s j ; then we can assume without loss of generality that c 0 = 1 and that c 4 = min( c 4 , c 5 , c 7 , c 8 ). (To incorporate these constraints, give only one option for card 1 and only eight options for cards 2–9; use ordering tricks like (26) to ensure that c 4 < c 5 , c 4 < c 7 , c 4 < c 8 .)
With this understanding, puzzle (i) has only one solution, and only when c 0 ... c 8 = 192435768. (That solution has six automorphisms, in the sense of exercise 114 .) Puzzle (ii) has a unique solution when c 0 ... c 8 = 149523786. It also has ten sudoku solutions when the slot permutation is 149325687; so we can’t use that placement.
67. (a) (Solution by A. E. Brouwer, homepages.cwi.nl/~aeb/games/sudoku/nrc.html , 2006.) The four new boxes force also aaaaaaaaa , ... , eeeeeeeee to be rainbows.
(b) Introduce new primary items b y k ′ for 0 ≤ y < 9 and 1 ≤ k ≤ 9. Add b y k ′ to option (30) with y = 3⌊ iτ /3⌋ + ⌊ jτ /3⌋, where τ is the permutation (03)(12)(58)(67).
(c) With items b y k ′ only considered for y ∈ {0, 2, 6, 8}, Algorithm X ’s search tree grows from 77 nodes to 231 for (i), and from 151 nodes to 708 for (ii).
[Puzzle (ii) is a variant of an 11-clue example constructed by Brouwer. The minimum number of clues necessary for hypersudoku is unknown.]
(d) True. (That’s the permutation τ in (b), applied to both rows and columns.)
68. (a) A simple backtrack program generates all convex n -ominoes whose top cell(s) are in row 0 and whose leftmost cell(s) are in column 0. [This problem has respectively (1, 2, 6, 19, 59, 176, 502) solutions for 1 ≤ n ≤ 7; see M. Bousquet-Mélou and J.-M. Fédou, Discrete Math. 137 (1995), 53–75, for the generating function.] The resulting (1, 4, 22, 113, 523, 2196, 8438) placements into an n × n box yield exact cover problems as in answer 62 . Considering symmetries, we find 1 · (8/4) = 2 patterns when n = 2; 1·(8/1)+1·(8/4) = 10 patterns when n = 3; 10·(8/1)+7·(8/2)+4·(8/4)+1·(8/8) = 117 when n = 4; 355·(8/1)+15·(8/2)+4·(8/4) = 2908 when n = 5; 20154·(8/1)+342·(8/2)+ 8·(8/4) = 162616 when n = 6; 2272821·(8/1)+1181·(8/2)+5·(8/4) = 18187302 when n = 7. ( Exercise 62 had different results because it disallowed straight n -ominoes.)
(b) There are 325 such nonominoes touching row 0 and column 0, leading to 12097 placements and 1014148 · (8/1) + 119 · (8/2) + 24 · (8/4) + 1 · (8/8) = 8113709 patterns. If we exclude the 3 × 3 nonomino, and its 49 placements, the number of patterns goes down to 675797 · (8/1) = 5406376.
[Convex polyominoes were introduced by Klarner and Rivest; see answer 303 .]
69. Say that an “ N k ” is a suitable nonomino placement that has k B s and 9 − k L s. Only two cases give seven wins for B : 1 N 6 , 6 N 5 , 2 N 0 ; 7 N 5 , 1 N 1 , 1 N 0 . With the given voting pattern there are respectively (1467, 2362, 163, 2) options for N 6 , N 5 , N 1 , N 0 . Algorithm M provides the desired multiplicities. After 12 M μ of computation we find that there are no solutions in case 1 but 60 solutions in case 2, one of which is shown.
(Of course the author does not recommend secret deals such as this! The point is that unfair gerrymandering is easy to do and hard to detect. Indeed, a trial of 1000 random voter patterns, each with 5/4 split in the nine standard 3×3 districts, included 696 cases that could be gerrymandered to seven Big-Endian districts using only convex nonominoes that fit in a 5 × 5. Eight of those cases could also achieve a 4 × 4 fit.)
[Similar studies, using realistic data, go back to R. S. Garfinkel’s Ph.D. thesis Optimal Political Districting (Baltimore: Johns Hopkins University, 1968).]
70. In (a), four pieces change; in (b) the solution is unique:
Notice that the spot patterns
,
, and
are rotated when a domino is placed vertically; these visual clues, which would disambiguate (a), don’t show up in the matrix.
(Dominosa was invented by O. S. Adler [Reichs Patent #71539 (1893); see his booklet Sperr-Domino und Dominosa (1912), 23–64, written with F. Jahn]. Similar “ quadrille” problems had been studied earlier by E. Lucas and H. Delannoy. See Lucas’s Récréations Mathématiques 2 (1883), 52–63; W. E. Philpott, JRM 4 (1971), 229–243.
71. Define 28 vertices D xy for 0 ≤ x ≤ y ≤ 6; 28 vertices ij for 0 ≤ i < 7, 0 ≤ j < 8, and i + j even; and 28 similar vertices ij with i + j odd. The matching problem has 49 triples of the form {D xy, ij, i ( j +1)} for 0 ≤ i, j < 7, as well as 48 of the form {D xy, ij, ( i +1) j } for 0 ≤ i < 6 and 0 ≤ j < 8, corresponding to potential horizontal or vertical placements. For example, the triples for exercise 70(a) are {D06, 00, 01}, {D56, 01, 02}, ... , {D23, 66, 67}; {D01, 00, 10}, {D46, 01, 11}, ... , {D12, 57, 67}.
72. Model (i) has M = 56!/8! 7 ≈ 4.10 × 10 42 equally likely possibilities; model (ii) has N = 1292697 · 28! · 2 21 ≈ 8.27 × 10 41 , because there are 1292697 ways to pack 28 dominoes in a 7 × 8 frame. ( Algorithm X will quickly list them all.) The expected number of solutions per trial in model (i) is therefore N/M ≈ 0.201.
Ten thousand random trials with model (i) gave 216 cases with at least one solution, including 26 where the solution was unique. The total number ∑ x of solutions was 2256; and ∑ x 2 = 95918 indicated a heavy-tailed distribution whose empirical standard deviation is ≈ 3.1. The total running time was about 250 M μ .
Ten thousand random trials with model (ii), using random choices from a precomputed list of 1292697 packings, gave 106 cases with a unique solution; one case had 2652 of them! Here ∑ x = 508506 and ∑ x 2 = 144119964 indicated an empirical mean of ≈ 51 solutions per trial, with standard deviation ≈ 109. Total time was about 650 M μ .
73. From 06151146/66611014/56132144/55326224/53632022/34300525/33040054 we get 807,752 solutions, which is the current record. This array, found in 2023 by Germán González-Morris based on previous work by Michael Keller, has the surprising property that every candidate placement occurs in at least 35,082 solutions!
74. One way to obtain candidate arrays is to formulate an MCC problem: Given one of the 1292697 matchings of answer 72 , let there be options ‘ P uv xy t u : x t v : y ’, ‘ P uv xy t u : y t v : x ’ for uv in the matching, and ‘ Q uv D xy t u : x t v : y ’, ‘ Q uv D xy t u : y t v : x ’ for uv not in the matching; here 0 ≤ x ≤ y ≤ 6, and duplicate options are omitted when x = y . Give each D xy multiplicity 3. Also add 28 further options ‘# D xy ’, where # has multiplicity 15 (because 15 pairs xy should have only two spurious appearances).
For fun, the author chose a tatami tiling for the matching (see exercise 7.1.4– 215), and obtained one candidate every 70 M μ or so when the nonsharp variant of Algorithm M was applied with randomization as in exercise 31 . Surprisingly, the first 10000 candidates yielded 2731 solutions, of which the hardest (with a 572-node search tree) was 15133034/21446115/22056105/65460423/22465553/61102332/63600044.
[See [www.solitairelaboratory.com/puzzlelaboratory/DominoGG.html](http://www.solitairelaboratory.com/puzzlelaboratory/DominoGG.html) .]
75. (a) ( x ○ y ) ○ x = ( x ○ y ) ○ ( y ○ ( x ○ y )) = y .
(b) All five are legitimate. (The last two are gropes because f ( t + f ( t )) = t for 0 ≤ t < 4 in each case; they are isomorphic if we interchange any two elements. The third is isomorphic to the second if we interchange 1 ↔ 2. There are 18 grope tables of order 4, of which (4, 12, 2) are isomorphic to the first, third, and last tables shown here.)
(c) For example, let x ○ y = (− x − y ) mod n . (More generally, if G is any group and if α ∈ G satisfies α 2 = 1, we can let x ○ y = αx − αy − α . If G is commutative and α ∈ G is arbitrary, we can let x ○ y = x − y − α .)
(d) For each option of type (i) in an exact covering, define x ○ x = x ; for each of type (ii), define x ○ x = y , x ○ y = y ○ x = x ; for each of type (iii), define x ○ y = z , y ○ z = x , z ○ x = y . Conversely, every grope table yields an exact covering in this way.
(e) Such a grope covers n 2 items with k options of size 1, all other options of size 3. [F. E. Bennett proved, in Discrete Mathematics 24 (1978), 139–146, that such gropes exist for all k with 0 ≤ k ≤ n and k ≡ n 2 (modulo 3), except when k = n = 6.]
Notes: The identity x ○( y ○ x ) = y seems to have first been considered by E. Schröder in Math. Annalen 10 (1876), 289–317 [see ‘( C 0 )’ on page 306], but he didn’t do much with it. In a class for sophomore mathematics majors at Caltech in 1968, the author defined gropes and asked the students to discover and prove as many theorems about them as they could, by analogy with the theory of groups. The idea was to “grope for results.” The official modern term for a grope is a real jawbreaker: semisymmetric quasigroup . “Gropes” of a completely different kind were introduced into the theory of topological manifolds by J. W. Cannon, Bull. Amer. Math. Soc . 84 (1978), 832–866.
76. (a) Eliminate the n items for xx ; use only the 2 ( n 3 ) options of type (iii) for which y ≠ z . (Idempotent gropes are equivalent to “ Mendelsohn triples,” which are families of n ( n − 1)/3 three-cycles ( xyz ) that include every ordered pair of distinct elements. N. S. Mendelsohn proved [ Computers in Number Theory (New York: Academic Press, 1971), 323–338] that such systems exist for all n ≢ 2 (modulo 3), except when n = 6.)
(b) Use only the ( n + 1 2 ) items xy for 0 ≤ x ≤ y < n ; replace options of type (ii) by ‘ xx xy ’ and ‘ xy yy ’ for 0 ≤ x < y < n ; replace those of type (iii) by ‘ xy xz yz ’ for 0 ≤ x < y < z < n . (Such systems, Schröder’s ‘( C 1 ) and ( C 2 )’, are called totally symmetric quasigroups; see S. K. Stein, Trans. Amer. Math. Soc. 85 (1957), 228– 256, §8. If idempotent, they’re equivalent to Steiner triple systems.)
(c) Omit items for which x = 0 or y = 0. Use only the 2 ( n − 1 3 ) options of type (iii) for 1 ≤ x < y, z < n and y ≠ z . (Indeed, such systems are equivalent to idempotent gropes on the elements {1,..., n − 1}.)
77. Use primary items v and v ′ for each vertex of G and H ; also secondary items ee ′ for each pair of edges e and e ′ in G and the complement of H . There are n 2 options, namely ‘ v v ′ ∪ e ( v ), e ′( v ′) e ( v ), e ′( v ′)’, where e ( v ) ranges over all edges v — u in G and e ′ ( v ′) ranges over all nonedges v ′ ⌿ u ′ in H . (The solutions to this problem are the one-to-one matchings v ↔ v ′ of the vertices such that u — v implies u ′ — v ′.)
78. For example, CATALANDAUBOREL , GRAMARKOFFKNOPP , ABELWEIERSTRASS , BERTRAND-HERMITE , CANTORFROBENIUS , GLAISHERHURWITZ , HADAMARDHILBERT , HENSELKIRCHHOFF , JENSENSYLVESTER , MELLINSTIELTJES , NETTORUNGESTERN , MINKOWSKIPERRON .
79. In an n × n array for word search, every k -letter word generates ( n + 1 − k ) · n · 4 horizontal/vertical options and ( n + 1 − k ) 2 · 4 diagonal options. So the desired answer is (2, 5, 6, 5, 3, 5, 0, 1) · (1296, 1144, 1000, 864, 736, 616, 504, 400) = 24320.
80. Item q is selected at level 0, trying option x 0 = 8, ‘ q x y : A p ’. We cover q , then cover x , then purify y to color A , and cover p ; but at level 1 we find that item r ’s list is empty. So we backtrack: Uncover p , unpurify y , uncover x — and try option x 0 = 20, ‘ q x : A ’, hence purifying x to color A . This time at level 1 we try x 1 = 12, ‘ p r x : A y ’. That causes us to cover p , then cover r , and then (since x is already purified) to cover y . At level 2 we discover that we’ve found a solution! Here’s what’s in memory:
i : | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
| — |
|
|
|
|
| — |
| 0 | 0 | 1 | 0 | 6 | 4 | 4 |
| 0 | 3 | 3 | 0 | 6 | 6 | 4 |
x : | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
| — | 1 | 2 | 1 | 2 | 0 | 0 |
— | 12 | 20 | 23 | 18 | 5 | — | |
— | 12 | 8 | 23 | 14 | 5 | 10 | |
| — | — | — | — | — | — | 0 |
x : | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 1 | 2 | 4 | 5 | −1 | 1 | 3 |
| 1 | 2 | 4 | 5 | 7 | 1 | 3 |
| 12 | 20 | 14 | 15 | 15 | 1 | 23 |
| 0 | 0 | 0 |
| 0 | 0 | 0 |
x : | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 4 | 5 −2 | 1 | 4 | −3 | 2 | |
| 4 | 5 | 12 | 12 | 14 | 17 | 8 |
| 18 | 24 | 18 | 1 | 4 | 21 | 2 |
| −1 | 0 | 0 | 0 |
| 0 | 0 |
x : | 21 | 22 | 23 | 24 | 25 |
|
|
| 4 | −4 | 3 | 5 | −5 |
|
|
| 18 | 20 | 3 | 5 | 23 |
|
|
| 4 | 24 | 3 | 5 | — |
|
|
|
| 0 | 0 |
| 0 |
|
|
81. Almost true, if TOP and COLOR are stored in the same octabyte (so that only one is charged to read both). The only difference is when processing the input, because Algorithm X has no COLOR fields to initialize but Algorithm C zeroes them out.
82. True; the LEN field of secondary items doesn’t affect the computation.
83. Before setting i ← TOP ( x 0 ) in step C6 when l = 0, let node x be the spacer at the right of x 0 ’s option, and set j ← TOP ( x − 1). If j > N 1 (that is, if x 0 ’s option ends with the secondary item j ), and if COLOR ( x − 1) = 0, cover( j ).
84. Let CUTOFF (initially ∞) point to the spacer at the end of the best solution found so far. We’ll essentially remove all nodes > CUTOFF from further consideration.
Whenever a solution is found, let node PP be the spacer at the end of the option for which x k \= max( x 0 ,..., x l −1 ). If PP ≠ CUTOFF , set CUTOFF ← PP , and for 0 ≤ k < l remove all nodes > CUTOFF from the list for TOP ( x k ). (It’s easy to do this because the list is sorted.) Minimax solutions follow the last change to CUTOFF .
Begin the subroutine ‘uncover′ ( i )’ by removing all nodes > CUTOFF from item i ’s list. After setting d ← DLINK ( q ) in unhide′ ( p ), set DLINK ( q ) ← d ← x if d > CUTOFF . Make the same modifications also to the subroutine ‘unpurify( p )’.
Subtle point: Suppose we’re uncovering item i and encounter an option ‘ i j ... ’ that should be restored to the list of item j ; and suppose that the original successor ‘ j a ... ’ of that option for item j lies below the cutoff. We know that ‘ j a ... ’ contains at least one primary item, and that every primary item was covered before we changed the cutoff. Hence ‘ j a ... ’ was not restored, and we needn’t worry about removing it. We merely need to correct the DLINK , as stated above.
85. Now let CUTOFF be the spacer just before the best solution known. When resetting CUTOFF , backtrack to level k − 1, where x k maximizes { x 0 ,..., x l −1 }.
86. The steps below also estimate the profile of the search tree. Running time is estimated in terms of “ updates” and “ cleansings.” The user specifies a random seed and a desired number of trials; the final estimates are the averages of the (unbiased) estimates from each trial. Here we specify only how to make a single trial.
In step C1, also set D ← 1.
In step C2, estimate that the search tree has D nodes at level l . If RLINK (0) = 0, also estimate that there are D solutions.
In step C3, let θ be the number of options in the list of the chosen item i . If θ = 0, estimate that there are 0 solutions, and go to C7.
At the end of step C4, let k be uniformly random in [0.. θ − 1]; then set x l ← DLINK ( x l ), k times.
Just before setting l ← l + 1 at the end of step C5, suppose you’ve just done U updates and C cleansings. (An “update” occurs when ‘cover’ sets LLINK ( r ) or ‘hide’ sets ULINK ( d ). A “cleansing” occurs when ‘commit’ calls ‘purify’ or ‘purify’ sets COLOR ( q ) ← −1.) Estimate that level l does D ( U ′ + θ · U ) updates and DC cleansings, where U ′ is the number of updates just done in step C4. Then set D ← θ · D .
Step C6 now should do absolutely nothing. Steps C7 and C8 don’t change.
Upon termination, all data structures will have been returned to their original state, ready for another random trial. These steps will have estimated the number of nodes, updates, and cleansings at each level. Sum those estimates to get the total estimated number of nodes, updates, and cleansings.
87. Use 2 n primary items a i , d j for the “across” and “down” words, together with n 2 secondary items ij for the individual cells. Also use W secondary items w , one for each legal word. The XCC problem has 2 Wn options, namely ‘ a i i 1: c 1 ... in : c n c 1 ... c n ’ and ‘ d j 1 j : c 1 ... nj : c n c 1 ... c n ’ for 1 ≤ i, j ≤ n and each legal word c 1 ... c n . (See (110).)
We can avoid having both a solution and its transpose by introducing W further secondary items w @ and appending c 1 ... c n @ at the right of each option for a 1 and d 1 . Then exercise 83 ’s variant of Algorithm C will never choose a word for d 1 that it has already tried for a 1 . (Think about it.)
But this construction is not a win for “dancing links,” because it causes massive amounts of data to go in and out of the active structure. For example, with the five-letter words of WORDS (5757), it correctly finds all 323,264 of the double word squares, but its running time is 15 tera mems! Much faster is to use the algorithm of exercise 7.2.2–28, which needs only 46 gigamems to discover all of the 1,787,056 unrestricted word squares; the double word squares are easily identified among those solutions.
88. One could do a binary search, trying varying values of W . But the best way is to use the construction of exercise 87 together with the minimax variant of Algorithm C in exercise 84 . This works perfectly, when the options for most common words come first.
Indeed, this method finds the double square ‘ BLAST|EARTH|ANGER|SCOPE|TENSE ’ and proves it best in just 64 G μ , almost as fast as the specialized method of exercise 7.2.2–28 . (That square contains ARGON , the 1720th most common five-letter word, in its third column; the next-best squares use PEERS , which has rank 1800.)
89. The “minimax” method of exercise 88 finds the first five squares of
I S T O M A Y A G E N O T S H O W N O N E O P E N W E S T S T A R T T H R E E R O O F S A S S E T P E E R S C H E S T S L U S T R E O B T A I N A R E N A S C I R C L E A S S E S S H E R T Z E S O P E R A T E M I M I C A L A C E R A T E G E N E T I C E N D M O S T R E S E N T S
in respectively 200 K μ , 15 M μ , 450 M μ , 25 G μ , 25.6 T μ . It struggles to find the best 6 × 6, because too few words are cut off from the search; and it thrashes miserably with the 24 thousand 7-letter words, because those words yield only seven extremely esoteric solutions. For those lengths it’s best to cull the 2038753 and 14513 unrestricted word squares, which the method of exercise 7.2.2–28 finds in respectively 4.6 T μ and 8.7 T μ .
90. An XCC problem works nicely, as in answer 88 : There are 2 p primary items a i and d i for the final words, and pn + W secondary items ij and w for the cells and potential words, where 0 ≤ i < p and 1 ≤ j ≤ n . The Wp options going across are ‘ a i i 1: c 1 i 2: c 2 ... in : c n c 1 ... c n ’. The Wp options going down are ‘ d i i 1: c 1 (( i +1) mod p )2: c 2 ... (( i + n −1) mod p ) n : c n c 1 ... c n ’ for left-leaning stairs; ‘ d i i 1: c n (( i +1) mod p )2: c n −1 ... (( i + n −1) mod p ) n : c 1 c 1 ... c n ’ for right-leaning stairs. The modification to Algorithm C in exercise 83 saves a factor of 2 p ; and the minimax modification in exercise 84 hones in quickly on optimum solutions.
There are no left word stairs for p = 1, since we need two distinct words. The left winners for 2 ≤ p ≤ 10 are: ‘ WRITE|WHOLE ’; ‘ MAKES|LIVED|WAXES ’; ‘ THERE|SHARE| WHOLE|WHOSE ’;‘ STOOD|THANK|SHARE|SHIPS|STORE ’;‘ WHERE|SHEEP|SMALL|STILL|WHOLE| SHARE ’;‘ MAKES|BASED|TIRED|WORKS|LANDS|LIVES|GIVES ’;‘ WATER|MAKES|LOVED|GIVEN| LAKES|BASED|NOTES|TONES ’; ‘ WHERE|SHEET|STILL|SHALL|WHITE|SHAPE|STARS|WHOLE| SHORE ’; ‘ THERE|SHOES|SHIRT|STONE|SHOOK|START|WHILE|SHELL|STEEL|SHARP ’. They all belong to WORDS (500), except that p = 8 needs WORDS (504) for NOTED .
The right winners have a bit more variety: ‘ SPOTS ’; ‘ STALL|SPIES ’; ‘ STOOD|HOLES| LEAPS ’; ‘ MIXED|TEARS|SLEPT|SALAD ’; ‘ YEARS|STEAM|SALES|MARKS|DRIED ’; ‘ STEPS| SEALS|DRAWS|KNOTS|TRAPS|DROPS ’; ‘ TRIED|FEARS|SLIPS|SEAMS|DRAWS|ERECT|TEARS ’; ‘ YEARS|STOPS|HOOKS|FRIED|TEARS|SLANT|SWORD|SWEEP ’; ‘ START|SPEAR|SALES|TESTS| STEER|SPEAK|SKIES|SLEPT|SPORT ’; ‘ YEARS|STOCK|HORNS|FUELS|BEETS|SPEED|TEARS| PLANT|SWORD|SWEEP ’. They belong to WORDS (1300) except when p is 2 or 3.
[Arrangements equivalent to left word stairs were introduced in America under the name “ Flower Power” by Will Shortz in Classic Crossword Puzzles (Penny Press, February 1976), based on Italian puzzles called “ Incroci Concentrici” in La Settimana Enigmistica . Shortly thereafter, in GAMES magazine and with p = 16, he called them “ Petal Pushers,” usually based on six-letter words but occasionally going to seven. Left word stairs are much more common than the right-leaning variety, because the latter mix end-of-word with beginning-of-word letter statistics.]
91. Consider all “ kernels” c 1 ...c 14 that can appear as illustrated, within a right word stair of 5-letter words. Such kernels arise for a given set of words only if there are letters x 1 ...x 12 such that x 3 x 4 x 5 c 2 c 3 , c 4 c 5 c 6 c 7 c 8 , c 9 c 10 c 11 c 12 x 6 , c 13 c 14 x 7 x 8 x 9 , x 1 x 2 x 5 c 5 c 9 , c 1 c 2 c 6 c 10 c 13 , c 3 c 7 c 11 c 14 x 10 , and c 8 c 12 x 7 x 11 x 12 are all in the set. Thus it’s an easy matter to set up an XCC problem that will find the multiset of kernels, after which we can extract the set of distinct kernels.
x 1 x 2 c 1 x 3 x 4 x 5 c 2 c 3 c 4 c 5 c 6 c 7 c 8 c 9 c 10 c 11 c 12 x 6 c 13 c 14 x 7 x 8 x 9 x 10 x 11 x 12
Construct the digraph whose arcs are the kernels, and whose vertices are the 9-tuples that arise when kernel c 1 ...c 14 is regarded as the transition
c 1 c 2 c 3 c 4 c 5 c 6 c 7 c 9 c 10 → c 3 c 7 c 8 c 9 c 10 c 11 c 12 c 13 c 14 .
This transition contributes two words, c 4 c 5 c 6 c 7 c 8 and c 1 c 2 c 6 c 10 c 13 , to the word stair. Indeed, right word stairs of period p are precisely the p-cycles in this digraph for which the 2 p contributed words are distinct.
Now we can solve the problem, if the graph isn’t too big. For example, WORDS (1000) leads to a digraph with 180524 arcs and 96677 vertices. We’re interested only in the oriented cycles of this (very sparse) digraph; so we can reduce it drastically by looking only at the largest induced subgraph for which each vertex has positive in-degree and positive out-degree. (See exercise 7.1.4–234, where a similar reduction was made.) And wow: That subgraph has only 30 vertices and 34 arcs! So it is totally understandable, and we deduce quickly that the longest right word stair belonging to WORDS (1000) has p = 5. That word stair, which we found directly in answer 90 , corresponds to the cycle
SEDYEARST → DRSSTEASA → SAMSALEMA → MESMARKDR → SKSDRIEYE → SEDYEARST.
A similar approach applies to left word stairs, but the kernel configurations are reflected left-to-right; transitions then contribute the words c 8 c 7 c 6 c 5 c 4 and c 1 c 2 c 6 c 10 c 13 . The digraph from WORDS (500) turns out to have 136771 arcs and 74568 vertices; but this time 6280 vertices and 13677 arcs remain after reduction. Decomposition into strong components makes the task simpler, because every cycle belongs to a strong component. Still, we’re stuck with a giant component that has 6150 vertices and 12050 arcs.
The solution is to reduce the current subgraph repeatedly as follows: Find a vertex v of out-degree 1. Backtrack to discover a simple path, from v , that contributes only distinct words. If there is no such path (and there usually isn’t, and the search usually terminates quickly), remove v from the graph and reduce it again.
With this method one can rapidly show that an optimum left word stair from WORDS (500) has period length 36: ‘ SHARE|SPENT|SPEED|WHEAT|THANK|CHILD|SHELL| SHORE|STORE|STOOD|CHART|GLORY|FLOWS|CLASS|NOISE|GAMES|TIMES|MOVES|BONES| WAVES|GASES|FIXED|TIRED|FEELS|WALLS|WORLD|ROOMS|WORDS|DOORS|PARTY|WANTS| WHICH|WHERE|SHOES|STILL|STATE ’, with 36 other words that go down. Incidentally, GLORY and FLOWS have ranks 496 and 498, so they just barely made it into WORDS (500).
Larger values of W are likely to lead to quite long cycles from WORDS ( W ). Their discovery won’t be easy, but the search will no doubt be instructive.
92. Use 3 p primary items a i , b i , d i for the final words; pn +2 W secondary items ij , w , w @ for the cells and potential words, with 0 ≤ i < p and 1 ≤ j ≤ n (somewhat as in answer 90 ). The Wp options going across are ‘ a i i 1: c 1 i 2: c 2 ... in : c n c 1 ...c n c 1 ...c n @’. The 2 Wp options going down in each way are ‘ b i i 1: c 1 (( i +1) mod p )2: c 2 ... (( i + n −1) mod p ) n : c n c 1 ...c n ’ and ‘ d i i 1: c n (( i +1) mod p )2: c n − 1 ... (( i + n −1) mod p ) n : c 1 c 1 ...c n ’. The items w @ at the right of the a i options save us a factor of p .
Use Algorithm C (modified). We can’t have p = 1. Then comes ‘ SPEND|SPIES ’; ‘ WAVES |LINED |LEPER ’; ‘ LOOPS |POUTS |TROTS |TOONS ’; ‘ SPOOL |STROP |STAID |SNORT | SNOOT ’;‘ DIMES|MULES|RIPER|SIRED|AIDED|FINED ’;‘ MILES|LINTS|CARES|LAMED|PIPED| SANER|LIVER ’;‘ SUPER|ROVED|TILED|LICIT|CODED|ROPED|TIMED|DOMED ’;‘ FORTH|LURES| MIRES|POLLS|SLATS|SPOTS|SOAPS|PLOTS|LOOTS ’; ‘ TIMES|FUROR|RUNES|MIMED|CAPED| PACED|LAVER|FINES|LIMED|MIRES ’. (Lengthy computations were needed for p ≥ 8.)
93. Now p ≤ 2 is impossible. A construction like the previous one allows us again to save a factor of p . (There’s also top/bottom symmetry, but it is somewhat harder to exploit.) Examples are relatively easy to find, and the winners are ‘ MILES|GALLS| BULLS ’; ‘ FIRES|PONDS|WALKS|LOCKS ’; ‘ LIVES|FIRED|DIKES|WAVED|TIRES ’; ‘ BIRDS| MARKS|POLES|WAVES|WINES|FONTS ’; ‘ LIKED|WARES|MINES|WINDS|MALES|LOVES|FIVES ’; ‘ WAXES|SITES|MINED|BOXES|CAVES|TALES|WIRED|MALES ’; ‘ CENTS|HOLDS|BOILS|BALLS| MALES|WINES|FINDS|LORDS|CARES ’; ‘ LOOKS|ROADS|BEATS|BEADS|HOLDS|COOLS|FOLKS| WINES|GASES|BOLTS ’. [Such patterns were introduced by Harry Mathews in 1975, who gave the four-letter example ‘ TINE|SALE|MALE|VINE ’. See H. Mathews and A. Brotchie, Oulipo Compendium (London: Atlas, 1998), 180–181.]
94. Set up an XCC problem with primary items k , p k , and secondary items x k , for 0 ≤ k < 16, and with options ‘ j p k x k : a x ( k +1) mod 16 : b x ( k +3) mod 16 : c x ( k+4) mod 16 : d ’ for 0 ≤ j, k < 16, where j = ( abcd ) 2 . The solution (0000011010111011) is essentially unique (except for cyclic permutation, reflection, and complementation). [See C. Flye Sainte-Marie, L’ Intermédiaire des Mathématiciens 3 (1896), 155–161.]
95. Use 2 m primary items a k , b k , and m secondary items x k , for 0 ≤ k < m . Define m 2 options of size 2 + n , namely ‘ a j b k x j : t 1 x ( j +1) mod m : t 2 ... x ( j + n −1) mod m : t n ’, where t 1 t 2 ... t n is the k th binary vector of interest. However, save a factor of m by omitting the options with j = 0 and k > 0, and the options with j > 0 and k = 0.
The case (7, 0, 3) has 137216 solutions, found in 8.5 gigamems; the case (7, 3, 4) has 41280 solutions, found in 3.2 gigamems. (We can make the items b k secondary instead of primary. This makes the search tree a bit larger. But it actually saves a little time, because the MRV heuristic causes branching on a j and maintains a good focus; less time is spent computing that heuristic when b k isn’t primary. Alternatively we could make the items a k secondary (or even omit them entirely, which would have the same effect). But that would be a disaster! For example, the running time for case (7, 0, 3) would then increase to nearly 50 tera mems, because focus is lost.)
Section 7.2.1 discusses other “ universal cycles,” which can be handled similarly.
96. In fact, there are 80 solutions for which the bottom four rows are the complements of the top four. (This problem extends the idea of “ ourotoruses” in exercise 7.2.1.1–109. One can also consider windows that aren’t rectangles. For example, the thirty-two ways to fill a cross of five cells can be identified with 32 positions of the generalized torus whose offsets are (4, ±4); see exercise 7 – 137 .)
00000110
00010111
11001010
10001110
11111001
11101000
00110101
01110001
97. Use primary items jk , p jk , and secondary items d j,k , for 0 ≤ j < 3 and 0 ≤ k < 9, with the following three options for each 0 ≤ i, j < 3 and 0 ≤ k, k′ < 9: ‘ jk p j′ k′ d j′, k′ : i d j′, k′+1 : ( i + a ) d j ′, k ′ :( i + b ) d j′ +1 ,k′ +1 :( i + c )’, for 0 ≤ j′ ≤ 1, and ‘ jk p 2 k ′ d 2, k′ : i d 2 ,k′ +1 :( i + a ) d 0, k′ −3 :( i + b −1) d 0, k ′ −2 :( i + c −1)’, where 9 j + k = ( abc ) 3 ; sums involving i are mod 3, while sums involving k′ are mod 9. We can assume that 00 is paired with p 00 . Then there are 2 · 2898 = 5796 solutions D ; all have D ≠ D T .
98. Given a 3SAT problem with clauses ( l i 1 ∨ l i 2 ∨ l i 3 ) for 1 ≤ i ≤ m , with each l i j ∈ { x 1 , x ¯ 1 , . . . , x n , x ¯ n } , construct an XCC problem with 3 m primary items ij (1 ≤ i ≤ m , 1 ≤ j ≤ 3) and n secondary items x k (1 ≤ k ≤ n ), having the following 6 m options: (i) ‘ i 1 i 2 ’, ‘ i 2 i 3 ’, ‘ i 3 i 1 ’; (ii) ‘ ij x k : 1 ’ if l ij \= x k , ‘ ij x k : 0 ’ if l i j \= x ¯ k . That problem has a solution if and only if the given clauses are satisfiable.
99. True — but perhaps with many more secondary items and much longer options: Let x be a secondary item to which a color has been assigned, in some XCC problem A ; and let O be the options in which x appears. Replace A by a new problem A′ , by deleting item x and adding new secondary items x { o,p } for each o, p ∈ O for which x gets different colors in A . And for each o ∈ O , replace item x in o by the set of all x { o,p } that apply. If A′ still involves colors, replace it by A′ in a similar way, until all colors disappear.
100. (a) There are five solutions: 00112, 00122, 01112, 01122, 11111.
(b) Let there be five primary items, {#1, #2, #3, #4, #5}, and five secondary items, { x 1 ,x 2 ,x 3 ,x 4 ,x 5 }. Item #1 enforces the binary constraint x 1 ≤ x 2 , and has the options ‘#1 x 1 :0 x 2 :0’; ‘#1 x 1 :0 x 2 :1’; ‘#1 x 1 :0 x 2 :2’; ‘#1 x 1 :1 x 2 :1’; ‘#1 x 1 :1 x 2 :2’; ‘#1 x 1 :2 x 2 :2’. Similar options for #2, #3, and #4 will enforce the constraints x 2 ≤ x 3 , x 3 ≤ x 4 , and x 4 ≤ x 5 . Finally, the options ‘#5 x 1 :0 x 3 :1 x 5 :2’; ‘#5 x 1 :0 x 3 :2 x 5 :1’; ‘#5 x 1 :1 x 3 :0 x 5 :2’; ‘#5 x 1 :1 x 3 :1 x 5 :1’; ‘#5 x 1 :1 x 3 :2 x 5 :0’; ‘#5 x 1 :2 x 3 :0 x 5 :1’; ‘#5 x 1 :2 x 3 :1 x 5 :0’ will enforce the ternary constraint x 1 + x 3 + x 5 = 3.
(c) Use primary items # j for 1 ≤ j ≤ m , one for each constraint, and secondary items x k for 1 ≤ k ≤ n , one for each variable. If constraint C j involves the d variables x i 1 , ... , x i d , include options ‘# j x i 1 : a 1 ... x i d : a d ’ for each legal d -tuple ( a 1 , . . . ,a d ).
(Of course this construction isn’t efficient for all instances of CSP; furthermore, we can often find substantially better ways to encode a particular CSP as an XCC instance, because this method uses only one primary item in each option. But the idea that underlies this construction is a useful mental tool when formulating particular problems.)
101. Notice that the final sentence implies two further clues:
-
Somebody trains a zebra.
-
Somebody prefers to drink just plain water.
Let there be primary items # k for 1 ≤ k ≤ 16, one for each clue. And let the 5 · 5 secondary items N j , J j , P j , D j , C j represent the nationality, job, pet, drink, and color associated with house j , for 0 ≤ j < 5. There are respectively (5, 5, 5, 5, 1, 5, 1, 5, 4, 5, 8, 5, 8, 8, 5, 5) options for clues (1, ... , 16), typified by ‘#1 N j :England C j :red’, for 0 ≤ j < 5; ‘#5 N 0 :Norway’; ‘#9 C i :white C i +1 :green’, for 0 ≤ i < 4; ‘#14 J i :nurse P i +1 :fox’, ‘#14 P i :fox J i +1 :nurse’, for 0 ≤ i < 4; ‘#15 P j :zebra’, for 0 ≤ j < 5.
A more complex formulation enforces the redundant “ all-different” constraint by introducing 5 · 5 additional secondary items to represent the inverses of N j , J j , P j , D j , C j . For example, the options for #1 then become ‘#1 N j :England N England − : j C j :red C red − : j ’. (With those additional items, Algorithm C will infer C 1 :blue immediately from #5 and #11; but without them, #5 doesn’t immediately make N 1 :Norway illegal. They reduce the search tree size from 112 to 32 nodes. However, the time they save during the search just barely compensates for the extra time that they consume in step C1.)
The inverses alone are not sufficient; they don’t forbid, say, N England − \= N Japan − .
[The author of this now-famous puzzle is unknown. Its first known publication, in Life International 35 (17 December 1962), 95, used cigarettes instead of occupations.]
102. As in answer 7.2.2–68 , let’s find all stable extensions of a given partially labeled digraph. And let’s allow sinks too; we can assume that every vertex with out-degree d ≤ 1 is labeled d . The following XCC formulation is based on ideas of R. Bittencourt.
Let Δ be the maximum out-degree. Introduce primary items H v , I v , E vd , and secondary items v , h vd , i vd , for 0 ≤ d ≤ Δ and all vertices v . The color of v will be λ ( v ), the label of v ; the color of h vd will denote the Boolean quantity ‘[ v sees d ]’, meaning that λ ( w ) = d for some w with v → w ; and the color of i vd will denote ‘[ λ ( v ) = d ]’. The options for H v are ‘ H v v : d ∪ k \= 0 Δ { h v k : e k } ’ where e 0 + ··· + e Δ = d . The options for I v are I v u:d ∪ k \= 0 Δ { i v k : [ k \= d ] } ∪ u → v { h u d : 1 } ’. And the options for E vd are ‘ E vd h vd :1 i w k d :1 ∪ j \= 1 k − 1 { i w j d : 0 } ’ for 1 ≤ k ≤ d + ( v ) and ‘ E v d h v d : 0 ∪ j \= 1 d + ( v ) { i w j d : 0 } ’ , when v → w 1 , ... , v → w d +( v ). For example, if the vertices of the puzzle in exercise 7.2.2–68 are named 00, ... , 99, some of the options of its unique solution are ‘ H 00 00:3 h 000 :0 h 001 :0 h 002 :0 h 003 :0 h 004 :1 h 005 :0 h 006 :0 h 007 :1 h 008 :0 h 009 :1’; ‘ I 00 00:3 i 000 :0 ... i 002 :0 i 003 :1 i 004 :0 ... i 009 :0 h 013 :1 h 033 :1 h 053 :1 h 703 :1 h 803 :1’; ‘ E 004 h 004 :1 i 104 :0 ... i 404 :0 i 504 :1’.
Of course many of those options can be greatly simplified, because many of the quantities are known from the given labels. We know the color of i vd when λ ( v ) is given; we know the color of h vd when v sees d in the given puzzle. We don’t need I v when v is labeled; we don’t even need E vd , when v is known to see d . If v has out-degree d and already sees some label twice, we know that i vd is 0. And so on. In the pi day puzzle such simplifications reduce 60 thousand options on 1200 + 1831 items to 11351 options on 880+1216 items. That’s still a lot, and Algorithm C needs 135 M μ to input them; but then it finds the solution and proves it unique after 25 more M μ . (The highly tuned method of answer 7.2.2–68 needed only 7 M μ to prove uniqueness. But that method solves only a small class of problems that happen to reduce nicely.)
Bittencourt notes that further speedup is possible when two arrows point in the same direction. (This happens 123 times in the pi day puzzle.) In general if v → w implies u → w , we must have λ ( u ) ≥ λ ( v ); and this condition can be enforced by introducing a new primary variable whose options allow u and v to have only appropriate combinations of colors.
103. (a) An all-interval row always has x n − 1 = (x 0 + 1 + ··· + ( n − 1)) mod n = (x 0 + n ( n −1)/2) mod n = (x 0 +[ n even] n/ 2) mod n .
(b) Let j , p j , d k , q k be primary items and let x j be a secondary item, for 0 ≤ j < n and 1 ≤ k < n . There’s an option ‘ j p t x j : t ’ for 0 ≤ j, t < n , omitted when ( j = 0 and t = 0) or ( j = n − 1 and t = n/ 2). And there’s an option ‘ d k q t x t − 1 : i x t :( i + k ) mod n ’ for 1 ≤ k, t < n and 0 ≤ i < n . Then the tone row and its intervals are permutations.
There are (1, 2, 4, 24, 288, 3856) solutions for n = (2, 4, 6, 8, 10, 12). [These values were first computed by D. H. Lehmer, Proc. Canadian Math. Congress 4 (1959), 171–173, for n = 12 and E. N. Gilbert SIAM Review 7 (1965), 189–198, for n < 12.]
For larger n , Algorithm C is not at all competitive with a straightforward backtrack algorithm, which uses Algorithm 7.2.1.2X to find all suitable permutations of the n −1 intervals: That method needs only 100 M μ to find all 89328 solutions when n = 14, compared to 107 G μ by Algorithm C ! With backtracking we can generate all 2755968 solutions for n = 16 in 4.7 G μ , and all 103653120 solutions for n = 18 in 281 G μ .
(c) The intervals between adjacent classes in x Q are the same as those of x , except that x k − x k − 1 is replaced by x 0 − x n − 1 . And we know that x 0 − x n − 1 = ± n/ 2.
(d) True; both are x k − 1 ... x 0 x n − 1 ... x k . (Also ( cx ) R = c ( x R ); ( cx ) Q = c ( x Q ).)
(e) The solution for n = 2 has every possible symmetry; and both solutions x for n = 4 are equivalent to x R , − x Q , and − x QR . But for n > 4 one can show that x is equivalent to at most one of the 4 ϕ ( n ) rows cx , cx R , cx Q , cx QR besides itself. We obviously can’t have x ≡ cx when c = 1. An elementary but nontrivial proof shows also that x ≡ cx R implies c mod n = 1; x ≡ cx Q implies c mod n = n −1; x ≡ cx QR implies c mod n = n/ 2 + 1 and n mod 8 = 4. (See N. Hodges et al. in AMM 132 (2025), 94–96.) Gilbert stated incorrectly [page 196] that no solutions of the latter kind exist; he had overlooked 12-tone rows such as 0 3 9 1 2 4 11 8 7 5 10 6, 0 1 4 9 3 11 10 8 5 7 2 6, 0 1 8 11 10 3 9 5 7 4 2 6, for which x ≡ 7 x QR . Similarly, the 20-tone row 0 1 3 11 2 19 13 9 12 7 14 18 4 17 16 8 6 15 5 10 satisfies x ≡ 11 x QR .
At any rate, the transformations of (c) partition the solutions into clusters of size 2 ϕ ( n ) when there’s symmetry, 4 ϕ ( n ) when there’s not. Gilbert enumerated the cases of symmetry when n < 12; R. Morris and D. Starr did it when n = 12[ J. Music Theory 18 (1974), 364–389]. For n = (6, 8, 10, 12, 14, 16, 18) the number of clusters with x ≡ x R turns out to be respectively (1, 1, 6, 22, 48, 232, 1872); the number of clusters with x ≡ −x Q turns out to be (0, 0, 2, 15, 0, 0, 1346); also n = 12 has 15 cases with x ≡ 7 x QR .
104. (a) We may assume that x 0 = 0. There’s a constant c r such that y kr ≡ x k −1 + c r (modulo n ) for 1 ≤ k ≤ n . Thus y r \= x r −1 ≡ c r ; y r 2 \= x ( r 2 −1) mod p ≡ x r −1 + c r ≡ 2 c r ; y r 3 \= x ( r 3 −1) mod p ≡ x ( r 2 −1) mod p + c r ≡ 3 c r ; etc. Let r be primitive modulo p , so that { r mod p,...,r n mod p } = {1 ,..., p − 1}, and let R = r d where c r d mod n = 1. Then we’ve proved R x ( r k −1 ) mod p ≡ ( r k mod p ) (modulo p ) for 1 ≤ k ≤ n ; that is, R x k −1 ≡ k .
Now suppose x k − x k−1 ≡ x l − x l −1 (modulo n ). Then R x k R x l −1 ≡ R x k −1 R x l (modulo p ); consequently ( k +1) l ≡ k ( l + 1) (modulo p ), hence k = l .
(b) x ( n ) \= x R . [See the papers by Lehmer and Gilbert in answer 103 .]
105. There are just five solutions; the latter two are flawed by being dis connected:
Historical notes: The earliest known word search puzzle was “ Viajando” by Henrique Ramos of Brazil, published in Almanaque de Seleções Recreativas (1966), page 43. Such puzzles were independently invented in America by Norman E. Gibat (1968). Jo Ouellet of Canada developed “ Wonderword,” which puts the unused letters to use, in 1970.
106. When Algorithm C is generalized to allow non-unit item sums as in Algorithm M , it needs just 24 megamems to prove that there are exactly eight solutions — which all are rotations of the two shown here.
107. To pack w given words, use primary items {P ij, R ic, C ic, B ic, # k | 1 ≤ i, j ≤ 9, 1 ≤ k ≤ w, c ∈ { A , C , E , M , O , P , R , T , U }} and secondary items { ij | 1 ≤ i, j ≤ 9}. There are 729 options ‘P ij R ic C jc B bc ij : c ’, where b = 3 ⌊( i − 1)/3⌋ + ⌈ j/ 3⌉, together with an option ‘# k i 1 j 1 : c 1 ... i l j l : c l ’ for each placement of an l -letter word c 1 ... c l into cells ( i 1 ,j 1 ), ... , ( i l ,j l ). Furthermore, it’s important to use the sharp preference heuristic ( exercise 10 ) in step C3 of the algorithm.
A brief run then establishes that COMPUTER and CORPORATE cannot both be packed. But all of the words except CORPORATE do fit together; the (unique) solution shown is found after only 7.3 megamems, most of which are needed simply to input the problem. [This exercise was inspired by a puzzle in Sudoku Masterpieces (2010) by Huang and Snyder.]
108. (a, b) The author’s best solutions, thought to be minimal (but there is no proof), are below. In both cases, and in Fig. 71 , an interactive method was used: After the longest words were placed strategically by hand, Algorithm C packed the others nicely.
[Solution (b) applies an idea by which Leonard Gordon was able to pack the names of presidents 1–42 with one less column. See A. Ross Eckler, Word Ways 27 (1994), 147; see also page 252, where OBAMA miraculously fits into Gordon’s 15 × 15 solution!]
109. To pack w given words, use w + m ( n − 1) + ( m − 1) n primary items {# k | 1 ≤ k ≤ w } and {H ij, V ij | 1 ≤ i ≤ m, 1 ≤ j ≤ n }, but with H in and V mj omitted; H ij represents the edge between cells ( i, j ) and ( i, j + 1), and V ij is similar. There also are 2 mn secondary items { ij, ij′ | 1 ≤ i ≤ m, 1 ≤ j ≤ n }. Each horizontal placement of the k th word c 1 ... c l into cells ( i, j + 1), ... , ( i, j + l ) generates the option
‘# k ij : . ij′ : 0 i ( j +1): c 1 i ( j +1)′: 1 H i ( j +1) i ( j +2): c 2 i ( j +2)′: 1 H i ( j +2) ...
H i ( j + l −1) i ( j + l ): c l i ( j + l )′: 1 i ( j + l +1): . i ( j + l +1)′: 0 ’
with 3 l + 4 items, except that ‘ ij : . ij′ : 0 ’ is omitted when j = 0 and ‘ i ( j + l +1): . i ( j + l +1)′: 0 ’ is omitted when j + l = n . Each vertical placement is similar. For example,
‘ # 1 11 : Z 11': 1 V11 21: E 21': 1 V21 31: R 31': 1 V31 41: 0 41': 1 51:. 51': 0 ’ ( * )
is the first vertical placement option for ZERO , if ZERO is word #1. When m = n , however, we save a factor of 2 by omitting all of the vertical placements of word #1.
To enforce the tricky condition (ii), we also include 3 m ( n −1)+3( m −1) n options:
‘H ij ij′ :0 i ( j +1)′:1 ij : | ‘V ij ij′ :0 ( i +1) j′ :1 ij : |
‘H ij ij′ :1 i ( j +1)′:0 i ( j +1): | ‘V ij ij′ :1 ( i +1) j′ :0 ( i +1) j : |
‘H ij ij′ :0 i ( j +1)′:0 ij : | ‘V ij ij′ :0 ( i +1) j′ :0 ij : |
This construction works nicely because each edge must encounter either a word that crosses it or a space that touches it. (Beware of a slight glitch: A valid solution to the puzzle might have several compatible choices for H ij and V ij in “blank” regions.)
Important: As in answer 107 , the sharp preference heuristic should be used here, because it gives an enormous speedup.
The XCC problem for our 11-word example has 1192 options, 123 + 128 items, and 9127 solutions, found in 23 G μ . But only 20 of those solutions are connected; and they yield only the three distinct word placements below. A slightly smaller rectangle, 7 × 9, also has three valid placements. The smallest rectangle that admits a solution to (i) and (ii) is 5 × 11; that placement is unique , but it has two components:
Suppose there are w words of total length s . Aaron Windsor suggests adding options ‘E ij : . ij′ :0’ for 1 ≤ i ≤ m and 1 ≤ j ≤ n , where E is a new primary item representing an empty cell. All solutions to the MCC problem with the number of E’s in the interval [ mn − s + w − 1 ..mn ] are then either connected or contain a cycle.
Instead of generating all solutions to (i) and (ii) and discarding the disconnected ones, there’s a much faster way to guarantee connectedness throughout the search; but it requires major modifications to Algorithm C . Whenever no H or V is forced, we can list all active options that are connected to word #1 and not smaller than choices that could have been made earlier. Then we branch on them, instead of branching on an item. For example, if (∗) above is used to place ZERO , it will force H00 and H20 and V30. The next decision will be to place either EIGHT or ONE , in the places where they overlap ZERO . (However, we’ll be better off if we order the words by decreasing length, so that for instance #1 is EIGHT and #11 is ONE .) Interested readers are encouraged to work out the instructive details. This method needs only 630 M μ to solve the example problem, as it homes right in on the three connected solutions.
110. Gary McDonald found this remarkable 20 × 20 solution in 2017:
A 19 × 19 is surely impossible, although no proof is known. L. Gordon had previously fit the names of presidents 1–42 into an 18 × 22 rectangle [ Word Ways 27 (1994), 63].
111. (a) Set up an XCC problem as in answer 109 , but with just three words AAA , AAAA , AAAAA ; then adjust the multiplicities and apply Algorithm M . The two essentially distinct answers are shown below; one of them is disconnected, hence disqualified.
(b) Similarly, we find four essentially different answers, only two of which are OK:
Algorithm M handles case (b) with ease (5 G μ ). But it does not explore the space of possibilities for case (a) intelligently, and costs 550 G μ .
112. (a) Yes: IMMATURE , MATURING , COMMUTER , GROUPING , TROUPING , AUTHORING , and THRUMMING . A straightforward backtracking program will quickly determine the presence or absence of any given string of letters.
(b) Let’s put DANCING and LINKS in there too. Then we obtain an array with 24 words from WORDS (5757) (like LOVER , ROSIN , SALVO , TOADS , TROVE ); also ASKING , DOSING , LOSING , ORDAIN , SAILOR , SIGNAL , SILVER ; also LANCING , LOANING , SOAKING , and even ORTOLAN . (Notice that TORTO occurs in two ways.)
To find such arrays, as suggested by R. Bittencourt, we can let word k be c 0 ... c t − 1 , and introduce primary items W kl for 1 ≤ l < t to represent the placement of c l − 1 c l . Let X u be a secondary item, for each cell u of the array, to be colored with some letter. Represent the king path for word k by giving color u to P kl and color l to Q ku when c l is in cell u , where P kl and Q ku are additional secondary items. There also are secondary items D kv , for each internal vertex v . For example, if the cells and vertices are numbered rowwise, two of the options chosen for DANCING and LINKS in the example above are ‘ W 03 X 3 : N X 0 : C P 02 :3 P 03 :0 Q 03 :2 Q 00 :3’ and ‘ W 12 X 4 : I X 2 : N P 11 :4 P 12 :2 Q 14 :1 Q 12 :2 D 11 ’. The ‘ D 11 ’ in the latter will prevent another step of word 1 between cells 2 and 4.
We can save a factor of nearly 4 by restricting the placement of, say, c l − 1 c l in word 0 when l = ⌊ t 0 /2⌋, so that c l − 1 lies in the upper left quadrant and c l isn’t in the rightmost column. Then W 0 l has only 26 options instead of the usual 94.
It turns out that exactly 10 essentially different Torto arrays contain DANCING , LINKS , TORTO , WORDS , and SOLVER ; exactly 1444 contain THE , ART , OF , COMPUTER , and PROGRAMMING . They’re found by Algorithm C in 713 G μ and 126 G μ , respectively.
(c) Yes, in 416 ways (but we can’t add ELEVEN ). Similarly, we can pack ZERO , ONE , ... , up to EIGHT , in 553 ways. And FIRST , ... , SIXTH can be packed in 72853 ways, sometimes without using more than 16 of the 18 cells. (These computations took (16, 5, 1.5) T μ . Interesting words lurk in these arrays — can you spot them? See Appendix E .)
[The name ‘Torto’ was trademarked by Coquetel/Ediouro of Rio de Janeiro in 1977, and an example appeared in issue #1 of Coquetel Total magazine that year. Monthly puzzles still appear regularly in Coquetel’s magazine Desafio Cérebro . Bitten-court posed the problem of constructing Torto arrays from a given list of required words in 2011; see [blog.ricbit.com/2011/05/torto-reverso.html](http://blog.ricbit.com/2011/05/torto-reverso.html) .]
113. First, we can find all sets of six or fewer letters that could be on such a block, by solving an MCC problem with 25 primary items TREES , ... , DEQUE of multiplicity [1 .. 26] and one primary item # of multiplicity [0 .. 6]. There are 22 options, ‘# ABOVE AVAIL GRAPH STACK TABLE VALUE ’ through ‘# EMPTY ’, one for each potential letter (listing all words that include that letter). This covering problem has 3223 solutions, found in 4 M μ and ranging alphabetically from { A , B , C , D , E , I } to { E , L , R , T } to { L , N , R , T , U , V }.
Then we set up an XCC problem with 25 primary items TREES , ... , DEQUE and five primary items 1, ... , 5, together with 5 · 22 secondary items A j , ... , Y j for 1 ≤ j ≤ 5. Each word has an option for each permutation of its letters (see Algorithm 7.2.1.2L), showing which letters it needs for that permutation of the blocks. (For example, QUEUE will have 30 options, beginning with ‘ QUEUE E 1 :1 E 2 :1 Q 3 :1 U 4 :1 U 5 :1’, which means that block 1 should have an E , ... , block 5 should have a U .) Break symmetry by giving only one of the 120 options for one of the words ( FIRST , for example). Each of the 3223 potential sets of letters has five options of size 23, showing exactly which letters are present if block j uses that set; for example, the five options for { A , B , C , D , E , I } are ‘ j A j :1 ... E j :1 F j :0 ... I j :1 ... Y j :0’ for 1 ≤ j ≤ 5. There are 18486 options altogether, of total length 403357; Algorithm C solves them in 202 G μ .
For these words the five blocks must be { E , F , G , L , O , S }, { C , E , I , R , U , Y }, { A , L , M , N , Q , R }, { A , B , E , P , S , T }, { D , H , K , T , U , V }. (The XCC problem actually has 8 solutions, because TIMES , TREES , and VALUE can each be formed in two ways from those blocks.)
[This exercise is based on an idea by E. Riekstiņš, who realized that a classic puzzle called Castawords could be extended to words of length 5.]
114. (Solution improved by P. Weigel.) Besides the primary items p ij , r ik , c jk , b xk of (30), introduce u k and v l to define a permutation. Also introduce secondary items π k to record the permutation and ij to record the value at cell ( i, j ). The permutation is defined by 81 options ‘ u k v l π k : l ’ for 1 ≤ k, l ≤ 9. And there are 9 4 = 6561 other options, one for each cell ( i, j ) of the board and each pair ( k, l ) of values before and after α is applied. If ( ij ) α = i′j′ , let x′ = 3 ⌊ i′ /3⌋ + ⌊ j′ /3⌋. Then option ( i, j, k, l ) is normally ‘ p i′j′ r i′l c j′l b x′l ij : k i′j′ : l π k : l ’. However, if i′ = i and j′ = j , that option is shortened to ‘ p ij r ik c jk b x k ij : k π k : k ’, and omitted when k ≠ l . The options ( i, j, k, l ) are also omitted when i = 0 and k ≠ j + 1, or i′ = 0 and l ≠ j′ + 1, or i > 0 and k = j + 1, or i′ > 0 and l = j′ + 1, in order to force ‘ 123456789 ’ on the top row.
With that top row and with α = transposition, Algorithm C produces 30,258,432 solutions in 171 gigamems. (Those solutions were first enumerated in 2005 by E. Russell; see [www.afjarvis.org.uk/sudoku/sudgroup.html](http://www.afjarvis.org.uk/sudoku/sudgroup.html) .)
115. A similar method applies, but with additional items b y k ′ as in answer 67(b) . The number of solutions is (a) 7784; (b) 16384; (c) 372; (d) 32. Here are examples of (a) and (d); the latter is shown with labels { 0 ,..., 7 , * }, to clarify its structure. [Enumerations (a), (b), (c) were first carried out by Bastian Michel in 2007.]
(a)
(d)
116. (a) Any triangle in μ ( G ) must be in G , because
.
(b) Suppose μ ( G ) can be c -colored with some coloring function α , where α ( w ) = c . If α ( v ) = c for any v ∈ V , change it to α ( v′ ). This gives a ( c − 1)-coloring of G . [Hence a triangle-free graph on n vertices can have chromatic number Ω(log n ). One can show nonconstructively that the triangle-free chromatic number can actually be Ω( n/ log n ) 1/2 ; but currently known methods of explicit construction for large n achieve only Ω( n 1/3 ). See N. Alon, Electronic J. Combinatorics 1 (1994), #R12, 1–8.]
(c) If G is χ -critical, so is μ ( G ): Let e ∈ E and suppose α is a ( c − 1)-coloring of G \ e . Then we get c -colorings of all but one edge of μ ( G ) in several ways: (i) Set α ( v′ ) ← c for all v ∈ V , and α ( w ) ← 1. (ii) Let u ∈ e , and set α ( u ) ← α ( w ) ← c ; also set α ( v′ ) = α ( v ) for all v ∈ V , either before or after changing α ( u ). If you want to remove an edge of μ ( G ) that’s in G , use (i); otherwise use (ii).
[See J. Mycielski, Colloquium Mathematicum 3 (1955), 161–162; H. Sachs, Einführung in die Theorie der endlichen Graphen (1970), §V.5.]
117. (a) Use the answer to (b), with each clique consisting of a single edge.
(b) Each vertex v has d options ‘ v c 1 j ... c kj ’ for 1 ≤ j ≤ d , where the cliques containing v are { c 1 ,...,c k }.
(c) We save a factor of 9! = 362880 by fixing the colors of the queens in the top row. Then there are 262164 solutions, found by Algorithm X in 8.3 T μ with method (a) but in only 0.6 T μ with method (b).
(d) Insert ‘ v′ : j ’ into the j th option for v , where v′ is secondary. (This reduces the running time for method (a) in part (c) to 5.0 T μ , without fixing any colors.)
(e) Using (d) to save a factor of c !, we get (2!·1, 3!·5, 4!·520, 5!·23713820) solutions, in approximately (600, 4000, 130000, 4100000000) mems. [ Monte Carlo estimates can be made for larger cases by combining exercises 86 and 122 ; the true branching factor at each level can be determined by rejecting options that involve illegal purification. It appears that M 6 can be 6-colored in approximately 6! · 2 . 0 × 10 17 ways.]
(f) Now (d) saves a factor of ( c −1)!, despite having no solutions; the running times are roughly (100, 600, 5000, 300000) mems. (But then for 5-coloring M 6 it’s 45 T μ !)
(g) There are (1! · 1, 2! · 1, 3! · (5 or 7), 4! · (1432, 1544, 1600, 2200, 2492, 2680, 3744, 4602, or 6640)) such colorings, depending on which edge is deleted.
118. In general, colorings of a hypergraph can be found with the construction of the previous exercise, but using Algorithm M and giving multiplicity [0 .. ( r −1)] to each hyperedge of size r . In this case, however, there are 380 independent sets of size 16 (see exercise 7.1.4– 242); we can simply use them as options to an exact cover problem with 64 items. There are four solutions, having a curious symmetry so that only two are “ essentially different”: One is shown, and the other is obtained by keeping A and C fixed but transposing the B ’s and D ’s.
A B C D C D A B
B D B D C A C A
C B A C D B A D
D D A B A B C C
A A D C D C B B
B C D B A C D A
C A C A B D B D
D C B A B A D C
119. Exactly three interior edges are white in every solution. Any other placement of the all-white piece defines those three edges. That leaves no way to place all three of the two-white pieces.
120. (a) Call the types 0 , 1 , ... , 9 , and use Algorithm C to find all ways to place a given type at the center of a 5 × 5 array. There are respectively (16, 8, 19, 8, 8, 8, 10, 8, 16, 24) ways to do this; and the intersection of all solutions for a given type shows that
? ? ? ? ? ? ? ? ? ? ? ? 0 ? ? ? ? 2 ? ? ? ? ? ? ? , 0490 ? 2023 ? ? 217 ? 8568 ? 490 ? ? , ? ? ? ? ? ? ? 0 ? ? ? ? 2 ? ? ? ? ? ? ? ? ? ? ? ? , 68568 0490 ? 2032 ? ? 217 ? 8568 ? , 21721 ? 6856 9049 ? 320 ? ? 172 ? ? , 32032 17217 68568 049 ? ? 20 ? ? ? , 2032 ? ? 217 ? 8568 ? 490 ? ? 032 ? ? , 49049 0320 ? 21721 ? 6856 9049 ? , 0320 ? 21721 ? 6856 9049 ? 320 ? ? , 17217 68568 049 ? ? 20 ? ? ? ? 2 ? ? ?
are the respective neighborhoods that are forced near a given type in any infinite tiling. Consequently every such tiling contains at least one 5 ; and if we place 5 at the origin everything in the entire plane is forced. The result is a torus in the sense of exercise 7 – 137 , with a periodic supertile of size 12:
(b) Similarly, there’s again a unique tiling, this time with a 13-cell supertile:
121. (a) Marek Tyburec noticed in 2017 that there are no 2 × 2 solutions with βUS at lower right; similarly, there are no 3 × 4 solutions with βUS at lower left. Hence βUS can appear only in the top row, or at the left of the next-to-top row.
(b) Let ( A k , B k , C k , D k ) be the (2 k −1)×(2 k −1) tilings defined by ( αa, αb, αc, αd ) when k = 1, otherwise by placing ( δNa, δNb, δNc, δNd ) in the middle and placing A k − 1 , B k − 1 , C k − 1 , D k − 1 at the corners as in answer 2.3.4.3–5. The unique tiling requested here has δRD in the middle and D k − 1 , C k − 1 , B k − 1 , A k − 1 at the corners.
(c) With δRU in the middle, another solution has C k − 1 , D k − 1 , A k − 1 , B k − 1 at the corners. With δLD , another solution has corners B k − 1 , A k − 1 , D k − 1 , C k − 1 . Both of those solutions work with δLU and δSU ; and δSU also has 54 additional solutions, with C k − 2 in the upper left corner. They use δ{{ L, P, S, T }{ J, U }, RU } in the middle of row 2 k −2 , and independently δ{ L, K, P, R, S, T } U in the middle of row 3 · 2 k −2 .
(d) Only one of each survives. As in (b), its four quadrants are D ∞ , C ∞ , B ∞ , A ∞ .
[Each of the other 86 types occurs in A 6 , hence in every sufficiently large tiling. Incidentally, the “ dragon sequence” (see answer 4.5.3–41) arises in the colors at the edges of A ∞ , B ∞ , C ∞ , D ∞ .]
122. A new global variable Θ, initially v , is the current “color threshold.” Every item has a new field CTH in addition to NAME , LLINK , and RLINK . That field is normally zero in primary items, although it has a special use in step C3 as described below. In secondary items, CTH will be used to undo changes to Θ.
Insert ‘ CTH( i ) ← Θ; if c = Θ, set Θ ← Θ + 1’ just after ‘ i ← TOP( p ) ’ in the purify routine (55). Insert ‘Θ ← CTH( i ) ’ just after ‘ i ← TOP( p ) ’ in the unpurify routine (57). Modify the commit routine (54) so that it jumps to the end of the uncommit routine (56), if COLOR( p ) > Θ, without changing j or p . (The effect is to avoid committing to any option that would have set a color value greater than Θ, by jumping from step C5 into the appropriate place within step C6. * )
* Backtrack programs often run into such cases where it is permissible, even desirable, to jump into the middle of a loop . See Examples 6c and 7a in the author’s paper “Structured programming with go to statements,” Computing Surveys 6 (1974), 261–301.
Finally, change step C3 so that it never chooses an item i for which CTH( i ) > Θ. That step should then go to C8 if no item is choosable. (This mechanism prohibits branching on primary items for which the assumption of total symmetry between all colors ≥ Θ isn’t yet valid. Exercise 126 has an example.)
123. When, say, m = 4 and n = 10, Algorithm C takes 49 megamems to produce 1048576 solutions. The modified algorithm (where we set v = 1) takes 2 megamems to produce 43947 solutions. (Notice that the value vectors q 1 ... q n are equivalent to the restricted growth strings a 1 ... a n of 7.2.1.5–(4), with q k \= a k + 1.)
124. Let ( x, y ) denote a Δ triangle, and let ( x, y )′ denote the ∇ triangle that lies immediately to its right. (Think of a square cell ( x, y ) that has been subdivided into right triangles by its main diagonal, then slanted and yscaled by 3 / 2 .) For example, an m × n parallelogram has 2 mn triangles ( x, y ) and ( x, y )′ for 0 ≤ x < m and 0 ≤ y < n , Cartesianwise; the 3×2 case is illustrated.
The boundary edges of triangle ( x, y ) are conveniently denoted by / xy , \ xy , and - xy . Then the boundary edges of ( x, y ) are / ( x +1) y , \ xy , and - x ( y +1).
[A “ barycentric” alternative with three coordinates is also of interest, because it’s more symmetrical: Each triangle corresponds to an ordered triple of integers ( x, y, z ) such that x + y + z = 1 or 2, under the correspondence ( x, y ) ↔ ( x, y, 2 − x − y ) and ( x, y )′ ↔ ( x, y, 1 − x − y ). The twelve symmetries are then the six permutations of { x, y, z } with an optional flip between ( x, y, z ) and ( x ¯ , y ¯ , z ¯ , ) \= ( 1 − z , 1 − y , 1 − z ) .]
[One can also use “ barycentric even/odd coordinates,” inspired by exercise 145 , which are ordered triples ( x, y, z ) with | x + y + z | ≤ 1. Cases with x , y , z odd represent triangles, with ( x, y ) ↔ (2 x −1, 2 y −1, 3−2 x −2 y ), ( x, y )′ ↔ (2 x −1, 2 y −1, 1−2 x −2 y ). Cases with x , y , z even represent vertices. Cases with just one even coordinate represent edges (the average of two adjacent triangles). Cases with two even coordinates could represent directed edges.]
125. Every original triangle ( x, y ) or ( x, y )′ expands to k 2 triangles of the forms ( kx + p, kx + q ) or ( kx + p′,kx + q′ )′ for 0 ≤ p, q, p′,q′ < k . Those obtained from ( x, y ) have p + q < k and p′ + q′ < k − 1 (of which there are ( k + 1 2 ) and ( k 2 ) , respectively). The others are obtained from ( x, y )′.
126. Let there be 24 primary items 01 ’, 02 , 02 ’, ... , 32 for the triangles, and 24 primary items aaa , aab , ... , ddd for the tiles, together with 42 secondary items \01 , -02 , /02 , ... , /41 for the edges. There are 24 · 64 options ‘ 01’ aaa -02:a /11:a \01:a ’, ‘ 01’ aab -02:a /11:a \01:b ’, ‘ 01’ aab -02:a /11:b \01:a ’, ... , ‘ 32 ddd -32:d /32:d \32:d ’ — one for each way to place a tile. Finally, to force the boundary conditions, add another primary item ‘ * ’, and another option ‘ * -20:a -30:a /40:a ... \10:a ’.
Algorithm C finds 11,853,792 solutions, after 340 G μ of computation; this total includes 72 different versions of every distinct solution, hence there really are just 164,636 of them (a number that was unknown until Toby Gottfried computed it in 2001).
Using exercise 119 we can remove all options for aaa except ‘ 20 aaa -20:a /20:a \20:a ’. Algorithm C then finds 11853792/12 = 987,816 solutions, in 25 G μ .
Furthermore, using exercise 122 (with v = b ), and not allowing step C3 to branch on a tile name until Θ = e (because there’s total symmetry with respect to triangle locations but not tile names), finds every distinct solution just once, in 6.9 G μ .
Finally, we can allow branching on aab whenever Θ ≥ c , and in general on a piece name whenever Θ exceeds all colors in its name. This reduces the runtime to 4.5 G μ .
[ MacMahon specifically designed pattern (59b) to include all three of the nonwhite solid-color triangles in the center. If we fix them in those positions, an unmodified Algorithm C quickly finds 2138 solutions. There also are 2670 solutions with those three fixed in positions { 11’ , 21’ , 12’ } instead of { 12 , 21 , 22 }.]
127. Every color appears in (3 · 24)/4 = 18 places among the triangles, hence 18 − 2 k times on the border when it occurs k times in the interior of a solution. Consequently no color occurs an odd number of times on the border. That leaves 2099200 possibilities.
All of those 2099200 are actually completable. (MacMahon would have been very happy to have known this!) The number of cases can be reduced to only 4054, using the methods of Section 7.2.3, because there are 576 symmetries: cyclic shifting and/or reflection and/or permutation of colors. The Monte Carlo procedure of Algorithm 7.2.2E not only finds solutions in each of those cases, it finds oodles of them. In fact, we can be confident that every all-even-but-not-constant border specification has more than four times as many solutions as the pure-white border does .
(More precisely, the pure-white border 000000000000 has 11853792 solutions, without reducing by symmetry; the next-smallest border, 000000000011, has 48620416; the next-smallest, 000000000101, has 49941040; and so on. There are more than 100 million solutions in the vast majority of cases, but probably never more than 500 million. Incidentally, 001022021121 is the only valid color pattern that has exactly three automorphisms.)
128. We can pack them into the 11-triangle region obtained by deleting triangle (2, 1)′ from the 2 × 3 parallelogram in answer 124 , in such a way that the edge colors satisfy -00 = -20 , /01 = /30 , -02 = -12 . There are 1032 ways to do this, one of which is shown. This yields a “ supertile” that nicely tiles the plane, in combination with its 180° rotation:
129. First consider rotation symmetry. Only 180° rotation applies, because of the four single-color tiles. To generate all of the strong solutions, assume that rotation changes a ↔ d , b ↔ c , and combine the options of answer 126 into pairs such as ‘ 02 abc -02:a /02:b \02:c 31’ bdc -32:d /41:c \31:b ’. The resulting 768 options have 68,024,064 solutions (found in about 0.5 T μ ); but many of those solutions are essentially the same (that is, obtainable from each other by rotation, reflection and/or color permutation).
It’s somewhat tricky to count the essentially distinct patterns; canonical representations can be obtained by distinguishing six types of solutions: (1) 02 aaa (hence 31’ ddd ) and 03 bbb (hence 30’ ccc ), and /12:a or /12:c . [The cases /12:b or /12:d are equivalent to these, if we reflect and swap a ↔ b , c ↔ d .] (2) 02 aaa , 23 bbb [or equivalently 03’ bbb ]. (3) 02 aaa , 13’ bbb , and \03:a or \03:c . (4) 02 aaa , and bbb in 12 , 12’ , 22 , 22’ , or 13 . (5) 13 aaa , 02’ bbb , and \12:a or \12:c . (6) 13 aaa , 12 bbb . Each type is easy, yielding 80768+164964+77660+819832+88772+185172 = 1417168 solutions.
[Notice that the illustrated example of strong symmetry actually tiles the plane without rotation; that is, it has -04 = -20 , -14 = -30 , /03 = /41 , ... , \10 = \32 . Exactly 40208 of the essentially distinct solutions satisfy this additional proviso.]
To generate the weak solutions, introduce new secondary items bxy , b x y ′ for each triangle ( x, y ) or ( x, y )′ with y > 1, representing color changes within the triangle. Typical options are now ‘ 02 aad -02:a /02:a \02:d b02:5 ’, ‘ 02 aad -02:a /02:d \02:a b02:3 ’, ‘ 02 aad -02:d /02:a \02:a b02:6 ’, ‘ 02 abc -02:a /02:b \02:c b02:7 ’, ‘ 31’ bdc -32:c /41:b \31:d b02:7 ’, ‘ 31’ ccd -32:c /41:c \31:d b02:5 ’. We may assume that ddd is opposite aaa , ccc is opposite bbb . Algorithm C generates each weak-not-strong solution twice, each strong solution once; the six types yield a total of 24516 + 45818 + 22202 + 341301 + 44690 + 130676 = 609203 weak-not-strong solutions.
Turning now to reflections of the hexagon, there are two essentially different possibilities: Top-bottom reflection preserves the values of four edges, but all triangles change; left-right reflection preserves the values of four triangles and two edges. Therefore strong reflection symmetry is impossible . (In the first case, all triangles change, hence all colors change. In the second case, two colors must be fixed. With colors a and d fixed but b ↔ c , eight triangles aaa , aad , abc , acb , bcd , bdc , dda , ddd must be fixed.)
Weak symmetry under top-bottom reflection can be assumed as before to take aaa to ddd , bbb to ccc . Again there are six types: [1] 02’ aaa , 22’ bbb , -13:a or -13:c . [2] 02’ aaa , bbb in 12’ , 03’ , 13 , 13’ , or 23 . [3] 12’ aaa , bbb in 03 or 03’ . [4] 03 aaa , 23 bbb , -13:a or -13:c . [5] 03 aaa , bbb in 13 or 13’ . [6] 03’ aaa , 13’ bbb , -13:a or -13:c . Surprisingly, some placements are “special”: They have strong rotational symmetry, as well as weak top-down symmetry! Algorithm C , which generates the special ones once and the others twice, produces respectively (88, 0, 0, 98, 0, 75) + 2(1108, 12827, 8086, 3253, 12145, 4189) solutions. Here are examples of the 88 + 98 + 75 = 261 special placements, which belong simultaneously to types [1] and (5), [4] and (3), [6] and (1):
Weak left-right symmetry is similar, but there now are some fixed triangles. If aaa is fixed, assume that ddd is also fixed; three such types arise, with 46975 + 35375 + 25261 = 107611 solutions. Otherwise assume that ddd is opposite aaa ; six types of this kind yield (75, 0, 98, 0, 0, 88) strong and (3711, 56706, 5889, 60297, 38311, 9093) non-strong solutions. So there’s a grand total of 281618 essentially distinct weak-not-strong placements with left-right symmetry — of which 194 are top-down symmetric too.
[Arrangements that have strong and weak symmetry were first discovered by Kate Jones, who presented them in the 1991 user manual for Multimatch® III, an attractively produced set of triangular tiles.]
130. The nicest coordinate system for an octahedron is probably to number the faces 000, 001, ... , 111 in binary, and to let the vertices be { 0** , 1** , *0* , *1* , **0 , **1 }; the edges are { xy * ,x * y, * xy } for x, y ∈ {0 , 1}. Construct 512 options ‘ 000 aaa *00:a 0*0:a 00*:a ’, ‘ 000 aab *00:a 0*0:b 00*:a ’, ‘ 000 aab *00:b 0*0:a 00*:a ’, ... , with face-name items 000 , ... , 111 primary and tile-name items aaa , ... , ddd secondary. Algorithm C quickly finds 2723472 solutions, which include 45356 distinct sets of eight. Those 45356 sets become, in turn, new options for Algorithm X (or C), with 24 primary tile-name items; now we get 1615452 solutions, which are the desired partitions.
Many symmetries are present, of course; we’ll study how to distinguish nonisomorphic representatives in Section 7.2.3. One of the most interesting solutions,
has four color-swap symmetries, with all the solid-color triangles on one octahedron.
131. (a) Each triangle edge is either a (straight) or b (a wave) or c (a hump) or d (a dip). We can set this up with options and items as in answer 126 , except that the edge-match condition is now a ↦ a , b ↦ b , c ↦ d , d ↦ c ; to get proper matching, the options of ∇ triangles should state the mate color, as in ‘ 01’ abc -02:a /11:b \01:d ’.
Every solution corresponds to 24 equivalent solutions, because we get a factor of 6 by rotating the hexagon, a factor of two by interchanging humps with dips, and another factor of two by reflection. (Reflection is a bit tricky, because a wave becomes an anti-wave when a piece is flipped over. However, every reflected piece has its own anti-piece, which yields the desired anti-solution.) Thus we can force aaa to be in position 02 . Treating c and d symmetrically as in answer 126 (with v = c ) produces exactly 2,231,724 canonical solutions and needs only 30 gigamems of running time.
[This puzzle is manufactured by Kadon Enterprises under the name Trifolia®.]
(b) A similar setup, letting c and d represent 0 spots and 3 spots so that it’s easy to treat them symmetrically, now has mates a ↦ b , b ↦ a , c ↦ d , d ↦ c ; hence one option is ‘ 01’ abc -02:b /11:a \01:d ’. The boundary colors in directions / and \ are a ; in direction - they are b . The solutions to this problem typically form groups of eight (not 24): We can swap c ↔ d , reflect left-right, reflect top-down, or rotate by 180°; the latter two are combined with swapping a ↔ b . Without attempting to remove any symmetries, we get 3,419,736,176 solutions, after 20.6 teramems of computation.
Left-right reflection always gives a distinct solution, whether we swap c ↔ d or not (because there are at least eight pieces that stay fixed, and only four places to put them). But the illustrated example shows that some solutions are fixed under 180° rotation; we can find them by adding 15 new primary items, such as # /23 , and 15 · 4 new options, such as ‘# /23 /23: x /20: x ’ for x ∈ { a , b , c , d }. Altogether 18656 solutions have that symmetry; such cases form groups of four, not eight. Similarly, 169368 cases turn out to have top-down symmetry. It follows from “ Burnside’s lemma” that the total number of essentially different solutions is (3419736176 + 18656 + 169368)/8 = 427490525.
To double the speed of all these computations, take v = c in exercise 122 .
132. This challenging problem was first resolved by Peter Esser in April 2002, and presented online at [www.polyforms.eu/coloredpolygons/triindex.html#trios24](http://www.polyforms.eu/coloredpolygons/triindex.html#trios24) . [See JRM 9 (1977), 209. One can show that the only solutions to the Diophantine equation d + d ( d −1) + d ( d −1)( d −2)/3 = m 2 are d = 1, 2, and 24, using advanced methods found in N. P. Smart, The Algorithmic Resolution of Diophantine Equations (1998).]
133. This problem is like exercise 126 , but considerably simpler because squares are easier than triangles. There are 24 · 81 options ‘ 00 aaaa h00:a v10:a h01:a v00:a ’, ... , ‘ 53 ccba h53:a v63:c h54:c v53:b ’, where h xy and v xy denote the horizontal and vertical edges between squares. Remove options with non-a on the border; also limit aaaa to four border positions; and save another factor of 2 by making b and c equivalent ( exercise 122 with v = b ). The resulting 13328 solutions are found in 15 G μ .
[Today it’s easy to count them; but this problem has a tortured history! T. H. O’Beirne missed two of the 20 possible ways to place the internal white edges, when he analyzed the situation by hand in New Scientist 9 (2 February 1961), 288–289. A few years later, the problem of solution counts for MacMahon squares was probably the very first large computation ever undertaken at Stanford Artificial Intelligence Laboratory; Gary Feldman found 12261 placements, during a 40-hour computer run (see Stanford AI Project , Memo 12 (16 January 1964), 8 pages). That number was believed to be correct until May 1977, when the true value was obtained by H. Fernández Long in Argentina.]
Instead of denoting squares by xy and edges by { h xy, v xy }, it’s convenient to use “ even/odd coordinates” instead (see exercise 145 ). In that system, a pair of odd numbers (2 x +1)(2 y +1) denotes a square, and the edge between two adjacent squares is represented by the midpoint between them. For example, the 24·81 options sketched above would then take the form
‘ 11 aaaa 01:a 12:a 21:a 10:a ’, ... , ‘ b7 ccba a7:a b8:c c7:c b6:b ’.
Such coordinates are easier to work with under reflection and rotation.
134. (O, P, Q, ... , Z) occur respectively (0, 1672, 22, 729, 402, 61, 36, 48, 174, 259, 242, 0) times, sometimes twice in the same solution; one solution features four pentominoes.
[Kate Jones introduced such questions in the Multimatch® I user manual (1991).]
135. Indeed, the total number of solutions is enormous; Monte Carlo estimates predict ≈ 9 × 10 8 of them for any fixed placements of aaaa , bbbb , cccc that aren’t obviously impossible. Therefore it’s natural to impose extra conditions. The elegant wrapping below permutes colors cyclically and has solid colors on every edge of the cube! Investigations by H. L. Nelson, F. Fink, and M. Risue˜no showed that 61 such solutions are possible; see W. E. Philpott, JRM 7 (1974), 266–275. See answer 145 for an even/odd coordinate system that is useful for representing this problem internally.
( Wrapping the surface of a symmetrical polyhedron is a nice way to avoid awkward boundary conditions when arranging MacMahon-like tiles. Dario Uri devised 39 such problems in 1993, together with ingenious mechanical frames for building the results. Here, for example, are a rhombic triacontahedron (30 rhombuses) and a stellated dodecahedron (60 isosceles triangles), based on all possible ways to put distinct colors from {red, green, blue, yellow, black} on the edges. His report “Tessere di Mac Mahon su superfici tridimensionali” is online at [www.uriland.it](http://www.uriland.it) .)
136. The main challenge is to find a good way to represent the faces and edges of a dodecahedron. Perhaps the nicest is to represent the faces by vertices of an icosahedron, with the three-dimensional coordinates (0, (−1) b ϕ , (−1) c ) σ a , where ( x, y, z ) σ = ( z, x, y ); let abc stand for this face, for 0 ≤ a < 3 and 0 ≤ b, c < 2. A face is adjacent to its five nearest neighbors; we can represent the edge between abc and a ′ b ′ c ′ as the midpoint ( abc + a ′ b ′ c ′)/2. These 30 midpoints have two forms, either ab = (0, (−1) b ϕ , 0) σ a or a b c d \= 1 2 ( ( − 1 ) b , ( − 1 ) c ϕ , ( − 1 ) d ϕ 2 ) σ a . The corresponding XCC problem can now be formulated as usual, with 120 options for each face. For example, a typical option for face 201 is ‘ 201 01243 20:3 1100:0 2001:1 2101:2 1110:4 ’.
We can force the first tile to be in a particular place by default. Algorithm C needs only 9 megamems to solve the resulting problem, and produces 60 solutions.
Of course many of those solutions are equivalent. There are 120 transformations that preserve the dodecahedron and icosahedron as represented above, generated by a reflection matrix and two orthogonal matrices,
D \= ( − 1 0 0 0 + 1 0 0 0 + 1 ) , P \= ( 0 0 1 1 0 0 0 1 0 ) , Q \= 1 2 ( 1 − ϕ 1 / ϕ ϕ 1 / ϕ − 1 1 / ϕ 1 ϕ ) .
Applying any combination of these, and remapping the colors to agree with the default placement, gives an equivalent solution. It turns out, as Conway discovered by hand(!), that there are just three inequivalent solutions, having respectively 4, 6, and 12 automorphisms (hence occurring 30, 20, and 10 times in the output of Algorithm C ):
[See M. R. Boothroyd and J. H. Conway, Eureka: The Archimedeans’ Journal 22 (1959), 15–17, 22–23. Conway has named them the “ quintominal dodecahedra.”]
137. (a) This is an easy application of Algorithm C , with 14 + 12 items and 7 · (1 + 6 × 6) = 259 options. (Clever reasoning also allows it to be established by hand, with a search tree of size 15.)
(b) No. Again Algorithm C gives the answer quickly.
(c) Thousands of random trials indicate that about 93% of the ( 120 7 ) choices have no solution; about 5% have just one solution; about 1% have two solutions; and the remaining 1% have three or more.
(d) About 0.4% of all cases work, as in the example shown.
Historical notes: Milton Bradley Company introduced Drive Ya Nuts in 1970; the name of its inventor has unfortunately been forgotten. It was preceded by a much more difficult puzzle with 19 hexagons in three concentric rings, called Super Dom [H. Hydes, British Patent 149473 (19 August 1920)], and by several similar puzzles [H. Hydes and F. R. B. Whitehouse, British Patent 173588 (29 December 1921); G. H. Haswell, U.S. Patent 1558165 (20 October 1925)], featuring both kinds of edge-matching rules.
138. (a) We can name the tiles ABcd , ABdc , ACbd , ... , DCba . Assuming that ABcd is in the top left corner, a straightforward application of Algorithm C (with 2118 options involving 48 + 48 items) will output 42680 solutions, in 13 gigamems. As in other such problems, however, these outputs include many that are essentially the same. Up to 96 equivalent solutions are related by the operations of shifting any cell to the top-left position and/or flipping horizontally and/or flipping vertically, then remapping the colors. For instance, the given example has six automorphisms: We can shift it two columns right, then map A ↦ C ↦ D ↦ A , a ↦ c ↦ d ↦ a ; we can also shift two rows down, reflect left-right, then A ↔ D and a ↔ d . Hence it contributes 96/6 = 16 cases to the total of 42680. Altogether there are (79, 531, 5, 351, 6, 68, 12, 4) cases with respectively (1, 2, 3, 4, 6, 8, 12, 24) automorphisms, hence 79 + 531+5+351+6+68+ 12+4 = 1056 essentially different solutions. One with 24 symmetries is shown below (it leads to itself if we move right 1 and down 2, and/or reflect horizontally or vertically).
(b) Now Algorithm C , given 1089 options involving 49+60 items, quickly finds just six solutions — three different pairs related by transposition, each of which is symmetric under 90° rotation, all with heads and tails in the same places.
(c) Take any of the three solutions to (b), reflect it top-down, interchange heads with tails, and swap B ↔ D , b ↔ d . For example, the dual of the given solution is shown below. Alternating all-heads with all-tails, in checkerboard fashion, yields uncountably many tilings of the plane.
[These tiles are believed to have originated in 1990 with a puzzle called “Super Heads & Tails,” designed by Howard Swift and produced in a limited edition.]
139. (a) Say that two sets of nine are essentially the same if one can be obtained from the other by remapping the colors, and/or reflecting all of the pieces, and/or interchanging heads with tails. For example, 4! × 2 × 2 = 96 different choices of nine are equivalent to the set
By considering canonical forms, as in exercise 138(a) , we find 14124 equivalence classes, of which (13157, 882, 7, 78) have the respective sizes (96/1, 96/2, 96/3, 96/4).
(b) There are exactly (9666, 1883, 1051, 537, 380, 213, 147, 68, 60, 27, 29, 9, 24, 4, 8, 2, 5, 4, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1) classes with (0, 1, 2, ... , 27) solutions; the amazing one with 27 is represented by (∗) above. Two of the 1883 puzzles with unique solutions are particularly interesting because they have four automorphisms:
In each case we can flip the pieces and/or swap heads ↔ tails, then remap the colors to get the original tiles.
[This problem was first solved by Jacques Haubrich in 1996, who considered color remapping only (hence he had 54498 equivalence classes). Haubrich has collected 435 inequivalent puzzles, from around the world, that consist of nine tiles with two heads opposite two tails. But only 17 of them have all tiles different and all four objects different on each tile; for example, at least one tile such as ABcb is usually present. The first “pure” HHtt puzzle in his collection was made by the Hoek Loos company in 1974.]
140. (a) We save a factor of 4! by applying exercise 122 with v = a . Then Algorithm C gives respectively (10, 5, 6) solutions. The true numbers, however, are (5, 3, 3), because the shapes are symmetrical — and because the middle solution has an additional symmetry: It goes into itself if we rotate by 180° and permute the colors.
(b) The scaled-up versions of
are impossible. But we have
with respectively (4, 4, 3) solutions; and there are unique solutions to the other five:
(c) These shapes, with respectively (7, 9, 48, 2, 23, 28, 18) solutions, are a bit easier to handle. The “wave” has six solutions with central symmetry; the “bar” has four.
[Vertex-colored triangles have been named ‘ Trioker’ by Marc Odier; see French Patent 1582023 (1968), U.S. Patent 3608906 (1971), and the book Surprenant Triangles , which he published with Yves Roussel in 1976. They also are sold as Multimatch® IV.]
141. (a) Using exercise 122 with v = a yields respectively (138248, 49336, 147708) solutions in (1390, 330, 720) gigamems. Then we divide by (8, 4, 4) to remove symmetries of the board, getting (17281, 12334, 36927) solutions that are essentially distinct. [These numbers were first computed by Toby Gottfried in (1998, 1999, 2002). He had been interested in the puzzle ever since seeing the 5 × 5 version that was sold by Skor-Mor in 1970 under the name “ Nitty Gritty.” The puzzle is extremely difficult to solve by hand, in spite of the many solutions; Langford himself was unable to solve the 3 × 8 case.]
The 12334 solutions for 4 × 6 include 180 that have matching colors at the left and right. Each of these patterns therefore tiles a “cylinder”; and the 180 form 30 families of 6 that are equivalent to each other by rotating the cylinder. Similarly, 1536 of the 36927 solutions for 3 × 8 are cylindrical, making 192 families of 8. The example illustrated is one of 42 that have the same solid color at both left and right.
(b) Any solution can be used to tile the plane in combination with its mirror reflections and its 180° rotation (which is a reflection of a reflection).
The 17281 solutions include 209 for which the hole is surrounded by a single color. Six of these have matching colors at two opposite sides; the one illustrated will tile the plane in conjunction with its mate, which is obtained by swapping b ↔ c .
The 4 × 6 example illustrated is the unique solution for which both pairs of opposite sides induce exactly the same color partition (the restricted growth strings 0121120 and 01220). Thus it too will tile the plane together with its b ↔ c mate.
[Vertex-matched squares, with incomplete sets of tiles, first appeared in puzzles devised by E. L. Thurston, U.S. Patents 487797 (1892), 490689 (1893).]
142. Each boundary between the square cells containing octagons now has two secondary items that receive color. For example, a typical option for Algorithm C is now ‘10 aabc a 10 : a r 10 : a l 11 : b a 11 : b b 21 : c l 21 : c r 20 : a b 20 : a ’, where a xy , b xy , l xy , and r xy denote the half edges above, below, left, and right of ( x, y ). The number of solutions, again using exercise 122 with v = a , is 2 · (132046861, 1658603, 119599) in cases (i), (ii), (iii), found in (2607, 10223, 77) gigamems. Case (i) includes 2 · (193920, 10512, 96) “cylindrical” arrangements in which the colors match at top/bottom, left/right, both; one of the 96 “ toroidal” examples is shown. Case (ii) includes 2 · 5980 cylindrical arrangements that match at left/right. Case (iii) has no cylindrical examples.
[Many other possibilities arise, because neighboring octagons can match without lying in a square grid. Kadon Enterprises offers attractive sets called ‘ Doris®’.]
143. (a) simplex (8, 6, 8, 2, 0, 0, 0); simplex (7, 4, 7, 3, 0, 0, 0); simplex (5, 5, 5, 4, 0, 0, 0).
(b, c) Nonnegative integers x 0 x 1 x 2 x 3 x 4 x 5 define such a polygon if and only if the boundary path returns to its starting point, which means that x 0 + x 1 = x 3 + x 4 and x 1 + x 2 = x 4 + x 5 . Rotating by 60° replaces x 0 x 1 x 2 x 3 x 4 x 5 by x 5 x 0 x 1 x 2 x 3 x 4 ; reflecting left ↔ right replaces x 0 x 1 x 2 x 3 x 4 x 5 by x 0 x 5 x 4 x 3 x 2 x 1 . Hence we get a canonical form by insisting that x 0 ≥ x 3 ≥ x 5 ≥ x 1 : Every sequence of nonnegative integers ( a, b, c, d ) with a ≥ b ≥ c ≥ d defines the boundary x 0 x 1 x 2 x 3 x 4 x 5 of a unique convex triangular polygon , where x 0 = a , x 1 = d , x 2 = a − b + c , x 3 = b , x 4 = a − b + d , x 5 = c . Furthermore, that polygon contains exactly N = ( a + c + d ) 2 − b 2 − c 2 − d 2 triangles.
Given N , the following algorithm visits all relevant ( a, b, c, d ). For c = 0, 1, ... , while 2 c 2 ≤ N do the following: For d = 0, 1, ... , while d ≤ c and 2 c ( c +2 d ) ≤ N , let x = N + c 2 + d 2 . If x mod 4 ≠ 2, for every divisor q of x such that q ≡ x/q (modulo 2) and q 2 ≤ x , set a ← ( x/q + q )/2− c − d and b ← ( x/q − q )/2. Visit ( a, b, c, d )if a ≥ b and b ≥ c .
When N = 24 this algorithm visits six ( a, b, c, d ), namely (7, 5, 0, 0), (5, 1, 0, 0), (12, 12, 1, 0), (6, 6, 2, 0), (2, 2, 2, 2), (4, 4, 3, 0). The fourth, sixth, and second are the shapes of exercise 140 . The other three cannot be tiled properly with Langford’s 24 tiles.
[See OEIS sequence A096004, contributed by P. Boddington in 2004.]
(d) Yes. One way is simplex ( a + c + d, a + c, a + d, a − b + c + d , 0, 0, 0).
144. The constraints are severe, because a solid color is needed at transitions between regimes. Algorithm C (with v = a as in answer 142 ) quickly finds 2·102 solutions to (ii). But surprisingly many arrangements arise in case (i); Algorithm C finds 2 · 37586004 of them, not so quickly (643 teramems)!
(These tiles suggest many intriguing questions. For example, suppose we restrict consideration to making a big hexagon from 24 small ones. There are 2 24 ways to specify whether each position should be matched at vertices or edges; but very few of those specifications are actually realizable. Can the realizable ones be nicely characterized?)
145. Suppose 0 ≤ i ≤ l , 0 ≤ j ≤ m , and 0 ≤ k ≤ n . Let (2 i , 2 j , 2 k ) represent vertex ( i, j, k ); let ( u + v )/2 represent the edge between adjacent vertices u and v ; let ( a + b )/2 represent the face containing parallel edges a and b ; let ( e + f )/2 represent the cell containing parallel faces e and f . Thus, the triple ( x, y, z ) represents a vertex, edge, face, or cell when it has respectively 0, 1, 2, or 3 odd coordinates.
For example, (2 i , 2 j +1, 2 k ) represents the edge between vertices ( i, j, k ) and ( i, j +1, k ); (2 i +1, 2 j , 2 k +1) represents the face whose vertices are ( i, j, k ), ( i +1, j,k ), ( i, j, k +1), ( i +1, j,k +1); and (2 i +1, 2 j +1, 2 k +1) represents the cell whose eight vertices are ( i +(0 or 1), j +(0 or 1), k +(0 or 1) ) .
Notice that ( a + b )/2 represents the vertex between adjacent parallel edges a and b ; ( e + f )/2 represents the edge between adjacent parallel faces e and f ; ( p + q )/2 represents the face between adjacent cells p and q .
(We can use a similar convention in two dimensions, as an alternative to the ‘H’ and ‘V’ items in situations like answer 109 .)
146. (a) Each color occurs four times on the “visible” faces and at most twice on the “hidden” faces. So the five adjacencies account for all six occurrences of five colors.
(b) For every partition of { a , b , c , d , e , f } into three pairs { u, u ′}, { v, v ′}, { w, w ′}, there are two chiral cubes having u opposite u ′, v opposite v ′, w opposite w ′. Order the colors so that u < u ′, u < v , v < v ′, v < w , v < w ′; there are 30 ways to do this. The cube named uu ′ vv ′ ww ′ is the one that can be placed with u on top, u ′ on the bottom, v in front, v ′ in the back, w at left, w ′ at the right. For example, the cubes in (∗) are named aebfcd , acbfde , acbdef , afbdec , abcedf , aebcfd .
(c) We can set this up for Algorithm C by specifying 6 · 30 · 24 options, one for each cube position, cube name, and cube placement. There are 6 primary items for the positions; 30 secondary items for the names; 4 · 6 primary items u c , d c , f c , b c for colors on the top, bottom, front, and back, where c ∈ { a , b , c , d , e , f }; and 6 secondary items h k for the colors hidden between positions k and k + 1. For example, the leftmost cube in (∗) corresponds to the option ‘1 aebfcd u a d e f b b f h 0 : c h 1 : d ’.
If we eliminate all but one option for position 1 (thus saving a factor of 720), there are 2176 solutions. Each solution is, however, potentially equivalent to 95 others, because there are 16 possible rotations/reflections together with 6 cyclic permutations (followed by remapping the colors of the leftmost cube). For example, the solution illustrated has 12 such automorphisms. Further study shows that only 33 solutions are “ essentially different” — of which (17, 9, 3, 1, 3) have (1, 2, 4, 6, 12) automorphisms.
(d) Yes, in lots and lots of ways. The 720 · 2176 solutions obtained without fixing the leftmost cube involve 15500 different 6-tuples of cubes; and the exact cover problem for which those 6-tuples are the options has 163,088,368 solutions.
[This problem was posed by Martin Gardner in Scientific American 204 , 3 (March 1961), 168–174 (long before the “Instant Insanity” craze), and he extended it to question (c) in Scientific American 239 , 3 (September 1978), 26. A solution to (d) that involves five symmetrical arrangements was found by Zoltan Perjés in 1981; see Gardner’s book Fractal Music, Hypercards, and More (1992), 97.]
147. (a) The “ even/odd coordinates” of exercise 145 are ideal for representing the cube positions and the faces between them. For example, the colors in the 1 × 2 × 2 brick that was illustrated with the exercise are nicely represented by the 3 × 5 × 5 array
[ ...... . a . a . ...... . a . a . ...... ] [ . d . d . c . e . c . f . f . c . d . c . e . e . ] [ ..... . b . b . ..... . b . b . ...... ] ,
where entry (0, 1, 1) = a , entry (1, 0, 1) = d , entry (1, 1, 0) = c , ... , entry (2, 3, 3) = b . The cubes in positions (1, 1, 1), (1, 1, 3), (1, 3, 1), (1, 3, 3) of this example have the respective names abcedf , abcefd , abcdfe , abcdef . In a similar way an l × m × n brick has colors represented by a (2 l +1) × (2 m +1) × (2 n + 1) tensor; and the tensor
[ ........... . a . a . a . a . a . ........... . a . a . a . a . a . ........... . a . a . a . a . a . ........... ] [ . c . c . c . c . c . b . f . d . f . d . b . e . e . b . b . f . b . c . d . f . e . b . f . f . e . d . d . b . e . d . b . e . b . c . c . c . c . c . ] [ ........... . d . b . e . e . e . ........... . d . b . c . c . c . ........... . d . b . f . f . f . ........... ] [ . c . c . c . c . c . b . f . d . b . f . b . e . e . f . d . d . b . c . d . e . f . b . f . f . b . b . e . b . e . d . e . d . b . c . c . c . c . c . ] [ ........... . a . a . a . a . a . ........... . a . a . a . a . a . ........... . a . a . a . a . a . ........... ]
represents a “magnificent brick” whose faces are colored a , b , c (each twice).
(b) Let there be lmn primary items (2 i + 1)(2 j + 1)(2 k + 1) for the cube positions, 30 secondary items for the cube names, and lm ( n +1) + l ( m +1) n +( l +1) mn secondary items xyz for the cube faces, where 0 ≤ x ≤ 2 l , 0 ≤ y ≤ 2 m , 0 ≤ z ≤ 2 n , ( x mod 2) + ( y mod 2) + ( z mod 2) = 2. For example, the option for position 135 in solution (a) is ‘135 acbefd 035: a 125: b 134: d 136: f 145: e 235: c ’. We also introduce six primary items to enforce the rule about solid colors on the brick’s faces. Each of them has six options, one for each color c ; for example, the options for the top face are ‘top 101: c 103: c 105: c 107: c 109: c 301: c 303: c 305: c 307: c 309: c ’. The number of solutions is reduced by a factor of 720 if we remove all but one of the 720 options for position 111.
It turns out that the brick’s face colors have an interesting property in every solution: A repeated face color occurs only on opposite, parallel faces. The example 1×2×2 brick has face colors ab × cc × de ; the 2×3×5 brick in (a) has colors aa × bb × cc .
A brick is considered to be essentially the same as any other that’s obtained from it by rotation, reflection, and/or permutation of colors. The example 1 × 2 × 2 brick above has 8 automorphisms; for example, we can reflect top ↔ bottom and swap d ↔ e . The 2 × 3 × 5 brick above has 2 automorphisms: The nontrivial one reflects front ↔ back, top ↔ bottom, e ↔ f .
There’s another 1 × 2 × 2 brick, whose face colors are ab × cd × ef . It has 16 auto-morphisms. Thus it occurs only once among the three solutions found by Algorithm C when ( l, m, n ) = (1, 2, 2); the other two solutions are equivalent to each other.
There’s a unique 1 × 2 × 3 brick, easily found by hand. It has colors ab × cc × dd , and 8 automorphisms. (Clearly 1 × m × n is possible only if mn ≤ 6.)
The 2 × 2 × 2 bricks are especially interesting because MacMahon himself and his friend J. R. J. Jocelyn considered this case (with six different face colors), when they introduced the 30 6-color cubes in U.K. Patent 8275 of 1892. They observed that one can choose any “prototype” cube and replicate it at twice the size, by assembling eight of the other cubes. This can be done in two ways — using, in fact, the same eight cubes. But those two solutions are isomorphic, in 24 different ways. [See Proc. London Math. Soc. 24 (1892), 145–155. Their eight-cube puzzle was sold under the name “ Mayblox.”]
Gerhard Kowalewski, in Alte und neue mathematische Spiele (1930), 14–19, found a 2 × 2 × 2 brick with face colors aa × bb × cd . Ferdinand Winter, in Mac Mahons Problem: Das Spiel der 30 bunten Würfel (1933), 67–87, found another, with face colors aa × bc × de . And there’s also a fourth solution, having Winter’s face colors:
M a c M a h o n K o w a l e w s k i [ ..... . a . a . ..... . a . a . ..... ] [ . c . c . e . b . f . f . e . e . b . f . d . d . ] [ ..... . d . d . ..... . c . c . ..... ] [ . c . c . e . a . f . f . e . e . a . f . d . d . ] [ ..... . b . b . ..... . b . b . ..... ] ; [ ..... . a . a . ..... . a . a . ..... ] [ . b . b . c . e . d . f . f . c . e . d . b . b . ] [ ..... . d . c . ..... . d . c . ..... ] [ . b . b . c . f . d . e . e . c . f . d . b . b . ] [ ..... . a . a . ..... . a . a . ..... ] ; W int e r F o u r t h [ ..... . a . a . ..... . a . a . ..... ] [ . b . b . d . c . e . e . d . d . f . e . c . c . ] [ ..... . f . f . ..... . b . b . ..... ] [ . b . b . d . c . e . e . d . d . f . e . c . c . ] [ ..... . a . a . ..... . a . a . ..... ] ; [ ..... . a . a . ..... . a . a . ..... ] [ . b . b . d . f . e . e . d . d . f . e . c . c . ] [ ..... . c . c . ... . b . b . ..... ] [ . b . b . d . f . e . e . d . d . f . e . c . c . ] [ ..... . a . a . ..... . a . a . ..... ] .
These solutions have respectively (24, 8, 4, 8) automorphisms; hence Algorithm C finds 48/24 + 48/8+48/4+48/8 = 26 solutions to the case l = m = n = 2.
Larger cases have solutions that are, perhaps, even more remarkable; but there’s room here for only a brief summary. For each feasible case of l × m × n bricks with particular face colors, we list the number of different solutions with (1, 2, 4, 8) automorphisms. Case 2 × 2 × 3 : aa × bb × cc , (0, 0, 1, 0); aa × bc × dd , (0, 2, 6, 1); aa × bc × de , (0, 1, 6, 0); ab × cd × ee , (0, 1, 2, 0); ab × cd × ef , (0, 0, 2, 0). Case 2 × 2 × 4 : aa × bb × cc , (0, 0, 1, 0); aa × bb × cd , (0, 0, 1, 0); aa × bc × dd , (0, 3, 4, 2); aa × bc × de , (0, 11, 14, 2); ab × cd × ee , (0, 2, 2, 3); ab × cd × ef , (0, 1, 1, 1). Case 2 × 2 × 5 : aa × bc × dd , (0, 5, 4, 0); aa × bc × de , (0, 18, 9, 0); ab × cd × ee , (0, 0, 1, 0); ab × cd × ef , (0, 2, 5, 1). Case 2×3×3 : aa × bb × cc , (2, 15, 4, 0); aa × bb × cd , (4, 8, 1, 0); aa × bc × de , (1, 4, 1, 2). Case 2×3×4 : aa × bb × cd , (6, 8, 1, 0); aa × bc × de , (0, 6, 0, 0); ab × cc × dd , (0, 4, 2, 0); ab × cc × de , (0, 2, 0, 0); ab × cd × ee , (0, 2, 0, 0); ab × cd × ef , (0, 7, 0, 0). Case 2 × 3 × 5 : aa × bb × cc , (0, 2, 0, 0).
(Conspicuous by its absence is the case l = m = n = 3. There’s no 3 × 3 × 3 brick, although we can come close: A 3 × 3 × 3 without a corner can be made from 26 of the 30; or without the middle cube and the one above it, from 25.)
148. There are eleven such cubes, and they can be matched in many pleasant ways:
[ ....... ....... ....... ... c ... ...... ...... ...... ] [ ...... ...... ... a ... .. a . c .. ... c ... ...... ...... ] [ ...... . a . b . a . ...... . b . a . b . ...... . a . b . a . ...... ] [ . a . a . a . a . b . a . c . c . b . c . a . b . a . c . b . a . a . a . c . b . c . c . c . c . ] [ ...... . b . c . b . ...... . c . b . c . ...... . b . c . b . ...... ] [ ...... ...... ... b ... .. b . c .. ... c ... ...... ...... ] [ ...... ...... ...... ... c ... ...... ...... ...... ]
149. Label the vertices with nonnegative barycentric coordinates wxyz , where w + x + y + z = 3. Also label the ten unit tetrahedra with barycentric coordinates stuv , where s + t + u + v = 2; the vertices wxyz of tetrahedron stuv are then stuv + {1000, 0100, 0010, 0001}. Introduce ten primary items stuv for the tetrahedra, and ten more abcd , abdc , abce , adec , ... , bcde , bced for the different colorings. And introduce 20 secondary items wxyz for the vertices.
Then the admissible vertex colors are the solutions to the XCC problem with 1200 options ‘ stuv α v 1 : p 1 ... v 4 : p 4 ’, where α is a coloring, v 1 v 2 v 3 v 4 are the vertices of stuv , and p 1 p 2 p 3 p 4 is an even permutation of α ’s colors. Curiously, this problem has 2880 solutions (found in 500 M μ ) — and they’re all equivalent to the one below, under the 5! 4! = 2880 automorphisms present.
(This problem was posed in 2015 by J. McComb, and solved by J. Scherphuis.)
150. Notice that there are fourteen distinct pieces, with four pairs of two. So we use Algorithm M , with 14 primary items for pieces and 64 for cells. We also introduce secondary items for edges between cells, with colors to indicate the presence or absence of links. The final two pieces must obviously be adjacent, hence we can combine them into a “super-piece” of size 11; then all interfaces between adjacent cells are identical. We can remove symmetry by forcing the super-piece to be in one of 18 positions.
Then 43 solutions are found, in 7 G μ . Here are some typical examples:
Solution (i) appears in Hoffmann’s Puzzles Old and New , puzzle 3–18. Solution (iii) avoids most of the lower left quadrant, and solution (iv) avoids the entire right column. If we ignore blank spaces, the links form eight different paths, all of length 34. Paths (i), (ii), (iii), (iv) occur in respectively 1, 15, 9, 3 of the 43 solutions. [The Endless Chain Puzzle was distributed circa 1887 by Reason Manufacturing Company.]
151. (a) The key idea is to start by factoring this problem, by considering only the task of edge-matching between adjacent dominoes, while ignoring the loop details.
Algorithm M applies, with primary items 1–9 and a–i for the distinct on-off patterns of attachment points, as well as primary items ij for each cell to be covered (0 ≤ i < 8, 0 ≤ j < 9), and two special primary items H, V. There are 63+64 secondary items h ij and v ij , to indicate path/nopath at internal attachment points. Typical options:
‘a 10 11 v 12 :1 h 21 :1 h 20 :1, h 10 :0 h 11 :1 H’,
‘a 11 21 h 11 :0 v 12 :0 v 22 :1, h 31 :1 v 21 :1 v 11 :1 V’;
the goal is to find an exact cover with multiplicities 1 for patterns 1–9, multiplicities 3 for patterns a–i, and multiplicities 18 for H and V. (There are millions of solutions.)
Once that task is solved, we need to assign the actual dominoes whose subpaths jointly define a single loop. A (nontrivial) program, whose structure has a lot in common with Algorithm X and exercise 413 , will find such assignments in microseconds (although a full day might be needed to actually write that program).
(b) Now H and V should have multiplicities 32 and 4. (Also, we can save about half of Algorithm M ’s running time by omitting vertical placements at odd height.) The algorithm finds 6420 solutions; suitable domino assignments are then found in a flash.
[These 36 path dominoes were first studied by Ed Pegg Jr. in 1999, and first placed into a single-loop 8 × 9 array by Roger Phillips later that year.]
152. This (factored) problem is like the previous one, but with an additional pattern j of multiplicity 11, and a blank pattern of multiplicity 1, but without H or V. One needs to be lucky to find a solution; the author struck it rich with Algorithm M after 35.1 T μ .
[Notice that exactly 32 of the 48 path dominoes have no crossings. Thus it is irresistible to try to place them on a chessboard, so as to form a single noncrossing loop. Unfortunately, Algorithm M tells us that such a mission is impossible, even with multiple loops, because the corresponding factored problem has no solution. Something interesting, however, can surely be done with those 32.]
153. (a) Algorithm M quickly verifies the uniqueness of the solution below, if we add a blank monomino of multiplicity 4. [“ Line puzzles” like this were invented by Bill Darrah; several of his ingenious designs were made by Binary Arts in 1994 and 1999.]
(b) There are 30 patterns, three for each distinct choice of three connection points.
(c) Trials with random choices of respectively (2, 2, 4) sets of (2, 3, 4) distinct connection points usually give no solutions at all. But one of the author’s first 1000 trials was suitable, and it led to a nice puzzle whose solution is shown.
154. The integer solutions to P ( n ) = n ( n +1) 2 ( n +2)/12 = m 2 involve perfect squares u 2 and v 2 with v 2 ≈ 3 u 2 . If | v 2 − 3 u 2 | is sufficiently small, v/u must be a convergent to the continued fraction 3 \= 1 + / / 1 , 2 , 1 , 2 , 1 , 2 , 1 , 2 , ... / / (see exercise 4.5.3–42).
Pursuing this idea, let θ \= 2 + 3 , θ ^ \= 2 − 3 , 〈 a n 〉 \= 〈 ( θ n + θ ^ n / 2 ) 〉 \= 〈 1 , 2 , 7 , 26 , 97 , ... 〉 and 〈 b n 〉 \= 〈 ( θ n − θ ^ n ) / ( 2 3 ) 〉 \= 〈 0 , 1 , 4 , 15 , 56 , ... 〉 . Notice that a n 2 \= 3 b n 2 + 1 ; ( a n + 3 b n ) 2 = 3( a n + b n ) 2 − 2. We find that P ( n ) is a perfect square if and only if n \= 6 b m 2 for some m (thus n = 0, 6, 96, 1350, 18816, ... ) or n = ( a m + 3 b m ) 2 for some m (thus n = 1, 25, 361, 5041, 70225, ... ).
[See R. Wainwright, in Puzzlers’ Tribute (A K Peters, 2002), 277–281; also Erich Friedman’s survey in erich-friedman.github.io/mathmagic/0607.html .]
155. (a) Algorithm M finds 8 · 7571 solutions, in 60 G μ .
(b) The maximum is 35 (not easy to find!), and the minimum is 5. [This exercise was suggested by Robert Reid, who found a minimum solution by hand in 2000.]
156. At level l of backtracking, branch on all ways to fill the leftmost unfilled cell of the topmost unfilled row. Even though no MRV heuristic is used, this method needs just 2.0 teramems (and negligible memory) to find 18656 solutions. The search tree has 61636037366 nodes.
We can save a factor of 8 by removing symmetry: The 1 × 1 square can be confined to cells ( i, j ) with i < 18 and j ≥ 35− i . Furthermore, if ( i, j ) is on the diagonal ( j = 35− i ), the context of the 1×1 square must be either
or
, and we can insist on the former. Now we find 2332 solutions (and 6975499717 nodes), in just 235 gigamems.
By contrast, the MCC problem (61) for n = 8 has 1304 items and 7367 options of total length 205753, when we restrict the options of #1 to i < 18 and j ≥ 35 − i . It needs 490.6 teramems to find 2566 solutions; postprocessing reduces that number to 2332, because 468 of those 2566 have #1 in position ( i, j ) with j = 35 − i .
We conclude that a dancing-links approach is decidedly not the method of choice for this partridge problem; straightforward backtracking with bitwise operations is more than 2000 times faster! Indeed, we might consider ourselves fortunate to pay “only” a 2000-fold cost penalty, since each of the 841 options for #8 in (61) contributes 65 nodes to doubly linked lists. Such updating and downdating keeps the dancers extremely busy.
[ Historical notes: The 2332 solutions for n = 8 were first found by Bill Cutler in 1996, using a refinement of the backtrack approach described above. At that time no solutions for n < 11 had been known, although Wainwright knew how to solve 12 ≤ n ≤ 15 in 1981; S. T. Ahearn and C. H. Jepsen had presented constructions for 11 ≤ n ≤ 33 in Crux Mathematicorum 19 (1993), 189–191. The puzzle can surely be solved for all n > 7, but no proof is yet known.]
157. Algorithm M readily shows the nonexistence of perfect packings, but the backtrack method of exercise 156 is much better to show that we can’t pack all but one 2 × 2. That method also shows that we can pack all but two of them:
158. The following solutions can be proved optimum with bitwise backtracking as in exercise 156 :
159. Replace # by four primary items # 0 , # 1 , # 2 , # 3 representing “ quadrants,” and use # 2 ⌊ i / 4 ⌋ + ⌊ j / 4 ⌋ in place of # in (64). Then partition into ten separate cases, in which the multiplicities m 0 m 1 m 2 m 3 of # 0 # 1 # 2 # 3 are respectively (2012, 2111, 2120, 3002, 3011, 3020, 3110, 4010, 4001, 5000). (Omit options containing # k of multiplicity 0.) These cases produce (134, 884, 33, 23, 34, 1, 16, 0, 22, 0) solutions, in (95, 348, 60, 23, 75, 8, 19, 2, 10, 0) megamems. (Notice that 4 · 134 + 4 · 884 + 8 · 33+4 · 23 + 8 · 34 + 8 · 1+4 · 16+8 · 0+4 · 22+4 · 0 = 4860.) The running time has decreased by a factor of 20.
[For larger values of n we could divide the cells into nine regions: eight octants, plus a special region containing the diagonals (and the middle row, column if n is odd).]
160. There are 589 components, among which are 388 isolated vertices and one giant of size 3804. The other 200 components have sizes ranging from 2 to 12. (For example, the first three solutions in (65) belong to the giant component; the other belongs to a component of size 8.)
161. In general, consider the problem of finding all the m-vertex dominating sets of a graph G ; the n × n m - queen problem is the special case where G is the queen graph of order n. Then the options (64) have the form ‘# v v 1 ... v t ’, where { v 1 ,..., v t } are the vertices adjacent to v, and # is a special primary item of multiplicity m .
Variant (i) is equivalent to asking for all kernels of size m (all of the maximal independent sets). Let there be a secondary item e for every edge in G; the options are then ‘# v v 1 ... v t e 1 ... e t ’, where e j is the edge between v and v j . An 8 × 8 chessboard has 8 · 91 = 728 kernels of size 5. (It also has 6912, 2456, and 92 kernels of sizes 6, 7, and 8; see exercise 7.1.4–241(a).)
For variant (ii) we simply shorten v’s option to ‘# v 1 ... v t ’; some other option must then cover v . Exactly 352 of the 5-queen solutions satisfy (ii).
Variant (iii) seems a bit harder to formulate. Let there be a secondary item v ^ for each vertex v . The option for choosing v can then be ‘ # v v ^ : 1 v 1 . . . v t u ^ 1 : 0 . . . u ^ s : 0 ’ , where { u 1 ,..., u s } = V \{ v , v 1 ,..., v t } is the set of vertices not adjacent to v . The 8 × 8 chessboard has 20 clique-dominators of size 5.
[Chapter 10 of the classic work Mathematische Unterhaltungen und Spiele by W. Ahrens (1910) is an excellent survey of early work on queen-domination problems.]
162. Formulate these as MCC problems, by starting with the ordinary options for the n queens problem (see (23)), then adding additional options such as ‘# r j c k +1 a j + k +1 b j − k −1 r j +1 c k +3 a j + k +4 b j − k −2 r j +2 c k a j + k +2 b j − k +2 r j +3 c k +2 a j + k +5 b j − k +1 ’ to represent a contained Q 4 , for 1 ≤ j , k ≤ n − 3. Here # is a new primary item, which is given the desired multiplicity, and we’ll use the sharp preference heuristic.
-
(a) 15; one can, in fact, get disjoint Q 4 and Q 5 in a Q 15 .
-
(b, c) 17. Put a queen in the center, make a pinwheel! [See Ahrens (1910), 258.]
-
(d) 22; see below. Algorithm M proves n = 21 impossible after 150 megamems.
-
(e) 16; there are four essentially different solutions.
-
(f) 19; see below. Less than 200 M μ to show that n = 18 is too small.
-
(g) 20(!). Once you know this, Algorithm X will find all 18 solutions in 2 M μ .
-
(h) 22; there are 28 essentially different solutions.
-
(i) 25; see below. (After 180 megamems, we learn that n = 24 doesn’t work.)
163. Sometimes Algorithm M is called on to choose zero or more items from an empty list. Then it sets FT[ l ] ← i and x l ← i , where i is the item whose list is empty; but step M5 doesn’t actually tweak anything. The peculiar rule in (71) ensures that step M8 doesn’t actually untweak anything as we backtrack.
164. If x j ≤ N , node x j is the header for item x j ; there’s no further option for such j .
[A good implementation will also extend answer 12 , so that the relative positions of each x j in the search tree are identified. For this purpose one can add a new array SCORE , setting SCORE[ l ] ← θ i and FT[ l ] ← 0 at the end of step M3. When printing the jth step x j of a solution, the old answer 12 is used if FT[ j ] = 0; otherwise that answer is modified as follows: If x ≤ N and ( x = FT[ j ] or x = TOP(FT[ j ]) ), print ‘ null NAME( x ) ’; otherwise print option x as before. Conclude by looping with i ← 0, q ← FT[ j ] rather than i ← TOP( x ) , q ← DLINK( i ) ; report ‘ k of SCORE[ j ] ’ rather than ‘ k of LEN( i ) ’.]
165. (a) To cover 2 of 4, we have 3 choices at the root, then 3 or 2 or 1 at the next level, hence (1, 3, 6) cases at levels (0, 1, 2). To cover 5 of 7, there are (1, 3, 6, 10, 15, 21) cases at levels (0, 1, ... , 5). Thus the search profile with item 1 first is (1, 3, 6, 6 · 3, 6 · 6, 6 · 10, 6 · 15, 6 · 21). The other way is better: (1, 3, 6, 10, 15, 21, 21 · 3, 21 · 6).
(b) With item 1 first the profile is ( a 0 , a 1 , ... , a p , a p a 1 , ... , a p a q ), where a j \= ( j + d d ) . We should branch on item 2 first because a p +1 < a p a 1 , a p +2 < a p a 2 , ..., a q < a p a q − p , a q a 1 < a p a q − p +1 , ... , a q a p −1 < a p a q −1 . (These inequalities follow because the sequence 〈 a j 〉 is strongly log-concave: It satisfies the condition a j 2 > a j − 1 a j + 1 for all j ≥ 1. See exercise MPR–125.)
166. (a) The “ monus” operation x ∸ y = max( x − y, 0) is good for situations like this:
θ p \= ( LEN( p ) +1) ∸ ( BOUND( p ) ∸ SLACK( p ) ).
(b) It’s better to branch on p' (although this may be counterintuitive).
[The author’s implementation of step M3 breaks ties by first preferring an item with smaller SLACK , then preferring longer LEN when the SLACK s are equal. Thus, his MRV replaces answer 9 by this: Set θ ← ∞, p ← RLINK( 0 ) . While p ≠ 0, do the following: Set λ ← θ p ; if λ < θ or ( λ = θ and SLACK( p ) < SLACK( i ) ) or ( λ = θ and SLACK( p ) = SLACK( i ) and LEN( p ) > LEN( i ) ) set θ ← λ , i ← p ; then set p ← RLINK( p ) .]
167. Step M3 isn’t precisely defined; therefore any change to v p could possibly affect the behavior. But let’s assume that step M3 is implemented as in exercise 166 .
Even so, there can be differences. A minor difference arises, for instance, if there are no options: A primary item with multiplicity [0 .. 1] will be deactivated by covering in step M4; with multiplicity [0 .. 2], it will become inactive at the end of step M5.
There can also be more significant differences. Suppose there’s just one option, ‘ a ’, and one primary item. If a has multiplicity 1, we simply cover a as in Algorithm X . But if a has multiplicity [1 .. 2], we’ll do some tweaking and untweaking — even entering a new level, and taking a null branch there.
On the other hand, the differences can’t get much worse. Let BOUND 0 ( p ) and BOUND 1 ( p ) denote the values of BOUND( p ) when the upper bound v p has respectively been specified as M p and M p + δ . If the same options are chosen, we’ll have BOUND 1 ( p ) = BOUND 0 ( p ) + δ throughout the algorithm, because BOUND( p ) is adjusted appropriately whenever the algorithm recursively reduces the problem by removing an option. Also SLACK 1 ( p ) = SLACK 0 ( p ) + δ . One can then prove, by induction on the computation, that the same options are indeed chosen (possibly with different amounts of tweaking).
Any two values of v p that are M p + 2 or more will be totally equivalent.
168. Introduce a new primary item ‘!’ and a new secondary item ‘+’. Replace the two copies of α by ‘! +:0’, ‘! α ’, ‘ α +:1’. [Similarly, three copies of α can be replaced by ‘! +:0’, ‘! α ’, ‘!! ++:0’, ‘!! α +:1’, ‘ α ++:1’, after introducing ‘!!’ and ‘++’.]
169. Let there be one primary item, #, together with one secondary item for each vertex. And let there be one option, ‘# v v 1 :0 ... v d :0’ for each vertex v , where v 1 through v d are the neighbors of v . Finally, let # have multiplicity t . [Notice that the secondary items in this construction are colored either with 0 or not at all!]
170. Introduce the primary item ! v for each vertex, and give it d + 1 options: ‘# ! v v :1 v 1 :0 ... v d :0’, ‘ ! v v :0 v 1 :1’, ‘ ! v v :0 v 1 :0 v 2 :1’, ..., ‘ ! v v :0 v 1 :0 ... v d −1 :0 v d :1’.
171. Let there be ten primary items v , for 0 ≤ v < 10; also fifteen primary items # uv , for each edge u −−− v , where the edges are 0 −−− 1 −−− 2 −−− 3 −−− 4 −−− 0, 0 −−− 5, 1 −−− 6, 2 −−− 7, 3 −−− 8, 4 −−− 9, and 5 −−− 7 −−− 9 −−− 6 −−− 8 −−− 5. Let there be 26 · 10 secondary items a v through z v , for 0 ≤ v < 10; also 26 · 30 secondary items a uv through z uv , for u ― v ; also a secondary item w for each word in, say, WORDS (1000). There are 26 options, ‘# uv a u :l a v :l’ through ‘# uv z u :l z v :l’, for each edge. And there are 10 options for each word; for example, the option for added at vertex 0 is ‘0 a 0 :1 b 0 :0 c 0 :0 d 0 :1 e 0 :1 f 0 :0 ... z 0 :0 a 02 a 03 a 06 a 07 a 08 a 09 d 02 ... e 09 added ’.
Every solution will be obtained at least 120 times, because the Petersen graph has 120 automorphisms, and the # uv options might apply more than once. But symmetry can be broken by introducing additional secondary items for pairwise ordering, or by modifying Algorithm C to choose the labels of 0, 1, and 3 first (see exercise 122 ).
There are two solutions in WORDS (834), namely muddy , thumb , books , knock , ended , apply , fifth , grass , civil , ( refer or fewer ).
172. A construction analogous to answer 170 generates all solutions to the weaker problem where connectivity isn’t tested; it’s easy to remove the unconnected solutions from Algorithm M ’s output. Consider cycles first: There are 1 + ( d 2 ) options for each primary item ! v , namely ‘ ! v v :0’ and ‘# ! v v :1 v 1 : a 1 ...v d : a d ’, where a 1 ...a d is a binary vector with a 1 + ··· + a d \= 2. We can safely omit options where v i ––– v j and a i \= a j \= 1; they force a triangle. For the path problem, the starting vertex should have d options, with a 1 + ··· + a d \= 1, not 2. The options for all other vertices that aren’t adjacent to the starting vertex should have d additional options ‘# E ! v v :1 v 1 : a 1 ... v d : a d ’, with a 1 +···+ a d \= 1, where E is a new primary item signifying the end vertex.
(a) Paths of length l are obtained when the multiplicity of # is set to l +1.
First let’s restrict consideration to paths that start in the corner cell (0, 0). Then every essentially distinct path occurs twice — reflected about the diagonal. (i) There are 16 distinct snake king paths of length 31 from a given corner, found in 270 G μ . One of them, illustrated below, also ends at a corner; hence it occurs four times, not two — twice in each direction. These paths are optimum, because we can divide the board into sixteen 2 × 2 subsquares, each of which can contain at most two kings. (ii) A single run, with the multiplicity of # set to [32 .. 33], suffices to find the 13 distinct knight solutions of length 31 in 58 G μ , simultaneously showing that length 32 is impossible. One of the most remarkable solutions is shown below. (iii) With bishops we should first eliminate all squares of the wrong parity, because they cannot be connected to the start. Then the 32 solutions of length 12 are found in just 54 M μ . (It’s not difficult to prove by hand that an n × n board has exactly 2 n −3 bishop solutions of length 2 n − 4, when n is even.) (iv) Rook solutions are even easier to enumerate by hand: There are ( n − 1)! 2 of them, because we always have n − k choices at steps 2 k − 1 and 2 k . (If we force the first step downward, Algorithm M finds the 7! 2 = 25401600 solutions in 365 G μ , while generating also 21488110 disconnected impostors.) However, ( n − 2)! 2 − ( n − 2)! of those solutions are counted twice, because they go from corner to corner and have no symmetry. Hence there are 25401600 − 517680/2 = 25142760 distinct rook solutions of length 14. (v) Finally, there are 134 distinct queen solutions of length 11 — found and proved optimum in 9.4 G μ , despite having 10422 options of total length 281934(!). The unique solution that occupies opposite corners is shown here. (You may enjoy finding another unique 11-step path, which begins slowly by moving just one diagonal step.)
Now let’s consider paths that start in cell (0, 1) and do not end in a corner. (i) No such solutions have 32 kings (proved in 166 G μ ). (ii) Knights, however, yield a big surprise: There’s a unique path of length 33, doubly counted! (Found in 43 G μ .) (iii) Bishop paths can’t have length 12 unless they start or end in a corner. (iv) There are N = ( n − 1)! 2 − 2( n − 2)! 2 solutions where the rook first moves down, and N where it first moves sideways. Of these, 2( n – 2)! 2 end at (1, n – 1) and are equivalent to those ending at ( n – 2, 0); ( n – 2)! 2 end at ( n − 1 , n − 2) and are double-counted by central symmetry; ( n – 2)! 2 – ( n – 2)! end at (1, 0) and are double-counted by transposition; ( n – 2)! 2 – ( n – 2)! end at ( n – 2, n – 1) and are double-counted by dual transposition. So there are 2( n − 1)! 2 − 9( n – 2)! 2 + 2( n – 2)! = 46139040 equivalence classes when n = 8. (v) Another nice surprise greets us, namely a unique queen path of length 12!
The next step is to consider paths that start in (0, 2) and don’t end in the 12 types of cells already considered. And so on, for seven more cases. Of course rook counting gets hairier and hairier; we shall omit it. Unexpectedly, there’s also another maximum queen path(!). All of these computations are fast; kings need the max time (170 G μ ).
(b) Cycles are similar, but symmetry now becomes even trickier. (i) The six distinct 31-cycles of a king are asymmetric, so they each appear eight times when reflected and/or rotated. (ii) But the four distinct 32-cycles of a knight include two that are equivalent to their transpose, and one (shown below) with central symmetry. (iii,v) A bishop has 72 distinct 12-cycles, and a queen has five 13-cycles, all asymmetric.
(iv) A rook, on the other hand, has oodles of 16-cycles, some of which (like the one illustrated) even have 4-fold symmetry under reflection about either diagonal. Every rook snake 16-cycle can be represented uniquely as ( p 0 q 0 p 0 q 1 p 1 q 1 p 1 q 2 ... p 7 q 7 p 7 q 0 ), where p 0 p 1 ...p 7 and q 0 q 1 ...q 7 are permutations of {0, 1 ,..., 7} with p 0 = 0 and q 0 < q 1 . Consequently there are 8! 2 /16 = 101606400 of them, if symmetry isn’t taken into account. That cycle is equivalent to its transpose if and only if p j \= q ( k − j ) mod 8 for some k and all j ; there are 8!/2 = 20160 such cases. It is equivalent to its 180° rotation if and only if p j + p 4+ j = q j + q 4+ j = 7 for 0 ≤ j < 4; there are 6 · 4 · 2 · 8 · 6 · 4 · 2/2 = 9216 such cases. And it is equivalent to both, in 6 · 4 · 2 · 8/2 = 192 cases. Hence by “ Burnside’s lemma” there are (101606400 + 0 + 9216+0+ 20160 + 0 + 20160 + 0)/8 = 12706992 equivalence classes of rook cycles.
[T. R. Dawson introduced this problem for knights, and presented an example path of length 31 and an example cycle of length 32, in L’Echiquier (2) 2 (1930), 1085; 3 (1931), 1150. C. C. Verbeek posed the problem of maximizing the number of queens such that each is “attacked by exactly two others” in Elsevier’s Weekly (June 1971); if we allow several queens in the same row, arguing that the first doesn’t attack the third, 14 queens are actually possible (see P. Torbijn, Cubism For Fun 17 (1991), 19). The name ‘snake-in-the-box’ was coined by W. H. Kautz, IRE Trans. EC-7 (1958), 179–180, for the case where G is an n -cube. The term ‘ coil-in-the-box’ is often used nowadays for a snake-in-the-box cycle.]
The maximum length of an n × n snake king path when n = 100 was the topic of a math olympiad problem in 2008, posed by A. and M. Chapovalov. Nikolai Beluhov has shown that such maximum paths can be characterized completely; they’re related to spirals when n is even, and to stamp-folding when n is odd(!). When n ≥ 6 is even, exactly 2 n + ( n mod 4)/2 such paths are distinct under symmetry, and they all start in a corner. Furthermore there are exactly six distinct snake king cycles of length n 2 /2 – 1, when n ≥ 8 is a multiple of 4. Beluhov has also proved that the longest snake paths and cycles of a knight , on an m × n board, have length mn /2 – O ( m + n ). [See Enumerative Combinatorics and Applications 3:2 (2023), #S2R16, 1–23.]
173. (a) Write ‘ k −−− ij ’ if clue k is a (knight or bishop) move away from cell ( i, j ). For each row, column, and box, compute “quotas” r i , c j , and b x , equal to 3 minus the number of pieces already present among the given clues. Also compute the quota p k for each clue k , equal to the label minus the number of neighboring cells already occupied. There is no solution if any quota is negative.
Say that cell ( i, j ) of box x is known if it is occupied, or if r i \= 0 or c j \= 0 or b x \= 0, or if p k \= 0 for some k −−− ij . Introduce primary items R i , C j , B x , P k for each row, column, box, or clue with a positive quota, having multiplicities r i , c j , b x , p k . There is one option for each unknown cell, namely ‘ R i C j B x ∪{ P k | k −−− ij }’.
(b, c, d) See Fig. A–3 . The knight puzzles with labels ≥ 6, and the bishop puzzles with labels 0, 10, and 12, are due to N. Beluhov; the others are mostly due to F. Stappers (and are minimum if they have < 5 clues). Solutions can be found in Appendix E .
Fig. A–3. A gallery of knight and bishop sudoku puzzles.
[These variants of sudoku were devised by David Nacin and first published in MAA Focus 38 , 6 (Dec. 2018/Jan. 2019), 36; see also [quadratablog.blogspot.com](http://quadratablog.blogspot.com) .]
174. Beluhov’s remarkable solution, which he obtained with the help of a SAT solver, is also a pair of “ rainbow puzzles” — every possible knight label occurs exactly once(!):
[Also shown are his 10-clue puzzles in which all the labels are equal.]
175. We can allow an option α to be repeated twice by simply replacing it by three options ‘ α x ’, ‘# x ’, ‘# α ’, where # is a new primary item and x is a new secondary item. (If α contains uncolored secondary items y 1 , ... , y s , we should first replace them by y 1 : c , ... , y s : c , where c is a new color.)
In general if α is the i th option and if r i \= r + 1 > 1, replace α by the 2 r + 1 options ‘ α x 1 i ’, ‘# 1 i x 1 i ’, ‘# 1 i α x 2 i ’, ‘# 2 i x 2 i ’, ‘# 2 i α x 3 i ’, ... , ‘# ri x ri ’, ‘# ri α ’, where # ti and x ti are new primary and secondary items.
176. (a) Introduce 3 N items { A j ,B j , # j | 1 ≤ j ≤ N }, to be used in M options {A j | a ij ≥ 1}∪ { B j | a ij \= 2} for 1 ≤ i ≤ M . (For example, the option for row (2, 1, 0, 2, 0, ... ) would be ‘ A 1 B 1 A 2 A 4 B 4 ’.) Add 2 N further options ‘# j A j ’, ‘# j B j ’ for 1 ≤ j ≤ N . Use Algorithm M with multiplicities (2, 1, 1) for ( A j , B j , # j ).
(b) The same construction works, but with multiplicities (3, 1, 1).
(c) Now use 4 N primary items { A j , B j , # j , # j ′ } and N secondary items x j . Change the 2 N special options to ‘ # j A j ’ , ‘ # j B j x j ’ , ‘ # j ′ A j x j ’ , ‘ # j ′ B j ’ , for 1 ≤ j ≤ N . Use multiplicities (4, 2, 1, 1).
(d) With 7 N primary items { A j ,B j , # 1 j ,..., # 5 j } and 4 N secondary items { x 1 j ,x 2 j ,x 3 j ,x 4 j }, the special options are ‘# 1 j A j ’, ‘# 1 j B j x 1 j ’, ‘# 2 j A j x 1 j ’, ‘# 2 j B j x 2 j ’, ... , ‘# 5 j A j x 4 j ’, ‘# 5 j B j ’, and the multiplicities are (11, 5, 1, 1, 1, 1, 1).
177. (a) The 2 s 3 t − 1 nonzero vectors a 1 ...a s b 1 ...b t with 0 ≤ a i ≤ 1 and 0 ≤ b i ≤ 2 form the rows of a matrix A . Allow the 2 t − 1 rows with a i \= 0 and b i ≠ 2 to be repeated, via answer 175 ; also encode the 2s via answer 176 . That leads to s +3 t +2 t −1 primary items, 2 t − 1 secondary items, and a total of 2 s 3 t − 1+2 t + 2(2 t − 1) options. (There are 91914202 multipartitions when s = t = 5. Algorithm M generates them at a rate of about 1300 mems per solution; that’s only about seven times slower than the special-purpose Algorithm 7.2.1.5M.)
(b) This problem is easier, because we simply disallow using an option twice. That leaves us with s +3 t primary items and 2 s 3 t − 1+2 t options.
(Exercise 7.2.1.5–73 enumerates the number of solutions P ( s, t ) for part (a). The same argument gives a similar recurrence for the number Q ( s, t ) of solutions to part (b):
Q ( s , 0 ) \= ϖ s ; 2 Q ( s , t + 1 ) \= Q ( s + 2 , t ) + Q ( s + 1 , t ) − ∑ K ( n k ) Q ( s , k ) .
With this formula one finds quickly, for example, that Q (5, 5) = 75114998.)
178. (a) Since 360 = 2 3 · 3 2 · 5, we need first to extend exercise 176 to matrices of 0s, 1s, 2s, and 3s. Encoding a ij \= 3 in option i can be done by using items A j , B j , C j . To ensure a total of 3 in that column, let # j and # j ′ be new primary items, and give multiplicity (3, 1, 1, 1, 1) to ( A j , B j , C j , # j , # j ′ ) ; also let x j be secondary. Then the special options ‘ # j A j ’ , ‘ # j B j x j ’ , ‘ # j ′ A j x j ’ , ‘ # j ′ | C j ’ will fix everything up.
This makes an MCC problem with 29 options, 9 + 1 items, and 34 solutions.
(b) Now use exercise 175 to allow the options for factors 3 and 2×3 to be repeated at most twice, and to allow the option for factor 2 to be repeated at most thrice. The MCC problem now has 37 options, 13+5 items, and 52 solutions. [These solutions were first studied by John Wallis; see exercise 7.2.1.7–28.]
179. From 1000 + 0110 + 0001 we get four solutions 100000 + {011100, 011100} + {000011, 000011}; from 1110 + 0001 we get two solutions 111100 + {000011, 000011}; and from 1010 + 0101 we get 101000 + 010111.
180. The text showed that o 1 = ‘ i 1 ’ and that i 2 and o 5 exist, when t = 4 and t′ ≥ 1. Continuing that example, if s 2 = 5 so that t′ ≥ 2, then option o 2 intersects only { o 1 ,...,o 5 }; hence o 2 = ‘ i 1 i 2 ’, and i 2 cannot occur in more than 4 options. Its appearances must therefore be in { o 2 ,o 3 ,o 4 ,o 5 }.
Furthermore, o 3 must be ‘ i 1 i 2 i 3 ... ’ for some third item, i 3 , since we can’t have o 3 = o 2 . Consequently there’s an option o 6 = ‘ i 2 i 3 ... ’. And so on.
181. ( c 0 ,c 1 ,c 2 ,c 3 ,c 4 ) = (188, 248, 320, 425, 566)/96, by the initial values in the text.
182. (To establish the lower bound in Theorem E, make n copies of this problem, on disjoint four-tuples of items. This yields 7 n solutions, in a search tree with (5 · 7 n − 3)/2 nodes. Notice that the branching factor never exceeds 3 in this construction.)
183. (Can one, for example, often make the branching factor t = 4?)
184. Yes. If we can write t = a n −1 ϖ n −1 + a n −2 ϖ n −2 + ··· + a 0 ϖ 0 , with 0 ≤ a j ≤ ( n − 1 j ) for 0 ≤ j < n , we get such a problem by letting the options consist of (i) all 2 n −1 −1 subsets of {1 ,...,n −1}; (ii) exactly a j subsets of {1 ,...,n } of size n − j that contain n .
To write t in that form, suppose t \= ( n − 1 n − 1 ) ϖ n − 1 + ⋅ ⋅ ⋅ + ( n − 1 n − k + 1 ) ϖ n − k + 1 + a n − k ϖ n − k + t ′ , where 0 ≤ a n − k < ( n − 1 n − k ) and 0 ≤ t′ < ϖ n − k . Then, by induction, we can write t′ = a n − k −1 ϖ n −1− k + ··· + a 0 ϖ 0 , with 0 ≤ a j ≤ ( n − k − 1 j ) ≤ ( n − 1 j ) .
For example, 10000 = 1·4140+6·877+(1·203+7·52+2·15+(0·5+(0·2+(1·1)))).
185. We get the most solutions when we have the most options, namely the 2 N 1 + N 2 − 2 N 2 subsets that aren’t entirely secondary. Then the solutions are the set partitions that include at most one entirely secondary block; and the number of such set partitions is seen to be ∑ m { N 1 m } ( m + 1 ) N 2 , when we consider their restricted growth strings. (See OEIS sequence A113547 for other interpretations of these numbers.)
186. (a) The list for i consists of all 2 n −1 subsets that contain i . So there are ( n − 1 k − 1 ) operations hide( p ) on options p of size k ; and u n \= 1 + ∑ k ( n − 1 k − 1 ) ( k − 1 ) \= ( n − 1 ) 2 n − 2 + 1 .
(b) The lists get shorter, so the algorithm does u n −1 + ··· + u n −( k −1) updates.
(c) Sum u n + ∑ k ( n − 1 k − 1 ) ( s n − 1 − s n − k ) , where s n \= ∑ k \= 1 n u k \= ( n − 2 ) 2 n − 1 + n + 1 .
For example, ( v 0 , v 1 ,..., v 5 ) = (0, 1, 3, 12, 57, 294); ( x 0 ,x 1 ,...,x 5 ) = (0, 1, 4, 18, 90, 484).
187. (a) We have X′ ( z ) = Σ n x n +1 z n /n ! = V ′( z )+ e z X ( z ), where V ( z ) = Σ n v n z n / n !. The given function solves this differential equation and has X (0) = 0.
(b) Similarly, we have T r , s ′ ( z ) \= e z T r , s ( z ) + z r and T r,s (0) = 0.
(c) Integrate by parts.
(d) For example, T 1,3 ( z ) = 4 e e z −1 + 2 T 0 , 0 ( z ) − ze 2 z − (2 z +1) e z − 2 z − 3, by (c).
188. By induction, ϖ ^ n k is the number of n -element, single- tail set partitions ( equivalence relations) for which n > 1 and 1 ≢ 2, ... , 1 ≢ k . (For example, if we know that 22 single-tail partitions of {1, 2, 3, 4, 5} have 1 ≢ 2, and that 6 such partitions of {1, 2, 3, 4} have 1 ≢ 2, then 6 single-tail partitions of {1, 2, 3, 4, 5} must have 1 ≢ 2 and 1 ≢ 3; hence 16 of them have 1 ≢ 2 and 1 ≢ 3.) Therefore ϖ ^ n n \= ϖ ^ n − 1 , for all n ≥ 1.
[Leo Moser played with this triangular array in 1968 and found the generating function ∑ n ϖ ^ n z n / n ! \= e e z ∫ 0 z e − e t d t ; he showed his results to R. K. Guy, who told N. J. A. Sloane; see OEIS sequences A046936 and A298804. If we start with ‘0, 0, 1’ on the diagonal instead of ‘0, 1’, we get Gould’s 〈 a n 2 〉 = 〈 0, 0, 1, 1, 4, 14, 54, 233 ,... 〉; etc.]
189. (a) | e e z | = | e e x cos y + ie x sin y | = exp( e x cos y ); | e − e z | = exp( e − x cos y ).
(b) | ∫ 0 θ exp ( − e ξ e i ϕ ) d ( ξ e i ϕ ) + ∫ ξ ∞ e − e t d t | \= O ( ξ exp( − e cos y ) ) + O ( exp( − e ξ ) ) ; | e e z | = O (exp( e ξ )); and we have x \= ξ cos θ ≥ ξ − 2.25 / ξ , cos y ≥ cos 3 2 .
(c) We have ∫ z ∞ e − e t d t \= ∫ z ∞ e − e t d t − ∫ z 1 e − e u z d ( u z ) \= g ^ / 3 − I . Let max | e e uz | for 0 ≤ u ≤ 1 be exp(− e u 0 x cos u 0 y ). If cos u 0 y ≥ 0 we have | I | = O ( ξ ). Otherwise if cos y − cos u 0 y ≤ 1 we have | e e z I | ≤ ξ exp( e x cos y − e u 0 x cos u 0 y ) ≤ ξ exp( e x cos y − e x cos u 0 y ) ≤ ξ exp( e x ). Otherwise we use a more delicate argument: Since cos( a − b ) − cos( a + b ) = 2(sin a )(sin b ), we have | sin u 0 − 1 2 y | \= 1 2 | ( cos y − cos u 0 y ) / sin u 0 + 1 2 y | ≥ 1 2 , hence u 0 ≤ 1 − π/ (3 y ). And in this range, u 0 x ≤ x − π 3 x / y \= ξ cos θ − π 3 cot θ ≤ ξ − c ξ 1 / 3 + O ( 1 ) , where c 3 \= 3 8 π 2 .
The desired bound now holds in each case because x \= ξ 1 − sin 2 θ ≤ ξ − 9 / ( 8 ξ ) .
(d) If π 2 ≤ θ ≤ π , | e e z | exp(− e u 0 x cos u 0 y ) = O (1). Since p n − 1 / ( n − 1 ) ! \= 1 2 π i ∮ R ( z ) d z / z n , and since ϖ n − 1 / ( n − 1 ) ! \= Θ ( e e ξ / ( ξ n − 1 ξ n ) ) by 7.2.1.5–(26), we have | p n − 1 / ϖ n − 1 | \= O ( ξ n exp ( − c 2 e ξ / ξ ) ) for all c 2 < 9 8 . And − e ξ /ξ = − n/ξ 2 < − n/ ln 2 n .
[These results, and considerably more, were proved by W. Asakly, A. Blecher, C. Brennan, A. Knopfmacher, T. Mansour, and S. Wagner, J. Math. Analysis and Applic. 416 (2014), 672–682. In particular, they proved that a nk / ϖ n rapidly approaches the constant g ^ k \= ∫ 0 ∞ t k − 1 e 1 − e t d t / k ! \= ∫ 0 ∞ e − x ln k ( 1 + x ) d x / k ! , for all k > 0.]
Historical notes: Leonhard Euler computed the constant ĝ when he argued that this value can be assigned to the divergent series ∑ n \= 0 ∞ ( − 1 ) n n ! [ Novi Comment. Acad. Sci. Pet. 5 (1754), 205–237]. Benjamin Gompertz, who did not know the constant ĝ explicitly, studied the probability distributions F ( x ) = 1 − a 1− b x for a, b > 0 and x ≥ 0 [ Philos. Trans. 115 (1825), 513–585]. His name came to be associated with ĝ because, for example, a random variable with a = e in his distribution has E X = ĝ/ ln b .
190. Empirically, these signs are essentially periodic, but with a slowly increasing period length as n grows. For example, the signs for 4000 ≤ n ≤ 4100 are + 2 − 4 + 4 − 5 + 4 − 4 + 5 − 4 + 4 − 5 + 4 − 4 + 4 − 5 + 4 − 4 + 5 − 4 + 4 − 5 + 4 − 4 + 4 − 5 . The quantities ϖ ^ n k − g ^ ϖ n k for 1 ≤ k ≤ n ≤ 100 have the interesting sign pattern shown at the right. (See exercise 188 .) Complex variables are evidently interacting here somehow!
191. The mean is G ′(1) = 1+ ĝ ; the variance is G ″(1)+ G ′(1)− G ′(1) 2 = 2 ĝ 2 + ĝ − ĝ 2 ≈ 0 . 773. [Incidentally, G ( z ) can also be written e Γ ( 1 + z ) − ∑ k \= 1 ∞ ( − 1 ) k e z / ( ( k + z ) k ! ) .]
192. Let ξe ξ \= n as in 7.2.1.5–(24). Then, when x = e ξ − 1+ t and t is small, we have e − x (ln(1 + x )) n ≈ A exp(−(1 + ξ ) t 2 /(2 n )), where A = exp (n ln ξ + 1 − e ξ ). Trading tails and integrating over −∞ < t < ∞ gives g ^ n ~ A 2 π n / ( 1 + ξ ) / n ! .
193. At level 0, when given the complete graph K t +1 , the algorithm does t + 1 updates when covering i in step X4, and t updates when covering each of t values of j in step X5. Thus U ( t +1) = 1+ t + t 2 + tU ( t − 1).
194. (a) In general we have X (2 q +1) = (2 q )(2 q −2) ... (2) (a 0 + a 2 /2+ a 4 /(2·4)+···+) a 2 q /(2·4·. . .·(2 q ))) = 2 q q ! S − R , where S = Σ n ≥ 0 a 2 n /(2 n n !) and R = a 2 q +2 /(2 q +2)+ a 2 q +4 /((2 q +2) · (2 q +4)) + ··· . Hence when a t \= 1 we have S = e 1/2 and 0 < R < 1. [This result was noticed in 1999 by Michael Somos; see OEIS A010844.]
(b) In general, X (2 q ) = ((2 q )!/(2 q q !) )S − R , where S = X (0) + a 1 + a 3 /3 + a 5 /(3 · 5) + a 7 /(3 · 5 · 7) + ··· and R = a 2 q +1 /(2 q +1) + a 2 q +3 /((2 q +1) · (2 q +3)) + ···. When a t \= X ( 0 ) \= 1 , S − 1 \= 1 + 1 + 1 / 3 + 1 / ( 3 ⋅ 5 ) + e 1 / 2 erf( 1 / 2 )/ ( ( 1 2 ) 1 / 2 / ( 1 2 ! ) ) , and 0 < R < 1. So the answer is ⌊ ( 1 + e π / 2 erf ( 1 / 2 ) ) ( 2 q ) ! / ( 2 q q ! ) ⌋ .
(c) 2 q q ! C − 2 q + O (1), where C = Σ _n ≥ 0 (1+2 n + 4 n 2 )/(2 n n !) = 5 e 1/2 ≈ 8 ._ 24361.
(d) ((2 q )!/(2 q q !)) C′ − 2 q + O (1), where C ′ \= 3 + 5 e π / 2 erf( 1 / 2 ) ≈ 10.05343 .
195. Assume that q, r > 1, and let v be the unique vertex of degree 2. The algorithm will try to match v with the vertex at its left; that leaves a problem of matching the independent graphs K 2 q and K 2 r . If q ≤ r , each matching of K 2 q will initiate a computation of the matchings of K 2 r ; otherwise each matching of K 2 r will initiate the matchings of K 2 q . So the running time of this phase will be C′ updates per solution, where C′ is the constant of answer 194(d) and there are (2 q )!(2 r )!/(2 q q !2 r r !) solutions.
The algorithm will also try to match v with the vertex at its right. That leaves a problem of independently matching K 2 q +1 and K 2 r −1 , and there are no solutions. The running time of this phase will be C times min(2 q q !, 2 r −1 ( r − 1)!), where C is the constant of answer 194(c) . (Curiously, it’s actually negligible compared to the other phase.)
196. (a) b 1 ...b 9 = 135778899. (Draw the bipartite graph, and rotate it 180°.)
(b) Let k ¯ \= n + 1 − k for 1 ≤ k ≤ n . Then ‘ X j Y k ’ is a dual option if and only if ‘ Y j ¯ X k ¯ ’ is an original option; q 1 ...q n is the inverse of an original solution if and only if q ¯ n . . . q ¯ 1 is a dual solution.
(c) 1 + a 1 ( n + 1), because each Y k for 1 ≤ k ≤ a 1 appears in n options.
(d) a 1 ( a 2 − 1)( a 3 − 2) ... ( a n − n + 1). [This number must therefore be equal to b 1 ( b 2 − 1)( b 3 − 2) ... ( b n − n + 1) — and that’s not an obvious fact!]
(e) Let Π j \= ∏ i \= 1 j ( a i − i + 1 ) . From (c), the answer is 1 + ( ∑ j \= 1 n ( n + 3 − j ) Π j ) − Π n .
(f) 1 + ( ∑ j \= 1 n ( n + 3 − j ) n j ) − n ! ≈ ( 4 e − 1 ) n ! . [ Perfect matchings of K n,n .]
(g) 6 · 2 n − 2 n − 7, because Π j = 2 j for 1 ≤ j < n , and Π n = 2 n −1 .
(h) Now ∏ n \= ⌊ n + 1 2 ⌋ ⌊ n + 2 2 ⌋ ; and the total number of updates, divided by Π n , is therefore 6 + 4/1! + 5/2! + ··· + O ( n 2 /( n/ 2)!) ≈ 4 e − 1.
(i) If b 1 < a 1 , the first branch is on Y n , not X 1 ; and 1+ b 1 ( n +1) updates are made at root level. (The example problem in (a) branches on Y 9 , then X 2 , then Y 8 , etc.)
197. (a, b). Induction; σ st can in fact be any permutation that takes s ↦ t and doesn’t increase any other element.
(c) C ( a 1 , . . . , a n ) \= ∏ j \= 1 n ( z + a j − j ) , by (a), since we gain a cycle in that product representation if and only if t j \= j . I ( a 1 , . . . , a n ) \= ∏ j \= 1 n ( 1 + z + ⋅ ⋅ ⋅ + z a j − j ) , by (b). [See exercise 7.2.1.5–29; also M. Dworkin, J. Combinatorial Theory B71 (1997), 17–53.]
( 1 2 1 2 0 0 0 0 0 0 0 1 8 1 8 1 4 1 4 1 4 0 0 0 0 1 8 1 8 1 4 1 4 1 4 0 0 0 0 1 12 1 12 1 6 1 6 1 6 1 3 0 0 0 1 24 1 24 1 12 1 12 1 12 1 6 1 2 0 0 1 72 1 72 1 36 1 36 1 36 1 18 1 6 1 3 1 3 1 72 1 72 1 36 1 36 1 36 1 18 1 6 1 3 1 3 1 72 1 72 1 36 1 36 1 36 1 18 1 6 1 3 1 3 1 72 1 72 1 36 1 36 1 36 1 18 1 6 1 3 1 3 )
198. (a) If s > a r we have π rs \= 0. Otherwise let q be the smallest j with a j ≥ s ; then q ≤ r . Each permutation of P ( a 1 ,...,a n ) with p r \= s corresponds to one of P ( a 1 ′ , . . . , a r − 1 ′ , a r + 1 ′ , . . . , a n ′ ) , where a j ′ \= a j − [ j ≥ q ] . Thus ( a r + 1 − r ) π r s \= ∏ j \= q r − 1 ( a j − j ) / ( a j + 1 − j ) .
(b) We have q ′ ≥ q when s ′ > s . Consequently π r s / π r s ′ \= ∏ j \= q q ′ − 1 ( a j − j ) / ( a j + 1 − j ) for all r ≥ q ′, if π rs′ > 0. [In such cases the parameters r and s are said to be “ quasi-independent.”]
199. Assume by symmetry that m ≤ ⌈ n /2⌉. With the MRV heuristic it’s not difficult to see that every branch at level l for l < m is on some a i for i ≤ m , with exactly ( n − l )( m − 1 − l ) descendants. Hence there are n l ( m − 1 ) l nodes on level l . The total number of nodes when m ≈ n /2 is huge, Θ(( n − 2)!); and there are no solutions.
200. (a) When all n 3 options are present, det Q ( X ) = Σ sign( p ) v 1 p 1 q 1 ... v n p n q n , summed over all permutations p = p 1 ... p n and all n -tuples q = q 1 ... q n with q j ∉ X . Summing (−1) | X | det Q ( X ) yields Σ sign( p ) v 1 p 1 q 1 ... v n p n q n where both p and q are permutations. (This is essentially an application of the inclusion-exclusion principle.) Set v ijk ← 0 if option ‘ a i b j c k ’ isn’t present.
(b) Assign a random integer in [0 .. p ) to each of the M given options, where p is a prime greater than 2 M , and evaluate s = S mod p . If s ≠ 0, S is nonzero. If s = 0, S is nonzero with probability less than 1 − (1−1 /p ) M < M/p < 1/2, by exercise 4.6.1–16, because S is linear in each variable. Repeating r times will fail with probability < 2 − r .
[In practice, 2 n is often an overestimate because many of the determinants are obviously zero. For example, if Q ( X ) has an all-zero row or column, so does Q ( X ′) for all X ′ ⊇ X . This method shines on unsolvable examples such as those of exercise 199 . Björklund’s paper, STACS 27 (2010), 95–106, has more general results.]
201. (a) “Given n people seated at a circular table, how many seating arrangements do not require anybody to move more than one place left or right?”
(b) Two solutions in which everybody moves, plus L n solutions (a Lucas number) in which at least one person remains in the same seat.
(c) An interesting recursive structure leads to the answer 5 L n +2 + 10 n − 33. [This analysis depends on using the given ordering to break ties in step X3 when several lists have the minimum length.]
202.
203. (a) Yes; T ⊕ T ′ ⊕ T ″ is the search tree corresponding to A ⊕ A ′ ⊕ A ″.
(b) No;
.
204. By definition of T ⊕ T ′, we have subtree( αα ′) = subtree( α ) ⊕ subtree( α ′). Hence deg( αα ′) = min(deg( α ), deg( α ′)).
Let ancestors( α ) = { α 0 ,...,α l } and ancestors ( α ′ ) \= { α 0 ′ , . . . , α l ′ ′ } . Suppose αα ′ is dominant in T ⊕ T ′ and deg( αα ′) = d . If 0 ≤ k < l , some ancestor α k ′ α k ′ of αα′ has deg( α k ) = deg( α k α′ k ′ ) < d ; hence α is dominant. Similarly, α′ is dominant.
We’ve proved the “only if” part, but the converse is false:
.
205. The first statement follows easily from the definition (see exercise 202 ). Suppose α α ′ \= α l α l ′ ′ ∈ T ⊕ T ′ , as in answer 204 , where neither α nor α′ is dominant, and where l + l ′ is minimum. Then l > 0 and l ′ > 0, because α 0 and α 0 ′ are dominant.
Assume that the parent of αα′ is α α l ′ − 1 ′ . Then α l ′ − 1 ′ is dominant, and α l isn’t. So there’s a k < l such that deg( α k ) = max(deg( α 0 ) ,..., deg( α l )). Hence there’s a maximum k ′ < l ′ such that α k α k ′ ′ is an ancestor of αα ′. Then deg( α k ′ ′ ) ≤ deg( α l ′ − 1 ′ ) < deg( α ) , and α k α k ′ + 1 ′ is also an ancestor. But α k α l ′ ′ isn’t. Contradiction.
A similar contradiction arises when the parent of αα′ is α l −1 α′ .
206. Replace each solution node of T by a copy of T′ .
207. (a) If λ j \= 4 we now prefer the 5-way branch on i , because λ i ′ \= 7 / 2 < 11 / 3 \= λ i ′ . If λ j \= 3 we prefer min( i, j ), because λ i ′ \= 3 \= λ j ′ . If λ j \= 2 we still prefer the binary branch on j to the ternary branch on i . And if λ j \= 1 or 0 we certainly prefer j .
(b) Include two new fields, ACT and STAMP , initially zero, in each item node. (They can share an octabyte, if ACT is a short float and STAMP is a tetrabyte.) A global variable TIME serves as the “convenient clock.” Another global, BUMP (which is a short float, initially 10 −32 ), is the amount by which we advance activity scores. Whenever i is covered or uncovered, or whenever LEN( i ) is changed, we check to see if STAMP( i ) = TIME ; if not, we set ACT( i ) ← ACT( i ) + BUMP and STAMP( i ) ← TIME .
The “clock” advances at the beginning of steps X4, X5, X6, and X7. This means that TIME ← ( TIME +1)mod2 32 and BUMP ← BUMP /ρ . (Furthermore, if BUMP ≥ 10 29 , we divide BUMP and all ACT fields by 10 64 , to avoid overflow. We limit ρ to be at most .999, so that each α i is at most 1000.)
These changes allow us to replace the definition of λ in step X3 ( answer 9 ) by λ ← ( LEN( p ) ≤ 1? LEN( p ) : 1+ LEN( p ) /( 1+ μ ACT( p ) / BUMP )) .
(c) Consider (90) first. After branching on 00 and trying option ‘00 01’, we have α 00 = α 02 = ρ , α 01 = 1+ ρ , α 04 = α 05 = α 06 = 1, and the other α ’s are zero. We want λ 05 ′ \= 1 \= 3 / ( 1 + μ α 05 ) to be less than λ 10 ′ \= 1 + 2 ; that is, μ > 1/2. Later, after trying option ‘00 02’, we’ll have α 05 > 1 and α 06 > 1; again, item 01 isn’t chosen.
Problem (92) is trickier. After trying ‘00 01’, the nonzero α ’s are α 00 = α 02 = ρ , α 01 = 1 + ρ , and α 03 = α 04 = α 05 = 1. We’ll prefer the 3-way branch on 02 to the 2-way branch on 20 if μ > 1/(2 ρ ); and we’ll even prefer the 4-way branch on 04 (or 05) to that 2-way branch, if μ > 1. In either case we’ll reach a solution to problem 0 before starting on problem 1. The same calculations then take us to problem 2 only when problem 1 has been solved; etc. (Furthermore, when coming back down there will be no incentive to go back up. In fact, 4-way branches will be done on the items k 3 because of their high activity scores.)
(d) The normal Algorithm X finds all 212 solutions in 92 G μ , with a 54-meganode search tree. This modification finds them in 51 G μ , if we set μ = 1/8 and ρ = . 99, with a 26-meganode search tree. (With μ = 1/2 and ρ = . 9, the time is 62 G μ . In long runs, the α scores tend to approach 1/(1 − ρ ); so increases in ρ usually imply decreases in μ .)
208. The original problem has primary items ij for 0 ≤ i, j ≤ e , and eight kinds of options ‘{ ij + δ | δ ∈ S k }’ for all cells ij + δ that are in range, where S 0 = {01, 11 , 21, 31, 10}, S 1 = {00, 01, 02, 03, 11}, S 2 = {00, 10, 20, 30, 21}, S 3 = {10, 11, 12, 13, 02}, S 4 = {01, 11, 21, 31, 20}, S 5 = {00, 01, 02, 03, 12}, S 6 = {00, 10, 20, 30, 11}, S 7 = {10, 11, 12, 13, 01}. Options that involve the center cell 77 come only from S 0 .
The modified problem adds secondary items V ij and H ji , for 0 ≤ i ≤ b , 1 ≤ j ≤ d . It inserts V ij , H ( i +1) j , V i ( j +1) , H ij respectively into the options with S 4 , S 5 , S 6 , S 7 .
(The 16 solutions to this problem represent 2 2 +2 4 +2 5 +2 2 +2 3 +2 2 +2 5 + 2 3 +2 5 +2 3 +2 2 +2 4 +2 3 +2 4 +2 2 +2 4 = 212 solutions to the original. We’re lucky that none of those solutions has an ‘H’ that includes 77 .)
209. With the modified options ‘0 1 A’, ‘0 2 B’, ‘1 4 5 B’, ‘2 3 4 A’, obtained from the bipairs (‘0 1’, ‘2 3 4’; ‘0 2’, ‘1 3 4’) and (‘0 1’, ‘2 4 5’; ‘0 2’, ‘1 4 5’), we get the balanced search tree shown here.
210. Add a new primary item #A and give it multiplicity [0 .. 2]. Insert it into options α ′, β ′, γ ′. Then use the nonsharp preference variant of Algorithm M .
211. No bipairs. (But Langford has bitriples, and all three have “ biquadruples.”)
212. (a) Order the options first by their smallest item, and secondly by lexicographic order among those with the same smallest item.
(b) Yes. For example, we can let 1 < 2, and 1 < 4 < 0 < 5.
213. Yes, provided that we regard a proper prefix of a string as lexicographically larger than that string (contrary to the conventions of a dictionary). Otherwise the condition fails when α is a prefix of α ′ (although exercise 212 remains valid).
Suppose the items of α and β are respectively represented by the digits j and k in rgs( π ), the restricted growth string of π . Then j will also represent α ′ in rgs( π ′), and both strings will be equal up to the point where j first appears.
Let β′ be represented by k′ in rgs( π′ ); then k′ > j . Consider the leftmost place where rgs( π ) differs from rgs( π′ ). If that digit is j in rgs( π ), it is k′ in rgs( π′ ). Otherwise it is k in rgs( π ); but then it is j in rgs( π′ ), and α is a prefix of α′ .
214. We can find all solutions Σ that reduce to a given strong solution Σ 0 , by repeatedly reversing the construction in the proof of Theorem S — replacing joint occurrences of α and β by joint occurrences of α′ and β′ , for all canonical bipairs, in all possible ways. (It’s a reachability problem: to find all nodes of an acyclic digraph, given the sinks.)
Notice that different strong solutions can lead to the same nonstrong solution. For example, in the 2DM problem with options { xX , xY , yX , yY , yZ , zY , zZ }, where uv stands for ‘ u v ’, we might have the canonical bipairs ( yX , xY ; yY , xX ), ( yZ , zY ; yY , zZ ). The strong solutions { xY , yX , zZ } and { xX , yZ , zY } both lead to the nonstrong { xX , yY , zZ }. (However, in that same problem, we could have made the bipairs ( yX , xY ; yY , xX ), ( yY , zZ ; yZ , zY ) canonical. Then there would have been only one strong solution.)
215. (a) This is the number of 4-cycles, of which there are 3 ( 2 q + 1 4 ) : Four vertices i < j < k < l can form three 4-cycles, with either j or k or l opposite i .
(b) For convenience, denote options by ij instead of ‘ i j ’. If i < j < k < l , we exclude ( i, j, k, l ) unless min( ij, ik, il, jk, jl, kl ) = ij or kl . We exclude ( i, k, j, l ) unless min( ij, ik, il, jk, jl, kl ) = ik or jl . We exclude ( i, l, j, k ) unless min( ij, ik, il, jk, jl, kl ) = il or jk . Hence exactly two of the three possibilities are excluded.
(c) When i < j < k < l they are ( i, k, j, l ) and ( i, l, j, k ).
(d) The root has 2 q children, branching on 0. All of them are leaves except for the branch ‘0 1’. That one has 2 q − 2 children, all of which are leaves except for the branch ‘2 3’. And so on, with 2( q − l ) nodes on level l > 0.
(e) Use only ( i, j, k, l ) for k = i +1 < min( j, l ) and i even.
(f) Put ‘1 2 q ’ first, then ‘2 2 q −1’, ... , then ‘ q q +1’, then the others. When we branch on ‘0 k ’ at the root, for 1 ≤ k ≤ 2 q , no options remain for item 2 q +1 − k .
(g) ‘0 k ’ and ‘2 q +1− k l ’ are excluded, for all l ∉ {0 ,k, 2 q +1 − k }. (Altogether (2 q )(2 q − 2) cases.) [Is it perhaps feasible to order the options dynamically ?]
216. The search tree is almost always smaller than that of answer 215(c) , which in fact has the worst case on every level. But it rarely seems to go below half of the worst-case size. (The author discovered the trick of answer 215(f) by studying randomly generated examples that had unusually small trees.)
Algorithm X needs 540 G μ to prove that K 21 has no perfect matching. It has potentially 2 ( 21 4 ) \= 11970 excludable quadruples. We can use Algorithm 3.4.2S to sample just m of them; then the running time for m = (2000, 4000, 6000, 8000, and 10000) decreases to about (40 G μ , 1.6 G μ , 145 M μ , 31 M μ , 12 M μ ), respectively.
217. Each delta α − α′ has k positive terms and k negative terms; we can assume that 1 ≤ k ≤ 4. Furthermore it suffices to work with “normalized” deltas, which are lexicographically smallest under rotation, reflection, and negation. The pentominoes (O, P, . . . , Z) have (10, 64, 81, 73, 78, 25, 23, 24, 22, 3, 78, 24) normalized deltas, of which (1, 7, 3, 3, 2, 0, 1, 0, 1, 0, 4, 0) have k = 1. Two of the deltas are shared by four different pentominoes: 00+01−23−33 (Q, S, W, Z); 00−02 (P, Q, R, Y). Eleven are shared by three.
A common delta is necessary but not sufficient; if α − α′ = β′ − β , we still need to fill in cancelled terms that don’t clash. For example, 00 − 23 is common to Q and W, but it doesn’t yield a bipair. Furthermore (although the exercise didn’t state this!), we don’t want the 10-cell region to have a hole; the delta 00 + 01 − 12 − 22 is common to P, U, and Y, but only PY makes a useful bipair. A delta can arise in more than one way: From 00 + 01 + 02 + 03 − 20 − 21 − 22 − 23 we can make a Q with either 10 or 13, and a Y with either 11 or 12; symmetry (and hole removal) yields only one bipair, not four.
The complete catalog has 34 essentially distinct entries. Eighteen of them
have 10-cell shapes with left-right symmetry. Fourteen have transposition symmetry:
The other two are especially interesting because they are asymmetric:
(These two each lead to eight varieties when rotated and reflected, not just four. See J. C. P. Miller in Eureka: The Archimedeans’ Journal 23 (1960), 14–15.)
218. If the only options involving p are ‘ p i :0’ and ‘ p i :1’, we can’t eliminate item i . [But if they all involve, say, i :0, we could eliminate it; Algorithm P doesn’t go that far.]
219. If option o contains i , but neither p nor q , it can be in a solution only with two other options { o′, o″ } that contain { p, q }. But o′ and o″ must then both contain j . [This argument is like the “ naked pairs” of sudoku lore. It’s tempting to go further, by also eliminating items i and j ; but that could increase the number of solutions.]
220. Let the option be ‘ i 1 i 2 [: c 2 ] ... i t [: c t ]’. We’ve already covered item i = i 1 , which is represented by node x . Nodes x +1, x +2, ... represent the other items, possibly with spacers that were inserted when this option was shortened (see exercise 222 ). We want to commit i 2 , ... , i t , and to determine whether this causes LEN( p ) to become 0 for some primary p ∉ { i 2 ,...,i t }. The tricky part is to be sure that p ∉ { i 2 ,...,i t }; to accomplish this, we set COLOR( i j ) ← x for 1 < j ≤ t . [In detail: Set p ← x + 1; while p > x , set j ← TOP( p ) , and if j ≤ 0 set p ← ULINK( p ) , otherwise set COLOR( j ) ← x , p ← p +1.]
Then we make a second pass over the option: Set p ← x +1. While p > x , set j ← TOP( p ) , and if j ≤ 0 set p ← ULINK( p ) , otherwise commit′ ( p, j ) and set p ← p +1. Here commit′ ( p, j ) emulates (54): Set c ← COLOR( p ) , q ← DLINK( j ) ; while q ≠ j , hide′″ ( q ) unless COLOR( q ) = c > 0, and set q ← DLINK( q ) . And hide′″ ( p ) is just like hide( p ), but it detects blocking if LEN( y ) becomes 0 for some y ≤ N 1 with COLOR( y ) ≠ x .
Finally, a third pass undoes our changes: Set p ← x − 1. While p ≠ x , set j ← TOP( p ) , and if j ≤ 0 set p ← DLINK( p ) , otherwise uncommit′( p, j ) and set p ← p − 1. Here uncommit′( p, j ) undoes commit′( p, j ) in the obvious way.
It is possible to switch immediately from committing to uncommitting as soon as blocking is detected, by jumping into the middle of a loop (see answer 122 ).
221. While S > 0, set x ← S , S ← TOP( x ) , TOP( x ) ← i , and do the following: Set q ← x ; while q ≥ x , set j ← TOP( q ) , and if j ≤ 0 set q ← ULINK( q ) ; otherwise if j ≤ N 1 and LEN( j ) = 1, go to P9; otherwise set u ← ULINK( q ) , d ← DLINK( q ) , ULINK( d ) ← u , DLINK( u ) ← d , LEN( j ) ← LEN( j ) − 1, q ← q +1.
222. Set p ← DLINK( i ) , and do the following steps while p ≠ i : Set p′ ← DLINK( p ) , q ← p + 1. While q ≠ p , set j ← TOP( q ) , and if j ≤ 0 set q ← ULINK( q ) ; otherwise if j = S , exit this loop; otherwise set q ← q + 1. Then if q ≠ p , set ULINK( p ) ← p +1, DLINK( p ) ← p − 1, TOP( p ) ← 0 (thereby making a spacer); otherwise set q ← p + 1 and perform the loop in answer 221 while q = p (instead of while q ≥ x ). Finally set p ← p′ .
223. In accordance with the conventions of exercise 8 , we first declare the items of the reduced problem: For 1 ≤ i ≤ N , output the distinguishing mark for secondary items, if i = N 1 + 1; and output the name of item i , if LEN( i ) > 0 or i = N = 1. Then we output the remaining options: For 1 ≤ i ≤ N , if LEN( i ) > 0, set p ← DLINK( i ) and do the following while p ≠ i : Set q ← p − 1 and while DLINK( q ) = q − 1 set q ← q − 1. If TOP( q ) ≤ 0 (hence i was the leftmost item to survive, in the option following the spacer node q ), output the option as explained below. Then set p ← DLINK( p ) and repeat.
To output the (possibly shortened) option that follows node q , set q ← q + 1; then, while TOP( q ) ≥ 0, output the name of item TOP( q ) if TOP( q ) > 0, followed by : c if COLOR( q ) = c > 0, and set q ← q + 1. (Afterwards, − TOP( q ) is the number of the corresponding option in the original input.)
224. Use 3 n −3 items p 1 , x 1 , i 1 , ... , p n − 1 , x n − 1 , i n − 1 (in that order), with the options ‘ i n − k p k x k ’, ‘ i n − k p k x k +1 ’, ‘ i n − k x k ’, ‘ i n − k p k +1 ’, for 1 ≤ k < n − 1, and also ‘ i 1 p n − 1 x n − 1 ’, ‘ i 1 x n − 1 ’. During round k , for 1 ≤ k < n , item i n − k is forced by p k .
225. Some options, like ‘Z 01 02 11 20 21’ and ‘U 30 31 41 50 51’, are obviously useless because they cut off a region of fewer than five cells. More of these options are discarded in the larger problem — but only because of piece U. Eight options, like ‘O 10 11 12 13 14’, are useless because they block a corner cell.
The smaller problem also has numerous options like ‘P 02 12 13 22 23’, which turn out to be useless because they block piece X. (That piece has been confined to just eight placements, in order to break symmetry. It has more freedom in the larger problem, and can’t be blocked there.) Round 2 also discovers that options like ‘O 22 23 24 25 26’ would block X, since round 1 has disabled one of X’s eight choices.
226. Since ∑ 1 ′ \= ∑ k \= 1 2 n ( 2 n + 1 − k ) α k , it’s clear that ∑ 1 + ∑ 1 ′ \= ( 2 n + 1 ) ∑ k \= 1 2 n α k \= ( 2 n + 1 ) ( n + 1 ) n . Similarly S + S ′ \= ( 2 n + 1 ) ∑ k \= 1 2 n α k 2 \= ( 2 n + 1 ) 2 ( n + 1 ) n / 3 .
The relation ∑ 2 ′ − ( 2 n + 1 ) ∑ 1 ′ \= ∑ 2 − ( 2 n + 1 ) ∑ 1 holds for any sequence a 1 ...a 2 n .
227. (a) $( ij 2 + ik 2 ). (b) $( i 2 j + i 2 k ). [$( C − ij 2 − ik 2 ), for large C , will maximize Σ 2 .]
228. Well, it certainly surprised the author. Intuitively, we expect small Σ 1 = ∑ ka k to be correlated with small Σ 2 = ∑ k 2 a k , but not nearly so well. For some mysterious reason, Langford pairings with the same Σ 1 tend to have the same Σ 2 , and vice versa!
That’s not always true. For example, 2 8 6 2 3 5 7 4 3 6 8 5 4 1 7 1 and 3 5 7 4 3 8 6 5 4 1 7 1 2 6 8 2 have the same Σ 1 but different Σ 2 ; 15174895114107638293261110 and 1 4 1 6 7 10 4 5 9 11 6 8 7 5 2 3 10 2 9 3 8 11 have the same Σ 2 but different Σ 1 . Yet such exceptions are rare. When n = 7, the four pairings that have Σ 1 = 444 are the same as the four that have Σ 2 = 4440; the six pairings that have the larger value Σ 1 = 448 are the same as the six that have Σ 2 = 4424, which is smaller than 4440. What is going on?
The special nature of Langford pairings does allow us to prove certain curious facts. For example, let j k be the index of the first occurrence of k . The other occurrence is at j k + k + 1; hence ∑ k \= 1 n j k \= ( 3 n − 1 ) n / 4 . Also ∑ k \= 1 n j k 2 \= ( 4 n 2 − 1 ) n / 3 − 1 2 ∑ 1 .
229. These pairings can be found by Algorithm 7.2.2L (or its reverse-order variant). But we can also find them via dancing links, using the sharp minimax modification of Algorithm X (or C ) in exercise 85 : Order options (16) so that ‘ i s j s k ’ precedes ‘ i′ s j′ s k′ ’ when j′ < j , or when j′ = j and i′ < i (for lex max) or i < i′ (for lex min). Then repeatedly (i) use the minimax algorithm to fill the smallest undetermined slot s j ; (ii) move the option that minimally covered s j to the front of the list, and remove all other options that involve s j .
Thus we find 1213248312134101415168961157121013659147151116 in sixteen such steps, all of which are easy (and need less than 110 K μ ) except for the placements of 8 in s 7 (4.5 M μ ) and 12 in s 9 (500 K μ ). The total time (6 M μ ) includes 465 K μ just for inputting the data in step X1. After placing 8 items, only 12 solutions remain, so it’s slightly faster to switch gears when finishing. (This pairing has Σ 1 = $5240, Σ 2 = $119192, S = $60324; somewhat high but not extreme.)
The lexicographic maximum turns out to be (108) — partially explaining why it is so “remarkable.” It can be obtained in the same fashion, in fewer than 2 M μ .
230. Assume that all solutions to the exact cover problem contain the same number of options, d . (For example, d = 16 in Fig. 74 .) Then we can replace each cost $ c by the complementary cost, $( C − c ), where C is sufficiently large to make this nonnegative. Solve the problem with the complementary costs; then subtract its total cost from Cd . [It’s convenient to implement a special version of Algorithm X $ that does this automatically, with appropriate changes to the presentation of intermediate and final results.]
231. (a) MAPLE ARRAY SMOKE TYPES ( $ 139 ) ;
(b) HAPPY EXILE ALLOW PELTS ( $ 176 ) ;
(c) JAMBS EQUIP TUMOR SASSY or MAGMA EQUIP OUNCE WAKED ( $ 197 ) .
Algorithm X $ needs 6 G μ , 80 G μ , and 483 G μ to find these; Algorithm X needs 5 G μ , 95 G μ , and 781 G μ to visit all solutions, of which there are 27, 8017, and 310077. ( Section 7.2.2 ’s trie-based methods are much faster: They need just 12 M μ , 628 M μ ,13G μ .)
232. No. Algorithm X $ finds 96 solutions of minimum cost $84; but the true solution in Fig. 74(a) actually costs $86 by this measure. The effects of 16 rounding errors, each potentially changing the result by nearly $1, have invalidated everything. [Therefore the author used $ ⌊2 32 d ( i, j )⌋ when preparing Fig. 74 . This was safe, because the distance between the first 8 solutions and the 9th was greater than 16 — in fact, much greater, although a difference of only 17 would have been convincing.]
233. With costs $ ⌊2 32 ln d ( i, j )⌋, we get the same answers (but faster: 1 . 2+0 . 2 G μ ).
234. By that measure, every placement of n nonattacking queens (or rooks!) costs
∑ k \= 1 n ( ( k − c ) 2 + ( p k − c ) 2 ) \= 2 ∑ k \= 1 n ( k − c ) 2 \= n ( n 2 − 1 ) 6 , where c \= ( n + 1 ) / 2.
235. Now the roles are reversed: We’re more interested in the periphery than in the center, and the minimum is easier to compute than the maximum. The minimum cost, $127760, is achievable in four ways, each symmetric; hence we must take K = 17, not K = 9. This computation took only 1.3 G μ . (The two examples below have different sets of distances, which coincidentally yield the same total cost.) But there’s a unique way to get the maximum cost, $187760, discovered (with K = 9) in 9.7 G μ :
236. The idea is first to minimize the longest distance; then, placing a queen at that distance in all possible ways, to minimize the next-longest distance; and so on. In other words, if the options are in nondecreasing order by cost, it’s almost like the search for lexicographically minimax solutions, iteratively as in answer 229 .
However, there’s a catch: Many options have the same cost. Different orderings of equal-cost options can lead to wildly different lex-min solutions. For example, suppose there are four options, ‘1’ for $1, ‘2’ for $2, ‘1 3’ for $3, and ‘2 3’ for $3. In that order, the minimax solution omits the final option and costs 3 N +2 N , which is not optimum.
The solution is to add to each option a primary item describing its cost, and to use Algorithm M iteratively by specifying the number of queens of highest costs, keeping this as low as possible until the problem has no solutions. Here are the best such ways to place n queens, for n = 17, 18, and 19:
The author was able to reach n = 47 with dancing-links-based methods, in an afternoon. But he knew that integer programming is significantly faster for “linear” applications such as the n queens problem (see answer 36 ). So he enlisted the help of Matteo Fischetti; and sure enough, Matteo was able to extend the results dramatically. Here, for example, are optimum placements for n = 32, 64, and 128:
It appears likely that these optimum queen placements have rotational symmetry only when n = 1, 4, 5, 16, and 32. But the solutions for n = 64 and 128 do have 2 6 and 2 12 equivalent mates, because they contain respectively 6 and 12 “tiltable squares” in the sense of exercise 7.2.2–11(c) .
(The limiting behavior may not “kick in” until N is quite large. For example, the optimum solution when n = 16 and N = 20 is not the symmetrical one illustrated; the placements 8 11 4 7 5 12 1 16 14 2 15 10 3 13 6 9 have total cost ≈ 2 . 08 × 10 21 , which beats ≈ 2 . 09 × 10 21 . The limiting shape turns out to be optimum if and only if N ≥ 21.)
237. False. For example, the square shown here is the smallest of ≈ 3 billion solutions for which 02 ≡ 20, 03 ≡ 30, 12 ≡ 21, 13 ≡ 31, 42 ≡ 24, 43 ≡ 34.
[ 1 2 1 1 3 1 1 0 0 3 1 0 1 0 3 1 0 3 6 9 3 1 3 9 1 ]
238. [ 1 1 3 3 0 7 1 3 9 ] [ 2 1 1 1 1 0 3 1 1 1 9 3 ] [ 2 1 2 1 1 1 0 3 0 1 1 1 3 9 3 ] [ 1 1 1 2 1 1 1 0 0 1 0 3 3 3 1 1 7 1 ] [ 1 1 1 1 2 1 1 1 0 0 0 4 0 3 3 1 9 3 1 7 1 ] ; [ 9 9 7 7 8 7 7 3 3 ] [ 8 9 9 9 8 6 9 9 7 7 1 7 ] [ 9 8 9 9 9 9 8 8 9 7 7 7 3 1 7 ] [ 9 8 9 9 9 9 9 8 8 5 7 9 7 7 3 3 7 1 ] [ 9 8 9 9 9 9 9 9 8 6 8 5 9 7 7 7 7 3 3 1 7 ] .
The problems for n = 7 have 1759244 options; yet they were solved in 20 G μ without preprocessing. Special methods would, however, be required for n ≥ 8.
239. Introduce primary items k and jk , for 1 ≤ k ≤ n and for all j with k ∈ S j . When S j \= { k 1 ,...,k t }, there’s an option ‘ jk 1 ... jk t ’ of cost w j , together with t options ‘ k i jk i ’ of “infinitesimal” cost j for 1 ≤ i ≤ t ; also t “ slack” options ‘ jk i ’ of cost 0.
For example, suppose the only sets that cover 1 are S 1 , S 2 , S 3 , S 4 ; and suppose that an optimum set cover uses S 2 and S 4 but neither S 1 nor S 3 . Then a maximum-cost solution to this exact cover problem will use option ‘11 ... ’ of cost w 1 , ‘31 ... ’ of cost w 3 , ‘1 21’ of cost ∊ 2 , and ‘41’ of cost 0 (because the alternative with ‘21’ and ‘1 41’ has smaller additional cost 0 + ⋴ 4 ).
[See M. Gondran and M. Minoux, Graphs and Algorithms (1984), exercise 10.35. When finding the k best solutions instead of a single optimum, all solutions that become identical when is set to zero should be counted just once.]
240. Add { WY , CO , NM } and either ID or UT or AZ . Or add { ID , UT , CO , OK }. Or add { SD , MO } and either { IA , OK } or { NE , AR } (a surprise to the author when he posed this problem).
241. No, although it does find the cases where regions of fewer than 6 vertices are cut off. Round 1 discovers that New England can be shrunk to a single item; then Round 2 is able to remove options such as ‘ LA AR TN VA MD PA ’. Altogether 3983 options and 5 items are removed, at a cost of 8 G μ .
242. Before visiting a solution in step R2′, use depth-first search to find the connected components of the residual graph. Reject the solution if any such component has a size d for which d < L · ⌈ d/ ( U − 1)⌉.
243. Let W = w 1 + ··· + w n be the sum of all weights. Then we have ∑ k \= 1 d ( x k − r ) 2 \= ∑ k \= 1 d x k 2 − 2 r W + r 2 d , because ∑ k \= 1 d x k \= W in an exact cover problem.
244. True: Let G have m edges and n vertices. A solution with k edges between vertices of the same option has total interior cost n ( t − 1) − 2 k , total exterior cost 2( m − k ).
[But answer 246 shows that this can fail with options of different sizes.]
245. For (a), exercise 242 gives 42498 − 25230 = 17268 options of size 7. Minimum cost $58 is discovered in 101 M μ . For (b), there are 1176310 − 1116759 = 59551 options with population in [43 .. 45] million. In the optimum solution shown below, which was found in 7.7 G μ , all populations lie in the range [43 . 51 .. 44 . 24] million.
246. Minimum exterior cost ($90 and $74, found in 612 and 11 M μ ):
Minimum interior cost ($176 and $230, found in 1700 and 100 M μ ):
247. Use the procedure of answer 8 for raw data entry, but also set COST( j ) ← the cost of the current option for p < j ≤ p + k at the beginning of step I5.
Then assign taxes “greedily” by doing the following for k = 1, 2, ... , n : If item k has no options, terminate with an unsolvable problem. Otherwise let c be the minimum cost of k ’s options, and set COST( k ) ← c ; this is the “tax” on k . If c > 0, subtract c from the cost of every option on k ’s list; this will affect all nodes of those options.
(The modified costs will be used internally. But all results reported to the user should be expressed in terms of the original costs, by adding the taxes back in.)
After all taxes have been assigned, sort the options by their (new) costs. (The “natural list merge sort,” exercise 5.2.4–12, works well for this purpose, with the COST fields in spacer nodes serving as links.)
Finally, achieve (118) by re-inserting all nodes, in order of cost.
[Taxes could be assessed in many other ways. In general we seek real numbers u 1 , ..., u n such that c j ≥ ∑ { u i | item i in option j } for 1 ≤ j ≤ m , where u 1 + ··· + u n is maximum. This is a linear programming problem, which happens to be dual to the ( fractional) exact cover problem of minimizing c 1 x 1 +···+ c m x m such that x 1 ,...,x m ≥ 0 and ∑ { x j | item i in option j } = 1 for 1 ≤ i ≤ n . An “optimum” taxation scheme, found by a linear programming solver, might make Algorithm C $ significantly faster than it is with the greedy scheme above, even on highly nonlinear XCC problems; careful tests have not yet been made. See M. Gondran and J. L. Laurière, Revue Française d’Automatique, Informatique et Recherche Opérationnelle 8 , V-1 (1974), 27–40.]
248. Set t ← ∞, c ← 0, j ← RLINK( 0 ) , and do the following while j > 0: Set p ← DLINK( j ) and c′ ← COST( p ) . If p = j or c′ ≥ ϑ , go to C8 $ . Otherwise set s ← 1, p ← DLINK( p ) , and loop as follows: If p = j or COST( p ) ≥ ϑ , exit the loop; otherwise if s = t , set s ← s + 1 and exit; otherwise if s ≥ L , set s ← LEN( j ) and exit; otherwise set s ← s +1, p ← DLINK( p ) , and continue. After exiting the loop, if s < t or ( s = t and c < c′ ), set t ← s , i ← j , and c ← c′ . Finally set j ← RLINK( j ) .
[The author uses L = 10. He considered doing a complete search, thereby avoiding the frequent updates to LEN in (13), (15), etc.; but that turned out to be a bad idea.]
249. After we’ve seen t costs, we know only that the remaining dk − t are nonnegative. The following algorithm sorts incoming costs into the rightmost positions of a buffer b 0 b 1 ...b dk − 1 , maintaining the best possible lower bound l : Set l ← t ← 0. When seeing a new cost c , set p ← t , y ← 0, r ← 1, and do this while rp > 0: Set x ← b dk − p . If c ≤ x , set r ← 0. Otherwise if p mod k = 0, set l ← l + x − y ; set y ← b dk − p − 1 ← x , p ← p − 1. After rp = 0, set b dk − p − 1 ← c , t ← t +1; if p mod k = 0, set l ← l + c − y . Stop if l ≥ θ .
250. Keep a separate “accumulator” for each character in Z , and another for z if it is present. Look at each active item i : If NAME( i ) begins with a character of Z , add COST(DLINK( i )) to the appropriate accumulator. Otherwise if z = 1, add that cost to the accumulator for z . Otherwise if z > 1, use exercise 249 to accumulate costs that are separated by z . If any of the accumulators becomes ≥ T − C l , go to C8 $ .
(When Z or z hints are given, step C1 $ should verify that they are legitimate.)
251. When all items have been covered, step Z2 will see the signature S[ 0 ] = 0, which was initialized in step Z1; Z[ 0 ] = 1 is the “success” node ‘⏉’.
252. Notice that this free ZDD is not ordered, because ‘02 12’ appears above ‘20 21’ in the left branch but below ‘20 21’ in the right branch. See exercise 264 .
253. Introduce a global variable COUNT ; also auxiliary variables c 0 c 1 ... indexed by the current level l ; also integer variables C[ t ] indexed by cache location t . Set COUNT ← 0 and C[ 0 ] ← 1 in step Z1. If a cache hit occurs in Z2, set COUNT ← COUNT + C[ t ] ; otherwise set c l ← COUNT . Set C[ m l ] ← COUNT − c l in step Z7.
254. (a) If the options include d different colors for item i , a subproblem has d + 2 distinct cases: Either item i does not appear in any remaining options, or its list has not been purified, or its list has been purified to a particular color. So we reserve ⌈lg( d + 2)⌉ bits for i in the signature. If, for example, d = 4, those three bits will contain one of the codes 000, 001, 010, 011, 100, 101.
[In order to recognize the relevant case, Algorithm Z ’s version of the ‘purify’ operation in (55) should set COLOR( i ) ← c in the header node for i ; the ‘unpurify’ in (57) should set COLOR( i ) ← 0; and step Z1 should set COLOR( i ) ← 0. That initialization step should also remap i ’s colors so that they appear internally as 1, 2, ... , d .]
(b) In large problems σ will occupy several octabytes. Give each item i a new field SIG( i ) , which is an index to a code table, and a new field WD( i ) . If LEN( i ) ≠ 0, item i will contribute CODE[SIG( i ) + COLOR( i )] to octabyte WD( i ) of σ .
[If hashing is used for the cache lookup in step Z2, the CODE table can also contain random bits, for convenience in computing a good hash function.]
(c) Operation hide′( p ) doesn’t remove node q from list TOP( q ) , if that list has been purified. But if TOP( q ) is included in the signature, we’ll never get a cache hit for solutions with different colors, even when subproblems don’t actually depend on those colors. Therefore we need to know when a secondary item has no active options in its list.
(d) The trick is to decrease LEN( i ) , while still retaining the nodes on list i . If LEN( i ) becomes zero, when i is a secondary item, we can then remove it from the list of active secondary items (whose head is N + 1, by answer 8 ).
[We can also use this trick in the ‘hide’ routine: Let hide′″ ( p ) be like hide( p ) except that DLINK( u ) and ULINK( d ) remain unmodified when COLOR( q ) < 0; LEN( x ) is decreased as usual.] Of course unpurify and unhide′″ should undo purify and hide′″.
Some delicate maneuvers are needed to avoid deactivating a secondary item twice, and to reactivate it at precisely the right time when unpurifying. (The author’s implementation temporarily sets the LEN to −1.)
255. Let V n \= ∑ k \= 0 n ( n − 1 − 2 k ) ( n − k k ) , W n \= ∑ k \= 0 n ( n − 12 k ) + ( n − 1 − 2 k ) 2 ) ( n − k k ) . Using the fact that ∑ k \= 0 n ( k r ) ( n − k r ) \= [ z n ] z 2 r / ( 1 − z − z 2 ) r + 1 , we obtain the closed forms V n \= (( n −5) F n +1 +2( n +1) F n )/ 5 and W n \= ((5 n 2 +7 n +25) F n +1 −6( n +1) F n )/25. (See the derivation of 1.2.8–(17).) When N is even, Algorithm Z performs W N − 1 updates and outputs a ZDD with V N + 2 nodes. When N is odd, it performs W N updates and outputs the trivial ZDD ‘⏊’.
256. Let T ( N ), Z ( N ), and C ( N ) be the time, ZDD size, and cache size needed for K N . With (89) the algorithm first spends T (2 q )+ T (2 r ) time to create a ZDD of size Z (2 q )+ Z (2 r ). Then it spends min( T (2 q +1) ,T (2 r − 1)) time to learn that no more ZDD nodes are desirable. The cache size is C (2 q )+ C (2 r ) + min( C (2 q +1) ,C (2 r − 1)).
257. (a) There are 2 n −1 +1 signatures: 11 ... 1 and all n -bit strings beginning with 0.
(b) Each nonzero signature σ has 2 νσ −1 branches.
258. See (84). Now it’s V n \= v n + ∑ k \= 1 n − 1 ( n − 1 k ) v k \= ( ( 72 n − 342 ) 5 n + ( 375 n − 875 ) 4 n + 600 ⋅ 3 n + 1800 n 2 n + 1550 ) / 3600 . [For example, V 16 = 40454337297; ϖ 16 = 10480142147.]
259. (a) The signatures at level l are { X l +1 ,...,X n } together with all ( n l ) l -element subsets of { Y 1 ,...,Y n }. So there are 2 n of them; also 2 + ∑ l \= 0 n ( n − 1 ) ( n l ) \= n 2 n − 1 + 2 ZDD nodes; and (( n 2 +3 n + 4)2 n − 4)/4 updates.
(b) Now the signatures are { X l +1 , . . . , X n } plus l -element subsets of { Y 1 ,...,Y l +1 }. So we get ( n 2 ) + 1 cache memos; n 2 + 2 ZDD nodes; (2 n 3 + 15 n 2 + n )/6 updates.
260. The ménage problem, with ≈ n ! /e 2 solutions, leads to unexpected running times: We seem to get roughly order n 3/2 ρ n updates, where ρ ≈ 3 . 1; but better results are obtained for n ≥ 13 when the MRV heuristic is not used in step Z3! Then the running time may well be Θ( ne n ), although the ZDD size apparently grows as nρ n with ρ ≈ 2 . 56.
The other problem, with L n + 2 solutions, needs just 6 n + 9 memos, 8 n − 9 ZDD nodes, and 34 n − 58 updates.
261. (a) Introduce primary items v − and v + for each vertex v , representing the possibility of passing through v ; but omit v − for v ∈ S , and v + for v ∈ T . Also introduce secondary items v , whose color (if nonzero) represents the path number. The main options are ‘ u + v − u : k v : k ’, for each arc u → v and for 1 ≤ k ≤ m . There also are options ‘ v − v :0’ for all v / ∈ S , and ‘ v + v :0’ for all v ∉ T .
Moreover, we need a way to number each path canonically, so that we don’t get m ! equivalent solutions. (The method of exercise 122 does not work with Algorithm Z .) If S = { s 1 ,...,s p }, introduce primary items x k and secondary items y k for 1 ≤ k ≤ p , with the following options: ‘ x k s k :0 y k − 1 : j y k : j ’ and ‘ x k s k :( j +1) y k − 1 : j y k :( j +1)’, for 1 ≤ k ≤ p and 0 ≤ j < k . [Omit the item y k − 1 : j when k = 1; omit options with y p ≠ m .]
Many of these options can never be used. Algorithm P readily removes them.
(b) Remove unreachable vertices and unreachable arcs from G , if necessary, so that the only sources and sinks are S = { s 1 ,...,s m } and T = { t 1 ,...,t m }. Then use items v − , v + , v and the main options of the construction in part (a); but omit any option that specifies s j : k or t j : k for j ≠ k .
(c) This is a trick question, because each path contains exactly one vertex on the diagonal. The problem therefore factors neatly into two independent subproblems. It suffices to find n − 1 vertex-disjoint paths from S = {(0, 1) ,..., (0 ,n −1), (1 ,n ) ,..., ( n −1 ,n )} to T = {(1, 1) ,..., ( n −1 ,n −1)} in the digraph with vertices ( i, j ) for 0 ≤ i ≤ j ≤ n , ( i, j ) ∉ {(0, 0), (0 ,n ), ( n, n )}, and arcs ( i, j ) →( i +1 ,j ), ( i, j ) →( i, j − 1).
If this problem has P n solutions, given by a ZDD Z with M n nodes, the original problem has p n 2 solutions, given by a ZDD Z ″ with 2 M n nodes. We obtain Z ″ by replacing ⏊ in Z with the root of Z′ , where Z′ specifies the reflections of the paths of Z .
Algorithm Z needs just 7 gigamems to find P 16 = 992340657705109416 and M 16 = 3803972. (In fact, P n is known to be ∏ 1≤ i ≤ j ≤ k ≤ n ( i + j + k −1)/( i + j + k −2), the number of plane partitions that are totally symmetric: N. Beluhov [to appear] has found a nice way to glue six triangular diagrams together, in kaleidoscope fashion, which establishes a one-to-one correspondence linking these paths to symmetrical diamond tilings like those of exercise 262(b) .)
(d) There are exactly 47356 solutions. Algorithm C finds them in 278 G μ , without preprocessing; but it needs only 760 M μ , after Algorithm P has removed redundant options. Algorithm Z , by contrast, handles the problem in 92 G μ , using 7 gigabytes of memo-cache memory (without preprocessing); 940 M μ and 90 megabytes (with). Hence Algorithm Z is undesirable for problem (d), but essential for problem (c).
262. (a) The ordering of the primary items — the cells of S n — is critical: Rowwise ordering (left-to-right, top-to-bottom) causes exponential growth; but columnwise ordering (top-to-bottom, left-to-right) yields linear ZDD size, and Θ( n 2 ) running time.
Furthermore, it turns out to be better not to use the MRV heuristic, when n ≥ 18. Then the number of ZDD nodes is 154440 n − 2655855 for all n ≥ 30. Only 2.2 G μ are needed for n = 32. There are 68719476736 \= ( 2 ) 72 solutions for S 16 , via exercise 7.1.4–208; for S 32 there are 152326556015596771390830202722034115329 ≈ 1.552 200 .
(An Aztec diamond of order m has exactly 2 m ( m +1)/2 domino tilings; and as m → ∞, the dominoes at the corners are q.s. aligned, except within an “ arctic circle” of radius m / 2 . See W. Jockusch, J. Propp, and P. Shor, arXiv:9801068v2 [math.CO] (1995, 2026), 42 pages; H. Cohn, N. Elkies, and J. Propp, Duke Math. J. 85 (1996), 117–166. See also D. Grensing, I. Carlsen, and H.-Chr. Zapp, Philos. Mag. A41 (1980), 777–781.)
[Tilings of the more general shapes S mn considered here, where we replace 16 by 2 m and 7 by m −1, are more mysterious. M. Ciucu observes that R (2 m )( n − 2 m ) ⊆ S mn ⊆ R (2 m )( n +2 m ) , where R kn is a k × n rectangle; furthermore both R (2 m )( n +2 m ) \ S mn and S mn \ R (2 m )( n −2 m ) are tilable. Richard Stanley has shown, in Discrete Applied Math. 12 (1985), 81–87, that R (2 m ) n has ~ α 2 m μ 2 m n + 1 tilings, for fixed m as n → ∞, where
a k \= ( 1 + 2 ) k + 1 − ( 1 − 2 ) k + 1 2 2 , μ 2 m \= r j \= 1 m ( cos θ j + 1 + cos 2 θ j ) , θ j \= j π 2 m + 1 .
Hence S mn has Θ ( μ 2 m n ) tilings in that limit. But if m = αn as n → ∞, the limiting “arctic curve” outside which dominoes tend to be frozen remains to be discovered.]
There is, incidentally, a beautiful connection between domino tilings and vertex-disjoint paths, discovered by D. Randall (unpublished):
every vertical domino has either a blue or red path
every horizontal domino has blue and red paths, crossed
(b) In this case the triangle coordinates of answer 124 yield linear growth if we use items ( x, y ) for 0 ≤ x < n + 8, 0 ≤ y < 16, x + y ≥ 8; ( x, y )′ for 0 ≤ x < n + 8, 0 ≤ y < 16, 7 ≤ x + y < n + 15. The options are ‘( x, y ) ( x′,y′ )’, where ( x′,y′ ) = ( x, y ) −{(0, 0), (0, 1), (1, 0)} and both items exist. Then the ZDD size (without MRV) turns out to be 257400 n − 1210061, for all n ≥ 7.
The convex triangular regions that can be tiled with diamonds are precisely those that have equally many Δ and ∇ triangles, namely the generalized hexagons T lmn with sides ( l, m, n, l, m, n ) for some l, m, n ≥ 0. These tilings are equivalent to plane partitions that fit in an l × m × n box. In fact you can “see” this equivalence, because the diagrams resemble cubies packed into a corner of the box! (David Klarner made this discovery in the 1970s, but didn’t publish it.) Therefore every tiling of T n has respectively (1, 2, ... , 8, 7, ... , 1) vertical diamonds in rows (1, 2, ... , 15), hence 64 in all; and these occurrences are nested. For example, the middle diagram corresponds to the reverse plane partition shown here. (See exercise 5.1.4–36, from which it follows that the generalized hexagon T lmn has exactly ∏ lm n \= ∏ i \= 1 l ∏ j \= 1 m ∏ k \= 1 n ( i + j + k − 1 ) / ( i + j + k − 2 ) tilings. In particular, we have Π 888 = 5055160684040254910720; Π 88(16) = 2065715788914012182693991725390625.)
00012457
1134569c
12368abc
25789bbc
4578accc
459aaccc
569aaccc
bbbbcccc
[In New York J. of Math. 4 (1998), 137–165, H. Cohn, M. Larsen, and J. Propp studied random tilings of T lmn when l , m , and n approach infinity with constant scaling, and conjectured that they are q.s. “frozen” outside of the largest enclosed ellipse. See also the more general results of C. Boutillier, Annals of Probability 37 (2009), 107–142.]
263. parameters solutions items options Alg C time, space Alg Z time, space ZDD
(a) | 14772512 | 32 + 58 | 256 | 40 G μ | 23 KB | 55 G μ | 4.1 GB | 56M | |
(b) | 6 × 10 | 2339 | 72 + 0 | 2032 | 4.1 G μ | 230 KB | 3.1 G μ | 23 MB | 11K |
(b) | 8 × 8, square | 16146 | 77 + 1 | 2327 | 20 G μ | 264 KB | 14 G μ | 101 MB | 59K |
(b) | 8 × 8, straight | 24600 | 77 + 1 | 2358 | 36 G μ | 267 KB | 26 G μ | 177 MB | 93K |
(b) | 8 × 8, skew | 23619 | 77 + 1 | 2446 | 28 G μ | 275 KB | 20 G μ | 137 MB | 84K |
(b) | 8 × 8, ell | 60608 | 77 + 1 | 2614 | 68 G μ | 291 KB | 44 G μ | 276 MB | 183K |
(b) | 8 × 8, tee | 25943 | 77 + 1 | 2446 | 35 G μ | 275 KB | 25 G μ | 166 MB | 92K |
(c) |
| 987816 | 49 + 42 | 1514 | 25 G μ | 149 KB | 18 G μ | 646 MB | 2.2M |
(7, 0, 3) | 137216 | 64 + 128 | 3970 | 8.5 G μ | 642 KB | 1.7 G μ | 20 MB | 210K | |
(d) | (7, 3, 4) | 41280 | 70 + 140 | 4762 | 3.2 G μ | 769 KB | 1.0 G μ | 13 MB | 122K |
(e) | 1 | 12 + 1230 | 14400 | 17 G μ | 2 MB | 25 G μ | 91 MB | 14 | |
(f) | kill symmetry | 44 * | 12 + 36 | 1188 | 1.3 G μ | 110 KB | 0.9 G μ | 10 MB | 186 |
(g) | unmodified | 18 | 1165 + 66 | 4889 | 202 G μ | 509 MB | 234 G μ | 8.9 GB | 2049 |
(g) | modified | 1 | 1187 + 66 | 5143 | 380 G μ | 537 MB | 424 G μ | 15 GB | 336 |
(g) | preprocessed | 18 | 446 + 66 | 666 | 223 M μ | 66 KB | 1.8 M μ | 136 KB | 574 |
* includes solutions that touch all cells
264. Let the primary items be linearly ordered, and let r ( o ) be the smallest primary item in option o . If ( o ¯ ? l : h ) is a ZDD node, every option o′ in the subZDD rooted at h has r ( o′ ) > r ( o ), because o covers r ( o ) and smaller items have already been covered. Moreover, if l ≠ 0, the option o′ in node l has r ( o′ ) = r ( o ); and o′ precedes o in the input.
Thus, if we use a stable sorting algorithm to sort the options by decreasing r ( o ), the ZDD will respect the reverse of this ordering. [This result was proved by Nishino, Yasuda, Minato, and Nagata in their original paper. Unfortunately, the algorithm is usually too slow without MRV, except in special situations like those of exercise 262 .]
265. Every solution below any given ZDD node covers the same primary items. If all items are primary, no two visible nodes have the same signature. And the nodes of the chain below every visible node are distinct, because they branch on different options.
Now suppose we have three primary items { p, q, r }, and one secondary item s , with options ‘ p ’, ‘ p r ’, ‘ p s ’, ‘ q r ’, ‘ q s ’. If we don’t use MRV, we’ll branch on p . Choice 1, ‘ p ’, leads to a subproblem with signature 0111 that outputs I 2 \= ( q r ¯ ? 0 : 1 ) , I 3 \= ( p ¯ ? 0 : 2 ) . Choice 2, ‘ p r ’, leads to a subproblem with signature 0101 that outputs I 4 \= ( q s ¯ ? 0 : 1 ) , I 5 \= ( p r ¯ ? 3 : 4 ) . Choice 3, ‘ p s ’, leads to a subproblem with signature 0110 that outputs I 6 \= ( q r ¯ ? 0 : 1 ) , I 7 \= ( p s ¯ ? 5 : 6 ) . And I 6 = I 2 .
A similar example, with items { q 1 ,q 2 ,q 3 ,r 1 ,r 2 ,r 3 } in place of { q, r }, and with 23 options ‘ p ’, ‘ p r i ’, ‘ p s ’, ‘ q i q j ’, ‘ r i r j ’, ‘ q i r i ’, ‘ q i r j ’, ‘ q j r i ’, ‘ q i s ’, for 1 ≤ i < j ≤ 3, fails when MRV dictates the choices.
266. Let the given shape be specified as a set of integer pairs ( x, y ). These pairs might simply be listed one by one in the input; but it’s much more convenient to accept a more compact specification. For example, the utility program with which the author prepared the examples of this book was designed to accept UNIX-like specifications such as ‘ [14-7]2 5[0-3] ’ for the eight pairs {(1, 2), (4, 2), (5, 2), (6, 2), (7, 2), (5, 0), (5, 1), (5, 3)}. (Notice that a pair is included only once, if it’s specified more than once.) The range 0 ≤ x, y < 62 has proved to be sufficient in almost all instances, with such integers encoded as single “ extended hexadecimal digits” 0 , 1 , ... , 9 , a , b , ... , z , A , B , ... , Z . The specification ‘ [1-3][1-k] ’ is one way to define a 3 × 20 rectangle.
Similarly, each of the given polyominoes is specified by stating its piece name and a set T of typical positions that it might occupy. Such positions ( x, y ) are specified using the same conventions that were used for the shape; they needn’t lie within that shape.
The program computes base placements by rotating and/or reflecting the elements of that set T . The first base placement is the shifted set T 0 = T − ( x min ,y min ), whose coordinates are nonnegative and as small as possible. Then it repeatedly applies an elementary transformation, either ( x, y ) ↦ ( y, x max − x ) or ( x, y ) ↦ ( y, x ), to every existing base placement, until no further placements arise. (That process becomes easy when each base placement is represented as a sorted list of packed integers ( x ≪16)+ y .) For example, the typical positions of the straight tromino might be specified as ‘ 1[1-3] ’; it will have two base placements, {(0, 0), (0, 1), (0, 2)} and {(0, 0), (1, 0), (2, 0)}.
After digesting the input specifications, the program defines the items of the exact cover problem, which are (i) the piece names; (ii) the cells xy of the given shape.
Finally, it defines the options: For each piece p and for each base placement T ′ of p , and for each offset ( δ x ,δ y ) such that T ′ +( δ x , δ y ) lies fully within the given shape, there’s an option that names the items { p }∪{( x + δ x ,y + δ y ) | ( x, y ) ∈ T ′}.
(The output of this program is often edited by hand, to take account of special circumstances. For example, some items may change from primary to secondary; some options may be eliminated in order to break symmetry. The author’s implementation also allows the specification of secondary items with color controls, along with base placements that include such controls.)
Historical notes: Early algorithms for polyomino packing failed to realize the essential unity between cells to be covered and pieces to be covered; their treatment of cells was quite different from their treatment of pieces. The fact that both cells and pieces are primary items of a “pure” exact cover problem was first noticed in connection with the Soma cube, by C. Peter-Orth [ Discrete Mathematics 57 (1985), 105–121]. The base placements of tiles that are to be translated (but not rotated or reflected) are called “ aspects” in Tilings and Patterns by Grünbaum and Shephard (1987).
267. RUSTY. [Leigh Mercer posed a similar question to Martin Gardner in 1960.]
268. As in the 3 × 20 example considered in the text, we can set up an exact cover problem with 12 + 60 items, and with options for every potential placement of each piece. This gives respectively (52, 292, 232, 240, 232, 120, 146, 120, 120, 30, 232, 120) options for pieces (O, P, ... , Z) in Conway’s nomenclature, thus 1936 options in all.
To reduce symmetry, we can insist that the X occurs in the upper left quarter; then it contributes just 10 options instead of 30. But some solutions are still counted twice, when X is centered in the middle row. To prevent this we can add a secondary item ‘s’: Append ‘s’ to the five options that correspond to those centered appearances, and to the 60 options that correspond to placements where the Z is flipped over.
Without those changes, Algorithm X would use 10.04 G μ to find 4040 solutions; with them, it needs just 2.93 G μ to find 1010.
This approach to symmetry breaking in pentomino problems is due to Dana Scott [Technical Report No. 1 (Princeton University Dept. of Electrical Engineering, 10 June 1958)]. Another way to break symmetry would be to allow X anywhere, but to restrict the W to its 30 unrotated placements. That works almost as well: 2.96 G μ .
269. There’s a unique way to pack P, Q, R, U, X into a 5 × 5 square, and to pack the other seven into a 5 × 7. (See below.) With independent reflections, together with rotation of the square, we obtain 16 of the 1010. There’s also a unique way to pack P, R, U into a 5 × 3 and the others into a 5 × 9 (noticed by R. A. Fairbairn in 1967), yielding 8 more. And there’s a unique way to pack O, Q, T, W, Y, Z into a 5 × 6, plus two ways to pack the others via a bipair, yielding another 16. (These paired 5 × 6 patterns were apparently first noticed by J. Pestieau; see answer 286 .) Finally, the packings in the next exercise give us 264 decomposable 5 × 12s altogether.
[Similarly, C. J. Bouwkamp discovered that S, V, T, Y pack uniquely into a 4 × 5, while the other eight can be put into a 4 × 10 in five ways, thus accounting for 40 of the 368 distinct 4 × 15s. See JRM 3 (1970), 125.]
270. Without symmetry reduction, 448 solutions are found in 1.24 G μ . But we can restrict X to the upper left quarter, as in answer 268 , flagging its placements with ‘s’ when centered in the middle row or middle column (but not both). Again the ‘s’ is appended to flipped Z’s. Finally, when X is placed in dead center, we append another secondary item ‘c’, and append ‘c’ to the 90 ° -rotated placements of W. This yields 112 solutions, after 0.35 G μ .
Or we could leave X unhindered but curtail W to 1/4 of its placements. That’s easier to do (although not quite as clever) and it finds those 112 in 0.44 G μ .
Incidentally, there aren’t actually any solutions with X in dead center.
271. The exact cover problem analogous to that in exercise 268 has 12 + 60 items and (56, 304, 248, 256, 248, 128, 152, 128, 128, 32, 248, 128) options. It finds 9356 solutions after 16.42 G μ of computation, without symmetry reduction. But if we insist that X be centered in the upper left quarter, by removing all but 8 of its placements, we get 2339 solutions after just 4.11 G μ . (The alternative of restricting W’s rotations is not as effective in this case: 5.56 G μ .) These solutions were first enumerated by C. B. and Jenifer Haselgrove [Eureka: The Archimedeans’ Journal 23 (1960), 16–18].
272. (a) Obviously only k = 5 is feasible. All such packings can be obtained by omitting all options of the cover problem that straddle the “cut.” That leaves 1507 of the original 2032 options, and yields 16 solutions after 104 M μ . (Those 16 boil down to just the two 5 × 6 decompositions that we already saw in answer 269 .)
(b) Now we remove the 763 options for placements that don’t touch the boundary, and obtain just the two solutions below, after 100 M μ . (This result was first noticed by Tony Potts, who posted it to Martin Gardner on 9 February 1960.)
(c) With 1237 placements/options, the unique solution is now found after 83 M μ .
(d) There are respectively (0, 9, 3, 47, 16, 8, 3, 1, 30, 22, 5, 11) solutions for pentominoes (O, P, Q, ... , Z). (The I/O pentomino can be “framed” by the others in 11 ways; but all of those packings also have at least one other interior pentomino.)
(e) Despite many ways to cover all boundary cells with just seve n pentominoes, none of them lead to an overall solution. Thus the minimum is eight; 207 of the 2339 solutions attain it. To find them we might as well generate and examine all 2339.
(f) The question is ambiguous: If we’re willing to allow the X to touch unnamed pieces at a corner, but not at an edge, there are 25 solutions (8 of which happen to be answers to part (a)). In each of these solutions, X also touches the outer boundary. (The cover and frontispiece of Clarke’s book show a packing in which X doesn’t touch the boundary, but it doesn’t solve this problem: Using Golomb’s piece names, there’s an edge where X meets I, and there’s a point where X meets P.) There also are two packings in which the edges of X touch only F, N, U, and the boundary, but not V.
On the other hand, there are just 6 solutions if we allow only F, N, U, V to touch X’s corner points. One of them, shown below, has X touching the short side and seems to match the quotation best. These 6 solutions can be found in just 47 M μ , by introducing 60 secondary items as sort of an “upper level” to the board: All placements of X occupy the normal five lower-level cells, plus up to 16 upper-level cells that touch them; all placements of F, N, U, V are unchanged; all placements of the other seven pieces occupy both the lower and the upper level. This nicely forbids them from touching X.
273. (a) We could set this up as twelve separate exact cover problems, one for each pentomino omitted. But it’s more interesting to consider all cases simultaneously, by giving a “free pass” to one pentomino as follows: Add a new primary item ‘#’, and twelve new options ‘# O ’, ‘# P ’, ... , ‘# Z ’. The sixty items ij are demoted to secondary status.
To remove symmetry, delete 3/4 of the options for piece V; also make its new option ‘# V s’, and add ‘s’ to 3/4 of the options for piece W, where ‘s’ is a new secondary item. That makes a total of 1194 options, involving 13 + 61 items.
If Algorithm X branches first on #, the effect is equivalent to 12 separate runs; the search tree has 7.9 billion nodes, and the run time is 16.8 teramems. But if we use the nonsharp preference heuristic (see answer 10 ), the algorithm is able to save some time by making decisions that are common to several subcases. Its search tree then has 7.3 billion nodes, and the run time is 15.1 teramems. Of course both methods give the same answer, which is huge: 118,034,464.
(b) Now keep items ij primary, but introduce 60 new secondary items ij ′ . There are 60 new options ‘ ij ij ′ ( i +1) j ′ i ( j +1) ′ ( i +1)( j +1) ′ ’, where we omit items containing ( i +1) when i = 2 or ( j +1) when j = 19. This problem has 1254 options involving 73+61 items. Its search tree (with deprecated # branching) has about 950 million nodes; it finds 4,527,002 solutions, after about 1.5 teramems of computation.
A related, but much simpler, problem asks for packings in which exactly one hole appears in each of the column pairs { 1 , 2 }, { 5 , 6 }, { 9 , a }, { d , e }, { h , i }. That one has 1224 options, 78+1 items, 20 meganodes, 73 gigamems, and 23642 solutions. Here’s one:
(c) A setup like the one in (a) yields 1127 options, 13+58 items, 1130 meganodes, 2683 gigamems, 22237 solutions. (One of the noteworthy solutions is illustrated above.)
274. Restrict X to five essentially different positions; if X is on the diagonal, also keep Z unflipped by using the secondary item ‘s’ as in answer 268 . There are respectively (16146, 24600, 23619, 60608, 25943) solutions, found in (20.3, 36.3, 28.0, 68.3, 35.2) G μ .
In each case the tetromino can be placed anywhere that doesn’t immediately cut off a region of one or two squares. [The twelve pentominoes first appeared in print when H. E. Dudeney published The Canterbury Puzzles in 1907. His puzzle #74, “The Broken Chessboard,” presented the first solution shown above, with pieces checkered in black and white. That parity restriction, with the further condition that no piece is turned over, would reduce the number of solutions to only 4, findable in 120 M μ .]
The 60-element subsets of the chessboard that can’t be packed with the pentominoes have been characterized by M. Reid in JRM 26 (1994), 153–154.
The earliest known polyomino puzzle appeared in P. F. Catel’s Verzeichniß von sämmtlichen Waaren (Berlin, 1785), #11: 4 Z pentominoes + 4 ells make a 6×6 square.
275. Yes, in seven essentially different ways. To remove symmetry, we can make the O vertical and put the X in the right half. (The pentominoes will have a total of 6 × 2+5 × 3 + 4 = 31 black squares; therefore the tetromino must be
.)
276. These shapes can’t be packed in a rectangle. But we can use the “ supertile”
to make an infinite strip
. [See B. Grünbaum and G. C. Shephard, Tilings and Patterns (1987), 508.] We can also tile the plane with a supertile like
, or even use a generalized torus such as
(see exercise 7 – 137 ). That supertile was used in 2009 by George Sicherman to make tetromino wallpaper.
277. The 2339 solutions contain 563 that satisfy the “ tatami” condition: No four pieces meet at any one point. Each of those 563 leads to a simple 12-vertex graph coloring problem; for example, the SAT methods of Section 7.2.2.2 typically need at most two or three kilomems to decide each case.
It turns out that exactly 94 are three-colorable, including the second solution to exercise 272(b) . Here are the three for which W, X, Y, Z all have the same color:
278. The 2339 solutions in answer 271 restrict X to the upper left quarter; we must be careful not to include bipairs that might swap X out of that region. One way (see exercise 212 ) is to order the items: Put X first, then the other piece names, then the place names from 00 to 59. All swaps involving X will then move it up or left.
The 34 bipairs of the catalog now result in an exact cover problem with the same primary items and options as before, but with 2804 new secondary items. They limit the number of solutions to 1523; but the running time increases to 4.26 G μ .
[The proof idea of Theorem S yields an interesting directed acyclic graph with 2339 vertices and 937 arcs. It has 1528 source vertices, 1523 sink vertices, and 939 isolated vertices (both sources and sinks). If we ignore the arc directions, there are 1499 components, of which the largest has size 10. That component contains the leftmost solution below, which belongs to four different bipairs. There also are two components of size 8, with three nonoverlapping bipairs. The rightmost solution belongs to a component of size 6, which would grow to size 8 if X were allowed to move downward.]
279. It’s also possible to wrap two cubes of size 5 × 5 × 5 , as shown by F. Hansson; see Fairy Chess Review 6 (1947–1948), problems 7124 and 7591. A full discussion appears in FGbook , pages 685–689.
280. (Notice that width 3 would be impossible, because every faultfree placement of the V needs width 4 or more.) We can set up an exact cover problem for a 4 × 19 rectangle in the usual way; but then we make cell ( x, y + 15) identical to (3 − x, y ) for 0 ≤ x < 4 and 0 ≤ y < 5, essentially making a half-twist when the pattern begins to wrap around. There are 60 symmetries, and care is needed to remove them properly. The easiest way is to put X into a fixed position, and allow W to rotate at most 90 ° .
This exact cover problem has 850 solutions, 502 of which are faultfree. Here’s one of the 29 strongly three-colorable ones, shown before and after its ends are joined:
281. Both shapes have 8-fold symmetry, so we can save a factor of nearly 8 by placing the X in (say) the north-northwest octant. If X thereby falls on the diagonal, or in the middle column, we can insist that the Z is not flipped, by introducing a secondary item ‘s’ as in answer 270 . Furthermore, if X occurs in dead center — this is possible only for shape (i) — we use ‘c’ as in that answer to prohibit also any rotation of the W.
Thus we find (a) 10 packings, in 3.5 G μ ; (b) 7302 packings, in 353 G μ ; for instance
It turns out that the monomino must appear in or next to a corner, as shown. [The first solution to shape (i) with monomino in the corner was sent to Martin Gardner by H. Hawkins in 1958. The first solution of the other type was published by J. A. Lindon in Recreational Mathematics Magazine #6 (December 1961), 22. Shape (ii) was introduced and solved much earlier, by G. Fuhlendorf in The Problemist: Fairy Chess Supplement 2 , 17 and 18 (April and June 1936), problem 2410.]
282. It’s easy to set up an exact cover problem in which the cells touching the polyomino are primary items, while other cells are secondary, and with options restricted to placements that contain at least one primary item. Postprocessing can then remove spurious solutions that contain holes. Typical answers for (a) are
representing respectively (9, 2153, 37, 2, 17, 28, 18, 10, 9, 2, 4, 1) cases. For (b) they’re
representing (16, 642, 1, 469, 551, 18, 24, 6, 4, 2, 162, 1). The total number of fences is respectively (3120, 1015033, 8660380, 284697, 1623023, 486, 150, 2914, 15707, 2, 456676, 2074), after weeding out respectively (0, 0, 16387236, 398495, 2503512, 665, 600, 11456, 0, 0, 449139, 5379) cases with holes. (See MAA Focus 36 , 3 (June/July 2016), 26; 36 , 4 (August/September 2016), 33.) Of course we can also make fences for one shape by using other shapes; for example, there’s a beautiful way to fence a Z with 12 Ps, also a unique way to fence one pentomino with only three copies of another.
283. The small fences of answer 282(a) already meet this condition — except for the X, which has no tatami fence. The large fences for T and U in 282(b) are also good. But the other nine fences can no longer be as large:
[The tatami condition can be incorporated into the exact cover problem by introducing a secondary item / ij for each interior point ij . Add this item to every placement option that has a convex corner at ij and occupies either the cell to the northeast or the cell to the southwest. However, for this exercise it’s best simply to apply the tatami condition directly to each ordinary solution, before postprocessing for hole-removal.]
284. This problem is readily solved with the “ second death” algorithm of exercise 19 , by letting the four designated piece names be the only primary items. The answers to both (a) and (b) are unique. [See M. Gardner, Scientific American 213 , 4 (October 1965), 96–102, for Golomb’s conjectures about minimum blocking configurations on larger boards.]
285. This exercise, with 3 × 30, 5 × 18, 6 × 15, and 9 × 10 rectangles, yields four increasingly difficult benchmarks for the exact cover problem, having respectively (46, 686628, 2567183, 10440433) solutions. Symmetry can be broken as in answer 270 . The 3×30 case was first resolved by J. Haselgrove; the 9×10 packings were first enumerated by A. Wassermann and P. Östergård, independently. [See New Scientist 12 (1961), 260– 261; J. Meeus, JRM 6 (1973), 215–220; and FGbook pages 455, 468–469.] Algorithm X needs (.006, 5.234, 15.576, 63.386) teramems to find them.
286. Two solutions are now equivalent only when related by 180 ° rotation. Thus there are 2 · 2339/64 = 73.09375 solutions per problem, on average. The minimum (42) and maximum (136) solution counts occur for the cases
[In U.S. Patent 2900190 (1959, filed 1956), J. Pestieau remarked that these 64 problems would give hi s pentomino puzzle “unlimited life and utility.”]
287. Let c = (12, 11,..., 1) for pieces (O, P,..., Z) when assigning costs to each option. Algorithm X $ , when told that every option contains one piece and five cells, finds
in respectively (1.5, 3.4, 3.3, 2.9, 3.2, 1.4, 1.1) G μ . The corresponding times for Algorithm X are (3.7, 10.0, 16.4, 16.4, 10.0, 3.7, 2.0) G μ . (However, we could reduce symmetry when applying Algorithm X , then calculate the values of four or eight different reflections or rotations whenever a solution is found; that would often be faster.)
288. When symmetry is removed efficiently, Algorithm X needs 63 T μ to visit all of the essentially different solutions. But Algorithm X $ wins this competition, by discovering
(which both are uniquely optimum) in 28.9 T μ and 25.1 T μ , respectively.
289. (a) One of the 8·2422·85·263·95·224·262·226·228·96·105·174 solutions is shown in Fig. A–4 . (It isn’t hard to keep pentominoes of the same shape from touching.)
(b) Now there are 1472 · 5915 · 596 · 251 · 542 · 204 · 170 · 226 · 228 · 96 · 651 · 316.
(c) The first seven columns left of the middle line can yield six 12-cell regions only by using all 72 cells. Thus the problem factors neatly into ten independent problems of the form (i). That problem has 7712 solutions with six connected regions; Algorithm X $ needs a search tree of only 622 nodes to determine that there are just 11 minimum-perimeter solutions. Three of them are symmetrical; and the nicest is shown in (ii). (And two of the solutions, such as (iii), maximize the total perimeter.)
Unfortunately (36) can’t be expanded into the desired 720-cell shape based on (ii), because the scaled-up Q can’t be packed. But the alternative form of (36) does lead to 16 · 2139 · 6 · 97 · 259 · 111 · 44 · 64 · 79 · 12 · 17 · 111 solutions, such as the one in Fig. A–4 .
290. There are no ways to fill 2 × 20; 4 · 66 ways to fill 4 × 10; 4 · 84 ways to fill 5 × 8. None of the solutions are symmetrical. [See R. K. Guy, Nabla 7 (1960), 99–101.]
291. The puzzles for January, April, September, and December (say) are equivalent; thus only 4·31 = 124 puzzles need to be solvable, not 366. Only 53 of the 220 pentomino triples are unsuitable: First reject all 55 that include X, and all 10 that are subsets of {O, R, S, W, Z}; then restore P{O, Q, S, T, U, V, Y}X and ORS, OSW, RSW; then reject RTZ and TWZ. Of the remaining 167 triples, PQV is by far the easiest: Every PQV puzzle has at least 1778 solutions! The hardest is QTX, which allows only about 33 solutions per day, on average. [This puzzle was designed by Marcel Gillen, © 2018, who made it with pentominoes R, U, W for the 2018 International Puzzle Party.]
292. Most of the hexominoes will have three black cells and three white cells, in any “checkering” of the board. However, eleven of them (shown as darker gray in the illustration) will have a two-to-four split. Thus the total number of black cells will always be an even number between 94 and 116, inclusive. But a 210-cell rectangle always contains exactly 105 black cells. [See The Problemist: Fairy Chess Supplement 2 , 9–10 (1934–1935), 92, 104–105; Fairy Chess Review 3 , 4–5 (1937), problem 2622.]
Fig. A–4. Pentominoes of pentominoes.
Benjamin’s triangular shape, on the other hand, has 1+3+5+···+19 = 10 2 = 100 cells of one parity and ( 21 2 ) − 10 2 \= 110 of the other. It can be packed with the 35 hexominoes in a huge number of ways, probably not feasible to count exactly.
293. The parity considerations in answer 292 tell us that this is possible only for the “unbalanced” hexominoes, such as the one shown. And in fact, Algorithm X readily finds solutions for all eleven of those, too numerous to count. Here’s an example:
[See Fairy Chess Review 6 (April 1947) through 7 (June 1949), problems 7252, 7326, 7388, 7460, 7592, 7728, 7794, 7865, 7940, 7995, 8080. See also the similar problem 7092.]
294. Each castle must contain an odd number of the eleven unbalanced hexominoes (see answer 292 ). Thus we can begin by finding all sets of seven hexominoes that can be packed into a castle: This amounts to solving ( 11 1 ) + ( 11 3 ) + ( 11 5 ) + ( 11 7 ) \= 968 exact cover problems, one for each potential choice of unbalanced elements. Each of those problems is fairly easy; the 24 balanced hexominoes provide secondary items, while the castle cells and the chosen unbalanced elements are primary. In this way we obtain 39411 suitable sets of seven hexominoes, with only a moderate amount of computation.
That gives us another exact cover problem, having 35 items and 39411 options. This secondary problem turns out to have exactly 1201 solutions (found in just 115 G μ ), each of which leads to at least one of the desired overall packings. Here’s one:
In this example, two of the hexominoes in the rightmost castle can be flipped vertically; and of course the entire contents of each castle can independently be flipped horizontally. Thus we get 64 packings from this particular partition of the hexominoes (or maybe 64 · 5!, by permuting the castles), but only two of them are “really” distinct. Taking multiplicities into account, there are 1843 “really” distinct packings altogether.
[Frans Hansson found the first way to pack the hexominoes into five equal shapes, using
as the container; see Fairy Chess Review 8 (1952–1953), problem 9442. His container admits 123189 suitable sets of seven, and 9298602 partitions into five suitable sets instead of only 1201. Even more packings are possible with the container
, which has 202289 suitable sets and 3767481163 partitions!]
In 1965, M. J. Povah packed all of the hexominoes into containers of shape
, using seven sets of five ; see The Games and Puzzles Journal 2 (1996), 206.
295. By exercise 292 , m must be odd, and less than 35. F. Hansson posed this question in Fairy Chess Review 7 (1950), problem 8556. He gave a solution for m = 19,
and claimed without proof that 19 is maximum. The 13 dark gray hexominoes in this diagram cannot be placed in either “arm”; so they must go in the center. (Medium gray indicates pieces that have parity restrictions in the arms.) Thus we cannot have m ≥ 25.
When m = 23, there are 39 ways to place all of the hard hexominoes, such as
However, none of these is completable with the other 22; hence m ≤ 21.
When m = 21, the hard hexominoes can be placed in 791792 ways, without creating a region whose size isn’t a multiple of 6 and without creating more than one region that matches a particular hexomino. Those 791792 ways have 69507 essentially distinct “footprints” of occupied cells, and the vast majority of those footprints appear to be impossible to fill. But in 2016, George Sicherman found the remarkable packing
which not only solves m = 21, it yields solutions for m = 19, 17, 15, 11, 9, 7, 5, and 3 by simple modifications. Sicherman also found separate solutions for m = 13 and m = 1.
296. Stead’s original solution makes a very pleasant three-colored design:
[See Fairy Chess Review 9 (1954), 2–4; also FGbook , pages 659–662.]
This problem is best solved via the techniques of dynamic programming (Section 7.7), not with Algorithm X , because numerous subproblems are equivalent.
297. Yes — in fact, there are so many ways, further conditions ought to be imposed. Torbijn’s original quest, to leave a hexomino-shaped “hole” in one square, turns out to have been impossible. But there’s a nice alternative: We can add the two trominoes .
A. van de Wetering showed in 1991 that exactly 13710 sets of six hexominoes can fit into a single square. [See JRM 23 (1991), 304–305.] Similarly, exactly 34527 sets of five hexominoes will fit, when supplemented by two trominoes that both occupy two black cells. So we’re left with a secondary covering problem, with 35 primary items and 48237 options, as in answer 294 . That problem has 163 solutions (found in 3 T μ ).
Another alternative, also suggested by van de Wetering, is to place six empty cells symmetrically. He also was able to add a monomino and one of the pentominoes: The secondary covering problems associated with pentominoes (O, P, ... , Z) turn out to have (94, 475, 1099, 0, 0, 2, 181, 522, 0, 0, 183, 0) solutions.
298. Make options for the pentominoes in cells xy for 0 ≤ x < 8, 0 ≤ y < 10 as in exercise 266 , and also for the tetrominoes in cells xy for 1 ≤ x < 7, 1 ≤ y < 9. In the latter options include also items xy ′ :0 for all cells xy in the tetromino, as well as xy ′ :1 for all other cells xy touching the tetromino, where the items xy ′ for 0 ≤ x < 8 and 0 ≤ y < 10 are secondary. We can also assume that the center of the X pentomino lies in the upper left quarter. There are 168 solutions, found after 1.5 T μ of computation. (Another way to keep the tetrominoes from touching would be to introduce secondary items for the vertices of the grid. Such items are more difficult to implement, however, because they behave differently under the rotations of answer 266 .)
[Many problems that involve placing the tetrominoes and pentominoes together in a rectangle were explored by H. D. Benjamin and others in the Fairy Chess Review , beginning already with its predecessor The Problemist: Fairy Chess Supplement 2 , 16 (February 1936), problem 2171. But this question seems to be new; it was inspired by Michael Keller’s 15 × 18 pentomino + hexomino construction in World Game Review 9 (1989), 3. See also P. Torbijn’s elegant 13 × 23 packing of all the n -ominoes for 1 ≤ n ≤ 6, in Cubism For Fun 25 , part 1 (1990), 11.]
299. P. J. Torbijn and J. Meeus [ JRM 32 (2003), 78–79] have exhibited solutions for rectangles of sizes 6 × 45, 9 × 30, 10 × 27, and 15 × 18; thus intuition suggests that enormously many solutions ought to be possible for this case too. But Peter Esser has surprisingly proved that no packing of the 35 hexominoes into a 5 × 54 rectangle will occupy all 114 of the border cells. Indeed, the pieces can individually occupy at most (6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 5 + x 24 , 4 + x 25 , 4 + x 26 , 4+ x 27 , 3+ x 28 , 3+ x 29 , 3+ x 30 , 2+ x 31 , 2+ x 32 , 4+2 x 33 , 3+2 x 34 , 3+2 x 35 ) border cells, respectively, under an appropriate numbering of the pieces, where x k \= 1 only if piece k is in a corner. Since there are only four corners, we can occupy at most 6+5+···+4+3+ 3+(1+2+2+2) = 114 border cells — but only if x 33 = x 34 = x 35 = 1. Unfortunately, those last three pieces (namely
,
,
) can’t simultaneously occupy corners.
300. Make options as usual ( exercise 266 ), but also include 100 new options ‘ xy R x C y ’ for 0 ≤ x, y < 10. Then use Algorithm M , assigning multiplicity 4 to each R x and C y . Remove symmetry by confining X to the upper left quarter, and by insisting that O be horizontal. (a) One of the 31 solutions (found in 12 G μ ) is shown below. (b) This case has 5347 solutions (found in 4.6 T μ ); and if we insist on filling also all cells just above the diagonals, the solution turns out to be unique (see below). (c) Instead of focusing on diagonals, Aad van de Wetering noticed that we can require the empty spaces to be symmetrical . For example, there are 1094 solutions (found in 19.2 T μ ) whose empty spaces are diagonally symmetric. Three of them, like the one shown here, are also rather close (92%) to being centrally symmetric (that is, under 180 ° rotation).
Three others, like the fourth example above, leave a 4 × 4 hole in the corner. Moreover, there are 98 solutions (found in 3.2 T μ ) whose empty spaces have 100% central symmetry. One of them has a large “moat” between two blocks of pentominoes; another has connected pentominoes, with holes of size at least 6.
Furthermore, van de Wetering reported that he had found “by accident” a solution where each of the four 5 × 5 quadrants of the 10 × 10 contained exactly three pentominoes. This additional stipulation is, indeed, easy to add to our MCC formulation: We omit options that cross quadrant boundaries, append a new item Q t to each option in the t th quadrant, and give multiplicity 3 to each Q t . It turns out that there actually are 1,124,352 inequivalent solutions(!), found by Algorithm M in 23 T μ .
But van de Wetering also discovered a class of solutions that’s even more interesting: He packed the empty spaces entirely with “ghost” pentominoes, all different!
To obtain such remarkable solutions, use primary items # xy , ! xy , #R x , and #C y for 0 ≤ x, y < 10, as well as O, P, ... , Z; use secondary items xy as well as O ′ , P ′ , ... , Z ′ . Items #R x and #C y have multiplicity 4. Specify two options for each pentomino placement, such as ‘V !00 00:1 !01 01:1 !02 02:1 !10 10:1 !20 20:1’ for V in the corner and ‘V ′ !00 00:0 !01 01:0 !02 02:0 !10 10:0 !20 20:0’ for its ghost in that place. Also specify 200 further options, ‘# xy #R x #C y xy :0’ and ‘# xy xy :1’, for 0 ≤ x, y < 10. Algorithm M with the nonsharp heuristic will then make intelligent choices. There are (amazingly) 357 solutions, found in 322 teramems with a search tree of 32 giganodes. The first solution above is one of six that cover exactly six cells of each main diagonal, answering a question that had been posed by Aad Thoen. The second solution is one of two for which all seven of the “unambiguously named pentominoes” T, U, V, W, X, Y, Z are among the ghosts. The third solution is one of two that respects 5×5 quadrants. [ Note: A similar question, but with identical polyominoes, was Erich Friedman’s “problem of the month” in May 2007; see erich-friedman.github.io/mathmagic/0507.html .]
301. (a) Algorithm M produces 4 · 13330 solutions when we specify the desired multiplicities for cell items. Symmetry under reflection can be removed by restricting, say, W to only 1/4 of its options.
(b) Consider the conflict graph on vertices O , P , ... , Z , defined by declaring pieces to be adjacent when they appear in the same cell. We can achieve ≤ d levels if and only if we can color that graph with ≤ d colors. The conflict graph for the given arrangement has the 4- clique { Q , X , Y , Z }; so it can’t be 3-colored.
(c, d) A SAT solver such as Algorithm 7.2.2.2D quickly determines that exactly (587, 12550, 193) of the conflict graphs for the 13330 distinct solutions to (a) have chromatic numbers (3, 4, 5). The first example below can be (uniquely) 3-colored OVYZ | PRWX | QSTU ; the second example has the clique { Q , R , S , W , Y }.
302. (a) There are 94. (But 16 of them have interior “ holes” and can’t be used in (b).)
(b) The two solutions are related by rotating four of the pieces:
(c) Sixteen different jigsaw sudoku diagrams can be used. The first of them collaborates with π as shown above; the others probably do too. [ Appendix E has the answer. This exercise was suggested by E. Timmermans, Cubism For Fun 85 (2011), 4–9.]
303. (a) Represent the tree as a sequence a 0 a 1 ... a 2 n −1 of nested parentheses; then a 0 will match a 2 n −1 . The left boundary of the corresponding parallomino is obtained by mapping each ‘ ( ’ into N or E, according as it is immediately followed by ‘ ( ’ or ‘ ) ’. The right boundary, similarly, maps each ‘ ) ’ into N or E according as it is immediately preceded by ‘ ) ’ or ‘ ( ’. For example, if we take 7.2.1.6–(1) and enclose it in an additional pair of parentheses, the corresponding parallomino is shown below with part (d).
(b) This series wxy + w 2 ( xy 2 + x 2 y ) + w 3 ( xy 3 + 2 x 2 y 2 + x 3 y ) + ··· can be written wxyH ( w, wx, wy ), where H ( w, x, y ) = 1/(1 − x − y − G ( w, x, y )) generates a sequence of “atoms” corresponding to places x , y , G where the juxtaposed boundary paths have the respective forms E E , N N , or N E 〈 inner 〉 E N . The area is thereby computed by diagonals between corresponding boundary points. (In the example from (a), the area is 1+1+1+1+2+2+2+2+2+2+2+2+2+1+1; there’s an “outer” G , whose H is yxyGy , and an “inner” G , whose H is xyyxyxxy .) Thus we can write G as a continued fraction,
G ( w , x , y ) \= w x y / ( 1 − w x − w y − w 3 x y / ( 1 − w 2 x − w 2 y / ( … ) ) ) .
[A completely different form is also possible, namely G ( w , x , y ) \= x J 1 ( w , x , y ) J 0 ( w , x , y ) , where
J 0 ( w , x , y ) \= Σ n \= 0 ∞ ( − 1 ) n y n w n ( n + 1 ) / 2 ( 1 − w ) ( 1 − w 2 ) … ( 1 − w n ) ( 1 − x w ) ( 1 − x w 2 ) … ( 1 − x w n ) ; J 1 ( w , x , y ) \= Σ n \= 1 ∞ ( − 1 ) n − 1 y n w n ( n + 1 ) / 2 ( 1 − w ) ( 1 − w 2 ) … ( 1 − w n − 1 ) ( 1 − x w ) ( 1 − x w 2 ) … ( 1 − x w n ) .
This form, derived via horizontal slices, disguises the symmetry between x and y .]
(c) Let G ( w, z ) = G ( w, z, z ). We want [ z n ] G ′ (1, z ), where differentiation is with respect to the first parameter. From the formulas in (b) we know that G (1, z ) = z ( C ( z ) − 1), where C ( z ) \= ( 1 − 1 − 4 z ) / ( 2 z ) generates the Catalan numbers. Partial derivatives ∂/∂w and ∂/∂z then give G ′ (1, z ) = z 2 /(1−4 z ) and G ′ ( 1 , z ) \= 1 / 1 − 4 z − 1 .
(d) This problem has four symmetries, because we can reflect about either diagonal. When n = 5, Algorithm X finds 4 × 801 solutions, of which 4 × 129 satisfy the tatami condition, and 4 × 16 are strongly three-colorable. (The tatami condition is easily enforced via secondary items in this case, because we need only stipulate that the upper right corner of one parallomino doesn’t match the lower left corner of another.) When n = 6 there are oodles and oodles of solutions. All of the trees/parallominoes thereby appear together in an attractive compact pattern.
[ References: J. Levine, Scripta Mathematica 24 (1959), 335–338; D. A. Klarner and R. L. Rivest, Discrete Math. 8 (1974), 31–40; E. A. Bender, Discrete Math. 8 (1974), 219–226; I. P. Goulden and D. M. Jackson, Combinatorial Enumeration (New York: Wiley, 1983), exercise 5.5.2; M.-P. Delest and G. Viennot, Theoretical Comp. Sci. 34 (1984), 169–206; W.-J. Woan, L. Shapiro, and D. G. Rogers, AMM 104 (1997), 926–931; P. Flajolet and R. Sedgewick, Analytic Combinatorics (2009), 660–662.]
304. E. D. Demaine and M. L. Demaine [ Graphs and Combinatorics 23 (2007), Supplement, 195–208] show the NP-completeness also of several other related problems, such as to exactly pack given boxes of sizes {1 × x 1 , ... , 1 × x n } into a given rectangle.
305. A scheme of “ even/odd coordinates” (see exercise 145 and answer 133 ) works beautifully to represent the space occupied by a windmill domino: Encode the large square in row i and column j by the ordered pair (2 i +1)(2 j +1); encode the small “tilted” square that overlaps two adjacent large squares by the midpoint between them. Then, for example, ‘15’ is the large square in row 0 and column 2; ‘25’ is the small tilted square whose top and bottom halves are the bottom and top quarters of 15 and 35. Large squares have area 4; small tilted squares have area 2; the encoding of each square specifies the coordinates of its center point. The relevant coordinates xy in an m × n box satisfy 0 < x < 2 n and 0 < y < 2 m , where x and y are integers that aren’t both even.
Therefore the possible placements of the leftmost windmill domino are either {13, 15, 12, 23} + (2 k , 2 l ), {33, 53, 23, 32} + (2 k , 2 l ), {33, 31, 34, 23} + (2 k , 2 l ), or {31, 11, 41, 32} + (2 k , 2 l ), where k and l are nonnegative integers.
(a) Two cases: We can use a 5 × 5 box, and require that the small squares of each option are either { 34 , 45 }, { 47 , 56 }, { 76 , 65 }, or { 63 , 54 }; or a 6 × 6 box, with those small-square coordinates shifted by 11 . For example, if we call the leftmost piece ‘ 0 ’, its 5 × 5 options are ‘ 0 35 37 34 45 ’, ‘ 0 57 77 47 56 ’, ‘ 0 53 33 63 54 ’, ‘ 0 75 73 76 65 ’. The 5 × 5 problem has 4 · 183 solutions, in groups of four that are related by 90°. rotation; the 6 × 6 problem, similarly, has 4 · 209 solutions. Reflection gives 4 · 183 + 4 · 209 more. Here are some of the 8 + 5 classes of equivalent solutions whose large squares form a symmetric shape; the last two of these look the same, but use different pieces(!):
(b) Algorithm X quickly finds 501484 = 2 · 4 + 4 · 125369 solutions, including four classes that are symmetric under reflection and 125369 unsymmetric classes. One of the symmetric examples is shown below; also one of the 164 asymmetric classes whose small squares do at least form a symmetric shape.
(c) The 288 = 2 · 4 + 4 · 70 solutions include four symmetric classes (like the one shown) and 70 that have no symmetry.
(d) We can set this up as a 7 × 7 problem in which the small squares form a rectangle whose corners are { 47 , 74 , 8b , b8 }. It has 2 · 2696 solutions, all asymmetric; 2 · 95 of them fit in a 5 × 5 box, and 2 · 3 of them have large squares that form the symmetric shape shown.
(e) Now there are two possibilities: We might have an 8 × 8 box, with small squares in the rectangle whose corners are { 34 , 43 , cd , dc }; or we might have a 9 × 9 box, with small squares confined to the rectangle { 45 , 54 , de , ed }. The first case has 69120 = 2 · 4 + 4 · 17278 solutions, four with reflective symmetry; the second case has a whopping 157398 = 2 · 75 + 4 · 39312 solutions, with 75 classes unchanged under reflection. Symmetric solutions of both types are shown.
306. Introduce items 0 to 9 and xy as in the previous answer, as well as p xy and # xy ; again x and y aren’t both even. But now we extend the ranges to 0 ≤ x ≤ 2 n and 0 ≤ y ≤ 2 m , allowing small squares to cross the boundary. Here p xy and # xy are primary, but the xy items are secondary. Options of the first kind, like ‘ 0 p35 35 :1 p37 37 :1 p34 34 :1 p45 45 :1’, specify placement of a piece. Options of the second kind, ‘ p xy xy :0’, allow square xy to be empty. Options of the third kind, either ‘ # xy xy :0’ or ‘ # xy xy :1 ( x −2) y : a ( x +2) y : b x ( y −2): c x ( y +2): d ’ for binary variables a , b , c , d with a + b + c + d = 2, and where both x and y are odd, enforce the snake condition for large squares. Options of the fourth kind, either ‘ # xy xy :0’ or ‘ # xy xy :1 ( x −1)( y −1): a ( x −1)( y +1): b ( x +1)( y −1): c ( x +1)( y +1): d ’ and where x + y is odd, enforce the snake condition for small squares. Nonsharp branching ( exercise 10 ) should be used.
Those options unfortunately produce a huge number of spurious solutions containing 4-cycles. One can rule out the 4-cycle whose large squares have a given x ′ y ′ as midpoint by using Algorithm M and introducing a new primary item # x ′ y ′ whose multiplicity is [0 .. 3]. (Notice that x ′ and y ′ are both even.) This primary item is appended to every option of type 3 that begins with ‘ # xy xy :1’, where xy is one of the four squares touching point x ′ y ′ . The 4-cycles of small squares can be ruled out similarly, with new primary items # xy ! , where x + y is even.
Every snake cycle of 20 large squares will fit into an extended box of size 3 × 9, 4×8, 5×7, or 6×6; and Algorithm M finds respectively (0, 0, 4 · 10, 8 · 10) solutions in those four cases. However, (0, 0, 4 · 1, 8 · 8) of those solutions are spurious, because their small squares form disjoint cycles instead of a single 20-cycle. Thus there are eleven essentially different solutions. Two of each size are shown below. [The middle two examples show two of the large squares touching at a corner. The definition of snake cycles doesn’t rule out corner-touching; but five of the eleven solutions don’t have that “defect.” See Cubism For Fun 41 (October 1996), 30–32.]
307. “ Factoring” with the residues ( i − j ) mod 3 and ( i + j ) mod 3, we see that the domino must go into adjacent cells with ( i − j ) mod 3 ≠ 1 and ( i + j ) mod 3 ≠ 2. That means either {(3 i , 3 j ), (3 i , 3 j + 1)} or {(3 i + 1, 3 j + 2), (3 i + 2, 3 j + 2)}. Conversely, it’s easy to insert straight trominoes after placing a domino into any of those cell pairs.
308. (a) Each shape now has integer pairs of the forms ( x, y ) and ( x, y ) ′ . One elementary transformation, which rotates by 60 ° , takes ( x, y ) ↦ ( x + y , − x ) ′ and ( x, y ) ′ ↦ ( x + y +1,− x ); the shape’s triangles should be shifted afterwards so that all coordinates are nonnegative and as small as possible. The other elementary transformation, which is a reflection, simply takes ( x, y ) ↦ ( y, x ) and ( x, y ) ′ ↦ ( y, x ) ′ .
For convenience, let’s write just xy for ( x, y ). One tetriamond is the triangle of size 2, {00, 01, 10, 00 ′ }. It has two base placements; the other one is {01 ′ , 10 ′ , 11 ′ , 11}. Another tetriamond is “straight,” {00, 00 ′ , 10, 10 ′ }, and it has six base placements. (Three of them, such as {00, 00 ′ , 01, 01 ′ }, involve reflection; hence that tetriamond has two one-sided versions.) The remaining tetriamond is “bent,” {00 ′ , 01, 10, 10 ′ }, a hexagon minus a diamond. Its six base placements are all obtained by rotation.
(b) Four of the 20-iamonds are convex, namely those parameterized by (6, 4, 0, 0), (10, 10, 1, 0), (4, 2, 1, 0), and (5, 5, 2, 0) in the notation of exercise 143 . But only (4, 2, 1, 0) can be packed with the four pentiamonds — in fact in two ways, differing by a bipair.
(c) The convex 30-iamonds (15, 15, 1, 0) and (7, 7, 1, 1) cannot be packed. But (4, 2, 1, 1), (5, 5, 3, 0), (3, 3, 3, 1) have respectively 23, 7, and 8 distinct solutions.
309. (a) (A, ... , L) have respectively (6, 3, 6, 1, 6, 6, 12, 12, 6, 12, 12, 12) placements.
(The hexiamonds have also been given descriptive names: A = lobster (or heart); B = butterfly (or spool); C = chevron (or bat); D = hexagon; E = crown (or boat); F = snake (or wave); G = hook (or shoe); H = signpost (or pistol or airplane); I = bar (or rhomboid); J = crook (or club or ladle); K = yacht (or steps); L = sphinx (or funnel).)
(b) Hexiamonds K and L are special, because they contain four triangles of one kind (∆ or ∇) and two of the other (∇ or ∆). The other hexiamonds are balanced, with three of each kind.
Eleven convex polygons are 72-iamonds, by exercise 143 . Those with height less than 4, namely (36, 36, 1, 0), (19, 17, 0, 0), (18, 18, 2, 0), and (12, 12, 3, 0), are unsolvable. So is (9, 3, 0, 0), which is out of balance by 6. The other six are solvable; for example,
The shape (6, 2, 2, 1) is out of balance by 4. Consequently we can restrict K and L to about half of the positions where they would otherwise fit. The running time to find all solutions (without removing symmetry) thereby decreases, from 16.8 G μ to 13.5 G μ ; thus the parity theory helps here, but not as much as might be expected.
What about the one-sided hexiamonds (with “flipped” versions of F through L, making 19 in all)? There are six convex polygons made up of 6 · 19 = 114 triangles, and again the small-height ones (57, 57, 1, 0), (28, 28, 1, 1), (19, 19, 3, 0) are unsolvable. The case (13, 9, 1, 0) has 1,687,429 solutions (found by Algorithm X in 11 T μ ). Shape (8, 8, 3, 3) has 4,790,046 distinct solutions (103 T μ ); (9, 5, 2, 1) has 17,244,919 (98 T μ ).
Historical notes: T. Scrutchin [ U.S. Patent 895114 (1908)] described an early puzzle based on assembling checkered polyiamonds of sizes 3–7 into a large equilateral triangle. The complete set of hexiamonds was perhaps first invented by Charles H. Lewis, who submitted a paper about them to the American Mathematical Monthly in April 1958. His paper wasn’t judged worthy of publication; but a copy survives in the files of Martin Gardner, to whom he had sent a preprint. (He’d been inspired by Martin’s exposition of polyominoes in December 1957.) Lewis named his pieces hexotinoes , and said that they belonged to the family of “polotinoes,” which began with the monotino, the dotino, the trotino, three tetrotinoes, and four pentotinoes. He knew the parity rule, and he exhibited one of the ways to pack all 12 hexotinoes into a 6 × 6 rhombus.
Other people came up with similar ideas independently a few years later. It was T. H. O’Beirne who coined the names “polyiamond” and “hexiamond” — to the eternal dismay of language purists — first in letters to Richard Guy in 1960, then in his popular weekly columns in New Scientist [ 12 (1961), 261, 316–317, 379, 706–707]. He introduced an intriguing problem about packing the one-sided hexiamonds into the rosette shape formed by 19 hexagons (12 surrounding 6 surrounding 1); see pages 452–455 of FGbook for details. Martin Gardner wrote about the subject in Scientific American 211 , 6 (December 1964), 123–130, and hexiamonds were soon sold as pleasing puzzles in Japan, Germany, the USA, and elsewhere. The 24 heptiamonds also have many aficionados, but they are beyond the scope of this book.
The earliest papers about hexiamonds considered mostly standard shapes like parallelograms, or shapes that are decidedly non-convex. Polygon (6, 2, 2, 1) above, the “diaper,” may have first appeared as problem 130 in the Russian magazine Nauka i Zhizn’ #6 (1969), 146; #7 (1969), 101; Michael Beeler enumerated its solutions in HAKMEM (M.I.T. A.I. Laboratory, 1972), Hack 112. Polygon (6, 6, 3, 2) has apparently not occurred previously in print, although it has more solutions than the others.
310. The container holds 4 m +2 triangles; m = 18 doesn’t work, so we need at least six empty cells. The author’s favorite way constrains them to be well-separated “teeth”:
311. H. Postl found a nice proof that N must be at least 190: Replace hexiamonds A, G, K by the heptiamond that includes a hexagon. The twelve resulting pieces contain 75 triangles; enlarge them by appending quarter-size triangles around all the edges. This adds 91 trapezoids and 163 quarter-triangles. The latter must occupy at least 91 + (163 − 91)/3 = 115 triangles, because we can’t fill a triangle without using a trapezoid.
Exercise 7–137 explains how to obtain many generalized toruses that are composed of 95 rhombuses; so we might as well make the repeating pattern as square as possible by choosing ( a, b, c, d ) = (11, −4, −1, 9), as in the solution below. There are (astonishingly) 321530 such packings, each of which represents 24 different solutions when the heptiamonds revert to {A, G, K}. The example shown is one of only 1768 solutions for which the three resulting “females” attract three neighboring “males.”
[The smallest region for pentomino wallpaper has 143 cells. See A. Thoen and A. van de Wetering, Facets of Pentominoes (2018), 95.]
312. Adrian Struyk wrapped the octahedron with hexiamonds, and showed it to Martin Gardner in 1964. An attractive solution by Walter Stead (1970, unpublished),
doesn’t bend any piece in more than two places. (Incidentally, Thijs Notenboom showed in 1967 how to wrap the icosahedron with the four pentiamonds .)
313. The whirled versions of pieces (A, ... , L) can be packed in respectively (13, 2 · 2, 10, 6 · 55, 19, 2 · 10, 9, 10, 2 · 10, 18, 6, 20) ways. But with flipped whirls, the one-sided pieces lead to different shapes, and the counts for (F, G, ... , L) change to (2 · 6, 7, 8, 2 · 0, 25, 7, 8). Here’s how the pattern of answer 310 looks when scaled up by 12 :
[The “whirl” in this exercise is the case n = 3 of an n -whirl, which has n 2 + 3 triangles for n ≥ 2. In 1936, Maurits Escher visited the Alhambra and saw a pattern related to the whirl tessellation. He was subsequently inspired to develop it much further; see The World of M. C. Escher (1971), plates 84 and 199.]
314. To make the same shape from two pairs { a, b } and { c, d } of polyiamonds (or polyominoes, etc.), choose an n -celled region A into which any solution will fit. Use four primary items { a, b, c, d } and 6 n secondary items 0 α , 1 α , aα , bα , cα , dα for each cell α . For each placement ‘ a α 1 ... α s ’ in A , and each of the 2 s sequences q 1 ... q s with q k ∈ { c, d }, create the option ‘ a 0 α 1 q 1 α 1 ... 0 α s q s α s aβ 1 ... aβ n−s ’, where { β 1 ,..., β n−s } = A \ { α 1 ,..., α s }. Also create similar options for each placement of b , c , d , with the roles of (0, a, c, d ) replaced respectively by (0, b, c, d ), (1, c, a, b ), (1, d, a, b ).
Choose one of { a, b, c, d } (one-sided if possible) and restrict it to a single placement. For the pentiamond problem, the author chose the piece a that includes a tetrahedron, and placed it in the center of a 70-iamond A . There are three separate cases, depending on which piece is called b ; they yielded three huge exact cover problems, each of which had 15300 options of length 76 (thus total length 1.2 million). Yet Algorithm X solved each problem in at most 1.5 G μ , including 0.3 G μ just to load the data.
The answer, as Sicherman observed, is unique. [See Ed Pegg Jr.’s blog, [www.mathpuzzle.com/30November2008.html](http://www.mathpuzzle.com/30November2008.html) . Solomon Golomb, in Recreational Math. Mag. #5 (October 1961), 3–12, had shown that the twelve pentominoes can be partitioned into three sets of four, each of which make congruent pairs.]
315. Proceed as in answer 308 , but simply let ( x, y ) ↦ ( x + y , − x ); ignore ( x, y ) ′ .
[There’s also an even/odd coordinate system for hexagons, with hexagon xy represented by (2 x + 1, 2 y + 1), and the edge between adjacent hexagons represented by their average. Then 60 ° rotation takes ( x, y ) ↦ ( x + y − 1, x max − x + 1).]
316. There are 12 · 12290 solutions, and it’s not hard to find one by hand. (The first solutions were discovered independently by T. Marlow and E. Schwartz in 1966; the total number was found by K. Noshita in 1974.) The example shown here has the trihexes “maximally separated.” [The seven tetrahexes pack the rhomboid { xy | 0 ≤ x < 4, 0 ≤ y < 7} in 2 · 9 ways, and the skew triangle { xy | 0 ≤ x < 7, x ≤ y < 7} in 2 · 5 ways; but they can’t pack the triangle { xy | 0 ≤ x < 7, 0 ≤ y < 7 − x }.]
317. The scaled-up “bar,” “wave,” and “ propeller” cannot be packed. But the “bee,” “arch,” “boot,” and “worm” are doable in respectively 2 · 2, 1, 10, and 4 ways, such as
[This problem was introduced by E. Schwartz in 1966 and independently by G. Edgar in 1967, who showed their solutions to Martin Gardner. Edgar pointed out that the rosettes can actually be placed in two ways — either rising or falling slightly from left to right when put together. The three one-sided tetrahexes therefore lead to distinct scaled-up shapes. Only one of those two is packable, for the boot and the worm; both are impossible for the wave. The slight tilting accounts for some of the remarkable properties of R. W. Gosper’s “ flowsnake” fractal; see M. Gardner, Scientific Amer. 235 , 6 (December 1976), 124–128, 133; A. Vince, SIAM J. Discrete Math. 6 (1993), 501–521.]
318. The “holes” in the T-grid correspond to vertices of the infinite triangular grid; and every hexagon of the T-grid is inside exactly one of the triangles made by those vertices. More formally, we can let
Δ ( x , y ) ↔ hexagon ( x − y , x + 2 y + 1 ) ; ∇ ( x , y ) ′ ↔ hexagon ( x − y , x + 2 y + 2 ) .
Adjacent triangles correspond to adjacent hexagons. The hexiamond hexahexes are
319. One way is to replace each square by a 3 × 3 array, representing
by
. But it uses only 4 pixels out of 9. A more compact scheme is able to use 4 pixels out of every 8: We rotate the pieces by 45 ° and represent
by
, separated by
. For example, the 14 tetraboloes take the following forms:
This scheme sets up a one-to-one correspondence between n -aboloes and 2 n -ominoes on the “ H-grid,” which is the set of all pixels ( x, y ) with ⌊ x /2⌋ + ⌊ y /2⌋ even. (Each 2 n -omino is kingwise connected; it actually consists of n dominoes.)
Formally speaking, let’s divide every square cell into four quarters, by cutting at the diagonals. Then every n -abolo occupies 2 n quarters; and the (north, east, south, west) quarters of cell ( x, y ), in polyabolo coordinates, correspond respectively to cells (2 x − 2 y , 2 x + 2 y ) + ((0, 1), (1, 1), (1, 0), (0, 0)) of the H-grid.
[After first seeing the H-grid versions of the tetraboloes, the author felt a foolish but irresistible urge to pack them into a 10 × 12 box, putting seven of them in the H-grid and the other seven in the complementary H-grid, leaving eight vacant pixels at the sides. This corresponds to putting the tetraboloes into two layers of a certain frame that’s capable of holding 29 halfsquares. It turned out that there are 8 · 305 ways to do this (found by Algorithm X in 10 G μ ). For example:
Nowadays, polyaboloes are often called “ polytans,” based on their connection to classical tangram puzzles from 18th-century China. T. H. O’Beirne introduced polyaboloes in New Scientist 13 (18 January 1962), 158–159.]
320. Every convex polyabolo can be characterized by six more-or-less independent parameters: We start with an m × n rectangle, then cut off triangles of sizes a , b , c , d at the lower left, lower right, upper right, and upper left corners, where a + b ≤ n , b + c ≤ m , c + d ≤ n , and d + a ≤ m . The number of halfsquares is N = 2 mn − a 2 − b 2 − c 2 − d 2 . To avoid duplicates, we require m ≤ n , and insist that ( a, b, c, d ) be lexicographically greater than or equal to ( b, a, d, c ), ( c, d, a, b ), ( d, c, b, a ). Furthermore, if m = n , this 4-tuple ( a, b, c, d ) should also be lexicographically greater than or equal to ( a, d, c, b ), ( b, c, d, a ), ( c, b, a, d ), ( d, a, b, c ).
The smallest positive area achievable with m < n is 2 m ( n − m ) halfsquares; and when m = n the smallest is 2 n − 1. Thus we must have n ≤ ( N + 2)/2, and it’s feasible to backtrack through a finite number of cases.
There are 63 solutions when N = 56. But most of them are unpackable, because of an important property noted by T. H. O’Beirne in 1962: Exactly five of the tetraboloes, namely {E, G, J, K, L}, have an odd number of unmatched 2 sides in each direction. It follows that a + c (and b + d ) must be odd.
Just 10 of the 63 solutions pass this extra test. Two of those ten — (1×29; 1, 1, 0, 0) and (3×11; 3, 1, 0, 0) — don’t work. But the other eight are achievable:
Most of them were cracked by E. S. Ainley in 1965; but H. Picciotto found ‘*’ in 1989.
[This enumeration problem was first studied by F. T. Wang and C.-C. Hsiung, AMM 49 (1942), 596–599, who proved that there are 20 convex 16-aboloes. The totals for general N are OEIS sequence A245676, contributed by E. Fox-Epstein in 2014.]
321. [In a letter to Martin Gardner dated 12 March 1967, O’Beirne said that he now knew of 13 solutions, with help from several readers. “Are these the lot?” The answer is yes: The total is indeed 13. The solution shown here leads to three of the others, via tricky rearrangements.]
322. (i) We can reduce polysticks to (disconnected) polyominoes, by 3-fold enlargement: Let vertex ij of a square grid correspond to pixel (3 i )(3 j ); and let the line segment between adjacent vertices ij — i ′ j ′ correspond to the two pixels between (3 i )(3 j ) and (3 i ′ )(3 j ′ ). Placements can intersect each other only at internal pixels where two parallel segments touch; we can prevent crossing by making such pixels secondary.
For example, to pack the 6 × 6 array in the example, we use the pixels xy for 0 ≤ x, y ≤ 18, where x or y is a multiple of 3; item xy is secondary if 3 divides both x and y . One of the options for the T-shaped tetrastick is ‘04 05 07 08 16 26 36 46 56’; one of the options for the V-shaped tetrastick is ‘34 35 36 37 38 49 59 69 79 89’. The secondary item 36 ensures that these options won’t both be chosen simultaneously.
(ii) Instead of scaling up by 3, we can scale up by 2, as in the even/odd coordinate system, by letting vertex ij correspond to pixel (2 i )(2 j ). Then segment ij — i ′ j ′ corresponds to pixel ( i + i ′ )( j + j ′ ); and the 6 × 6 example involves primary items xy for 0 ≤ x, y ≤ 12 with x + y odd, together with secondary items xy with x and y both even. The example T and V options in this scheme become ‘03 05 14 24 34’ and ‘23 24 25 36 46 56’; now it’s the secondary item 24 that keeps them from interacting.
Scheme (i) can be used without change to answer 266 . Scheme (ii) is almost twice as fast; but answer 266 must then be modified so that it never shifts by odd amounts. (Notice, for example, that the O and X tetrasticks each have only one base placement in scheme (ii), namely ‘01 10 12 21’ and ‘12 21 23 32’. Shifting by 11 would change O to X and vice versa!) Thus, 90 ° rotation must be redefined as ( x, y ) ↦( y, x max + ( x max & 1) − x ), in the modified answer 266 ; also, δ x and δ y must be even.
[Polysticks were named and explored by B. R. Barwell in JRM 22 (1990), 165– 175. They had actually been studied in the 1940s by H. D. Benjamin and T. R. Dawson, who already knew how to pack the pieces for n ≤ 4 into a 6 × 6 grid; see G. P. Jelliss, JRM 29 (1998), 140–142. See also FGbook , pages 457–472.]
323. (a) For example, the vertices ( m, n ) of an ordinary square grid can be skewed to
( m , n ) ′ \= ( m − ( n mod 2 ) ϵ , n − ( m mod 2 ) ϵ ) , where ϵ is the degree of skew .
Notice that each square of the skewed grid has a clockwise or counterclockwise “spin.”
(b) There’s a nice way to represent each square as a 5-pixel cross, and each rhombus as a 3-pixel diagonal. For example, here are pixel equivalents of the tetraskews:
(Lowercase letters indicate the rhombuses here only for clarity; all pixels are either “in” or “out.” The shapes fit together only when squares and rhombuses alternate properly.)
(c) The 4 × 10 frame in the example has 486 solutions; the analogous 5 × 8 frame has 572; these were first enumerated by Brendan Owen in 2000. There are 3648 ways to fit the pieces into a 2 × 21 frame, but 2 × 20 is too tight.
However, those counts can be divided by 2, because solutions to this problem come in pairs. Consider an arrangement of ten unskewed tetrominoes that involves one square, one straight, two skews, two tees, and four ells. It can be skewed in four ways, because we have two choices for which cells should be rhombuses and two choices for the spins; and it will be a valid skewed solution if and only if the resulting ten tetraskews are distinct. Changing the spins of a valid solution always gives another valid solution in which K ↔ L, S ↔ Z, U ↔ V are swapped. Every solution therefore has a dual , which looks rather different but is well defined.
For example, the 486 solutions to the 4 × 10 rectangle problem correspond to exactly 226 unskewed arrangements that are distinct under reflections, 17 of which actually yield two dual pairs of skewed solutions, in which the roles of squares and rhombuses are reversed! Here’s one such case:
[Michael Keller named the polyskews in 1993, and found a way to pack the tetraskews into two 4×5 frames, thus solving the 4×10 and 5×8 rectangles simultaneously. (See World Game Review 12 (1994), 12. That problem has just 24 solutions.) Generalizations to 3D await investigation.]
References: Polyforms live on many excellent and well-illustrated websites — notably puzzler.sourceforge.net by David Goodger; [www.polyforms.eu](http://www.polyforms.eu) by Peter Esser; [sicherman.net/polycur.html](http://sicherman.net/polycur.html) by George Sicherman; [www.recmath.org/PolyPages/](http://www.recmath.org/PolyPages/) by Andrew Clarke; [abarothsworld.com/Puzzles.htm](http://abarothsworld.com/Puzzles.htm) by Abaroth. [www.iread.it/lz/polymultiforms2.html](http://www.iread.it/lz/polymultiforms2.html) by Livio Zucca; [userpages.monmouth.com/~colonel/polycur.html](http://userpages.monmouth.com/~colonel/polycur.html) by George Sicherman; [www.recmath.org/PolyPages/](http://www.recmath.org/PolyPages/) by Andrew Clarke; [abarothsworld.com/Puzzles.htm](http://abarothsworld.com/Puzzles.htm) by Abaroth. In particular, Abaroth’s page “Squaring the Hexagon” discusses many ways to reduce one polyform to another. See also Ed Pegg Jr.’s chapter in Tribute to a Mathemagician (2005), 119–125.
324. The same ideas apply, but with three coordinates instead of two, and with the elementary transformations ( x, y, z ) ↦ ( y, x max − x, z ), ( x, y, z ) ↦ ( y, z, x ).
Pieces (1, 2, ... , 7) have respectively (12, 24, 12, 12, 12, 12, 8) base placements, leading to 144 + 144 + 72 + 72 + 96 + 96 + 64 options for the 3 × 3 × 3 problem.
325. It’s tempting, but wrong, to try to compute the Somap by considering only the 240 solutions that restrict the tee and the claw as suggested in the text; the pairwise semidistances between these special solutions will miss many of the actual adjacencies. To decide if u — v , one must compare u to the 48 solutions equivalent to v .
(a) The strong Somap has vertex degrees 7 1 6 7 5 19 4 31 3 59 2 63 1 45 0 15 ; so an “average” solution has (1 · 7 + 7 · 6 + … + 15 · 0)/240 ≈ 2.57 strong neighbors. (The unique vertex of degree 7 has the level-by-level structure
from bottom to top.) This graph has two edges between
and
, so it’s actually a multigraph. The two-piece substructure
occurs only in the two solutions
and
.
The full Somap has vertex degrees 21 2 18 1 16 9 15 13 14 10 13 16 12 17 11 12 10 16 9 28 8 26 7 25 6 26 5 16 4 17 3 3 2 1 1 1 0 1 , giving an average degree ≈ 9.14. (Its unique isolated vertex is
, and its only pendant vertex is
. It has 14 instances of repeated edges.)
(b) The Somap has just two components, namely the isolated vertex and the 239 others. The latter has just three bicomponents, namely the pendant vertex, its neighbor, and the 237 others. Its diameter is 8 (or 21, if we use the edge lengths 2 and 3).
The strong Somap has a much sparser and more intricate structure. Besides the 15 isolated vertices, there are 25 components of sizes {8 × 2, 6 × 3, 4, 3 × 5, 2 × 6, 7, 8, 11, 16, 118}. Using the algorithm of Section 7.4.1.2, the large component breaks down into nine bicomponents (seven of size 1, and another of size 2, not counting articulation points; the other of size 109); the 16-vertex component breaks into seven; and so on, totalling 58 bicomponents altogether for the nonisolated vertices.
(One can also consider “physical” Somaps with 480 vertices, by saying that solutions are equivalent under rotation but not reflection. There are no repeated edges. The degree sequences are 7 2 6 14 ... 0 30 and 21 4 18 2 ... 0 2 , double what we had before.)
[The Somap was first constructed by R. K. Guy, J. H. Conway, and M. J. T. Guy, without computer help. It appears on pages 910–913 of Berlekamp, Conway, and Guy’s Winning Ways , where all of the strong links are shown, and where enough other links are given to establish near-connectedness. Each vertex in that illustration has been given a code name; for example, the seven special solutions mentioned in part (a) have code names B5f, W4e, W2f, R7d, LR7g, YR3a, and R3c, respectively.]
326. Let the cubie coordinates be 51 z , 41 z , 31 z , 32 z , 33 z , 23 z , 13 z , 14 z , 15 z , for z ∈ {1, 2, 3}. Replace matrix A of the exact cover problem by a simplified matrix A ′ having only items (1, 2, 3, 4, 5, 6, 7, S), where S is the sum of all items xyz of A where x · y · z is odd. Any solution to A yields a solution to A ′ with item sums (1, 1, 1, 1, 1, 1, 1, 10). But that’s impossible, because the S counts of pieces (1, ... , 7) are at most (1, 2, 2, 1, 1, 1, 1). [See the Martin Gardner reference in answer 333 .]
327. (a) The solution counts, ignoring symmetry reduction, are: 4 × 5 corral (2), gorilla (2), smile (2), 3 × 6 corral (4), face (4), lobster (4), castle (6), bench (16), bed (24), doorway (28), piggybank (80), five-seat bench (104), piano (128), shift 2 (132), 4 × 4 coop (266), shift 1 (284), bathtub (316), shift 0 (408), grand piano (526), tower 4 (552), tower 3 (924), canal (1176), tower 2 (1266), couch (1438), tower 1 (1520), stepping stones (2718). So the 4 × 5 corral, gorilla, and smile are tied for hardest, while stepping stones are the easiest. (The bathtub, canal, bed, and doorway each have four symmetries; the couch, stepping stones, tower 4, shift 0, bench, 4 × 4 coop, castle, five-seat bench, piggybank, lobster, piano, gorilla, face, and smile each have two. To get the number of essentially distinct solutions, divide by the number of symmetries.)
(b) Notice that the stepping stones, canal, bed, and doorway appear also in (a). The solution counts are: W-wall (0), almost W-wall (12), bed (24), apartments 2 (28), doorway (28), clip (40), tunnel (52), zigzag wall 2 (52), zigzag wall 1 (92), underpass (132), chair (260), stile (328), fish (332), apartments 1 (488), goldfish (608), canal (1176), steps (2346), stepping stones (2718); hence “almost W-wall” is the hardest of the possible shapes. Notice that the stepping stones, chair, steps, and zigzag wall 2 each have two symmetries, while the others in Fig. 75(b) all have four. The 3×3×3 cube, with its 48 symmetries, probably is the easiest possible shape to make from the Soma pieces.
[Piet Hein himself published the tower 1, shift 2, stile, and zigzag wall 1 in his original patent; he also included the bathtub, bed, canal, castle, chair, steps, stile, stepping stones, shift 1, five-seat bench, tunnel, W-wall, and both apartments in his booklet for Parker Brothers. Parker Brothers distributed four issues of The SOMA ® Addict in 1970 and 1971, giving credit for new constructions to Noble Carlson (fish, lobster), Mrs. C. L. Hall (piano, clip, underpass), Gerald Hill (towers 2–4), Craig Kenworthy (goldfish), John W. M. Morgan (piano, face, gorilla, smile), Rick Murray (grand piano), and Dan Smiley (doorway, zigzag wall 2). Sivy Farhi published a booklet called Somacubes in 1977, containing the solutions to more than one hundred Soma cube problems including the bench, the couch, and the piggybank.]
328. By eliminating symmetries, there are (a) 421 distinct cases with cubies omitted on both layers, and (b) 129 with cubies omitted on only one layer. All are possible, except in the one case where the omitted cubies disconnect a corner cell. The easiest of type (a) omits { 000 , 001 , 200 } and has 3599 solutions; the hardest omits { 100 , 111 , 120 } and has 2·45 solutions. The easiest of type (b) omits { 000 , 040 , 200 } and has 3050 solutions; the hardest omits { 100 , 110 , 140 } and has 2 · 45 solutions. (The two examples illustrated have 2 · 821 and 4 · 68 solutions. Early Soma solvers seem to have overlooked them!)
329. (a) The 60 distinct cases are all quite easy. The easiest has 3497 solutions and uses { 002 , 012 , 102 } on the top level; the hardest has 268 solutions and uses { 002 , 112 , 202 }.
(b) Sixteen of the 60 possibilities are disconnected. Three of the others are also impossible — namely those that omit { 01 z , 13 z , 21 z } or { 10 z , 11 z , 12 z } or { 10 z , 11 z , 13 z }. The easiest has 3554 solutions and omits { 00 z , 01 z , 23 z }; the hardest of the possibles has only 8 solutions and omits { 00 z , 12 z , 13 z }.
(The two examples illustrated have 2 · 132 and 2 · 270 solutions.)
330. T. Bundgård and C. McFarren found in 1999 that all but 216 are realizable [ [www.fam-bundgaard.dk/SOMA/NEWS/N990308.HTM](http://www.fam-bundgaard.dk/SOMA/NEWS/N990308.HTM) ]. Five cases have unique (2 · 1) solutions:
331. Every polycube has a minimum enclosing box for which it touches all six faces. If those box dimensions a × b × c aren’t too large, we can generate such polycubes uniformly at random in a simple way: First choose 27 of the abc possible cubies; try again if that choice doesn’t touch all faces; otherwise try again if that choice isn’t connected.
For example, when a = b = c = 4, about 99.98% of all choices will touch all faces, and about 0.1% of those will be connected. This means that about .001 ( 64 27 ) ≈ 8 × 10 14 of the 27-cubie polycubes have a 4 × 4 × 4 bounding box. Of these, about 5.8% can be built with the seven Soma pieces.
But most of the relevant polycubes have a larger bounding box; and in such cases the chance of solvability goes down. For example, ≈ 6.2 × 10 18 cases have bounding box 4 × 5 × 5; ≈ 3.3 × 10 18 cases have bounding box 3 × 5 × 7; ≈ 1.5 × 10 17 cases have bounding box 2 × 7 × 7; and only 1% or so of those cases are solvable.
Section 7.2.3 will discuss the enumeration of polycubes by their size.
332. Each interior position of the penthouse and pyramid that might or might not be occupied can be treated as a secondary item in the corresponding exact cover problem. We obtain 2 · 10 solutions for the staircase; (223, 8 · 286) solutions for the penthouse with hole at the (bottom, middle); and 2 · 32 solutions for the pyramid, of which 2 · 2 have all three holes on the diagonal and 2 · 3 have no adjacent holes.
333. A full simulation of gravity would be quite complex, because pieces can be prevented from tipping with the help of their neighbors above and/or at their side. If we assume a reasonable coefficient of friction and an auxiliary weight at the top, it suffices to define stability by saying that a piece is stable if and only if at least one of its cubies is immediately above either the floor or a stable piece.
The given shapes can be packed in respectively 2 · 202, 2 · 21, 2 · 270, 8 · 223, and 2 · 122 ways, of which 2 · 202, 2 · 8, 2 · 53, 8 · 1, and 2 · 6 are stable. Going from the bottom level to the top, the layers
give a decently stable cot; a fragile vulture comes from
; a delicate mushroom comes from
; and a delicate cantilever from
. The author’s cherished set of Skjøde Skjern Soma pieces, made of rosewood and purchased in 1967, includes a small square base that nicely stabilizes both mushroom and cantilever. The vulture needs a book on top.
[The casserole and cot are due respectively to W. A. Kustes and J. W. M. Morgan. The mushroom, which is hollow, is the same as B. L. Schwartz’s “penthouse,” but turned upside down; John Conway noticed that it then has a unique stable solution. See Martin Gardner, Knotted Doughnuts (1986), Chapter 3.]
334. Infinitely many cubies lie behind a wall; but it suffices to consider only the hidden ones whose distance is at most 27 − v from the v visible ones. For example, the W-wall has v = 25, and the two invisible cubies are {332, 331} if we use the coordinates of answer 326 . We’re allowed to use any of {241, 242, 251, 252, 331, 332, 421, 422, 521, 522} at distance 1, and {341, 342, 351, 352, 431, 432, 531, 532, 621, 622} at distance 2. (The stated projection doesn’t have left-right symmetry.) The X-wall is similar, but it has v = 19 and potentially (9, 7, 6, 3, 3, 2, 1) hidden cubies at distances 1 to 7 (omitting cases like 450, which is invisible at distance 2 but “below ground”).
Using secondary items for the optional cubies, we must examine each solution to the exact cover problem and reject those that are disconnected or violate the gravity constraint of exercise 333 . Those ground rules yield 282 solutions for the W-wall, 612 for the X-wall, and a whopping 1,130,634 for the cube itself. (These solutions fill respectively 33, 275, and 13842 different sets of cubies.) Here are examples of some of the more exotic shapes that are possible, as seen from behind and below:
There also are ten surprising ways to make the cube façade if we allow hidden “underground” cubies: The remarkable construction
raises the entire cube one level above the floor, and is gravitationally stable, by exercise 333 ’s criteria! Unfortunately, though, it falls apart — even with a heavy book on top.
[The false-front idea was pioneered by Jean Paul Francillon, whose construction of a fake W-wall was announced in The SOMA ® Addict 2 , 1 (Spring 1971).]
335. (a) Each of 13 solutions occurs in 48 equivalent arrangements. To remove the symmetry, place piece 7 horizontally, either (i) at the bottom or (ii) in the middle. In case (ii), add a secondary ‘s’ item as in answer 268 , and append ‘s’ also to all placements of piece 6 that touch the bottom more than the top. Run time: 400 K μ .
[This puzzle was number 3–39 in Hoffmann’s Puzzles Old and New (1893). Another 3 × 3 × 3 polycube dissection of historical importance, “Mikusinski’s Cube,” was described by Hugo Steinhaus in the 2nd edition of his Mathematical Snapshots (1950). That one consists of the ell and the two twist pieces of the Soma cube, plus the pentacubes B, C, and f of exercise 340 ; it has 24 symmetries and just two solutions.]
(b) Yes: Michael Reid, circa 1995, found the remarkable set
which also makes 9 × 3 × 1 uniquely(!). [See Rodolfo Marcelo Kurchan, JRM 25 (1993), 300; 26 (1994), 311–312.] George Sicherman carried out an exhaustive analysis of all relevant flat polyominoes in 2016, finding exactly 320 sets that are unique for 3 × 3 × 3, of which 19 are unique also for 9 × 3 × 1. In fact, one of those 19,
is the long-sought “ Holy Grail” of 3 × 3 × 3 cube decompositions: Its pieces not only have flatness and double uniqueness, they are nested (!!). There’s also Yoshiya Shindo’s
known as the “ Neo Diabolical Cube” (1995); notice that it has 24 symmetries, not 48.
336. (Solution by P.Weigel.) We can model such a piece by three cubies and one dowel, where the dowel is not allowed to have the same coordinates as the solid cubie: Let there be 27 primary items C ( x , y , z ) and 27 secondary items D ( x , y , z ), for 0 ≤ x , y , z ≤ 3, representing cubies and dowels. There are 2 · 2 · 2 · 24 = 192 options, obtained by translation and rotation of the prototype piece ‘ C (0, 1, 0) C (1, 1, 0) C (0, 0, 0) D (0, 0, 0) D (0, 0, 1)’. (In other words, we consider the solid cubie to be essentially the same as a drilled cubie that’s occupied by a dowel.)
Algorithm X needs only 500 kilomems to discover 24 solutions, all of which are equivalent under rotation. One solution has the cubies in positions
and their dowels in positions
.
Our model has a surprising corollary that was noted by Ronald Kint-Bruynseels, the designer of this remarkable puzzle: It’s possible to drill two holes in each solid cubie, perpendicular to the dowel, without destroying the uniqueness of the solution. [ Cubism For Fun 75 (2008), 16–19; 77 (2008), 13–18.]
337. Let’s use even/odd coordinates as in exercise 145 , so that each final face has one coordinate in {0, 6} and two coordinates in {1, 3, 5}. The first goal has red spots on faces 330, 105, 501, 015, 033, 051, 611, 615, 651, 655, 161, 165, 363, 561, 565, 116, 136, 156, 516, 536, 556. The other goal has green spots on 19 of those 21 faces; but 303 replaces 033 and 633 replaces 363. (For simplicity, we’ll ignore alternative setups; there are 16 ways to put spots on dice, not just two.)
Nine bent tricubes will pack a 3 × 3 × 3 cube in 5328 ways. (They fall into 111 equivalence classes of size 48, under rotation and reflection; but that fact is irrelevant here.) Take any such solution and color its 54 external faces with the red solution. Then see if its pieces can be rearranged to give the green solution.
Notice that each bent tricube has fourteen square faces; but the two “inner” faces are never visible in the final assembly. That assembly will specify from 2 to 7 of the 12 potential faces, leaving 5 to 10 faces unconstrained. Altogether we’ll have 21 faces specified red, 33 specified blank, and 54 still free.
It turns out that 371 of the 5328 red solutions can be rearranged into green solutions; in fact one case leads to 6048 different green solutions! And there are 52 combinations of red+green solutions that leave 18 faces unspecified, such as this:
We’re free to put anything we like on those 18 faces — giving red or green spots that are false clues, and/or concealing a third pattern that the puzzler is challenged to achieve.
(The classic “ Spots Puzzle” in Hoffmann’s Puzzles Old and New (1893), No. 3–17, distributed by E. Wolff & Son’s pencil company, assembled a single die from straight tricubes. Lavery’s elegant “ Twice Dice” was produced by Pentangle Puzzles in 1990.)
338. The straight tetracube
and the square tetracube
, together with the size-4 Soma pieces in (39), make a complete set.
We can fix the tee’s position in the twin towers, saving a factor of 32; and each of the resulting 40 solutions has just one twist with the tee. Hence there are five inequivalent solutions, and 256 · 5 altogether.
The double claw has 6 · 63 solutions. But the cannon, with 4 · 1 solutions, can be formed in essentially only one way. ( Hint: Both twists are in the barrel.)
There are no solutions to ‘up 3’. But ‘up 4’ and ‘up 5’ each have 8 · 218 solutions (related by turning them upside down). Gravitationally, four of those 218 are stable for ‘up 5’; the stable solution for ‘up 4’ is unique, and unrelated to those four.
References: Jean Meeus, JRM 6 (1973), 257–265; Nob Yoshigahara, Puzzle World No. 1 (San Jose: Ishi Press International, 1992), 36–38.
339. All but 48 are realizable. The unique “hardest” realizable case,
, has 2 · 2 solutions. The “easiest” case is the 2 × 4 × 4 cuboid, with 11120 = 16 · 695 solutions.
340. (a) A, B, C, D, E, F, a, b, c, d, e, f, j, k, l, ... , z. (It’s a little hard to see why reflection doesn’t change piece ‘l’. In fact, S. S. Besley once patented the pentacubes under the impression that there were 30 different kinds! See U.S. Patent 3065970 (1962), where Figs. 22 and 23 illustrate the same piece in slight disguise.)
Historical notes: R. J. French, in Fairy Chess Review 4 (1940), problem 3930, was first to show that there are 23 different pentacube shapes, if mirror images are considered to be identical. The full count of 29 was established somewhat later by F. Hansson and others [ Fairy Chess Review 6 (1948), 141–142]; Hansson also counted the 35 + 77 = 112 mirror-inequivalent hexacubes. Complete counts of hexacubes (166) and heptacubes (1023) were first established soon afterwards by J. Niemann, A. W. Baillie, and R. J. French [ Fairy Chess Review 7 (1948), 8, 16, 48].
(b) The cuboids 1×3×20, 1×4×15, 1×5×12, and 1×6×10 have of course already been considered. The 2 × 3 × 10 and 2 × 5 × 6 cuboids can be handled by restricting X to the bottom upper left, and sometimes also restricting Z, as in answers 268 and 270 ; we obtain 12 solutions (in 350 M μ ) and 264 solutions (in 2.5 G μ ), respectively.
The 3 × 4 × 5 cuboid is more difficult. Without symmetry-breaking, we obtain 8 · 39408 solutions in about 200 G μ . To do better, notice that O can appear in four essentially different positions. With four separate runs we can find 5430/2 + 1348/4 + 716/2 + 2120/4 = 3940 solutions, in 35.7 + 10.0 + 4.5 + 7.1 ≈ 57 G μ .
[The fact that solid pentominoes will fill these cuboids was first demonstrated by D. Nixon and F. Hansson, Fairy Chess Review 6 (1948), problem 7560 and page 142. Exact enumeration was first performed by C. J. Bouwkamp in 1967; see J. Combinatorial Theory 7 (1969), 278–280, and Indagationes Math. 81 (1978), 177–186.]
(c) Almost any sub set of 25 pentacubes can probably do the job. But a particularly nice one is obtained if we simply omit o, q, s, and y, namely those that don’t fit in a 3 × 3 × 3 box. R. K. Guy proposed this subset in Nabla 7 (1960), 150, although he wasn’t able to pack a 5 × 5 × 5 at that time.
The same idea occurred independently to J. E. Dorie, who trademarked the name “ Dorian cube” [ U.S. Trademark 1,041,392 (1976)].
An amusing way to form such a cube is to make 5-level prisms in the shapes of the P, Q, R, U, and X pentominoes, using pieces {a, e, j, m, w}, {f, k, l, p, r}, {A, d, D, E, n}, {c, C, F, u, v}, {b, B, t, x, z}; then use the packing in answer 269 (!). This solution can be found with six very short runs of Algorithm X , taking only 300 megamems overall.
Another nice way, due to Torsten Sillke, is more symmetrical: There are 70,486 ways to partition the pieces into five sets of five that allow us to build an X-prism in the center (with piece x on top), surrounded by four P-prisms.
One can also assemble a Dorian cube from five cuboids, using one 1 × 3 × 5, one 2 × 2 × 5, and three 2 × 3 × 5s. Indeed, there are zillions more ways, too many to count.
341. (a) Make an exact cover problem in which a and A, b and B, ... , f and F are required to be in symmetrical position; there are respectively (86, 112, 172, 112, 52, 26) placements for such 10-cubie “super-pieces.” Furthermore, the author decided to force piece m to be in the middle of the top wall. Solutions were found immediately! So piece x was placed in the exact center, as an additional desirable constraint. Then there were exactly 20 solutions; the one below has also n, o, and u in mirror-symmetrical locations.
(b) The super-pieces now have (59, 84, 120, 82, 42, 20) placements; the author also optimistically forced j, k, and m to be symmetrical about the diagonal, with m in the northwest corner. A long and apparently fruitless computation (34.3 teramems) ensued; but — hurrah — two closely related solutions were discovered at the last minute.
(c) This computation, due to Torsten Sillke [see Cubism For Fun 27 (1991), 15], goes much faster: The quarter-of-a-box shown here can be packed with seven non-x pentacubes in 55356 ways, found in 1.3 G μ . As in answer 294 , this yields a new exact cover problem, with 33412 different options.
Another 11.8 G μ then yields seven suitable partitions into four sets of seven, one of which is illustrated below. [See also Cubism For Fun 49 (1999), 26.]
342. As in previous exercises, the key is to reduce the search space drastically, by asking for solutions of a special form. (Such solutions aren’t unlikely, because pentacubes are so versatile.) Here we can break the given shape into four pieces: Three modules of size 3 3 +2 3 to be packed with seven pentacubes, and one of size 4 3 − 3 · 2 3 to be packed with eight pentacubes. The first problem has 13,587,963 solutions, found with 240 G μ of computation; they involve 737,695 distinct sets of seven pentacubes. The larger problem has 15,840 solutions, found with 400 M μ and involving 2074 sets of eight. Exactly covering those sets yields 1,132,127,589 suitable partitions; the first one found, {a, A, b, c, j, q, t, y}, {B, C, d, D, e, k, o}, {E, f, l, n, r, v, x}, {F, m, p, s, u, w, z}, works fine. (We need only one partition, so we needn’t have computed more than a thousand or so solutions to the smaller problem.)
Pentacubes galore: Since the early 1970s, Ekkehard Künzell and Sivy Farhi have independently published booklets that contain hundreds of solved pentacube problems.
343. We can use an instructive variety of methods to deduce that the tallest towers have heights ( h O , h P ,..., h Z ) = (12, 29, 28, 28, 29, 25, 26, 23, 24, 17, 28, 27): Case O is trivial. A perfect tower for P was published by S. Farhi in Pentacubes , 5th edition (1981), Fig. 78 . And it’s easy to show that h W ≤ 24, because r, t, v, x, z can’t be placed.
Factorization yields most of the upper bounds. For example, let the cells of a tower for R be {00 k , 01 k , 11 k , 12 k , 21 k | 1 ≤ k ≤ h }, and add a new “weight” column to the exact-cover matrix, representing the sum of all items/columns 00 k and 12 k . (Thus the option ‘y 122 113 123 124 125’ has weight 4.) An exact cover by disjoint options/rows will then make the new column sum 2 h . But the maximum weights of the pentacubes (a, A, ... , f, F, j, k, ... , z) are respectively (1, 1, 1, 1, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 1, 1, 3, 5, 3, 4, 2, 3, 0, 3, 0, 0, 0, 4, 0). Their sum is 57; hence h R ≤ 57/2 < 29.
Similar arguments prove that h U < 27, h V < 24, h X < 18, h Z < 28. But case T is more complicated. Let’s introduce a column for the weights (100 · 00 k ) + (100 · 02 k )+ (10 · 11 k ) + (101 · 21 k ), and compute the 29 maximum weights (312, 312, 310, 310, 311, 311, 221, 221, 210, 210, 220, 220, 220, 210, 211, 210, 310, 505, 323, 414, 300, 323, 400, 400, 400, 300, 200, 414, 400). The heaviest 27 sum to 8296, which is less than 311 · 27; hence h T < 27. And if h T = 26, further study shows that we must omit x and two of {e, E, k, m}. Moreover, each piece must use an option of maximum weight, except that c and C should use weight 310. These restrictions narrow down the search considerably; Algorithm X is able to prove that h T < 26 in 11 T μ (and Algorithm M in 7.6 T μ ).
It’s difficult to prove that h Q < 29, and even harder to prove that h Y < 29. But in both cases a suitable weighted factorization makes the calculations feasible. (See [www.math.uni-bielefeld.de/~sillke/POLYCUBE/TOWER/pentacube](http://www.math.uni-bielefeld.de/~sillke/POLYCUBE/TOWER/pentacube) .)
Such weights also greatly accelerate the successful searches, for towers of maximum height. Here are some that were hardest-to-find (add piece ‘s’ atop the first one):
344. Reduce the placements that occupy the center cell from 72 to 3. That problem has 2528 solutions, found by Algorithm X in 25 G μ ; and those solutions form 1264 mirror-symmetric pairs. [See C. J. Bouwkamp and D. A. Klarner, JRM 3 (1970), 10–26.]
345. A variation of even/odd coordinates works nicely: Let the pieces fill 13 cells like ( x, y, z )+{(±1, ±1, ±3), (1, ±1, ±1)}, xyz odd, where the items ( x, y, z ) for 0 ≤ x, y ≤ 10 and 0 ≤ z ≤ 6 are primary for x, y, z even and secondary for x, y, z odd. The solution is unique. [This puzzle, marketed as “ Vier Farben Block,” was designed by T. Geerinck in 2004.]
|
|
|
|
346. (a) Shifting by multiples of (0, 1, 1) gives N disjoint tripods whose corners are on layer 0 of the torus, filling all cells of that layer except for a (possibly broken) diagonal, and also filling all cells of such a diagonal on layer 1. We can plug the holes on layer 0 by appropriately placing N tripods whose corners are on layer N − 1. And so on.
(b) Here’s a way to pack twelve of them into a 3 × 6 × 6 torus. (Is 7/9 optimum?)
|
|
|
(c) Place 13 tripods in a 6 × 6 × 6 torus, with corners at (0, 0, 0), (0, 1, 1), (0, 2, 2), (1, 1, 3), (1, 2, 4), (2, 3, 2), (2, 4, 4), (3, 3, 3), (3, 4, 5), (4, 4, 0), (4, 5, 1), (5, 0, 5), (5, 5, 3).
(d) One can place 2 r ( l, m, n ) nonoverlapping tripods in a 2 l × 2 m × 2 n torus, by putting the tripod corners at the positions of the pod corners, plus (0, 0, 0) and ( l, m, n ).
(e) With one primary item # and lmn secondary items xyz , and with options such as ‘# 123 023 103 113 120 121 122’ (one for each pod with 0 ≤ x < l , 0 ≤ y < m , 0 ≤ z < n ), we can find solutions with t pods by giving multiplicity t to #. Furthermore we can save time by letting the items 000 and ( l −1)( m −1)( n −1) be primary, because those two pods can be assumed to be present. In this way we find 444 ↦ 8, 445 ↦ 9, 446 ↦ 9, 455 ↦ 10, 456 ↦ 10, 466 ↦ 12, 555 ↦ 11, 556 ↦ 12, 566 ↦ 13, 666 ↦ 14. ( Algorithm M can determine that r (6, 6, 6) < 15 in reasonable time, 253 G μ , despite its rather weak heuristics for pruning the search. But the SAT solver Algorithm 7.2.2.2C solves this problem in only 2 G μ ; it can also establish that r (7, 7, 7) = 19 in 169 G μ , while Algorithm M as it stands would be hopeless for that task.)
[ Notes: Sherman Stein initiated the study of tripods (actually an n-dimensional generalization called “ semicrosses”) in IEEE Trans. IT-30 (1984), 356–363; see also his paper with W. Hamaker on pages 364–368. They proved that the function r ( n ) = r ( n, n, n ) is Ω( n 1.516 ), and that r ( l, n, n ) /n approaches a limit as n → ∞. The initial values ( r (1) ,...,r (9)) = (1, 2, 5, 8, 11, 14, 19, 23, 28) were found by C. Morgan, in an undergraduate project at the University of Warwick in 2000; see also S. Szabό, Ann. Univ. Sci. Budapestinensis, Sect. Computatorica 41 (2013), 307–322. With extensive computations, P. R. J. Östergård and A. Pöllöanen have proved that r (10) = 32 and (surprisingly) that r (11) = 38 [ Discrete and Computational Geometry 61 (2019), 271– 284]. See also A. Tiskin, Discrete Math. 307 (2007), 1973–1981, who showed among other things that r (12) ≥ 43, r ( n ) = Ω( n 1.534 ), r ( n ) = O ( n 2 / (log n ) 1/15 ).]
347. Many proofs have been given by S. Wagon, AMM 94 (1987), 601–617. [No simple necessary and sufficient conditions for a × b × c packing l × m × n are known. For generalizations, see R. J. Bower and T. S. Michael, Math. Magazine 79 (2006), 14–30.]
348. See F. W. Barnes’s complete solution, Discrete Mathematics 133 (1994), 55–78.
349. Let t = s/ 4. Each brick of an m -brick packing contains at least one of the 27 “special points” {( it, jt, kt ) | 0 < i,j,k < 4}, because a , b , and c exceed t . Hence m ≤ 27.
In a packing with m = 27, each of the “special lines” l *jk , l i * k , l ij * with two coordinates fixed will be totally full, because the bricks collectively occupy 27( a + b + c ) units of space on those lines. The special lines also intersect the bricks in 27 segments of each length a , b , c ; hence each special line has a segment of each length.
Thus we’re led to solve an XCC problem with primary items p ijk , l * jk , l i * k , l ij * and secondary items x ijk , y ijk , z ijk , and with options like ‘ p ijk x ijk :π 1 y ijk :π 2 z ijk :π 3 ’ and ‘ l i * k y i 1 k :π 1 y i 2 k :π 2 y i 3 k :π 3 ’, where π 1 π 2 π 3 is a permutation of { a, b, c }. That problem has 7712 solutions, when we fix one of the six options for p 111 .
Only 168 of those solutions, in 21 equivalence classes under the 48 symmetries of the cube, actually pack properly when ( a, b, c ) = (2, 3, 4). And it can be shown that those 21 solutions will solve Hoffman’s problem for arbitrary ( a, b, c ). Here, for example, is the unique solution that is “ self-dual” — isomorphic to itself when a ↔ c :
[See Hoffman’s exposition in The Mathematical Gardner (1981), 212–225.]
350. Set this up for Algorithm M with 28 instances of a 3×4×5 brick and 48 instances of a single cubie. We can omit all options where a brick lies 1 or 2 units from a face but not on the face, because the brick could move outward in such solutions. We can also force the placement of a brick at corner (0, 0, 0). Furthermore, an empty corner would imply at least 27 cubies there; hence we can omit placing a cubie in any corner except (11, 11, 11). This problem, with 715 options of size 61 and 1721 options of size 2, has 112 solutions(!), found in 440 Gμ. (The author’s first attempt, in 2004, took much longer.)
There are three species of solutions: (i) Pack seven bricks into 5 × 7 × 12; arrange four of those in a pinwheel (see exercise 365 ), leaving a 2 × 2 × 12 hole. (ii) Pack 12 into 5 × 12 × 12; add a pinwheel of four 5 × 7 × 7s, each of which is a pinwheel of four 3 × 4 × 5s. (iii) Assemble the bricks in a bizarre way that includes two such 5 × 7 × 7s:
Types (i), (ii), (iii) contribute 6+10+4 nonisomorphic solutions. [George Miller’s puzzle with bricks of tricolored faces is called Perfect Packing, because 28 is a perfect number.]
351. (Generalizing exercise 349 , Hoffman observed that such a construction would yield a nice geometrical way to prove the inequality ( abcde ) 1/5 ≤ ( a + b + c + d + e ) / 5.)
352. None. But any eleven of the “ hypersolid pentominoes” can easily be squeezed in;
for example,
is one way to pack all but V.
353. There are exactly 9 (including a mirror pair). They pack a 3 × 3 × 3 cube in 48 · 8789 ways, such as
. [See J. Lou, Danish patent 126840 (1973).]
354. (a) Let cell ( x, y ) of a polyomino correspond to (– x, x, y, – y ). Let cell ( x, y ) of a polyhex, as represented in exercise 315 , correspond to (0 ,x,y, – x – y ).
(b) A polysphere is planar if and only if the differences between its adjacent cells lie in a plane. Each of those differences has the form e ij \= e i – e j , where e 1 = (1, 0, 0, 0), ... , e 4 = (0, 0, 0, 1). Three such differences can’t be linearly independent yet lie in a plane; the linearly dependent cases are polyominoes and/or polyhexes.
(c) Every connected graph has at least one vertex whose removal doesn’t disconnect the graph. So the result follows by induction on n .
(d) An orthogonal matrix fixes w + x + y + z if and only if its row and column sums are 1. The matrices (i) T and (ii) R below respectively rotate by 120° about x = y = z and by 90° about ( x = y ) ∧ ( w = z ).
T \= ( 1 0 0 0 0 0 1 0 0 0 0 1 0 1 0 0 ) ; R \= 1 2 ( 1 − 1 1 1 1 1 1 − 1 − 1 1 1 1 1 1 − 1 1 ) ; R 2 \= ( 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 ) ; H \= 1 6 ( 5 − 1 − 1 3 − 1 − 1 5 3 − 1 5 − 1 3 3 3 3 − 3 ) .
(e) The matrices (i) R 2 and (ii) H above respectively rotate by 180° about ( x = y ) ∧ ( w = z ) and about ( x = y ) ∧ ( w = 3 z – 2 x ). Thus H can be used when z = 0.
(f) Suppose V ′ \= { v 1 ′ , ... , v n ′ } is a rotation of V = { v 1 ,..., v n }⊂ S , where v k \= ( w k , x k , y k , z k ), v k ′ T \= ( w k ′ , x k ′ , y k ′ , z k ′ ) T \= Q v k T , v 1 \= v 1 ′ \= ( 0 , 0 , 0 , 0 ) , and v 2 = e 12 = (1, –1, 0, 0). The matrix Q = ( q ij ) is orthogonal, with row and column sums and determinant 1. By applying an even permutation to the coordinates of v ′ and the rows of Q , we can assume without loss of generality that v 2 ′ \= e 12 \= v 2 . Hence q k 1 = q k 2 + δ k 1 – δ k 2 , q 11 = q 22 . If Q ≠ I we have v p − v q \= e i j ≠ e i ′ j ′ \= v p ′ − v q ′ for some p , q , i , j , i ′ , and j ′ , with i < j . By orthogonality, e 12 ⋅ e ij \= e 12 ⋅ e i ′j ′ ∈ {–1, 0, +1}.
If e 12 ⋅ e ij \= 1, there are six cases, depending on ( i, j, i ′ ,j ′ ): (1, 3, 1, 4) implies Q = TH ; (1, 4, 1, 3) implies Q = HT 2 ; (1, 3, 4, 2) implies Q = T 2 RT or THR 3 T 2 ; (1, 4, 3, 2) implies Q = T 2 RT or HR ; (1, 3, 3, 2) and (1, 4, 4, 2) are impossible.
If e 12 ⋅ e ij \= 0, we have ( i, j, i ′ ,j ′ ) = (3, 4, 4, 3) and Q is forced to be TR . Finally, the case ( i, j, i ′ ,j ′ ) for e 12 ⋅ e ij \= –1 is the same as the case ( i, j, j ′ ,i ′ ) for e 12 ⋅ e ij \= +1.
Note: Some authors represent S as the set of integer triples ( X, Y, Z ) with X + Y + Z even. The Hadamard transform provides an isomorphism between these representations: If –2 M is the upper left 4 × 4 submatrix of 7.2.1.1–(21), we have M 2 = I , det M = 1, and M takes (– x – y – z, x, y, z ) ↦ (0 ,x + z, y + z, x + y ) = (0 ,X,Y,Z ).
355. (a) Normalize the given polysphere by subtracting ( x min ,y min ,z min ), to get its base placement. Then, for each base placement P , form up to three others until no more can be formed: (i) Replace each xyz by yzx . (ii) Replace each xyz by ( x + y + z )( t – z )( t – x ), for some large t ; then normalize. (iii) If z = 0 in each cell of P , replace each xy 0 by yx 0.
[The ( X, Y, Z ) representation mentioned in answer 354 suggests “ polyjubes” — George Sicherman’s name for the sets of edge-connected cubes that don’t touch face-to-face. Transformation (iii) does not apply to polyjubes; hence there are 5 trijubes and 28 tetrajubes. Polyjubes are also equivalent to “ polyrhons” — the connected sets of rhombic dodecahedra, which are the Voronoi regions of the face-centered cubic lattice. See S. Coff in, The Puzzling World of Polyhedral Dissection (1990), Figure 167.]
(b) Phenalene has eight base placements; in lexicographic order they are {000, 001, 010}, {000, 001, 100}, {000, 010, 100}, {001, 010, 011}, {001, 010, 100}, {001, 100, 101}, {010, 100, 110}, {011, 101, 110}. The straight trisphere has six base placements, namely {000, 001, 002}, {000, 010, 020}, {000, 100, 200}, {002, 011, 020}, {002, 101, 200}, {020, 110, 200}. The bent trisphere has twelve, from {001, 010, 101} to {011, 100, 110}. And phenanthrene has twenty-four, from {000, 001, 011} to {020, 101, 110}.
(c) There are 853 connected subsets, with 475 different base placements. (Each placement with max( x + y + z ) = (1, 2, 3) occurs respectively (10, 4, 1) times.) They form 25 distinct tetraspheres — five from tetrominoes and six additional planar pieces from tetrahexes, plus four nonplanar nonchiral pieces and five chiral pairs:
Each piece has been given an identifying letter. This chart shows the number of base placements and the number of occurrences in simplex (3, 3, 3, 3, 3, 0, 0), as well as the lexicographically smallest base placement. Notice that j and p have 48 base placements, while a polycube can have at most 48. Piece s is simplex (1, 1, 1, 1, 1, 0, 0), a tetrahedron with four equidistant spheres. Piece x is perhaps the most fascinating to play with.
[The tetraspheres were first enumerated by K. Takizawa; then T. Sillke enumerated the nonplanar polyspheres of larger sizes. See B. Wiezorke, Cubism For Fun 25 , part 3 (1990), 10–17; G. Bell, Cubism For Fun 81 (2010), 18–23; OEIS A038174.]
356. (a) The n -tetrahedron, which is the same as simplex ( n – 1, n – 1, n – 1, n – 1, n –1, 0, 0), has base placement { xyz | x, y, z ≥ 0 , x + y + z < n }; ( n + 2 3 ) cells. (It has one other base placement, namely {( n –1– x )( n –1– y )( n –1– z ) | x, y, z ≥ 0 , x + y + z < n }.)
One of the 12 base placements of the m × n roof is { x ( y + k )( m –1– y ) | k ≥ 0, 0 ≤ x < n – k, 0 ≤ y < m – k }. If m ≤ n , it has m ( m + 1)(3 n – m +1) / 6 cells.
The stretched m × n roof is based on slicing the face-centered cubic lattice into layers with constant y – z . (Each cell has two neighbors on its own layer, four neighbors on each adjacent layer, and two neighbors that are two layers away.) One of its 12 base placements is {( x + m –1– y )( y + k ) y | k ≥ 0, 0 ≤ x < n – k, 0 ≤ y < m – k }.
(b) Let’s call the four shapes T 4 , R 3×4 , S 3×4 , and S 4×3 . Here are the stats:
Shape | Total | All planar | Mixed | All nonplanar | ||
| multisets(sets) | (balanced) | (balanced) | (chiral) | (balanced) | (chiral) |
T 4 | 2952(1211) | 174(34) | 308(115) | 2442(1062) | 2(0) | 26(0) |
R 3×4 | 11531(6274) | 372(69) | 1250(583) | 9818(5608) | 3(0) | 88(14) |
S 3×4 | 1184(480) | 51(6) | 108(48) | 1014(426) | 1(0) | 10(0) |
S 4×3 | 266(52) | 2(0) | 27(8) | 234(44) | 1(0) | 2(0) |
For example, {j, j, p, p, t} is one of 174 multisets of five planar pieces that can make T 4 . [In fact, the solution is unique — and {j, j, p, p, t} also uniquely solves R 3×4 and S 3×4 ! G. Bell used this fact as the basis for his elegant Triple Pyradox puzzle; see Cubism For Fun 94 (2014), 10–13.] Of those 174 cases, 34 have five different pieces; for instance, {n, o, p, u, y} is one of only seven that contains y, the “ propeller.”
Many other suitable sets of five mix planar pieces with nonplanar ones. Of these, 115 (like {g, G, i, s, x}) are closed under reflection; that one has 24 solutions, all essentially the same. The other 1062 form 531 mirror-image pairs (like {d, e, f, G, i} and {D, E, F, g, i}); every solution for a chiral set has 12 equivalents, not 24.
Algorithm M discovers all such solutions quickly, if we assign multiplicity [0 .. 5] to each piece. There are respectively (88927, 77783, 3440, 996) solutions to ( T 4 , R 3×4 , S 3×4 , S 4×3 ), without symmetry removal; they’re found in (840, 607, 48, 13) Mμ.
Six of the multisets — three mirror pairs — are actually able to make all four shapes. These versatile combinations of pieces are {e, g, g, p, p} and {E, G, G, p, p}, {g, j, p, p, p} and {G, j, p, p, p}, {g, p, p, p, p} and {G, p, p, p, p}.
There’s an obvious, yet interesting, way to make T 4 with the “pure” multiset {s, s, s, s, s}. The only other pure multiset that works is {p, p, p, p, p}, which is able to form both T 4 and R 3×4 , as well as many other shapes noted by W. Schneider in 1995.
[A 2 × 7 roof also has 20 cells. So we might want to consider additional stats:
R 2×7 | 3940(1628) | 608(116) | 1296(512) | 1970(1000) | 14(0) | 52(0) |
S 2×7 | 426(84) | 58(4) | 48(20) | 306(60) | 2(0) | 12(0) |
S 7×2 | 4(0) | 0(0) | 0(0) | 0(0) | 2(0) | 2(0) |
The long and skinny S 7×2 can be made in only two ways, both with x in the middle, surrounded by g’s or G’s. The set {i, j, n, o, p} packs both S 2×7 and S 7×2 , as well as T 4 .]
(c) Let’s name the trispheres 1, 2, 3, 4, according to the squared distance between the two farthest-apart cells; thus the pieces in exercise 355 are 2, 4, 1, 3. The pyramid P 4 is buildable from 296 such multisets, many of which allow huge numbers of solutions. (For example, each of the ten multisets that contain {1, 1, 2, 2, 3, 3, 4, 4} leads to more than 30,000 solutions; {1, 1, 2, 2, 2, 3, 3, 4, 4, 4} has more than 120,000!) Most interesting are the cases with unique solution ({2, 2, 4, 4, 4, 4, 4, 4, 4, 4}‡, {1, 1, 1, 4, 4, 4, 4, 4, 4, 4}, {1, 2, 2, 2, 2, 2, 2, 2, 2, 2}), or with just two solutions ({2, 2, 2, 2, 2, 2, 2, 2, 2, 2}†, {1, 1, 3, 3, 3, 3, 3, 3, 3, 3}, {2, 4, 4, 4, 4, 4, 4, 4, 4, 4}‡); † = noted by L. Gordon (1986); ‡ = noted by J. Becker (2009). The stretched pyramid S 4 has 213 such multisets, all of which can also make P 4 . Unique solutions occur for {1, 1, 1, 3, 4, 4, 4, 4, 4, 4} and {1, 3, 3, 3, 3, 3, 3, 3, 4, 4}; almost for {3, 3, 3, 3, 3, 3, 3, 3, 4, 4}.
Historical notes: The first polysphere puzzle may have been “ Pyramystery,” copyright by Piet Hein in 1967 when his Soma cube was becoming popular. Pyramystery had the six pieces {1, 1, 3, 4, o, p}; Hein knew that it could form T 4 , as well as two copies of T 3 , and several planar designs. A similar puzzle of unknown origin, called Kugelpyramide, may have been created earlier, because it was seen by B. Wiezorke in 1968. Kugelpyramide’s pieces, {1, 3, 4, 4, o, p} were slightly different. With either Pyramystery or Kugelpyramide one can make T 4 , T 3 + T 3 , R 3×4 , R 2×7 , and S 2×7 ; and with the not-thought-of pieces {1, 2, 3, 4, o, p}, one could have made also S 3×4 but not T 3 + T 3 . The first puzzle to mix polyomino-type polyspheres with polyhex-type polyspheres — a nonobvious possibility — was Tetra, by A. Kuwagaki and S. Takenaka; see Sugaku Seminar 11, 7 (July 1972), cover, 34–38; also U.S. Patent 3837652 (1974). That patent describes making P 3 from the dispheres and trispheres, and making the 44-ball octahedron P 4 P 3 R from the planar tetraspheres {i, j, l, n, o, p, q, t, u, y, z}. In those early days, the stretched roofs and pyramids weren’t known to be possible; they were first introduced by Leonard Gordon, in his WARP-30 puzzle ( Kadon Enterprises, 1986).
(d) The unique base placement is { xyz | x, y, z ∈ {0, 1, 2, 3} ,x ≠ y ≠ z ≠ x }. Stats are 95(0) 5(0) 13(0) 70(0) 3(0) 4(0). Only pieces a, c, d, q, u will fit in this shape. Here’s how to make it with {a, a, c, d, u, u}, {c, c, c, C, C, C}, or {u, u, u, u, u, u}:
(Note that {q, q, q, q, q, q} is trivial.) This is a hollow object that can’t stand on its own.
357. Truncated octahedra are the Voronoi regions of the “ body-centered cubic lattice,” which is less tight than the face-centered cubic lattice: It can be represented as the set of all integer triples ( x, y, z ) with x mod 2 = y mod 2 = z mod 2. Two truncated octahedra whose centers are two such points are adjacent if and only if the distance between those points is either 3 (eight neighbors, joined at hexagonal faces) or 2 (six neighbors, joined at square faces). There are 2 displatts, 6 trisplatts, and 44 tetrasplatts — including 9 chiral pairs. [See M. Owen and M. Richards, Eureka 47 (1987), 53–58.]
Base placements can be found almost as in exercise 324 , except that we must set ( x, y, z ) ↦ ( y, 2 ⌈ x max ⌉ – x, z ). Furthermore, each base placement should be normalized, by adding (±1, ±1, ±1) if needed, so that x min + y min + z min ≤ 1.
[One might also consider truncating further, leaving only the union of four small hexagonal prisms between diametrically opposite hexagonal faces. This yields a sub-family of polysplatts called “ polycrunches” — named and enumerated by G. Sicherman: Adjacent crunches, with centers 3 apart, are pasted together where the prisms meet. The polycrunch family has 1 monocrunch, 1 dicrunch, 3 tricrunches, and 14 tetra-crunches (including 2 chiral pairs). The tricrunches have respectively (4, 12, 12) base placements; the tetracrunches have respectively (4, 6, 6, 8, 12, 12, 12, 12, 24, ... , 24).]
358. This fascinating packing is considerably more difficult than the other. For example, there are six distinct trihexaspheres, having respective angles of (60°, 90°, arccos(–1 / 3) ≈ 109 . 5°, 120°, arccos(–5/6) ≈ 146.4°, 180°) and respective maximum squared distances (1, 2, 8/3, 3, 11/3, 4). G. Bell has discovered a convenient way to represent magnified polyhexaspheres within the face-centered cubic lattice: Consider the subset S ^ of S whose elements have the special form αj +β k +γ l for integers j , k , l , where α = (0, 3, –3, 0), β = (0, 0, 3, –3), γ 2 l = (6 l, –2 l, –2 l, –2 l ), and γ 2 l +1 = (6 l +3, –3 – 2 l, – l, –2 l ). Two cells of S ^ are called adjacent if the distance between them is 18 . Thus each cell v of layer l has six neighbors v ± {(0, 3, –3, 0), (0, 0, 3, –3), (0, –3, 0, 3)} on the same level; three neighbors v + A [ l even] + B [ l odd] on level l + 1, where A = {(3, –3, 0, 0), (3, 0, –3, 0), (3, 0, 0, –3)} and B = {(3, 1, –2, –2), (3, –2, 1, –2), (3, –2, –2, 1)}; and three neighbors v – A [ l odd] – B [ l even] on level l – 1.
All of the tetraspheres are tetrahexaspheres, because they fit on at most two levels. But many of the pentaspheres, for example the planar one for pentomino T, are not pentahexaspheres. A polyomino polyhexasphere exists if and only if the polyomino fits in a 2× k box: Connected subsets of {(0, 0, 3 k, –3 k ), (–3, –1, 2+3 k, 2–3 k )} are OK.
The matrices T and R 2 HR 2 of answer 354 are rotations of S ^ . Therefore we can obtain equivalent base placements in the manner of answer 355 , replacing each xyz by either yzx or ( y + 2 3 w ) ( x + 2 3 w ) ( z + 2 3 w ) , where w = – x – y – z . Normalize a placement by adding or subtracting 666 or 3 3 ¯ 0 or 03 3 ¯ or 3 ¯ 03 . But the analysis is still incomplete: Are further transformations of base placements needed? How many n -hexaspheres are possible, for n = 4, 5, ... ? [See Cubism For Fun 106 (2018), 24–29.]
359. First we realize that every edge of the square must touch at least three pieces; hence the pieces must in fact form a 3 × 3 arrangement. Consequently any correct placement would also lead to a placement for nine pieces of sizes (17 – k ) × (20 – k ), ... , (24 – k ) × (25 – k ), into a (65 – 3 k ) × (65 – 3 k ) box. Unfortunately, however, if we try, say, k = 16, Algorithm X quickly gives a contradiction.
But aha — a closer look shows that the pieces have rounded corners . Indeed, there’s just enough room for pieces to get close enough together so that, if they truly were rectangles, they’d make a 1 × 1 overlap at a corner.
So we can take k = 13 and make nine pieces of sizes 4 × 7, ... , 11 × 12, consisting of rectangles minus their corners. Those pieces can be packed into a 26×26 square, as if they were polyominoes (see exercise 266 ), but with the individual cells of the enclosing rectangle treated as secondary items because they needn’t be covered. (Well, the eight cells adjacent to corners can be primary.) We can save a factor of 8 by insisting that the 9 × 11 piece appear in the upper left quarter, with its long side horizontal.
Algorithm X solves that problem in 620 gigamems — but it finds 43 solutions, most of which are unusable, because the missing corners give too much flexibility. The unique correct solution is easily identified, because a 1 × 1 overlap between rectangles in one place must be compensated by a 1 × 1 empty cell between rectangles in another. The resulting cross pattern (like the X pentomino) occurs in just one of the 43.
360. Let there be mn primary items p ij for 0 ≤ i < m and 0 ≤ j < n , one for each cell that should be covered exactly once. Also introduce m primary items x i for 0 ≤ i < m , as well as n primary items y j for 0 ≤ j < n . The exact cover problem has ( m + 1 2 ) ⋅ ( n + 1 2 ) options, one for each subrectangle [ a..b ) × [ c..d ) with 0 ≤ a < b ≤ m and 0 ≤ c < d ≤ n . The option for that subrectangle contains 2 + ( b – a )( d – c ) items, namely x a , y c , and p ij for a ≤ i < b , c ≤ j < d . The solutions correspond to reduced decompositions when we insist that each x i be covered [1 ..n ] times and that each y j be covered [1 ..m ] times. (We can save a little time by omitting x 0 and y 0 .)
The 3×5 problem has 20165 solutions, found in 18 Mμ. They include respectively (1071, 3816, 5940, 5266, 2874, 976, 199, 22, 1) cases with (7, 8, ... , 15) subrectangles.
[See C. J. Bloch, Environment and Planning B6 (1979), 155–190, for a complete catalog of all reduced decompositions into at most seven subrectangles.]
361. The minimum is m + n – 1. Proof (by induction): The result is obvious when m = 1 or n = 1. Otherwise, given a decomposition into t subrectangles, k ≥ 1 of them must be confined to the n th column. If two of those k are contiguous, we can combine them; the resulting dissection of order t – 1 reduces to either ( m – 1) × n or m × n , hence t – 1 ≥ ( m – 1) + n – 1. On the other hand if none of them are contiguous, the reduction of the first n – 1 columns is m × ( n – 1); hence t ≥ m +( n – 1) – 1+ k .
Close examination of this proof shows that a reduced decomposition has minimum order t if and only if its boundary edges form m – 1 horizontal lines and n – 1 vertical lines that don’t cross each other. (In particular, the “ tatami condition” is satisfied; see exercise 7.1.4–215.) See C. F. Earl, Environment and Planning B5 (1978), 179–187.
362. Simply remove the offending subrectangles, so that the cover problem has only ( ( m + 1 2 ) − 1 ) ( ( n + 1 2 ) − 1 ) options. Now there are 13731 3×5 solutions, found in 11 Mμ, and (410, 1974, 3830, 3968, 2432, 900, 194, 22, 1) cases with (7, 8, ... , 15) subrectangles.
363. Introduce additional primary items X i for 0 < i < m , to be covered [1 ..n – 1] times, as well as Y j for 0 < j < n , to be covered [1 ..m – 1] times. Then add items X i for a < i < b and Y j for c < j < d to the constraint for subrectangle [ a..b ) × [ c..d ).
Now the 3 × 5 problem has just 216 solutions, found in 1.9 megamems. They include (66, 106, 44) instances with (7, 8, 9) subrectangles. Just two of the solutions are symmetric under left-right reflection, namely
and its top-bottom reflection.
364. We can delete non-tromino options from the exact cover problem, thereby getting all faultfree tromino tilings that are reduced. If we also delete the constraints on x i and y j — and if we require X i and Y j to be covered [1 ..n ] and [1 ..m ] times instead of [1 ..n – 1] and [1 ..m – 1] — we obtain all of the m × n faultfree tromino tilings.
It is known that such nontrivial tilings exist if and only if m, n ≥ 7 and mn is a multiple of 3. [See K. Scherer, JRM 13 (1980), 4–6; R. L. Graham, The Mathematical Gardner (1981), 120–126.] So we look at the smallest cases in order of mn : When ( m, n ) = (7, 9), (8, 9), (9, 9), (7, 12), (9, 10), we get respectively (32, 32), (48, 48), (16, 16), (706, 1026), (1080, 1336) solutions. Hence the assertion is false; a smallest counterexample is shown.
365. Augment the exact cover problem of answer 362 by introducing ( m + 1 2 ) + ( n + 1 2 ) − 2 secondary items x ab and y cd , for 0 ≤ a < b ≤ m and 0 ≤ c < d ≤ n , ( a, b ) ≠ (0 ,m ), ( c, d ) ≠ (0 ,n ). Include item x ab and y cd in the option for subrectangle [ a..b ) × [ c..d ). Furthermore, cover x i [1 ..m – i ] times, not [1 ..n ]; cover y j [1 ..n – j ] times.
366. The hint follows because [ a..b ) × [0 ..d ) cannot coexist motleywise with its left-right reflection [ a..b ) × [ n – d..n ). Thus we can forbid half of the solutions.
Consider, for example, the case ( m, n ) = (7, 7). Every solution will include x 67 with some y cd . If it’s y 46 , say, left-right reflection would produce an equivalent solution with y 13 ; therefore we disallow the option ( a, b, c, d ) = (6, 7, 4, 6). Similarly, we disallow ( a, b, c, d ) = (6, 7 ,c,d ) whenever 7 – d < c .
Reflection doesn’t change the bottom-row rectangle when c + d = 7, so we haven’t broken all the symmetry. But we can complete the job by looking also at the top-row rectangle, namely the option where x 01 occurs with some y c d . Let’s introduce new secondary items t 1 , t 2 , t 3 , and include t c in the option that has x c ′ d ′ with y c (7 – c ) . Then we include t 1 , t 2 , and t 3 in the option that has x 01 with y c d ′ for c ′ + d ′ > 7. We also add t 1 to the option with x 01 and y 25 ; and we add both t 1 and t 2 to the option with x 01 and y 34 . This works beautifully, because no solution can have c = c ′ and d = d ′ .
In general, we introduce new secondary items t c for 1 ≤ c < n/ 2, and we disallow all options x ( m – 1) m y cd for which c + d > n . We put t c into the option that contains x ( m – 1) m y c ( n – c ) ; t 1 thru t ( n – 1) / 2 into the option that contains x 01 y c d when c ′ + d ′ > n ; and t 1 thru t c –1 into the option that contains x 01 y c' (n–c ′ ) . (Think about it.)
For example, when m = n = 7 there now are 717 options instead of 729, 57 secondary items instead of 54. We now find 352546 solutions after only 13.2 gigamems of computation, instead of 705092 solutions after 26.4. The search tree now has just 7.8 meganodes instead of 15.7.
(It’s tempting to believe that the same idea will break top-bottom symmetry too. But that would be fallacious: Once we’ve fixed attention on the bottommost row while breaking left-right symmetry, we’ve lost all symmetry between top and bottom.)
367. From any m × n dissection of order t we get two ( m +2) × ( n +2) dissections of order t + 4, by enclosing it within two 1 × ( m +1) tiles and two 1 × ( n +1) tiles. So the claim follows by induction and the examples in exercise 365 , together with a 5 × 6 example of order 10 — of which there are 8 symmetrical instances such as the one shown here. (This construction is faultfree, and it’s also “tight”: The order of every m × n dissection is at least m + n – 1, by exercise 361 .)
In general, Helmut Postl observes that we can create nested motley dissections by motley-dissecting any subrectangle of a motley dissection (taking care not to repeat any internal boundary coordinates) and reducing the result. For example, one of the 2 ⋅ (6+3+3+3+1+9+3) = 56 ways to nest a pinwheel within the second motley 4 × 4 is shown here.
368. The number of subrectangles [ a..b ) × [ c..d ) that have either c = k or d = k , given k , is ≥ 2 when k ∈ {0 ,n } and ≥ 3 when 0 < k < n . Hence 2 t ≥ 2+3( n – 1)+2.
369. All 214 of the 5×7 motley dissections have order 11, which is far short of ( 6 2 ) − 1 \= 14 ; and there are no 5×8s, 5×9s, or 5×10s. Surprisingly, however, 424 of the 696 dissections of size 6×12 do have the optimum order 20, and 7×17 dissections with the optimum order 27 also exist. Examples of these remarkable patterns are shown. (The case m = 7 is still not fully explored except for small n . For example, the total number of motley 7×17 dissections is unknown. No 7×18s exist, by exercise 368 . If we restrict attention to symmetrical dissections, the maximum orders for 5 ≤ m ≤ 8 are 11 (5×7); 19 (6×11); 25 (7×15); 33 (8×21).)
370. The basic idea is to combine complementary options into a single option whenever possible. More precisely: (i) If a + b = m and c + d = n , we retain the option as usual; it is self-complementary. (ii) Otherwise, if a + b = m or c + d = n , reject the option; merging would be non-motley. (iii) Otherwise, if a + b > m , reject the option; we’ve already considered its complement. (iv) Otherwise, if b = 1 and c + d < n , reject the option; its complement is illegal. (v) Otherwise, if b > m/ 2 and c < n/ 2 and d > n/ 2, reject the option; it intersects its complement. (vi) Otherwise merge the option with its complement. For example, when ( m, n ) = (4, 5), case (i) arises when ( a, b, c, d ) = (1, 3, 2, 3); the option is ‘ x 1 y 2 p 12 p 22 x 13 y 23 ’ as in answer 366 . Case (ii) arises when ( a, b, c, d ) = (1, 3, 0, 1). Case (iii) arises when ( a, b ) = (2, 3). Case (iv) arises when ( a, b, c, d ) = (0, 1, 0, 1); the complement (3, 4, 4, 5) isn’t a valid subrectangle in answer 366 . Case (v) arises when ( a, b, c, d ) = (1, 3, 1, 3); cells p 22 and p 23 occur also in the complement (1, 3, 2, 4). And case (vi) arises when ( a, b, c, d ) = (0, 1, 4, 5); the merged option is the union of ‘ x 0 y 4 p 04 x 01 y 45 t 1 t 2 ’ and ‘ x 3 y 0 p 30 x 34 y 01 ’. (Well, x 0 and y 0 are actually omitted, as suggested in answer 360 .)
Size 8 × 16 has (6703, 1984, 10132, 1621, 47) solutions, of orders (26, ... , 30).
371. (a) Again we merge compatible options, as in answer 370 . But now ( a, b, c, d ) → ( c, d, n – b, n – a ) → ( n – b, n – c, n – b, n – a ) → ( n – b, n – a, c, d ), so we typically must merge four options instead of two. The rules are: Reject if a = n – 1 and c + d > n , or c = n – 1 and a + b < n , or b = 1 and c + d < n , or d = 1 and a + b > n . Also reject if ( a, b, c, d ) is lexicographically greater than any of its three successors. But accept, without merging, if ( a, b, c, d ) = ( c, d, n – b, n – a ). Otherwise reject if b > c and b + d > n , or if b > n/ 2 and c < n/ 2 and d > n/ 2, because of intersection. Also reject if a + b = n or c + d = n , because of the motley condition. Otherwise merge four options into one.
For example, the merged option when n = 4 and ( a, b, c, d ) = (0, 1, 2, 4) is ‘ x 0 y 2 p 02 p 03 x 01 y 24 t 1 x 2 y 3 p 23 p 33 x 24 y 34 x 3 y 0 p 30 p 31 x 34 y 24 p 00 p 10 x 02 y 01 ’, except that x 0 and y 0 are omitted. Notice that it’s important not to include an item x i or y j twice, when merging in cases that have a = c or b = d or a = n – d or b = n – c .
(b) With bidiagonal symmetry it’s possible to have ( a, b, c, d ) = ( c, d, a, b ) but ( a, b, c, d ) ≠ ( n – d, n – c, n – b, n – a ), or vice versa. Thus we’ll sometimes merge two options, we’ll sometimes merge four, and we’ll sometimes accept without merging. In detail: Reject if a = n – 1 and c + d > n , or c = n – 1 and a + b > n , or b = 1 and c + d < n , or d = 1 and a + b < n . Also reject if ( a, b, c, d ) is lexicographically greater than any of its three successors. But accept, without merging, if a = c = n – d = n – b . Otherwise reject if b > c or b > n – d or a + b = n or c + d = n . Otherwise merge two or four distinct options into one.
Examples when n = 4 are: ‘ x 1 y 1 p 11 p 12 p 21 p 22 x 13 y 13 ’; ‘ x 0 y 3 p 03 x 01 y 34 t 1 x 3 y 0 p 30 x 34 y 01 ’; ‘ x 0 y 2 p 02 x 34 y 23 t 1 x 1 y 3 p 13 x 12 y 34 x 3 y 1 p 31 x 34 y 12 x 2 y 0 p 20 x 23 y 01 ’; again with x 0 and y 0 suppressed.
(c) The unique solution for n = 10 is shown. [The total number of such patterns for n = (10, 11, ... , 16) turns out to be (1, 0, 3, 6, 28, 20, 354). All 354 of the 16×16 solutions are found in only 560 megamems; they have orders 34, 36, and 38–44. Furthermore the number of n × n motley dissections with symmetry (a), for n = (3, 4, 5, ... , 16), turns out to be (1, 0, 2, 2, 8, 18, 66, 220, 1024, 4178, 21890, 102351, 598756, 3275503), respectively. Algorithm M needs 3.3 teramems when n = 16; those patterns have orders 4 k and 4 k + 1 for k = 8, 9, ... , 13.]
372. (a) This fact, and the others noted below, can be proved by induction on the number of rooms: If the lower right corner of the upper left room is a ⊥ junction, we can “flatten” and remove that room by bringing its right bound left; otherwise we can bring its bottom bound up. All floorplans can be built up by reversing this flattening process.
Let the rooms be r 1 ...r n in diagonal order and r p 1 ...r p n in antidiagonal order (left to right). Then r i ⇓ r j ⇔ i < j and i follows j in the permutation p = p 1 ...p n ; r i ⇒ r j ⇔ i < j and i precedes j in p . The number of horizontal bounds is the number of descents in p , plus 2. The number of vertical bounds is the number of ascents , plus 2.
(b) Here’s the twin tree structure for the example. Notice that its leftward and rightward chains are the ordered sequences of rooms adjacent to the bounds.
Every twintree structure arises in a remarkably simple way: Let p = p 1 p 2 ...p n be any permutation of {1, 2 ,...,n }. Obtain T 0 by inserting p 1 , p 2 , ... , p n into an initially empty binary tree; obtain T 1 similarly by inserting p n , ... , p 2 , p 1 . Those trees can be constructed in linear time (exercise 6.2.2–50); and it’s easy to see that they are twins, both with inorder 12 ...n . Although different permutations can yield the same twintree, exactly one Baxter permutation (exercise MPR–135) does so; and it can be computed from the twintree in linear time(!). Thus there are nice one-to-one correspondences between floorplans, twintrees, and Baxter permutations.
[Floorplans are important in VLSI layout, where rooms correspond to modules and bounds correspond to channels. Twintrees were introduced by S. Dulucq and O. Guibert in Discrete Math. 157 (1996), 91–106, purely for their combinatorial interest, then applied to floorplans by B. Yao, H. Chen, C.-K. Cheng, and R. Graham in ACM Trans. Design Aut. Electronic Syst. 8 (2003), 55–80. See also J. M. Hart, Int. J. Comp. Inf. Sciences 9 (1980), 307–321; H. Murata, K. Fujiyoshi, T. Watanabe, and Y. Kajitani, Proc. Asia and South Pacific Design Aut. Conf. 2 (1997), 625–633; E. Ackerman, G. Barequet, and R. Y. Pinter, Discrete Applied Mathematics 154 (2006), 1674–1684; and the author’s programs FLOORPLAN-TO-TWINTREE, TWINTREE-TO-BAXTER, BAXTER-TO-FLOORPLAN , available online (2021).]
373. The reduction of a perfectly decomposed rectangle is a motley dissection. Thus we can find all perfectly decomposed rectangles by “unreducing” all motley dissections.
For example, the only motley dissection of order 5 is the 3 × 3 pinwheel. Thus the perfectly decomposed m × n rectangles of order 5 with integer dimensions are the positive integer solutions to x 1 + x 2 + x 3 = m , y 1 + y 2 + y 3 = n such that the ten values x 1 , x 2 , x 3 , x 1 + x 2 , x 2 + x 3 , y 1 , y 2 , y 3 , y 1 + y 2 , y 2 + y 3 are distinct. Those equations are readily factored into two easy backtrack problems, one for m and one for n , each producing a list of five-element sets { x 1 ,x 2 ,x 3 ,x 1 + x 2 ,x 2 + x 3 }; then we search for all pairs of disjoint solutions to the two subproblems. In this way we quickly see that the equations have just two essentially different solutions when m = n = 11, namely ( x 1 ,x 2 ,x 3 ) = (1, 7, 3) and ( y 1 ,y 2 ,y 3 ) = (2, 4, 5) or (5, 4, 2). The smallest perfectly decomposed squares of order 5 therefore have size 11 × 11, and there are two of them (shown below); they were discovered by M. van Hertog, who reported them to Martin Gardner in May 1979. (Incidentally, a 12×12 square can also be perfectly decomposed.)
There are no solutions of order 6. Those of orders 7, 8, 9, 10 must come respectively from motley dissections of sizes 4 × 4, 4 × 5, 5 × 5, and 5 × 6. By looking at them all, we find that the smallest n × n squares respectively have n = 18, 21, 24, and 28. Each of the order- t solutions shown here uses rectangles of dimensions {1, 2 ,..., 2 t }, except in the case t = 9: There’s a unique perfectly decomposed 24 × 24 square of order 9, and it uses the dimensions {1, 2 ,..., 17, 19}.
[W. H. Cutler introduced perfectly decomposed rectangles in JRM 12 (1979), 104–111.]
374. (a) False (but close). Let the individual dimensions be z 1 , ... , z 2 t , where z 1 ≤ ... ≤ z 2 t . Then we have { w 1 ,h 1 } = { z 1 ,z 2 t }, { w 2 ,h 2 } = { z 2 ,z 2 t – 1 }, ... , { w t ,h t } = {z t ,z t +1 }; consequently z 1 < ... < z t ≤ z t +1 < ... < z 2 t . But z t \= z t +1 is possible.
(b) False (but close). If the reduced rectangle is m × n , one of its subrectangles might be 1 × n or m × 1; a motley dissection must be strict .
(c) True. Label the rectangles { a, b, c, d, e } as shown. Then there’s a contradiction: w b > w d ⇔ w e > w c ⇔ h e < h c ⇔ h d < h b ⇔ w b < w d .
(d) The order can’t be 6, because the reduction would then have to be a pinwheel together with a 1 × 3 subrectangle, and the argument in (c) would still apply. Thus the order must be 7, and we must show that the second dissection of exercise 365 doesn’t work. Labeling its regions { a,...,g } as shown, we have h d > h a ; hence w a > w d . Also h e > h b ; so w b > w e . Oops: w f > w g and h f > h g .
In the other motley 4 × 4 dissection of exercise 365 we obviously have
w 4 < w 5 , w 4 < w 6 , w 6 < w 7 , h 4 < h 3 , h 3 < h 1 , h 4 < h 2 ;
therefore h 4 > h 5 , h 4 > h 6 , h 6 > h 7 , w 4 > w 3 , w 3 > w 1 , w 4 > w 2 . Now h 5 < h 6 ⇔ w 5 > w 6 ⇔ w 2 > w 3 ⇔ h 2 < h 3 ⇔ h 6 + h 7 < h 5 . Hence h 5 < h 6 implies h 5 > h 6 ; we must have h 5 > h 6 , thus also h 2 > h 3 . Finally h 2 < h 1 , because h 7 < h 5 .
(e) The condition is clearly necessary. Conversely, given any such pair of solutions, the rectangles w 1 × αh 1 , ... , w t × αh t are incomparable for all large enough α .
[Many questions remain unanswered: Is it NP-hard to determine whether or not a given motley dissection supports an incomparable dissection? Is there a motley dissection that supports incomparable dissections having two different permutation labels? Can a symmetric motley dissection ever support an incomparable dissection?]
375. (a) By exercise 374(d) , the widths and heights must satisfy
w 5 = w 2 + w 4 , | w 6 = w 3 + w 4 , | w 7 = w 1 + w 3 + w 4 ; |
h 3 = h 4 + h 5 , | h 2 = h 4 + h 6 , + h 7 | h 1 = h 4 + h 5 + h 6 . |
To prove the hint, consider answer 374(a) . Each z j for 1 ≤ j ≤ t can be either h or w ; then z 2 t +1 – j is the opposite. So there are 2 t ways to shuffle the h ’s and w ’s together.
For example, suppose all the h ’s come first, namely h 7 < ... <h 1 ≤ w 1 < ... <w 7 :
1 ≤ h 7 , h 7 +1 ≤ h 6 , h 6 +1 ≤ h 5 , h 5 +1 ≤ h 4 , h 4 +1 ≤ h 4 + h 5 , h 4 + h 5 +1 ≤ h 4 + h 6 + h 7 , h 4 + h 6 + h 7 +1 ≤ h 4 + h 5 + h 6 , h 4 + h 5 + h 6 ≤ w 1 , w 1 +1 ≤ w 2 , w 2 +1 ≤ w 3 , w 3 +1 ≤ w 4 , w 4 +1 ≤ w 2 + w 4 , w 2 + w 4 +1 ≤ w 3 + w 4 , w 3 + w 4 +1 ≤ w 1 + w 3 + w 4 .
The least semiperimeter in this case is the smallest value of w 1 + w 2 + w 3 + w 4 + h 7 + h 6 + h 5 + h 4 , subject to those inequalities; and one easily sees that the minimum is 68, achieved when h 7 = 2, h 6 = 3, h 5 = 4, h 4 = 5, w 1 = 12, w 2 = 13, w 3 = 14, w 4 = 15.
Consider also the alternating case, w 1 < h 7 < w 2 < h 6 < w 3 < h 5 < w 4 ≤ h 4 < w 2 + w 4 < h 4 + h 5 < w 3 + w 4 < h 4 + h 6 + h 7 < w 1 + w 3 + w 4 < h 4 + h 5 + h 6 . This case turns out to be infeasible. (Indeed, any case with h 6 < w 3 < h 5 requires h 4 + h 5 < w 3 + w 4 , hence it needs h 4 < w 4 .) Only 52 of the 128 cases are actually feasible.
Each of the 128 subproblems is a classic example of linear programming, and a decent LP solver will resolve it almost instantly. The minimum semiperimeter with seven subrectangles is 35, obtained uniquely in the case w 1 < w 2 < w 3 < h 7 < h 6 < h 5 < h 4 ≤ w 4 < w 5 < w 6 < w 7 < h 3 < h 2 < h 1 (or the same case with w 4 ↔ h 4 ) by setting w 1 = 1, w 2 = 2, w 3 = 3, h 7 = 4, h 6 = 5, h 5 = 6, h 4 = w 4 = 7. The next-best case has semiperimeter 43. In one case the best-achievable semiperimeter is 103!
To find the smallest square, we simply add the constraint w 1 + w 2 + w 3 + w 4 = h 7 + h 6 + h 5 + h 4 to each subproblem. Now only four of the 128 are feasible. The minimum side, 34, occurs uniquely when ( w 1 ,w 2 ,w 3 ,w 4 ,h 7 ,h 6 ,h 5 ,h 4 ) = (3, 7, 10, 14, 6, 8, 9, 11).
(b) With eight subrectangles the reduced pattern is 4 × 5. We can place a 4 × 1 column at the right of either the 4 × 4 pattern or its transpose; or we can use one of the first two 4 × 5 patterns in exercise 365 . (The other six patterns can be ruled out, using arguments similar to those of answer 374 .) The labeled diagrams are
For each of these four choices there are 256 easy subproblems to consider. The best semiperimeters are respectively (44, 44, 44, 56); the best square sizes are respectively — and surprisingly — (27, 36, 35, 35). [With eight subrectangles we can dissect a significantly smaller square than we can with seven! Furthermore, no smaller square can be incomparably dissected, integerwise, because nine subrectangles would be too many.] One way to achieve 44 is with ( w 1 ,w 2 ,w 3 ,w 4 ,w 5 ,h 8 ,h 7 ,h 6 ,h 5 ) = (4, 5, 6, 7, 8, 1, 2, 3, 8) in the third diagram. The only way to achieve a square of side 27 is with ( w 1 ,w 2 ,w 3 ,w 4 ,w 5 ,h 8 ,h 7 ,h 6 ,h 5 ) = (1, 3, 5, 7, 11, 4, 6, 8, 9) in the first diagram.
These linear programs usually have integer solutions; but sometimes they don’t. For example, the optimum for the second diagram in the case h 8 < h 7 < w 1 < h 6 < w 2 < w 3 < w 4 < h 5 turns out to be 97/2, achievable when ( w 1 ,w 2 ,w 3 ,w 4 ,w 5 ,h 8 , h 7 ,h 6 ,h 5 ) = (7, 11, 13, 15, 17, 3, 5, 9, 17)/2. The minimum rises to 52, if we restrict to integer solutions, achieved by ( w 1 ,w 2 ,w 3 ,w 4 ,w 5 ,h 8 ,h 7 ,h 6 ,h 5 ) = (4, 6, 7, 8, 9, 1, 3, 5, 9).
[The theory of incomparable dissections was developed by A. C. C. Yao, E. M. Reingold, and B. Sands in JRM 8 (1976), 112–119. For generalizations to three dimensions, see C. H. Jepsen, Mathematics Magazine 59 (1986), 283–292.]
376. This is an incomparable dissection in which exercise 374(d) applies. Let’s try first to solve the equations a ( x + y + z ) = bx = c ( w + x ) = d ( w + x + y ) = ( a + b ) w = ( b + c ) y = ( b + c + d ) z = 1, by setting b = x = 1. We find successively c = 1/( w +1), a = (1– w ) /w , y = ( w +1)/( w + 2), d = ( w +2)/(( w + 1)( w + 3)), z = ( w + 1)( w +3)/(( w + 2)( w + 4)). Therefore x + y + z –1 /a = (2 w +3)(2 w 2 +6 w –5)/(( w –1)( w +2)( w +4)), and we must have 2 w 2 +6 w = 5. The positive root of this quadratic is w = (√ –3)/2, where √ = 19 .
Having decomposed the rectangle ( a + b + c + d )×( w + x + y + z ) into seven different rectangles of area 1, we normalize it, dividing ( a, b, c, d ) by a + b + c + d \= 7 15 ( √ + 1 ) and dividing ( w, x, y, z )by w + x + y + z \= 5 6 ( √ − 1 ) . This gives the desired tiling (shown), with rectangles of dimensions 1 14 ( 7 − √ ) × 1 15 ( 7 + √ ) , 5 42 ( − 1 + √ ) × 1 15 ( 1 + √ ) , 5 21 × 3 5 , 1 21 ( 8 − √ ) × 1 15 ( 8 + √ ) , 1 21 ( 8 + √ ) × 1 15 ( 8 − √ ) , 5 42 ( 1 + √ ) × 1 15 ( − 1 + √ ) , 1 14 ( 7 + √ ) × 1 15 ( 7 − √ ) .
[See W. A. A. Nuij, AMM 81 (1974), 665–666. To get eight different rectangles of area 1/8, we can shrink one dimension by 7/8 and attach a rectangle (1/8) × 1. Then to get nine of area 1/9, we can shrink the other dimension by 8/9 and attach a (1/9) × 1 sliver. And so on. The eight-rectangle problem also has two other solutions, supported by the third and fourth 4 × 5 patterns in exercise 375(b) .]
377. (a) We can obtain h × w except when w is odd and h is not a multiple of 3. For if w is even, we can concatenate w/ 2 instances of size h × 2; if h is a multiple of 3, we can concatenate h/ 3 instances of size 3 × w ; otherwise we can’t use concatenation to obtain w as the sum of two even numbers, or h as the sum of two multiples of 3.
(b) The shapes 2×3, 2×4, 2×5, 3×4, 3×5, 3×6, 3×7 are necessary and sufficient. (And then Λ( S ) = { h × w | h > 1 ,w > 3}∪{ 2 h ×3 | h ≥ 1}.)
(c) S = {2×4, 3×8, 4×2, 8×3}.
(d) h × w ∈ S if and only if h = an ′ for some a with ⌊ m/n ′ ⌋ < a < 2⌊ m/n ′ ⌋ + 2 and w = bn " for some b with ⌊ m/n " ⌋ < b < 2 ⌊ m/n " ⌋ + 2, where n ′ = n /gcd( n, w ) and n " = n /gcd( n, h ).
378. Consider first a one-dimensional analog: If A is a set of positive integers, let Λ( A ) be the integers obtainable by adding together one or more elements of A . We can prove that any set B of positive integers has a finite subset A such that B ⊆ Λ( A ). For if B is empty, there’s nothing to prove; otherwise let b = min( B ). Let q r be the smallest element of B such that q r mod b = r , for 0 ≤ r < b , or let q r be un defined if no such element exists. Then every element of B is some q r plus a multiple of q 0 = b .
Therefore in two dimensions, there’s a finite set X = { h 1 × w 1 ,...,h t × w t } ⊆ T such that the width of every element of T is in Λ( X * ), where X * = { w 1 ,...,w t } is the set of widths in X . Let p = h 1 ...h t be the product of all heights in X . It follows that p × w ∈ Λ( X ) whenever h × w ∈ T .
For 0 ≤ r < p , let T r be the elements h × w of T with h mod p = r , and let Q r be a finite subset of T r such that every element of T r has a width in Λ ( Q r * ) . Let q be the largest height of any element of any Q r . Notice that if h × w ∈ T with h > q , and if h ′ × w ′ ∈ Q h mod p, we have h × w ′ ∈ Λ( X ∪ Q r ), because p × w ′ ∈ Λ( X ) and h – h ′ is a positive multiple of p . Hence h × w ∈ Λ ( { h × w ′ | h ′ × w ′ ∈ Q r } ) ⊆ Λ( X ∪ Q r ).
Finally, for 1 ≤ i ≤ q , let T i ′ be the elements h × w of T with h = i , and let P i be a finite subset of T i ′ such that every element of T i ′ has a width in Λ ( P r * ) . Then every element of T belongs to Λ( X ∪ Q 0 ∪ … ∪ Q p – 1 ∪ P 1 ∪…∪ P q ).
[This argument extends to any number of dimensions. See N. G. de Bruijn and D. A. Klarner, Philips Research Reports 30 (1975), 337 * –343 * ; Michael Reid, J. Combinatorial Theory A111 (2005), 89–105.]
379. A 2×5 packing is obvious; thus the basis contains 2×5 (and 5×2). The case 5× w and w > 2 has a packing only if 5×( w – 2) does. The case h = 3 is clearly impossible.
The case h = 7 is more interesting: 7×10 follows by concatenation, while 7×15 has 80 distinct and easily found solutions. Hence the basis contains 7×15 and 15×7.
This basis is complete: We’ve shown that if h is not a multiple of 5, h × w is possible whenever w is a multiple of 5, except when h = 1 or h = 3 or ( h is odd and w = 5). If h and w are both multiples of 5, h × w is possible except when h or w equals 5 and the other is odd. [See W. R. Marshall, J. Combinatorial Theory A77 (1997), 181–192; M. Reid, J. Combinatorial Theory A80 (1997), 106–123.]
380. The minimum basis consists of 15×15 (see Fig. 73 ) plus 39 pairs { h × w, w × h }, where ( h, w ) ∈ {(5, 10), (9, 20), (9, 30), (9, 45), (9, 55), (10, 14), (10, 16), (10, 23), (10, 27), (11, 20), (11, 30), (11, 35), (11, 45), (12, 50), (12, 55), (12, 60), (12, 65), (12, 70), (12, 75), (12, 80), (12, 85), (12, 90), (12, 95), (13, 20), (13, 30), (13, 35), (13, 45), (14, 15), (15, 16), (15, 17), (15, 19), (15, 21), (15, 22), (15, 23), (17, 20), (17, 25), (18, 25), (18, 35), (22, 25)}. (This problem has a long history, going back to the discovery by David Klarner that ten one-sided Y pentominoes can be packed uniquely in a 5 × 10 box [ Fibonacci Quarterly 3 (1965), 20]. Klarner eventually found 14 of the 39 basic pairs by hand, including the difficult case (12, 80). The other nine cases (12 ,w ) were found by J. Bitner [ JRM 7 (1974), 276–278], using a frontier-transition method that works much faster than Algorithm X in cases where h is much less than w . The complete set was nailed down by T. Sillke in 1992 [unpublished], then independently by J. Fogel, M. Goldenberg, and A. Liu [ Mathematics and Informatics Quarterly 11 (2001), 133–137].)
381. Algorithm X quickly finds examples for n = 7, 11, 12, 13, 15, 16, 17; hence it’s possible for all n ≥ 11. [J. B. Kelly discovered the case n = 7 in AMM 73 (1966), 468. Are all packable rectangles consequences of this basis?]
382. Let the back corner in the illustration be the point 777, and write just ‘ abcdef ’ instead of [ a..b )×[ c..d )×[ e..f ). The subcuboids are 670517 (270601) 176705 (012706) 051767 (060127), 561547 (260312) 475615 (122603) 154756 (031226), 351446 (361324) 463514 (243613) 144635 (132436), 575757 (020202), 454545 (232323) — with the 11 mirror images in parentheses — plus the central cubie 343434. Notice that each of the 28 possible intervals is used in each dimension, except [0 .. 4), [1 .. 6), [2 .. 5), [3 .. 7), [0 .. 7).
I started from a central cube and built outwards, all the while staring at the 24-cell in Hilbert’s Geometry and the Imagination.
— SCOTT KIM, letter to Martin Gardner (December 1975)
383. (Solution by Helmut Postl.) We can use the 7-tuples (2, 10, 27, 17, 11, 20, 5), (1, 14, 18, 8, 21, 24, 6), (3, 19, 16, 7, 34, 9, 4) to “unreduce” the 1st, 2nd, 3rd coordinates. For example, subcuboid 670517 becomes 5×(1+14+18+8+21)×(19+16+7+34+9+4). The resulting dissection, of a 92×92×92 cube into blocks of sizes 1×70×87, 2×77×88, 3 × 80 × 86, 4 × 67 × 91, 5 × 62 × 89, 6 × 79 × 90, 7 × 8 × 17, 9 × 51 × 65, 10 × 38 × 71, 11 × 21 × 34, 12 × 15 × 22, 13 × 25 × 30, 14 × 39 × 66, 16 × 18 × 27, 19 × 33 × 75, 20 × 47 × 61, 23 × 32 × 48, 24 × 36 × 76, 26 × 37 × 50, 28 × 40 × 43, 29 × 31 × 42, 35 × 44 × 53, 41 × 45 × 54, makes a fiendishly difficult puzzle.
How were those magic 7-tuples discovered? An exhaustive search such as that of exercise 374 was out of the question. Postl first looked for 7-tuples that led to very few dimensions in the “popular” ranges [13 .. 23] and [29 .. 39]. With luck, a large set of other 7-tuples would lead to no conflict in the 23 relevant subtotals; and with further luck, some of those wouldn’t conflict with each other.
(Postl also proved that no 91 × 91 × 91 decomposition is possible.)
384. The exact cover problem of answer 365 is readily extended to 3D: The option for every admissible subcuboid [ a..b ) × [ c..d ) × [ e..f ) has 6 + ( b – a )( d – c )( f – e ) items, namely x a y c z e x ab y cd z ef and the cells p ijk that are covered.
We can do somewhat better, as in exercise 366 : Most of the improvement in that answer can be achieved also 3Dwise, if we simply omit cases where a = l – 1 and either c + d > m or e + f > n . Furthermore, if m = n we can omit cases with ( e, f ) < ( c, d ).
Without those omissions, Algorithm M handles the case l = m = n = 7 in 98 teramems, producing 2432 solutions. With them, the running time is reduced to 43 teramems, and 397 solutions are found.
(The 7 × 7 × 7 problem can be factored into subproblems, based on the patterns that appear on the cube’s six visible faces. These patterns reduce to 5 × 5 pinwheels, and it takes only about 40 Mμ to discover all 152 possibilities. Furthermore, those possibilities reduce to only 5 cases, under the 48 symmetries of a cube. Each of those cases can then be solved by embedding the 5 × 5 reduced patterns into 7 × 7 unreduced patterns, considering 15 3 = 3375 possibilities for the three faces adjacent to vertex 000. Most of those possibilities are immediately ruled out. Hence each of the five cases can be solved by Algorithm C in about 70 Gμ — making the total running time about 350 Gμ. However, this 120-fold increase in speed cost the author two man-days of work.)
All three methods showed that, up to isomorphism, exactly 56 distinct motley cubes of size 7 × 7 × 7 are possible. Each of those 56 dissections has exactly 23 cuboids. Nine of them are symmetric under the mapping xyz ↦ (7 – x )(7 – y )(7 – z ); and one of those nine, namely the one in exercise 382 , has six automorphisms.
[These runs confirm and slightly extend the work of W. H. Cutler in JRM 12 (1979), 104–111. His computer program found exactly 56 distinct possibilities, when restricting the search to solutions that have exactly 23 cuboids.]
385. No; there are infinitely many. For example, Postl has constructed a primitive 11 × 11 × 13 by pasting Kim’s 7 × 7 × 7 to its mirror image, perturbing a few planes normal to the splice, and reducing.
386. The twelve possible symmetries can be represented as the permutations of {0, 1, 2, 3, 4, 5} defined by x ↦ ( ax + b ) mod 6, where a = ±1 and 0 ≤ b < 6; let’s denote that permutation by b or b , according to the sign of a . There are ten symmetry classes, depending on the automorphisms that are present: (i) all twelve; (ii) { 0 , 0 ¯ , 2 , 2 ¯ , 4 , 4 ¯ } ; (iii) { 0 , 1 ¯ , 2 , 3 ¯ , 4 , 5 ¯ } ; (iv) {0, 1, 2, 3, 4, 5}; (v) { 0 , 3 , 0 ¯ , 3 ¯ } or { 0 , 3 , 2 ¯ , 5 ¯ } or { 0 , 3 , 4 ¯ , 1 ¯ } ; (vi) {0, 2, 4}; (vii) {0, 3}; (viii) { 0 , 0 ¯ } or { 0 , 2 ¯ } or { 0 , 4 ¯ } ; (ix) { 0 , 1 ¯ } or { 0 , 3 ¯ } or { 0 , 5 ¯ } ; (x) {0}.
(Types (ii), (iii) and (viii), (ix) depend on whether a reflection is left-right or top-down. Notice that there are 12 /k base placements when there are k automorphisms.)
387. The 24 potential symmetries S can be represented as signed permutations of {±1,±2,±3}, meaning that coordinates are permuted and/or complemented. Using the notation of answer 7.2.1.2–20, they are 123 , 123 ¯ , 1 ¯ 2 3 ¯ , ... , 321 ¯ , where the number of inversions of the permutation plus the number of complementations is even.
Each of those symmetries is a rotation in 3-space about some line through the origin. (After a polycube has been rotated by one of its symmetries, we should shift the result, if necessary, to bring it into the original position.) For example, 1 ¯ 32 takes ( x, y, z ) ↦ ( c – x, z, y ); it’s a rotation of 180° about the diagonal line x = c/ 2, y = z . It’s a symmetry of the bent tricube {000, 001, 010} when c = 0; it’s a symmetry of the L-twist {000, 001, 100, 110} when c = 1.
All subgroups of this group are easily found by constructing the BDD for the Boolean function whose 24 variables are the potential symmetries. Indeed, all subsets of any set S that are closed under any given binary operator % on that set are the solutions to Λ x , y ∈ S ( ¬ x ∨ ¬ y ∨ ( x * y ) ) . In this case the resulting BDD (found in 2.5 Mμ) has 197 nodes, and it characterizes exactly 30 subgroups.
Two subgroups T and T ′ are said to be conjugate if T ′ = t – Tt for some t ∈ S . Such subgroups are considered to be equivalent, because they amount to viewing the objects from a different direction. The distinct conjugacy classes of subgroups according to this equivalence relation are called the “ symmetry types,” and there are 11 of them:
Class (ii) consists of the 12 symmetries whose permutations are even. The smallest polycube which admits these symmetries and no more — and hence it has just two base placements — contains 20 cubies, with 12 surrounding a central core of 8. Class (iv) has one symmetry for each permutation of the three coordinates. Classes (iii), (v), (vi), (vii), (ix), (x), (xi) correspond to the eight symmetry types of a square, with reflections implemented by “turning the square over” to the opposite side. In this interpretation bi axial symmetry becomes “tricentral,” because it corresponds to central symmetry about each coordinate axis. The former class called “180°” is now the same as “axial,” when viewed from either of the two other axes. [Many of these twelve examples have reflective symmetries too; but those don’t count. Under the full set of 48 hyperoctahedral symmetries, when reflections are allowed, there are 33 symmetry types(!), nicely presented by W. F. Lunnon in Graph Theory and Computing (Academic Press, 1972), 101–108. Lunnon also exhibited the ten symmetry types for polyhexes on pages 87–100.]
388. The directed path of four weak clues in (a) is equivalent to the five strong clues (1, 2, 3, 4, 5) . Then there are “ hidden singles” in columns 1 and 2, leading to a “ naked single” in cell (4, 2), etc.; we cruise to victory with out branching. Puzzle (b) has a naked single in (4, 2) — and we notice, by the way, that the middle cell needn’t be 5 even though it is greater than each of its four neighbors. Then (4, 4) is naked, and so on; again everything is forced. Puzzle (c) begins with hidden singles, which place the three missing 1 s and then the 5 in row 0. After we fix cell (4, 2), the rest falls into place.
[ Historical note: Futoshiki was invented by Yoshihiko Asao, who called it Dainarism (“Greater Than”); see Puzzle Communication Nikoli 92 (September 2000).]
389. In general, given a digraph in which each vertex v is supposed to be given an integer label l ( v ) with l ( v ) ≥ a ( v ), where the lower bounds a ( v ) have been specified, we can refine them as follows: For each vertex with d + ( v ) > 0, push v ⇒ S , where S is an initially empty stack. Then while S is nonempty, repeatedly do this: Pop S ⇒ v ; for each w with v ––→ w and a ( w ) ≤ a ( v ), set a ( w ) ← a ( v )+1, and push w ⇒ S if d + ( w ) > 0.
A similar algorithm will refine a given set of upper bounds b ( v ). For futoshiki, we apply these algorithms with a ( v ) = 1 and b ( v ) = n initially, except that a ( v ) = b ( v ) = l when a strong clue has specified v ’s label. ( Note: This method isn’t clever enough to prove that the middle element of puzzle (b) must be 3 or more. But it’s still very useful.)
390. In both cases we use primary items p ij , r ik , and c jk for 0 ≤ i, j < n and 1 ≤ k ≤ n , as we did for sudoku. There will be one option analogous to (30) for every ( i, j ) and for every k ∈ [ a ij ..b ij ], where the bounds a ij and b ij are calculated as in exercise 389 , except when k is ruled out by a strong clue.
(a) Suppose there are w weak clues, where the t th weak clue is l ( i t j t ) < l ( i ′ t j ′ t ). Introduce ( n – 3) w secondary items g td for 1 < d < n – 1 and 1 ≤ t ≤ w . Such an item informally means that l ( i t j t ) > d and d ≥ l ( i ′ t j ′ t ); so we don’t want it to appear twice. We include g td in each option for ij with d < k , and in each option for i ′ j ′ with d ≥ k .
For example, the options for cells (0, 0) and (0, 1) in puzzle 388(b) are ‘ p 00 r 03 c 03 g 13 ’, ‘ p 00 r 04 c 04 ’, ‘ p 00 r 05 c 05 ’; ‘ p 01 r 01 c 11 ’, ‘ p 01 r 02 c 12 ’, ‘ p 01 r 03 c 13 g 12 ’. (There’s no option for ( i , j , k ) = (0, 0, 2) or (0, 1, 4).) Another option is ‘ p 22 r 23 c 23 g 23 g 33 g 43 g 53 ’.
(b) Introduce w primary items g t , and 3 n 2 secondary items P ij , R ik , C jk . The options for p ij , r ik , and c jk are ‘ p ij r ik c jk P ij : k R ik : j C jk : i ’ for 0 ≤ i, j < n and a ij ≤ k ≤ b ij . The options for g t are ‘ g t P i t j t : k P i t ′ j t ′ : k ′ R i t k : j t R i t ′ k ′ : j t ′ C j t k : i t C j t ′ k ′ : i t ′ ’ for k < k ′ , where k and k ′ are within the bounds for l ( i t j t ) and l ( i t ′ j t ′ ) .
Experience shows that formulation (a) is a clear winner over formulation (b).
391. Given 5 ⋅ 5 ⋅ 5 options ‘ p ij r ik c jk ’ as in answer 390 , Algorithm X needs just 230 megamems to generate 161280 = 5! ⋅ 4! ⋅ 56 solutions. [ Euler enumerated them in his major paper on latin squares [ Verhandelingen Genootschap Wetenschappen Vlissingen 9 (1782), 85–239, §148], though he was nearly blind at the time.] Every 5 × 5 latin square has 40 pairs of adjacent elements, leading to a string of 40 inequality signs; and we can sort those 161280 strings. Only 115262 distinct strings actually occur; and only 82148 of them occur just once. The other 79132 cannot be identified by weak clues only.
392. Here are the first examples found of each type, and the total number of cases:
(More detailed counting shows exactly (369404, 2976, 4216, 3584, ... , 80) cases with at least one long path and (0, 1, 2, 3, ... , 1344) solutions; (405636, 4000, 4400, 1888, ... , 72) cases with no long path and (0, 1, 2, 3, ... , 24128) solutions.) Example (i) below is one way to get the maximum number of solutions, using six particularly unhelpful clues.
The most interesting cases, of course, are those that make valid puzzles. They fall into equivalence classes under rotation and/or reflection and/or complementation; thus sixteen examples are typically equivalent to any given one. However, there are 46 equivalence classes with only eight members, self-dual under transposition, of which 26 have long paths (as in (ii), (iii), (iv) below) and 18 do not (as in (v), (vi), (vii)). Thus (173+26)+(241+18) = 458 essentially different futoshiki puzzles with six weak clues are valid; however, many of these are really the same, under row-and-column permutations that preserve all clues. The most difficult symmetric instance is probably (vii), because exercise 390 needs a 374-node search tree to solve it. (A clever solver will, however, deduce immediately that all diagonal elements of a symmetric puzzle must be 3!)
393. The 5 6 = 15625 ways to label six cells can be reduced to ω ¯ 6 \= 203 , by limiting consideration to restricted growth strings (Section 7.2.1.5), multiplying the results for every such string by 5 k when it has k different labels. (In fact, only 202 such strings are relevant, because the last one (123456) will be multiplied by 5 6 = 0 and never used.) Running through each subset of five cells, we find respectively (1877807500, 864000, 0, 0, 1296000, 10368000, ... , 144000) cases that have (0, 1, 2, 3, 4, 5, ... , 336) solutions.
Every case with a unique solution is obtained from the example shown by independently permuting the rows, columns, and labels. (Indeed, 864000 = 5! 3 /2.)
394. Let there be h strong clues and k = 5 – h weak clues. Four solutions are obtained only in (144, 2016, 2880) cases for h = (1, 2, 3). In every such case, two rows and two columns are completely free from clues; thus the four solutions arise from swapping those two rows and/or those two columns. As in answer 392 , most of the cases belong to classes of 16 puzzles that are equivalent under rotation, transposition, and/or complementation. But when h = 3 there are 30 classes of size 8, having transposition symmetry (see (iii) and (iv) below); also 6 self-dual classes of size 8 (see (v)). Hence there are 9 + 126 + (36 + 162) = 333 inequivalent 4-solution 5-clue futoshikis altogether.
[This exercise was inspired by a talk that Dan Katz gave at the Joint Mathematics Meetings in January 2012. He observed, among other things, that valid puzzles exist with h + k = 6 for all values 0 ≤ h ≤ 6. Indeed, we can start with example (iv) in answer 392 , and repeatedly insert a clue (5, 1, 5, 1, 4, 2) while removing an inequality.]
[The minimum number of strong clues needed to specify an n × n latin square is known to be ⌊ n 2 /4⌋ for n ≤ 8. See R. Bean, arXiv:math/0403005 [math.CO] (2004).]
395. Let L solve (vi) in answer 394 . [See Appendix E if you’re stuck.] The only way to distinguish L from fifteen other latin squares that have the same string of 40 inequality signs is to give at least one clue 2 or 3 in a boundary row or column, at least one clue 4 or 5 in a boundary row or column, and at least one 4 or 5 in cells {(1, 1), (1, 3), (3, 1), (3, 3)}.
396. For example, here’s one that Algorithm P + X solves in 90 Mμ. (See Appendix E .)
397. (a) Assuming an m × n grid, let there be ( m +1)( n +1) – 4 primary “endpoint” items ij for 0 ≤ i ≤ m , 0 ≤ j ≤ n , and [ i =0] + [ i = m ]+ [ j =0]+[ j = n ] ≤ 1; also “sheep” items s ij when a sheep is in cell ij ; also “start-stop” items + and –. Let there be mn secondary items x ij for 0 ≤ i < m and 0 ≤ j < n , one for each cell. Three kinds of options are used: (i) There are 14( m –1)( n –1) “junction” options ‘ ij x ( i – 1)( j – 1) : a x ( i – 1) j : b x ij : c x i ( j – 1) : d ’, for 0 < i < m and 0 < j < n and 0 ≤ a, b, c, d ≤ 1 and ( a = b or b = c or c = d ). (ii) There are 2 m +2 n – 4 sets of four “boundary” options typified by ‘02 x 01 :0 x 02 :0’, ‘02 x 01 :0 x 02 :1 –’, ‘02 x 01 :1 x 02 :0 +’, ‘02 x 01 :1 x 02 :1’, for 0 ≤ i ≤ m , 0 ≤ j ≤ n , and [ i =0]+[ i = m ]+[ j =0]+[ j = n ] = 1; adjacent boundary cells, like x 01 and x 02 in this example, are listed in clockwise order. (For example, one of the options at the right boundary when n = 5 is ‘35 x 24 :0 x 34 :1 –’; one of the options at the left is ‘20 x 20 :1 x 10 :0 +’.) (iii) Each sheep has up to six “sheep” options, ‘ s ij x ij :1 x ( i – 1) j : a x i ( j +1) : b x ( i +1) j : c x i ( j – 1) : d ’, where a + b + c + d = 2; the x items are omitted if the corresponding cells lie outside of the grid, in which case their values are assumed to be 1. For example, the topmost sheep has only three options in the example puzzles, namely ‘ s 03 x 03 :1 x 04 : b x 13 : c x 02 : d ’, where b + c + d = 1.
This XCC problem for the rightmost example puzzle has five solutions:
To eliminate the spurious ones, we traverse the fence from ‘+’ to ‘–’, accepting a solution only if that path contains all of the color transitions between adjacent cells.
(b) There’s a unique solution if we put k sheep into a diagonal of length k ; but that puzzle is trivial, not “interesting.” Random trials show that about one configuration in every 10,000 makes a suitable puzzle; the author found the first three examples below in that way. The fourth example was contrived by hand. All are solvable by hand:
[E. Olson invented this game; see J. Henle, Math. Intelligencer 40 , 1 (2018), 69–70.]
398. The blanks in rows 0 and 4 of (c) can be filled with 3 and 5 in two ways.
[Tetsuya Miyamoto invented KenKen ® in 2004, as an aid to education. The special case where all operations are multiplication, and all cages are rectangular, had been published by Ryuoh Yano in Puzzle Communication Nikoli 92 (September 2000).]
399. (Solution by P. Weigel.) Let r ik and c jk be primary items for 0 ≤ i , j ≤ n and 1 ≤ k ≤ n . Also, if there are w cages, introduce primary items g t for 1 ≤ t ≤ w . Furthermore, introduce primary items p ij for all cells i j that belong to clueless cages. Every such p ij has n options ‘ p ij r ik c jk ’, for 1 ≤ k ≤ n . Finally, let C t be the cells of the t th cage, and let there be an option
‘ g t ∪ { r i l ( i t , j t ) , C j l ( i t , j t ) } ’
for every feasible way to assign labels l ( i t , j t ) to the cells of C t . For example, there are two labelings that satisfy the clue ‘15×’ in the third cage in puzzle 398(a), namely either l (0, 3) = 3 and l (0, 4) = 5 or l (0, 3) = 5 and l (0, 4) = 3; the two options for g 3 are therefore ‘ g 3 r 03 c 33 r 05 c 45 ’ and ‘ g 3 r 05 c 35 r 03 c 43 ’. The cage of that puzzle whose clue is ‘9×’ has just one option: ‘ g 4 r 13 c 03 r 11 c 11 r 23 c 13 ’.
The option for a one-cell cage is trivial, and the options for two-cell cages are also easy. The options for larger cages are readily listed by a straightforward backtrack algorithm: We can represent unchosen labels in each row and column by bit vectors, just as unchosen values in the queens problem were represented in Algorithm 7.2.2B * . Simple upper and lower bounds on the final sum or product, given a partial labeling, yield satisfactory cutoffs in the analog to step B3 * of that algorithm, based on the ρ and λ functions of Section 7.1.3. The ten-cell ‘34560×’ cage of puzzle 398(b) turns out to have 288 options, with 31 items each; the links will dance merrily around them all.
(Incidentally, this formulation doesn’t require the cells of a cage to be connected.)
400. Algorithm X breezes through those 2048 problems almost instantaneously, and finds that exactly 499 of them are uniquely solvable. The number of such puzzles with (5, 6, ... , 11) given clues is (14, 103, 184, 134, 52, 11, 1); for example, one can solve it when given only the clues ‘15×’, ‘6+’, ‘3–’, ‘5+’, ‘5’, in five cages! Exactly (14, 41, 6) of those 499 puzzles have (5, 6, 7) minimal clues; minimal-clue puzzles correspond to the prime implicants of the associated monotone Boolean function.
Similar remarks apply to puzzle 398(b), which can be solved uniquely without knowing either of the clues ‘34560×’ or ‘2’ — although the reader probably made heavy use of those clues when solving it. (On the other hand, its clue ‘9+’ cannot be omitted.)
401. There are 36 ways to cover a 4×4 board with dominoes, but nearly all of them are unsuitable. For example,
can’t define the cages of a valid kenken problem, because the middle rows of any solution could be swapped to give another solution. And no two dominoes can cover a 2 × 2 region whose solution has the form a b b a . Therefore we’re left with only two cage patterns,
and its transpose.
A given cage pattern can be filled with two clues of each type in 8!/2! 4 = 2520 ways. Most of those ways are obviously impossible, because ÷ cannot be applied to the pairs {2, 3} or {3, 4}. It turns out that (1620, 847, 52, 1) of the cases give a kenken puzzle with respectively (0, 1, 2, 4) solutions. Notable examples are
and
,
where the first is among the “most difficult,” in the sense that its search tree via the construction of exercise 399 has most nodes (12). The second is the one with four solutions.
402. (The solution appears below, following answer 403 .) The author constructed this puzzle by first designing the cages, then generating a dozen or so random latin squares via exercise 86 until finding one that had a unique solution. Then the domino clues were permuted at random, ten times; the most difficult of those ten puzzles was selected.
The construction of answer 399 gives an XC problem with 9186 options, 342 items, and 107388 total entries. There are respectively (720, 684, 744, 1310, 990, 360, 792, 708, 568, 1200, 606, 30) options for the pentominoes (O, P, ... , Z); preprocessing with Algorithm P reduces those counts to (486, 231, 60, 957, 852, 186, 360, 572, 175, 765, 477, 22). Overall, the reduced problem has 5528 options, 324 items, and 62914 total entries. The total time to find the solution and prove its uniqueness was 2.5 Gμ for Algorithm P and 11 Gμ for Algorithm X , with a search tree of 829 kilonodes. (Without preprocessing, Algorithm X would have taken 27.4 Gμ, and its search tree would have had 1.8 meganodes. Could a human being solve this puzzle by hand?)
403. Filip Stappers has devised the stunning puzzle shown below, which matches π’s first 42 digits perfectly(!). The construction of answer 399 fails spectacularly on this particular instance, because the monster cage for ‘64+’ has 354,896,640 options. We can, however, work around that problem by simply treating row 4 as an additional cage without a clue, and subtracting 1 + 2 + . . . + 9 = 45 from the original cage total. (A latin square is determined by any n – 1 of its rows.) Then Algorithm X solves the problem handily, with a cost of only 292 M μ (from 173875 options, 200 items, 2766956 total entries), and with a search tree of only 194 nodes. (See Appendix E .)
404. Such puzzles can be defined on any N -vertex graph G , some of whose vertices are labeled with elements of {1, 2 ,...,N }; the problem is to extend such a labeling to a full Hamiltonian path, in all possible ways. We imagine an additional vertex ∞, which is adjacent to all the others. A Hamiltonian path in G is then equivalent to a Hamiltonian cycle in G ∪∞, with ∞ interposed between the first and last vertices of the path.
For 1 ≤ k ≤ N , let v k be the vertex labeled k , or v k \= Λ if there’s no such vertex. Also let v 0 = v N +1 = ∞. We define an XCC problem with two kinds of primary items: (i) – v and + v for all unlabeled vertices v ; (ii) s k for 0 ≤ k ≤ N , except when both v k \= Λ and v k +1 = Λ. We also introduce secondary items p v for all unlabeled v , and q k for all unused labels k . (Thus the example has 35 primary items {–00, +00, –10, +10, –11, ... , +33, s 1 , ... , s 7 , s 9 , ... , s 16 }, and 20 secondary items { p 00 , ... , p 33 , q 2 , q 4 , ... , q 15 , q 16 }.) The options for s k are ‘ s k – u p u : k q k : u + v p v : k +1 q k +1 : v ’ for all pairs of vertices u ––– v such that u = u k or might be labeled k and v = v k +1 or might be labeled k + 1. But we omit – u p u : k q k : u if u = v k ; we omit + v p v : k +1 q k +1 : v if u = v k +1 . For example, four of the options in the 4 × 4 toy problem are
‘ s 3 +11 p 11 :4 q 4 :11’, ‘ s 6 –31 p 31 :6 q 6 :31 +30 p 30 :7 q 7 :30’,
‘ s 4 –10 p 10 :4 q 4 :10’, ‘ s 6 –30 p 30 :6 q 6 :30 +31 p 31 :7 q 7 :31’;
the bottom two appear in the solution, but the top two do not. The secondary items are colored so that interdependent options will always link up properly.
Suppose l < k < r and v l ≠ Λ, v l +1 = … = v k \= … = v r – 1 = Λ, v r ≠ Λ. The statement “ u might be labeled k ” in the specification above means more precisely that there is a simple path of length k – l from v l to u and a simple path of length r – k from u to v r . (This condition is necessary for u to be labeled k , but not sufficient. It is, however, sufficient for our purposes.) A simple path of length 1 is equivalent to adjacency. A simple path of length > 1 can be decided using the algorithm in the following exercise; but if that algorithm is taking too long, we can proceed safely by assuming that a simple path does exist. The value of min( k – l, r – k ) is usually small.
[Gyora Benedek invented Hidato ® in 2005 and began to publish examples in 2008. Similar brainteasers sprang up later, based on other kinds of paths; but king moves P m ⊠ P n have a special appeal because they can cross each other.]
405. For l = 0, 1, ... , L , find the set S l of all pairs ( S, w ) such that at least one simple path from v to w runs through the vertices of S ∪ v , where S is an l -element set. Clearly S 0 = {(∅ ,v )}; and S l +1 = {( S ∪ w, w ) | w ––– u and w ∉ S for some ( S, u ) ∈ S l }.
If at most 58 vertices w are reachable from v in ≤ l steps, we can represent each pair ( S, w ) in a single octabyte, with 6 bits for w and 58 bits for S . These octabytes can be stored in two stacks, alternately at the low and high ends of a sequential list.
406. The moves from 12 to 19 are forced, as are those on several other diagonals. So everything is quickly filled in, except for blanks between 42 and 51. Aha.
407. Using exercise 404 , Algorithm C finds the 52 solutions quickly (1500 kilomems). Only one of them has ‘18’ in row 3, column 3; and that clue makes a puzzle with a nicely symmetric solution (see Appendix E ). [We could also put ‘27’ in cell (2, 4); or ‘18’ in (4, 3); or ‘17’ in (4, 4). But that would destroy the smile.]
408.
409. Yes! (This puzzle is fiendishly difficult to solve by hand, although that has actually been done. Algorithm C finds the unique solution in 330 Mμ, with a search tree of 161612 nodes. (If you give up, the solution can be found in Appendix E .) A “ pidato puzzle” like this is presumably possible only because 10 × 10 hidato solutions are quite abundant. Indeed, the actual number of 10 × 10 king paths is 721833220650131890343295654587745095696; it can be determined with ZDD technology, as explained in Section 7.1.4.)
410. Puzzles (a), (b), (d) have unique solutions; remarkably, all 12 of the clues in (b) are essential. But (c) has 40 solutions, including two whose loop doesn’t touch a corner.
Pattern (x), incidentally, has unique solutions for x = 0, 1, 2 , but none for x = 3 .
[ Historical note: Slitherlink was invented by Nikoli editor Nobuhiko Kanamoto, who combined the puzzle ideas of Ayato Yada and Kazuyuki Yuzawa. See Puzzle Communication Nikoli 26 (June 1989).]
411. False; for instance,
has two. [But such cases are somewhat mysterious. There are 93 of size 5 × 5, including three that give two loops despite 8-fold symmetry. A 6 × 6 example yields four loops; can you find them? (See Appendix E .) If m + 1 and n + 1 are relatively prime, N. Beluhov [arXiv:2308.08798 [math.CO] (2023), 28 pages] has proved that an m × n slitherlink diagram with all clues given cannot have more than one solution. He has also found (4 k +3) × (4 k + 3) fully clued examples that are solvable with exactly three loops, for all k > 0. It’s currently unknown whether or not exactly five loops are possible.]
412. With an m × n grid it’s convenient to use the (2 m + 1)(2 n + 1) pairs xy for 0 ≤ x ≤ 2 m and 0 ≤ y ≤ 2 n , with xy representing either (i) a vertex, if x and y are both even; (ii) a cell, if x and y are both odd; or (iii) an edge, if x + y is odd. The edge between two adjacent vertices is their midpoint. The four edges surrounding a cell are obtained by adding (±1, 0) and (0, ±1) to the coordinates of the cell.
To obtain the weak solutions for any slitherlink diagram on a planar graph, introduce one primary item for each vertex, one primary item for each face in which the number of edges is specified, and one secondary item for each edge. There are 1 + ( d 2 ) options for each vertex υ of degree d , namely ‘ υ e 1 : x 1 … e d : x d ’ where x j ∈ {0, 1} and x 1 + … + x d \= 0 or 2. There are ( d k ) options for each face f of degree d that should have k edges in the path, namely ‘ f e 1 : x 1 … e d : x d ’ with x j ∈ {0, 1} and x 1 + … + x d \= k .
For example, the options for vertex 00 in the diagram of exercise 410(i) are ‘00 01:1 10:1’ and ‘00 01:0 10:0’. The options for cell 11 are ‘11 01:1 10:1 12:1 21:0’, ‘11 01:1 10:1 12:0 21:1’, ‘11 01:1 10:0 12:1 21:1’, ‘11 01:0 10:1 12:1 21:1’.
This construction yields (2, 2, 104, 2) weak solutions for puzzles 410(a) to 410(d). (In cases (a), (b), (d) we can delete or insert the 4-cycle that surrounds the middle cell.)
413. (Solution simplified by R. Molinari.) Let each record for an item include two new fields U and V . The U and V fields of a secondary item that represents edge u —— υ will point to the primary items u and υ . The U and V fields of a primary item that represents vertex υ are renamed MATE and INNER . MATE( υ ) is zero until υ first becomes the endpoint of an edge, after which it points to the other endpoint of the path fragment containing that edge. INNER( υ ) is nonzero when υ lies within a path fragment.
Introduce two new global variables: Global variable F is the current number of fragments. Global variable E is the edge that closed a loop, or zero if there’s no loop.
For example, suppose two edges currently have color 1, say υ 1 —— υ 2 and υ 3 —— υ 4 . Then we’ve set MATE( υ 1 ) ← υ 2 , MATE( υ 2 ) ← υ 1 , MATE( υ 3 ) ← υ 4 , MATE( υ 4 ) ← υ 3 , and F ← 2. If now υ 2 —— υ 5 joins the fray, we set MATE( υ 5 ) ← υ 1 , MATE( υ 1 ) ← υ 5 , and INNER( υ 2 ) ← 1; but we leave MATE( υ 2 ) unchanged. Subsequent edges to υ 2 are rejected.
When the ‘purify’ routine (55) is called to give color 1 to a new edge i , it will refuse to do so when E is nonzero, because a loop has already been closed. Furthermore, when E = 0, it will know that edge i shouldn’t be chosen if U( i ) and V( i ) are mates and F ≠ 1, because that would close a loop disjoint from other fragments. On the other hand, it will close the loop if F = 1, also setting E ← i .
All of these operations are nicely and easily undone when we need to ‘unpurify’. For example, suppose edge i loses color 1 when u = U( i ) and υ = V( i ) . If υ = MATE( u ) , we set E ← 0 (to unclose the loop), if i = E ; but if i ≠ E , we set MATE( u ) ← MATE ( v ) ← 0 and F ← F – 1. If MATE ( u ) ≠ = MATE ( v ), we set MATE ( MATE ( u )) ← u , MATE ( MATE ( v )) ← v , and INNER ( u ) ← INNER ( v ) ← 0, F ← F + 1. The case MATE ( u ) = MATE ( v ) is easy too.
Caution: Algorithm P must be modified so that it never discards redundant items, when it is used to preprocess a problem for this extension of Algorithm C .
414. After the forced moves have been made as shown, only two edges are undecided between the vertices of rows 1 and 2. A strongest possible algorithm will know that those two edges must either both be present or both absent. (In fact, a truly strongest possible algorithm will force both to be present as soon as any edge in or between rows 0 and 1 has been chosen.)
In general, consider the graph G consisting of the original vertices V and all the currently undecided edges. If X is any proper subset of V , connected or not, any loop will contain an even number of edges between X and V \ X . Thus any cutset of size two will force a relation between two undecided edges. An algorithm that dynamically maintains minimum cutsets of G (see Section 7.5.3) will therefore be helpful.
415. Instead of solving millions of puzzles, we can use the ZDD technology of Section 7.1.4 to list all the loops in P 6 □ P 6 , of which there are 1222363. Say that the “signature” of a loop is the full sequence of 25 clues — the number of edges around each cell. It turns out that 93 pairs of loops have the same signature (see exercise 411 ); those 186 loops cannot be the solution to any 5 × 5 slitherlink puzzle. Let S be the set of 1222270 distinct signatures, and let S ′ be the subset of 1222177 that give a valid 25-clue puzzle.
Suppose s ′ ∈ S ′ has t > 0 entries equal to digit d ; and for s ∈ S let p ( s, s ′ ) be the binary “projection vector” x 1 … x t , where x k \= 1 if and only if s has d in the k th cell where s ′ has d . For example, if d = 1, the signatures s and s ′ shown above have t = 10 and p ( s, s ′ ) = 1011101111. Form the set P ( s ′ ) = { p ( s, s ′ ) | s ≠ s ′ }. Then s ′ , with all clues restricted to digit d , is a valid puzzle if and only if 11 … 1 ∉ P ( s ′ ). Moreover, the valid puzzles contained in that one are precisely those whose projections aren’t contained in any element of P ( s ′ ). (If we regard P ( s ′ ) as a family of sets, such projections are the elements of ℘ ↗ P ( s ′ ) , in the notation of exercise 7.1.4–236.) We can find those vectors, and the minimal ones, with a reachability algorithm such as Algorithm 7.1.3R.
In this way we discover exactly (9310695, 833269, 242772, 35940, 25) valid puzzles for d = (0, 1, 2, 3, 4), of which exactly (27335, 227152, 11740, 17427, 25) have no redundant clues. The minimum number of clues, in such irredundant homogeneous puzzles, is respectively (7, 8, 11, 4, 1); and the maximum number is respectively (12, 14, 18, 10, 1). Many of the extreme cases make pleasant little puzzles:
(See Appendix E . This minimum- 1 s puzzle is one of two based on signature s ′ above.)
416. Of course d = 4 is trivial. So is d = 0; but that case has an amusing sparse construction. The following puzzles generalize to all n with ( n + d )mod 4 = 1:
(See the solutions in Appendix E .) N. Beluhov, who found these patterns for d = 2 and 3, has raised interesting problems of optimum density: Let β ( d ) \= lim inf n → || S || /n 2 and β ( d ) ¯ \= lim sup n → ∞ | | S | | / n 2 , where S ranges over all valid n × n slitherlink puzzles that are d -homogeneous, and where || S || denotes the number of clues. Clearly || S || ≤ n 2 /2 when d = 3, because no 2 × 2 subsquare can contain more than two 3 s. Furthermore || S || ≥ n 2 /4 − O ( n ) when d = 0. For we must eliminate at least n 2 + 2 n of the 2 n ( n + 1) edges if all but one cycle is to be cut; each 0 eliminates at most four. If n > 5 we obtain a valid puzzle with only fourteen 1 s, by placing a suitable 4×6 pattern in the upper left corner. Similarly, there’s a valid puzzle with only four 3 s, if n > 3. Therefore these constructions prove that β ( 0 ) ¯ \= β ( 1 ) ¯ \= β ( 2 ) ¯ \= 1 ; β ( 3 ) ¯ \= 1 / 2 ; β ( 1 ) ¯ \= β ( 3 ) ¯ \= β ( 4 ) ¯ \= β ( 4 ) ¯ \= 0 ; β ( 0 ) ¯ \= 1 / 4 .
The intriguing c ase of β (2) remains unknown. Beluhov proved that it is at most 11 16 , using a construction for n = 4 k that’s illustrated here for n = 12. Palmer Mebane has constructed this 2-homogeneous puzzle on an 8 × 8 board that has only 24 clues [see puzsq.jp/main/puzzle_play.php?pid=14178 ].
417. The pattern for d = 3 in answer 416 works also for d = 0, if we remove one clue from the top row. Fascinating diagrams arise when such patterns are attempted for d = 1; Beluhov’s largest example so far is the 30 × 30 puzzle obtained when removing the 1 in column 26 of row 0. (Such puzzles are extremely difficult for the algorithm of answer 413 to handle; but SAT solvers have no trouble with them.)
418. (a) 6 · 26 12 ≈ 5 . 7 × 10 17 , from the central cell and 12 complementary pairs.
(b, c, d, e) As in answer 415 , we define the projection p ( s, s ′ ) = x 1 …x 13 , where x k \= 1 if and only if s and s ′ agree in the k th pair (or in the center, when k = 13). We obtain altogether 2,692,250,947 puzzles, of which 199,470,026 are minimal. The minimal ones include (1, 24, 0, 7, 42, 1648, 13428, 257105, … , 184, 8) that have respectively (1, 2, 3, 4, 5, 6, 7, 8, … , 19, 20) clues; here are some choice specimens:
419. To design this puzzle, the author began with the signature of the desired loop (see answer 415 ), then removed pairs of centrally opposite clues, more-or-less at random, until no redundant pairs remained. The construction of exercise 412 produced 2267 options on 404+573 items from the final clue set; and Algorithm P needed just 17 M μ to remove 1246 of those options. Then the algorithm of exercise 413 discovered the solution, and proved it unique, with 5.5 G μ of computation and a search tree of 15 meganodes. (It’s another big win for preprocessing: Otherwise that algorithm would have taken 37 T μ , with a 78-giganode search tree!) Reference: D. E. Knuth, Computer Modern Type-faces (Addison–Wesley, 1986), 158–159.
420. (Solution by Palmer Mebane.) In any solution, each cell is either inside or outside the loop. Lemma: Every 2 has exactly two neighbors inside. (For if the 2 is outside, the neighbors opposite its two edges are inside; otherwise the neighbors opposite its two non edges are inside.) Let S be the set of cells next to a 2 . Color each 2 alternately red or blue; then each cell of S is a neighbor of exactly one red 2 and exactly one blue 2 . In particular, that’s true for each inside cell of S . Thus, by the lemma, there are equally many red and blue cells. But that contradicts m mod 4 = n mod 4 = 1!
[This exercise is due to N. Beluhov, who observes that solutions aplenty exist when m is odd and n mod 4 = 3.]
421.
[ Historical note: Masyu was invented by Ryuoh Yano, who developed a white-circles-only version, together with Mitsuhiro Ase, who contributed the black circles. See Puzzle Communication Nikoli 84 (April 1999); 90 (March 2000).]
422. Now we use the 4 mn pairs xy for 0 ≤ x ≤ 2 m and 0 ≤ y ≤ 2 n . Cell ( i, j ) corresponds to x = 2 i and y = 2 j (a “vertex”); clue ( i, j ) corresponds to x = 2 i + 1 and y = 2 j + 1. Edges are as before, and we use the same options to ensure that either 0 or 2 edges touch every vertex in a solution. The only essential change from answer 412 is the treatment of clues, since masyu clues are different from slitherlink clues.
A black masyu clue in ( i, j ) has four options, corresponding to north-west, northeast, south-west, and south-east legs; for example, the north-west option is
‘ C ( i, j ) N ( i, j ):1 NN ( i, j ):1 W ( i, j ):1 WW ( i, j ):1’,
where C ( i, j ) = (2 i +1)(2 j +1), N ( i, j ) = C ( i, j )−21, NN ( i, j ) = C ( i, j ) − 41, W ( i, j ) = C ( i, j ) − 12, WW ( i, j ) = C ( i, j ) − 14; N ( i , j ) is the edge between cells ( i , j ) and ( i – 1, j ). Edges off the grid have “color” 0, so this option is omitted when i ≤ 1 or j ≤ 1.
A white masyu clue in ( i, j ) has six options, three for north-south orientation and three for east-west. The three for east-west are
‘ C ( i , j ) E ( i , j ) : 1 E E ( i , j ) : 0 W ( i , j ) : 1 W W ( i , j ) : 0 ’ ‘ C ( i , j ) E ( i , j ) : 1 E E ( i . j ) : 0 W ( i , j ) : 1 W W ( i , j ) : 1 ’ ‘ C ( i , j ) E ( i , j ) : 1 E E ( i , j ) : 1 W ( i , j ) : 1 W W ( i , j ) : 0 ’
Again we omit an option that would set an off-board edge to 1. An off-board edge item that sets color 0 is silently dropped.
For example, the options for the black clue in exercise 421 ’s puzzle are ‘15 14:1 34:1 03:1 01:1’, ‘15 14:1 34:1 05:1 07:1’. The options for the white clue in the bottom row are ‘97 87:1 85:1 83:0’, ‘97 87:1 85:1 83:1’. That puzzle has 15 clue options altogether, and 119 vertex options ‘00 01:1 10:1’, ‘00 01:0 10:0’, ‘02 01:1 03:1 12:0’, … , ‘88 78:0 87:0’.
423. Obtain a representative of each class of equivalent variables, for example by adapting Algorithm 2.3.3E. This calculation may show that certain variables are constant. A contradiction might also arise — for example, if there’s a white clue in a corner; in such cases the masyu puzzle has no solution.
The vertex options of answer 422 can now be eliminated, at all vertices for which a clue was given. The clue options can also be consolidated, so that equivalent variables don’t appear together, and so that constants are suppressed. Every option that tries to set a variable both true and false is, of course, eliminated.
For example, variables 14, 50, 70, 85, and 87 in the puzzle of exercise 421 are forced to be true; variables 61 and 76 are forced to be false. We can eliminate variables 05, 16, 27, 36, 54, 65, and 74 because 05 = ∼03, 16 = 36 = ∼25, 27 = 25, 54 = 74 = ∼63, 65 = 63. The options for the black clue become ‘15 01:1 03:1 34:1’, ‘15 03:0 07:1 34:1’. The options for the white clue in the bottom row become ‘97 83:0’, ‘97 83:1’.
Caveat: These simplifications are very nice, but they mess up the single-loop-detection mechanism of answer 413 — because that answer uses several fields of item nodes as key elements of its data structure! To keep that algorithm happy, we must append a special option that covers all of the supposedly eliminated vertex items and constant-edge items; this option is ‘04 26 60 64 86 87:1 85:1 76:0 50:1 70:1 61:0 14:1’ in the example. We also need pairs of options such as ‘#25 16:1 36:1 27:0 25:0’ and ‘#25 16:0 36:0 27:1 25:1’, to keep all variables of an equivalence class in sync.
A tenfold speedup is achieved even on small puzzles like the 8 × 10 in exercise 426 .
424. As in answer 415 , we can begin with the 1222363 loops that are potential solutions. But this time the “ signature” of a loop is the maximum set of clues that it supports. Such a signature turns out to have at most 24 clues; indeed, only puzzle (i) in Fig. A–5 , along with its rotations or reflections, attains this maximum. (At the other extreme, 64 loops have an entirely empty signature, despite having lengths up to 28.)
Let S be the set of 905472 distinct signatures; and let S ′ be the subset of 93859 that aren’t contained in (or equal to) the signature of any other loop. These are the signatures of loops that can solve a valid 6 × 6 puzzle. If s ′ ∈ S ′ has t clues, we define the projection vector p ( s, s ′ ) = x 1 …x t for s ∈ S by setting x j \= 1 when s agrees with s ′ in the j th cell where s ′ has a clue. For example, when s ′ is puzzle (i) and s is its transpose, the projection p ( s, s ′ ) is 000011000011101110110011.
Form the set P ( s ′ ) = { p ( s, s ′ ) | s ≠ s ′ }. We know that 11 … 1 ∉ P ( s ′ ), because s ′ isn’t dominated by any other signature. Moreover, the valid puzzles having the loop of s ′ as their solution are precisely t hose whose clues are not contained in any element of P ( s ′ ). We can find such puzzles, and the minimal ones, with a reachability computation like Algorithm 7.1.3R, whose running time is O (2 t ). For example, the loop of (i) turns out to be the solution to 8924555 puzzles(!). Four of them, such as (ii) and (iii), are minimal with only four clues; three of them, such as (iv), are minimal with eleven.
Most elements of S ′ have far fewer than 24 clues. Hence it isn’t difficult to determine that there are exactly 1,166,086,477 valid 6 × 6 masyu puzzles altogether, of which 4,366,185 are minimal. (There are (80, 1212, 26188, 207570, … , 106) minimal puzzles with (3, 4, 5, 6, … , 12) clues. One of the 3s is puzzle (v); it also has the shortest loop. One of the 12s is puzzle (vi); it also has the longest loop — a Hamiltonian cycle. (A Hamiltonian cycle can actually be forced by only four clues; see puzzle (xvii).)
The valid puzzles include 5571407 that are pure white, 4820 that are pure black. The white clues can take on 22032015 different patterns; the black clues can assume only 39140. A surprisingly large number of 6 × 6 puzzles, 37472, can be “inverted,” remaining valid when white and black are swapped. If we restrict consideration to minimal puzzles, these figures become: 574815 pure white, 1914 pure black, 2522171 white patterns, 22494 black patterns, 712 invertible. The latter include many amusing and amazing pairs, such as (vii)–(viii), (ix)–(x), (xi)–(xii), as well as self-dual examples such as (xiii), (xiv), (xv), (xvi); there are 49 essentially distinct invertible puzzles of size 6 × 6. [Considerably larger invertible puzzles have been published in the anonymous blog [uramasyu.blog80.fc2.com/](http://uramasyu.blog80.fc2.com/) , every few days since 2006.]
The author thinks puzzle (vi) may well be the hardest 6 × 6, although its search tree via exercise 423 has only 212 nodes. (That tree has 1001 nodes with exercise 422 .)
425. A “ balanced” n × n masyu solution of order k clearly requires 2 ≤ k ≤ ⌊ n 2 /4⌋. All such k turn out to be achievable, for n ≤ 6, except that the upper limit ⌊ n 2 /4⌋ is not. Solutions for k = 2 exist for all n ≥ 3; solutions for k = 3 exist for all n ≥ 4; solutions for k = 4, due to B. S. Ho, exist for all n ≥ 5; solutions for 5 ≤ k ≤ 10, due to G. J. H. Goh, are also known. (See (xviii)–(xxiv) in Fig. A–5 ; https://boonsuan.github.io/masyu.pdf .)
426. The clue in the corner must obviously be ‘
’. That leaves us with 2 28 other possibilities to consider, many of which can be rejected immediately because certain local patterns are impossible. (For example, there cannot be three consecutive ‘
’s.) Consider the Boolean function of x 0 x 1 …x 27 that’s true if and only if the diagram has at least one solution, with ‘
’ when x j \= 1 and ‘ ○ ’ when x j \= 0. One can easily verify that there’s no solution when we have x 0 x 1 or x 1 x 3 or x 0 x ¯ 1 x 4 or … or x ¯ 3 x ¯ 4 x ¯ 5 or x 6 x 7 or x ¯ 7 x ¯ 8 x ¯ 10 x ¯ 11 , etc.; also when we replace x j by x j +12 . We can also rule out extreme cases such as x ¯ 1 x ¯ 26 .
Fig. A–5. A gallery of interesting 6 × 6 masyu puzzles.
After compiling several dozen such “bad” configurations, the author applied BDD technology: Less than a megamem sufficed to generate a BDD of size 715, which showed that exactly 10239 vectors x 0 x 1 … x 27 were not yet ruled out. The masyu solver of exercise 423 tossed off those cases with search trees of 3 nodes per problem, on average; and it turned out that exactly (10232, 1, 1, 1, 4) vectors had (0, 1, 2, 3, 4) solutions. The unique winning puzzle is shown here (and solved in Appendix E ).
427. Here’s an example with 8 · 15 white clues (solved in Appendix E ):
It turns out to be problematic for the method of exercise 423 , which severely loses focus and takes forever to prove that there’s only one solution. One can, however, exploit symmetry by modifying Algorithm C as follows: Whenever a color setting is made on the rightmost branch of the search tree, all settings that are equivalent to it by symmetry can be forced. Then uniqueness is proved in about 36 M μ , provided that the primary items are suitably ordered. [This exercise was inspired by Nikoli’s Giant Logic Puzzles for Geniuses (Puzzlewright Press, 2016), #53.]
428. (Solution by N. Beluhov.) 3 n − 12 black clues suffice when n mod 4 = 0; 5 n − 21 white clues suffice when n mod 4 = 1. (Are these constants 3 and 5 the best possible?)
429. (a) Incidentally, each of these puzzles is minimal (all clues important):
(b) In fact, two permutations of the colors are possible in each case:
430. (a) The lower right corner must contain 5. See Appendix E for the other cells.
(b) Set c nk ← 0 for all n and k . Now do this for 3 ≤ x < 512: Set k ← n ← 0; for 0 ≤ t < 9 set k ← k +1, n ← n + t +1 if x &(1 ≪ t ) ≠ 0; finally if k > 1, set C nkc nk ← x and c nk ← c nk + 1. The n -in- k combinations are now C nkj for 0 ≤ j < c nk .
The maximum c nk , 12, is obtained for ( n, k ) = (20, 4) or (25, 5). Notice that c nk \= c (45− n )(9− k ) when 1 < k < 8. Cases with c nk \= 1 are called “restricted” or “ magic blocks”; they’re extremely helpful when present (but our example doesn’t have any).
(c) The middle must be 7 9 8 (an odd digit < 9, 9, then an even digit).
(d) The tables from (b) convert kakuro to generalized kakuro. Introduce a primary item ij for each cell to be filled. Let there be H horizontal blocks, and assume that horizontal block h has c h combinations X hp of length k h , for 1 ≤ h ≤ H and 1 ≤ p ≤ c h . Introduce c h k h primary items H hpx , for x ∈ X hp , to represent the elements of block h ’s p th combination. (For example, the primary items for the first horizontal block of our example are H 111 , H 114 , H 122 , H 123 because the two combinations are {1, 4} and {2, 3}.) Similarly, introduce primary items V υqy for the elements of the q th combination Y υq of vertical block υ , for 1 ≤ υ ≤ V and 1 ≤ q ≤ d υ .
Also introduce secondary items H h and V υ for 1 ≤ h ≤ H and 1 ≤ υ ≤ V , one for each block. The “color” of such an item represents the choice of combination to be used.
The options for cell ij are ‘ ij H hpx H h : p V υqx V υ : q ’, where h and υ indicate the horizontal and vertical blocks through ij , for 1 ≤ p ≤ c h and 1 ≤ q ≤ d υ and x ∈ X hp ∩ Y υq . (Thus, the options for the upper left blank cell in our example are ‘11 H 111 H 1 :1 V 111 V 1 :1’, ‘11 H 114 H 1 :1 V 124 V 1 :2’, ‘11 H 122 H 1 :2 V 122 V 1 :2’. Set intersections are easily computed from the bitmaps X hp and V υq .)
Additional options are also necessary to “absorb” the combinations not used. These are ‘ ∪{H hpx | x ∈ X hp } H h : p ′ ’ for 1 ≤ p, p ′ ≤ c h and p ≠ p ′ ; ‘∪{V υqy | y ∈ Y υq } V υ : q ′ ’ for 1 ≤ q, q ′ ≤ d υ and q ≠ q ′ . (Thus the options for h = 1 in our example are ‘H 111 H 114 H 1 :2’, ‘H 122 H 123 H 1 :1’.) This instructive construction deserves careful study.
431. There are 18 solutions, because of two ways to complete the middle left portion and (independently) nine ways to complete the lower left corner. (The digits that are uniquely determined by his conditions are shown below.) We can freeze most of those digits, and extract two much smaller problems, then insert a few wildcards as in exercise 433 until obtaining uniqueness. One suitable patch, shown below, changes seven clues and has the solution found in Appendix E . (In this problem, preprocessing greatly improves the focus, reducing the search tree size from 115 million to just 343!)
[ Funk had copyrighted a Cross Sums Puzzle already in September 1935; see Canadian Patent Office Record and Register of Copyrights and Trade Marks 63 (1935), 2253.]
432. (a) We save a lot of time by considering only “ restricted growth strings” as solutions (see Section 7.2.1.5). That is, we can assume that the top row is ‘12’; then the second row is either ‘213’ or ‘234’ or ‘312’ or ‘314’ or ‘34 x ’ for 1 ≤ x ≤ 5; etc. Altogether there are (5, 28, 33, 11, 1) such strings with maximum element (3, 4, 5, 6, 7). Thus we know that the blanks can be filled in 5 · 9 3 + 28 · 9 4 + 33 · 9 5 + 11 · 9 6 + 9 7 \= 1432872 ways. And we can quickly compute the 1432872 sequences of block sums from those restricted growth strings, using a table of 9! permutations built by Algorithm 7.2.1.2L. Exactly 78690 of those sequences, about 5.5%, occur uniquely and define a kakuro puzzle.
Every kakuro puzzle has a dual , obtained by replacing all clue-sums s for blocks of length k by 10 k − s ; the dual is solved by changing each digit d to 10 − d . Thus, if a puzzle of type (a) is defined by horizontal and vertical sums s 1 s 2 s 3 /t 1 t 2 t 3 , its dual is defined by (20− s 1 )(30− s 2 )(20− s 3 )/(20− t 1 )(30− t 2 )(20− t 3 ). Diagonal symmetry also makes s 1 s 2 s 3 /t 1 t 2 t 3 equivalent to s 3 s 2 s 1 /t 3 t 2 t 1 and t 1 t 2 t 3 /s 1 s 2 s 3 ; so we get up to eight equivalent puzzles from each sequence. There are 9932 essentially distinct puzzles, only one of which has four symmetries, namely 6 15 14/14 15 6; 190 have one symmetry, and the remaining 9741 are asymmetric. (The asymmetric ones are, of course, more difficult to solve, because a symmetric puzzle will have a symmetric solution.) The example 5196/6 10 14 in exercise 430 is asymmetrical; but it’s relatively easy because it has a forced move in the lower right corner. The easiest puzzles, with four forced moves, are 41512/12 15 4 and 4 15 16/12 15 8, both symmetric. Altogether 4011 of the asymmetric puzzles have no forced moves. And of those, 570 have no “ magic blocks.” And of those, puzzle 6 19 6/8 11 10 is the hardest, in the sense that it maximizes the number of nodes (79) in Algorithm C ’s search tree, using the construction of answer 430(d) .
(b) Similarly, this shape has 2 · 9 3 + 42 · 9 4 + 186 · 9 5 + 234 · 9 6 + 105 · 9 7 + 18 · 9 8 + 9 9 \= 43038576 sequences of block sums, of which 6840 ≈ 0 . 016% are unique. Those 6840 yield 49 equivalence classes under the symmetries s 1 s 2 s 3 /t 1 t 2 t 3 ↦ s 2 s 1 s 3 /t 1 t 2 t 3 , s 3 s 2 s 1 /t 1 t 2 t 3 , s 1 s 2 s 3 /t 2 t 1 t 3 , s 1 s 2 s 3 /t 3 t 2 t 1 , t 1 t 2 t 3 /s 1 s 2 s 3 , (30− s 1 )(30− s 2 )(30− s 3 ) / (30− t 1 )(30− t 2 )(30− t 3 ). All but 3 of those 49 puzzles are asymmetric; 7 11 20/71120 and 71920/7 19 20 are self-transpose, and 7 15 23/10 15 20 is self-dual. They aren’t great, because they all have at least one forced move from 7 opposite 20 or from its dual.
[It’s extremely difficult to find a kakuro puzzle whose spaces make a 4 × 4 grid. But Johan de Ruiter discovered in 2010 that there are five essentially different ways. For example, 11 15 23 29/12 15 23 28 has a 488-node search tree, so it’s a nice little challenge.]
433. A slight extension to the construction of answer 430(d) allows “wildcard” blocks, with unspecified length and with the universal combination {1 ,..., 9} as their X or Y . The items H h 1 x or V υ 1 y for such wildcards are secondary, not primary. Algorithm C now pumps out 89638 solutions (in 150 M μ ); and 12071 of the corresponding sum sequences s 1 …s 7 /t 1 …t 7 occur once only and yield valid puzzles. (The easiest ones, 16418( d +14) 16 16 16/934246 d 12 15 for 7 ≤ d ≤ 9, have a search tree of only 47 nodes. A median puzzle such as 16 4 20 18 16 16 15/9 22 24 6 17 12 15 needs 247 nodes. And the hardest, 16 4 23 19 16 16 13/9 25 24 6 17 11 15, needs 1994.)
[The author tried 10000 experiments in which all 21 cells of this diagram were simply filled at random, and their block sums recorded. Those 10000 problems had ≈ 75 solutions, on average, with standard deviation ≈ 1200. Only five of them led to valid puzzles; the most difficult one, 15 3 21 16 27 8 10/9 22 28 11 21 5 4, needed 1168 nodes.]
434. In 700 M μ , a BDD with 64 variables and 124487 nodes characterizes 93,158,227,648 solutions. N. Beluhov proved in 2018 that there are at most 38 blocks, achieved for example as shown, by listing all cases with 38 or more. He also observed that the maximum for n × n kakuro is n 2 /3 − O ( n ), using a similar construction with ( i, j ) black ⇔ ( i + j ) mod 3 = 0 except near the boundary.
435. The search tree for this one has 566 nodes. (See Appendix E .)
436. (a) Any solution with a black seed works also with that cell white.
(b) A solution with a non- articulation point would work also with that cell black.
437. Introduce a primary item ∗ to make the seeds white; also primary items R ic and C jc for each character c that occurs more than once in row i or column j . Introduce secondary items ij for 0 ≤ i < m and 0 ≤ j < n , representing cell ( i, j ). For example, the first option for puzzle 436( α ) is ‘ ∗ 01:0 02:0 10:0 13:0 14:0 21:0 31:0 32:0’.
Suppose row i contains character c in columns j 1 , … , j t , where t > 1. Then R ic normally has t + 1 options ‘ R ic ij 1 : e 1 … ij t : e t u 1 :0 … u s :0’ for e 1 + … + e t ≥ t − 1, where { u 1 ,...,u s } are the non-seed neighbors of the cells being colored 1. However, this option is suppressed if it would assign two colors to the same item. For example, if i = 1, t = 3, and j 1 j 2 j 3 = 123, there is only one option ‘ R 1 c 11:1 12:0 13:1 01:0 03:0 10:0 14:0 21:0 23:0’ (but with entries deleted that color a seed with 0), because the other three options are contradictory.
Of course the options for C jc are similar. For example, the options for C 3 L in puzzle 436( α ) are ‘ C 3 L 23:0 33:1 34:0’ and ‘ C 3 L 33:0 23:1 22:0 24:0’.
[Notice, incidentally, that this XCC problem is a special case of 2SAT . Therefore it can be solved in linear time. Furthermore, by Theorem 7.1.1S, the median of any three solutions is also a solution — a curious fact!]
438. The basic idea is to abandon partial solutions that cut off any white cells from the first seed. Connectedness can be assured by maintaining a triply linked spanning tree, rooted at that seed, with the help of new fields in each item record. Changes to the spanning tree need not be undone when unblackening a cell while backtracking; any spanning tree on the currently nonblack cells is satisfactory.
[This method can be patched to handle the rare instances that have no seeds. To ensure uniqueness, as in exercise 436(b) , each solution should also be tested for articulation points. Hopcroft and Tarjan’s algorithm for bicomponents does that efficiently. See Section 7.4.1.2; also The Stanford GraphBase , pages 90–99.]
439. (a) Property (ii) states that U is a vertex cover (or equivalently that V \ U is independent). Thus (i) and (ii) together state that U is a connected vertex cover. Adding property (iii) gives us a minimal connected vertex cover. [Minimal connected vertex covers were introduced by M. R. Garey and D. S. Johnson in SIAM J. Applied Math. 32 (1977), 826–834, who proved that it is NP-complete to decide if a planar graph with maximum degree 4 has a connected vertex cover of a given size.]
(b) This is the thrust of exercise 436(b) . [N. Beluhov has proved constructively that every m × n hitori cover for m, n > 1 solves at least one valid puzzle, using an alphabet of at most max( m, n ) letters.]
440. False (if neither A is alone in its column). Consider
or
.
441. When n = 1 any single letter a is trivially a valid puzzle. When n > 1 the possibilities are (i) a α a for every string α of n − 2 distinct letters containing an a (thus ( n − 2) d n − 2 puzzles); (ii) a α b for a ≠ b and every string α of n − 2 distinct letters containing a and b (thus ( n − 2) 2 d n − 2 puzzles); altogether ( n − 2) 2 d n −2 valid puzzles.
442. A “ frontier-based” algorithm analogous to those of answers 7.1.4–55 and 7.1.4–225 will produce an unreduced ZDD for the family f of all complements V \ U of connected vertex covers, from which a variant of Algorithm 7.1.4R will give a ZDD. Then the NONSUB subroutine of answer 7.1.4–237 will produce a ZDD for f ↑ , the complements of hitori covers (the black cells of potential solutions). In the most complicated case, m = n = 9, an unreduced ZDD of size 203402 is reduced quickly to 55038 nodes; then 550 G μ of computation produces a ZDD of size 1145647 for the family of maximal black cells.
Those ZDDs make it easy to count and generate hitori covers; we obtain the totals
( 1 2 1 1 1 1 1 1 1 2 4 6 12 20 36 64 112 200 1 6 11 30 75 173 434 1054 2558 1 12 30 110 382 1270 4298 14560 49204 1 20 75 382 1804 7888 36627 166217 755680 1 36 173 1270 7888 46416 287685 1751154 10656814 1 64 434 4298 36627 287685 2393422 19366411 157557218 1 112 1054 14560 166217 1751154 19366411 208975042 2255742067 1 200 2558 49204 755680 10656814 157557218 2255742067 32411910059 )
Further statistics about these fascinating patterns are also of interest:
The left-hand matrix shows how many black cells can occur in hitori covers. The right-hand matrix shows how many hitori covers have both horizontal and vertical symmetry; when m ≠ n , such covers are counted just once in the previous totals, while the unsymmetrical covers are counted twice or four times. When m = n , such covers are counted either once (if there’s 8-fold symmetry) or twice (otherwise); there are respectively (1, 0, 1, 0, 2, 0, 2, 0, 11) n × n hitori covers with 8-fold symmetry. Further types of 4-fold symmetry are possible when m = n : There’s 90 ° rotational symmetry (but not 8-fold) in (0, 0, 0, 1, 1, 3, 11, 30, 106) pairs of cases; there’s symmetry about both diagonals (but not 8-fold) in (0, 0, 0, 0, 0, 1, 4, 9, 49) pairs of cases. Figure A–6 shows some of the winners in this beauty contest for symmetrical hitori covers.
Fig. A–6. A gallery of interesting hitori covers.
Fourfold horizontal and vertical symmetry is impossible when m and n are both even, because it forces at least 12 white cells near the center. The number of 2 × n hitori covers can readily be shown to satisfy the recurrence X n \= 2 X n −2 + 2 X n −3 , growing as Θ( r n ) where r ≈ 1 . 76929.
443. (Solution by N. Beluhov.) Let there be s black cells, of which a lie in the interior, b on the boundary but not in a corner, and c in a corner. One can show that b + 2 c ≤ m + n + 2 − [ m even] − [ n even] − [ mn odd]. Therefore the number of edges in P m □ P n | U is m ( n − 1) + ( m − 1) n − 4 a − 3 b − 2 c = 2 mn − m − n − 4 s + b + 2 c ≤ 2 mn − 4 s + 1. But P m □ P n | U is connected, so it has at least mn − s − 1 edges.
[Beluhov has also proved that the number of black cells is always at least mn/ 5 − O ( m + n ). One can obtain a small hitori cover by blackening ( i, j ) when i + 2 j is a multiple of 5, and possibly a few more cells; this cover has at most mn/ 5 + 2 black cells.]
444. No. By exercise 443 , the solution has at most ⌊( n 2 / 3 + 2) /n ⌋ black cells in some row. This is at most n/ 3, when n > 5; hence 2 n/ 3 elements of that row are white. Conversely, the puzzle illustrated here for n = 9 can be generalized to 3 k ×3 k for all k > 1. (It’s a simplification of a construction by N. Beluhov. Notice that every nonzero element is a seed!)
445. Array ( α ) below is a seedless puzzle that corresponds to (ii), if you change its lowercase letters to uppercase. (The lowercase letters are convenient for our purposes in understanding seedlessness, because they indicate the cells that we’ll want to darken.) When every black cell has a different letter to be hidden, a seedless puzzle must fill each white cell ( i, j ) with a hidden letter from either row i or column j .
Given a hitori cover, its “ RC problem” is to put either R or C into each white cell so that the number of Rs in each row is at most the number of black cells in that row, and the number of Cs is similar but for columns. Array ( β ) shows the RC solution that corresponds to ( α ); this is one of four ways to solve the RC problem for (ii).
Suppose a hitori cover has s black cells. Every solution to its RC problem has at most s white cells marked R and at most s marked C; so we must have s ≥ n 2 /3 in an n × n cover. Consequently s must be 12 when n = 6, by exercise 443 . In particular, pattern (i) can’t lead to a seedless puzzle. Also, equality must hold when we said “at most.”
It’s easy to formulate the RC problem as an MCC problem, by introducing a primary item ij for each white cell ( i, j ), also primary items R i and C j for each nonwhite row i and column j . In the problem for pattern (ii) we have, for example, two options ‘23 R 2 ’ and ‘23 C 3 ’ for item 23. The multiplicity of C 3 is 2. (This is actually a bipartite matching problem; we use Algorithm M only because of the multiplicities.)
Array ( γ ) shows a seedless puzzle different from ( α ) that comes from the same RC solution ( β ). Indeed, ( β ) yields 3!1!2!2!1!3! · 3!1!2!2!1!3! = 20736 different seedless puzzles, because the letters chosen in each row and column can be permuted arbitrarily.
All such permutations yield valid puzzles. Proof: Each of the 12 letters occurs thrice. To solve the puzzle we must blacken each letter at least once, preserving white connectedness. One successful solution is to kill two birds with each stone; any other way would blacken 13 or more. But no 6 × 6 hitori cover has more than 12 black cells.
Pattern (iii) has eight RC solutions, and 20736 seedless puzzles for each of them.
Pattern (iv) has no RC solutions. But pattern (v) has the unique solution ( δ ), and one of its 3!0!3!2!1!3! · 2!2!1!3!1!3! = 62208 seedless puzzles is ( ∈ ).
[N. Beluhov has proved that valid n × n seedless puzzles exist ⇔ n mod 6 = 0.]
446. There are only 1804 hitori covers, according to answer 442 ; but the exact probability appears to be difficult to compute. Experiments with millions of random numbers show convincingly, however, that the probability is ≈ . 0133. It drops to ≈ . 0105 with radix 8, and even further to ≈ . 0060 with radix 16; the “sweet spot” appears to be radix 10(!). [Also, the probability for decimal 4 × 4 is ≈ . 0344; for 6 × 6 only ≈ . 0020.]
447. Yes, when 2 ≤ m ≤ 4 and n = 6! (Johan discovered the 4 × 6, and the 5 × 5 for e , in 2017. The cases 2 × 6, 3 × 2, and 4 × 5 also work for e . By exercise 443 , we can assume that m, n ≤ 15.)
448. There are just two answers. (Also a nice 6 × 6 with only one not-so-common word.)
449. A few more nuggets: Johan noticed (i) in the (appropriately named) 1990 movie Home Alone ; and he found (ii) in the King James Bible, Luke 9 : 56. George Sicherman hit on Falstaff’s famous repartee (iii) in 1 Henry IV , Act V, Scene 4, Line 119. The author found (iv) within the graffiti on page 278 of CMath ; also (v), an inspiring remark by Francis Sullivan, on page 2 of Computing in Science and Engineering 2 ,1 (January/February 2000). Example (vi) appears in the front matter to Volume 1. And example (vii), also 11 × 3, shows that a nice hitori can involve lowercase letters, spaces, and punctuation; it’s a quote from Samuel Rogers’s poem Human Life (1819).
Literary hitori nuggets longer than 80 characters were first reported by Gary McDonald in 2023: (7 × 12 = 84) “he stood and carefully examined the sky, to ascertain the time of night from the altitudes of the stars.” [Thomas Hardy, Far from the Madding Crowd (1874)]. (11 × 8 = 88) “ ‘. . . But talk to me of poverty and wealth, and there indeed we touch upon realities.’ ‘My De-ar, this is becoming Awful—’ ” [Charles Dickens, Our Mutual Friend (1864)]. (10 × 10 = 100) “shall never forget his flying Henry’s kite for him that very windy day last Easter—and ever since his particular kindness” [Jane Austen, Emma (1816)].
450. The solutions are characterized by 25 items { tot , tibi , … , caelo , 1a, 1b, 1c, … , 5a, 5b, 5c, 6a, 6b} and 80 options ‘ tot 1a’, ‘ tot 1b 1c’, … , ‘ tot 4b 4c’, ‘ tot 5a’, ‘ tot 6a’, ‘ tot 6b’; ‘ tibi 1b 1c’, ‘ tibi 1c 2a’, … , ‘ tibi 5c 6a’; … , ‘ sidera 1a 1b 1c’, … , ‘ sidera 5a 5b 5c’; ‘ caelo 1a 1b 1c’, ‘ caelo 1b 1c 2a’, … ,‘ caelo 4b 4c 5a’, ‘ caelo 6a 6b’.
Section 7.2.2.2
1. (a) ∅ (no clauses). (b) { ∈ } (one clause, which is empty).
2. Letting 1 ↔ lazy, 2 ↔ happy, 3 ↔ unhealthy, 4 ↔ dancer, we’re given the respective clauses { 314 , 1 ¯ 42 , 3 4 ¯ 2 , 2 ¯ 4 3 ¯ , 1 ¯ 3 2 ¯ , 2 3 ¯ 1 , 1 ¯ 4 3 ¯ } , , matching R ′ in (7). So all known Pincusians dance happily, and none are lazy. But we know nothing about their health. [And we might wonder why travelers have bothered to describe so many empty sets.]
3. f ( j − 1, n ) + f ( k − 1, n ), where f ( p , n ) \= Σ d \= 1 q ( n − p d ) \= p ( q 2 ) + q ( n mod p ) ≈ n 2 / ( 2 p ) , if we set q = ⌊ n/p ⌋.
4. Those constraints are unsatisfiable if and only if we remove a subset of either { 357 , 456 , 3 ¯ 5 ¯ 7 ¯ , 4 ¯ 5 ¯ 6 ¯ } , { 246 , 468 , 2 ¯ 4 ¯ 6 ¯ , 4 ¯ 6 ¯ 8 ¯ } , { 246 , 357 , 468 , 4 ¯ 5 ¯ 6 ¯ } or { 456 , 2 ¯ 4 ¯ 6 ¯ , 3 ¯ 5 ¯ 7 ¯ , 4 ¯ 6 ¯ 8 ¯ } .
5. The upper bound W (3, k ) = e O (log k ) 11 follows from (surprising) results of Z. Kelley and R. Meka, arXiv:2302.05537 [math.NT], 79 pages. The (surprising) superpolynomial lower bound W (3, k ) = k Ω(log k / log log k ) was proved by B. Green and Z. Hunter in Forum of Mathematics , Pi 10 (2022), e18:1–51; Combinatorica 42 (2022), 1231–1252.
6. Let each x i be 0 with probability p = (2ln k ) /k , and let n be at most k 2 /(ln k ) 3 . There are two kinds of “bad events”: A i , a set of three equally spaced 0s, occurs with probability P = p 3 ; and A ′ j , a set of k equally spaced 1s, occurs with probability P ′ = (1 − p ) k ≤ exp(− kp ) = 1 /k 2 . In the lopsidependency graph, which is bipartite, each A i is adjacent to at most D = 3 k 3 /(( k − 1)(ln k ) 3 ) nodes A ′ j ; each A ′ j is adjacent to at most d \= 3 2 k 3 / ( ln k ) 3 nodes A i . By Theorem L, we want to show that, for all sufficiently large values of k , P ≤ y (1 − x ) D and P ′ ≤ x (1 − y ) d , for some x and y .
Choose x and y so that (1 − x ) D = 1/2 and y = 2 P . Then x = Θ((log k ) 3 /k 2 ) and y = Θ((log k ) 3 /k 3 ) ; hence (1 − y ) d = exp(− yd + O ( y 2 d ) ) = O (1). [See T. Brown, B. M. Landman, and A. Robertson, J. Combinatorial Theory A115 (2008), 1304–1309.]
7. Yes, for all n , when x 1 x 2 x 3 … = 001001001 … .
8. For example, let x i,a signify that x i \= a , for 1 ≤ i ≤ n and 0 ≤ a < b . The relevant clauses are then x i, 0 ∨ … ∨ x i,b −1 for 1 ≤ i ≤ n ; and x ¯ i , a ∨ x ¯ i + d , a ∨ … ∨ x ¯ i + ( k a − 1 ) d , a for 1 ≤ i ≤ n − ( k a − 1) d and d ≥ 1. Optionally include the clauses x ¯ i , a ∨ x ¯ i , a ′ for 0 ≤ a < a ′ < b . (Whenever the relevant clauses are satisfiable, we can also satisfy the optional ones by falsifying some variables if necessary.)
[V. Chvátal found W (3, 3, 3) = 27. Kouril’s paper shows that W (2, 4, 8) = 157, W (2, 3, 14) = 202, W (2, 5, 6) = 246, W (4, 4, 4) = 293, and lists many smaller values.]
9. W (2, 2 ,k ) = 3 k − (2, 0, 2, 2, 1, 0) when k mod 6 = (0, 1, 2, 3, 4, 5). The sequence 2 k −1 02 k −1 12 k −1 is maximal when k ┴ 6; also 2 k −1 02 k −1 12 k −3 when k mod6 = 3; also 2 k −1 02 k −2 12 k −1 when k mod 6 = 4; otherwise 2 k −1 02 k −2 12 k −2 . [See B. Landman, A. Robertson, and C. Culver, Integers 5 (2005), A10:1–A10:11, where many other values of W (2 ,..., 2 ,k ) are also established.]
10. If the original variables are {1 ,...,n }, let the new ones be {1 ,...,n }∪{1′ ,...,n ′}. The new problem has positive clauses {11′ ,...,nn ′}. Its negative clauses are, for example, 2 ¯ ′ 6 ¯ 7 ¯ 9 ¯ ′ if 2 6 ¯ 7 ¯ 9 was an original clause. The original problem is equivalent because it can be obtained from the new one by resolving away the primed variables.
[One can in fact construct an equivalent monotonic problem of size O ( m + n ) in which ( x 1 ∨ … ∨ x k ) is a positive clause if and only if ( x ¯ 1 ∨ … ∨ x ¯ k ) is a negative clause. Such a problem, is equivalent to 2-colorability of hypergraphs. See L. Lovász, Congressus Numerantium 8 (1973), 3–12; H. Kleine Büning and T. Lettmann, Propositional Logic (Cambridge Univ. Press, 1999), §3.2, Problems 4–8.]
11. For each variable i , the only way to match vertices of the forms ij ′ and ij ″ is to choose all of its true triples or all of its false triples.
Furthermore, the only way to match j ′1 is to choose one of the satisfiability triples for clause j . Suppose l ¯ k j belongs to the chosen triple; then we must also have chosen the true triples for literal l k . Thus a perfect matching implies satisfiable clauses.
Conversely, if all clauses are satisfied, with l k true in clause j , there always are exactly two ways to match l ¯ k j with j ′1 while matching ωj , xj , yj , zj , and the other two l ¯ j vertices with j ′2, … , j ′7. (It’s a beautiful construction! Notice that no vertex appears in more than three triples.)
12. Equation (13) says S 1 ( y 1 ,...,y p ) = S ≥1 ( y 1 ,...,y p ) ∧ S ≤1 ( y 1 ,...,y p ). If p ≤ 4, use ∧ 1 ≤ j < k ≤ p ( y ¯ j ∨ y ¯ k ) for S ≤1 ( y 1 ,...,y p ); otherwise S ≤1 ( y 1 ,...,y p ) can be encoded recursively via the clauses S ≤ 1 ( y 1 , y 2 , y 3 , t ) ∧ S ≤ 1 ( t ¯ , y 4 , … , y p ) , where t is a new variable. [This method saves half of the auxiliary variables in the answer to exercise 7.1.1–55(b).]
Note: Langford’s problem involves primary items only; in an exact cover problem with non primary items, such items only need the constraint S ≤1 ( y 1 ,...,y p ).
13. (a) S 1 ( x 1 , x 2 , x 3 , x 4 , x 5 , x 6 ) ∧ S 1 ( x 7 , x 8 , x 9 , x 10 , x 11 ) ∧ S 1 ( x 12 , x 13 ) ∧ S 1 ( x 14 , x 15 , x 16 ) ∧ S 1 ( x 1 , x 7 , x 12 , x 14 ) ∧ S 1 ( x 2 , x 8 , x 13 , x 15 ) ∧ S 1 ( x 1 , x 3 , x 9 , x 16 ) ∧ S 1 ( x 2 , x 4 , x 7 , x 10 ) ∧ S 1 ( x 3 , x 5 , x 8 , x 11 , x 12 ) ∧ S 1 ( x 4 , x 6 , x 9 , x 13 , x 14 ) ∧ S 1 ( x 5 , x 10 , x 15 ) ∧ S 1 ( x 6 , x 11 , x 16 ).
(b) Duplicate clauses occur when options intersect more than once. We avoid them if we simply generate clauses x ¯ i ∨ x ¯ j for every pair ( i, j ) of intersecting options.
(c) When langford (4) is generated in this way, it has 85 distinct clauses in 16 variables, namely ( x 1 ∨ x 2 ∨ x 3 ∨ x 4 ∨ x 5 ∨ x 6 ) ∧ ( x 7 ∨ x 8 ∨ x 9 ∨ x 10 ∨ x 11 ) ∧ … ∧ ( x 6 ∨ x 11 ∨ x 16 ) ∧ ( x ¯ 1 ∨ x ¯ 2 ) ∧ ( x ¯ 1 ∨ x ¯ 3 ) ∧ … ∧ ( x ¯ 15 ∨ x ¯ 16 ) .
But langford ′ (4) cannot use the trick of (b). It has 85 (nondistinct) clauses in 20 variables, beginning with 123456 , 1 ¯ 2 ¯ , 1 ¯ 3 ¯ , 1 ¯ 1 ¯ ′ , 2 ¯ 3 ¯ , 2 ¯ 1 ¯ ′ , 3 ¯ 1 ¯ ′ , 1 ′ 4 ¯ , 1 ′ 5 ¯ , 1 ′ 6 ¯ , 4 ¯ 5 ¯ , 4 ¯ 6 ¯ , 5 ¯ 6 ¯ , … , if we denote the auxiliary variables by 1′, 2′, …. Two of those clauses ( 1 ¯ 3 ¯ and 4 ¯ 6 ¯ ) are repeated. (Incidentally, langford ′ (12) has 1548 clauses, 417 variables, 3600 literals.)
14. (Answer by M. Heule.) Those clauses sometimes help to focus the search. For example, if we’re trying to color the complete graph K n with n colors (or pigeons), we don’t want to waste time trying v 2 = 1 when v 1 is already 1.
On the other hand, other instances of SAT often run slower when redundant clauses are present, because more updates to the data structures are needed.
We might also take an opposite approach, and replace (17) by nd clauses that force every color class to be a kernel . (See exercise 21 .) Such clauses sometimes speed up a proof of uncolorability.
15. There are N = n ( n +1) vertices ( j, k ) for 0 ≤ j ≤ n and 0 ≤ k < n . If ( j, k ) = (1, 0) we define ( j, k ) −−− ( n, i ) for x ≤ i < n , where x = ⌊ n/ 2⌋. Otherwise we define the following edges: ( j, k ) −−− ( j + 1, k + 1) if j < n and k < n − 1; ( j, k ) −−− ( j + 1, k ) if j < n and j ≠ k ; ( j, k ) −−− ( j, k + 1) if k < n − 1 and j ≠ k + 1; ( j, k ) −−− ( n, n − 1) if j = 0; ( j, k ) −−− ( n − j, 0) if k < n − 1 and j = k ; ( j, k ) −−− ( n + 1 − j , 0) if j > 0 and j = k ; ( j, k ) −−− ( n − j, n − j −1) if k = n −1 and 0 < j < k ; ( j, k ) −−− ( n + 1− j, n − j )if k = n −1 and 0 < j < n . Finally, (0, 0) −−− (1, 0), and (0, 0) −−− ( n, i ) for 1 ≤ i ≤ x . That makes a grand total of 3 N − 6 edges. (It’s a maximal planar graph; see exercise 7 – 46 .)
16. There’s a unique 4-clique for all n ≥ 3, namely {(0 ,n − 2), (0 ,n − 1), (1 ,n − 1), ( n, n −1)}. All other vertices, except (0, 0) and (1, 0), are surrounded by neighbors that form an induced cycle of length 4 or more (usually 6). [See J.-L. Lauriere, Artificial Intelligence 10 (1978), 117.]
17. Let mcgregor ( n ) be the clauses (15) and (16) for the graph. For example, let the Boolean variable V jkc mean that vertex (j, k) has color c ; then (15) is the set of clauses ( υ jk 1 ∨ υ jk 2 ∨ υ jk 3 ∨ υ jk 4 ), for 0 ≤ j ≤ n and 0 ≤ k < n. Add clauses to enforce the symmetric threshold function S ≤ r (υ 001 , . . . , υ n ( n – 1)1), using either (18) and (19) or (20) and (21). The resulting clauses are satisfiable if and only if f(n) ≤ r. Similarly, if S ≥ r is substituted for S ≤ r , the clauses are satisfiable if and only if g(n) ≥ r .
Additional unit clauses that specify the colors of the four clique vertices will speed up the computation: Four cases should be run, one with each clique vertex receiving color 1. If all four cases are unsatisfiable, we’ve proved that f ( n ) > r or g ( n ) < r , respectively. Binary search with different values of r will identify the optimum.
For speedier g ( n ), first find a maximum independent set instead of a complete 4-coloring; then notice that the colorings for f ( n ) already achieve this maximum.
The results turn out to be f ( n ) = (2, 2, 3, 4, 5, 7, 7, 7, 8, 9, 10, 12, 12, 12) for n = (3, 4 ,..., 16), and g ( n ) = (4, 6, 10, 13, 17, 23, 28, 35, 42, 50, 58, 68, 77, 88).
18. Assuming that n ≥ 4, first assign to vertex ( j, k ) the following “default color”: 1+ ( j + k )mod 3 if j ≤ k ; 1 + ( j + k +1 − n )mod 3 if k < j/ 2; otherwise 1 + ( j + k + 2 − n ) mod 3. Then make the following changes to exceptional vertices: Vertex (1, 0) is colored 2 if n mod 6 = 0 or 5, otherwise 3. Vertex ( n, n − 1) is colored 4. For k ← 0 up to n − 2, change the color of vertex ( n, k ) to 4, if its default color matches vertex (0, 0) when k ≤ n/ 2 or vertex (1, 0) when k > n/ 2. And make final touchups for 1 ≤ j < n/ 2, depending again on n mod 6:
Case 0: Give color 4 to vertex (2 j, j − 1) and color 1 to vertex (2 j + 1 ,j ).
Case 1: Give color 4 to vertex (2 j, j ) and color 2 to vertex (2 j + 1 ,j ).
Case 2: Give color 4 to vertex (2 j, j ) and color 1 to vertex (2 j + 1 ,j ). Also give ( n, n − 2) the color 1 and ( n − 1 ,n − 3) the color 4.
Cases 3, 4, 5: Give color 4 to vertex (2 j + 1 ,j ).
For example, the coloring for the case n = 10 (found by Bryant) is shown in Fig. A–7(a) .
Fig. A–7. Colorings and kernels of McGregor’s graph.
The color distribution is (⌊ n 2 /3⌋, ⌊ n 2 /3⌋, ⌊ n 2 /3⌋, 5 k ) + ((0, 1, k, −1), (1, k, 1, 0), (−1, k + 1, 1, 2), (0, k , 1, 2), (1, k + 1, 1, 2), (0, 2, k + 1, 3)), for n mod 6 = (0, 1, 2, 3, 4, 5), k = ⌊ n /6⌋. Since this construction achieves all of the optimum values for f ( n ) and g ( n ), when n ≤ 16, it probably is optimum for all n . Moreover, the value of g ( n ) agrees with the size of the maximum independent set in all known cases. A further conjecture is that the maximum independent set is unique , whenever n mod 6 = 0 and n > 6.
19. Use the clauses of mcgregor ( n ), together with ( υ 1 ∨ υ 2 ∨ υ 3 ∨ υ ¯ x ) ∧ ( υ 1 ∨ υ 2 ∨ υ 4 ∨ υ ¯ x ) ∧ ( υ 1 ∨ υ 3 ∨ υ 4 ∨ υ ¯ x ) ∧ ( υ 2 ∨ υ 3 ∨ υ 4 ∨ υ ¯ x ) for each vertex v , together with clauses from (20) and (21) that require at least r of the variables v x to be true. Also assign unique colors to the four clique vertices. (One assignment, not four, is sufficient to break symmetry here, because h ( n ) is a more symmetrical property than f ( n ) or g ( n ).) These clauses are satisfiable if and only if h ( n ) ≥ r . The SAT computation goes faster if we also provide clauses that require each color class to be a kernel (see exercise 21 ).
The values h ( n ) = (1, 3, 4, 7, 9, 13) for n = (3, 4 ,..., 8) are readily obtained in this way. Furthermore, if we extend color class 4 in the construction of answer 18 to a suitable kernel, we find h (9) ≥ 17 and h (10) ≥ 23. The resulting diagram for n = 10, illustrated in Fig. A–7(b) , nicely exhibits 2 23 solutions to McGregor’s original coloring problem, all at once.
A good SAT solver also shows that h (9) ≤ 18 and h (10) ≤ 23, thus proving that h (10) = 23. And Armin Biere’s solver proved in 2013 that h (9) = 18, by discovering the surprising solution shown here. (This exercise was inspired by Frank Bernhart, who sent a diagram like Fig. A–7(b) to Martin Gardner in 1975; his diagram achieved 2 21 solutions.)
20. Arrange the vertices ( j, k ) of answer 15 in the following order v 0 , v 1 , … : ( n, n −1); (0, n − 1), (0, n − 2), … , (0, 0); (1, n − 1), (1, n − 2), … , (1, 1); … ; ( n − 2, n − 1), ( n − 2, n − 2); ( n − 1, n − 2), ( n − 2, n − 3), … , (2, 1); ( n − 1, n − 1); (2, 0), (3, 1), … , ( n, n − 2); (3, 0), (4, 1), … , ( n, n − 3); (1, 0); (4, 0), … , ( n, n − 4); … ; ( n − 1, 0), ( n, 1); ( n, 0). Then if V t \= { v 0 ,..., v t − 1 }, let the “ frontier” F t consist of all vertices ∈ V t that have at least one neighbor ∉ V t . We can assume that ( v 0 ,v 1 ,v 2 ) are colored (0, 1, 2), because they are part of the 4-clique.
All 4-colorings of V t that have a given sequence of colors on F t can be enumerated if we know the corresponding counts for F t − 1 . The stated ordering ensures that F t never will contain more than 2 n − 1 elements; in fact, at most 3 2 n −2 sequences of colors are feasible, for any given t . Since 3 18 is less than 400 million, it’s quite feasible to do these incremental calculations. The total (obtained with about 6 gigabytes of memory and after about 500 gigamems of computation) turns out to be 898,431,907,970,211.
This problem is too large to be handled efficiently by BDD methods when n = 10, but BDD calculations for n ≤ 8 can be used to check the algorithm. The frontiers essentially represent level-by-level slices of a QDD for this problem. The 4-coloring counts for 3 ≤ n ≤ 9 are respectively 6, 99, 1814, 107907, 9351764, 2035931737, 847019915170.
21. With one Boolean variable v for every vertex of a graph G , the kernels are characterized by the clauses (i) u ¯ ∨ υ ¯ whenever u −−− υ ; (ii) υ ∨ ∨ u −− υ u for all v . Adding to these the clauses for the symmetric threshold function S ≤ r ( x 1 ,...,x N ), we can find the least r for which all clauses are satisfiable. The graph of Fig. 76 yields satisfiability for r = 17; and one of its 46 kernels of size 17 is shown in Fig. A–7(c) .
[BDD methods are slower for this problem; but they enumerate all 520,428,275,749 of the kernels, as well as the generating function 46 z 17 + 47180 z 18 + … + 317 z 34 + 2 z 35 .]
22. Eight colors are needed. The coloring
is “balanced,” with each color used at least thrice.
23. Writing k for x k and k j for s j k , the clauses from (18)–(19) are 1 ¯ 1 1 2 , 1 ¯ 1 2 3 , 2 ¯ 2 1 2 , 2 ¯ 2 2 3 , 3 ¯ 3 1 2 , 3 ¯ 3 2 3 , 4 ¯ 4 1 2 , 4 ¯ 4 2 3 , 1 ¯ 1 1 , 2 ¯ 2 1 , 3 ¯ 3 1 , 2 ¯ 1 ¯ 2 1 1 , 3 ¯ 1 ¯ 2 2 2 , 4 ¯ 1 ¯ 2 3 3 , 3 ¯ 2 ¯ 3 1 1 , 4 ¯ 2 ¯ 3 2 2 , 5 ¯ 2 ¯ 3 3 3 , 4 ¯ 3 ¯ 4 1 1 , 5 ¯ 3 ¯ 4 2 2 , 6 ¯ 3 ¯ 4 3 3 , 5 ¯ 4 1 , 6 ¯ 4 ¯ 2 , 7 ¯ 4 ¯ 3 .
Similarly, (20) and (21) define the clauses 7 ¯ 1 6 , 6 ¯ 1 6 , 6 ¯ 7 ¯ 2 6 ; 5 ¯ 1 5 , 4 ¯ 1 5 , 4 ¯ 5 ¯ 2 5 ; 3 ¯ 1 4 , 2 ¯ 1 4 , 2 ¯ 3 ¯ 2 4 ; 1 ¯ 1 3 , 6 ¯ 3 1 1 , 1 ¯ 1 6 ¯ 3 2 , 6 ¯ 3 2 2 , 1 ¯ 2 6 ¯ 3 3 ; 5 ¯ 2 1 1 , 4 ¯ 2 1 1 , 5 ¯ 2 2 2 , 4 ¯ 2 2 2 , 4 ¯ 5 ¯ 2 1 2 3 , 4 ¯ 5 ¯ 2 1 2 3 , 4 ¯ 5 ¯ 2 2 1 3 , 4 ¯ 5 ¯ 2 2 2 4 ; 2 ¯ 3 ¯ 4 1 , 2 ¯ 3 ¯ 3 2 , 2 ¯ 3 ¯ 2 3 . So this tree-based method apparently needs one more variable and two more clauses when ( n, r ) = (7, 4). But the next exercise shows that (18) and (19) don’t really win!
24. (a) The clause ( b ¯ 1 2 ∨ b ¯ r 3 ) appears only if t 3 = r ; and t 3 ≤ n/ 2.
(b) For example, t 3 = min( r, 4) < r when n = 11 and r = 5.
(c) In this case t k is the number of leaves below node k , and the only auxiliary variables that survive pure literal elimination are b t k k . We’re left with just n −1 surviving clauses, namely ( b ¯ t 2 k 2 k ∨ b ¯ t 2 k + 1 2 k + 1 ∨ b t k k ) for 1 < k < n , plus ( b ¯ t 2 2 ∨ b ¯ t 3 3 ) .
(d) If 2 k ≤ n ≤ 2 k + 2 k −1 we have ( n ′ ,n ″ ) = ( n − 2 k −1 , 2 k −1 ); on the other hand if 2 k + 2 k −1 ≤ n ≤ 2 k +1 we have ( n ′ ,n ″ ) = (2 k ,n − 2 k ). (Notice that n ″ ≤ n ′ ≤ 2 n ″ .)
(e) No pure literals are removed in this completely balanced case (which is the easiest to analyze). We find a (2 k , 2 k −1 ) = ( k − 1)2 k and c (2 k , 2 k −1 ) = (2 k −2 + k − 1)2 k .
(f) One can show that a ( n, r ) = ( r ≤ n ″? b ( n ′, r ) + b ( n ″, r ): r ≤ n ′? b ( n ′, n ″)+ b ( n ″, n ″): b ( n ′, n − r ) + b ( n ″, n − r )), where b (1, 1) = 0 and b ( n, r ) = r + b ( n ′, min( r, n ′)) + b ( n ″, min( r, n ″)) for n ≥ 2. Similarly, c ( n, r ) = ( r ≤ n ″? r + f ( n ′, 0, r ) + f ( n ″, 0, r ): r ≤ n ′? n ″ + f ( n ′, r − n ″, r ) + f ( n ″, 0, n ″): n − r + f ( n ′, r − n ″, n ′) + f ( n ″, r − n ′, n ″)), where f ( n , l , r ) \= Σ k \= l + 1 r min( k + 1, n ″ + 1, n + 1− k )+( r ≤ n ″? r + f ( n ′, 0, r ) + f ( n ″, 0, r ): r ≤ n ′? n ″ + f ( n ′, 0, r ) + f ( n ″, 0, n ″): r < n ? n − r + f ( n ′, 0, n ′) + f ( n ″, 0, n ″): f n ′ , ( n ′ + l ) − ˙ r , n ′ ) + f ( n ″ , ( n ″ , + l ) − ˙ r , n ″ ) ) for n ≥ 2 and f (1, 0, 1) = 0. The desired results follow by induction from these recurrence relations.
Incidentally, ternary branching can give further savings. We can, for example, handle the case n = 6, r = 3 with 17 clauses in the 6 variables b 1 2 , b 2 2 , b 3 2 , b 1 3 , b 2 3 , b 3 3 .
25. From (18) and (19) we obtain 5 n − 12 clauses in 2 n − 4 variables, with a simple lattice-like structure. But (20) and (21) produce a more complex tree-like pattern, with 2 n − 4 variables and with ⌊ n/ 2⌋ nodes covering just two leaves. So we get ⌊ n/ 2⌋ nodes with 3 clauses, n mod 2 nodes with 5 clauses, ⌈ n/ 2⌉ nodes with 7 clauses, and 2 clauses from (21), totalling 5 n − 12 as before (assuming that n > 3). In fact, all but n − 2 of the clauses are binary in both cases.
26. Imagine the boundary conditions s j 0 \= 1 , s j r + 1 \= 0 , s 0 k \= 0 , for 1 ≤ j ≤ n − r and 1 ≤ k ≤ r . The clauses say that s 1 k ≤ … ≤ s n − r k and that x j + k s j k ≤ s j k + 1 ; so the hint follows by induction on j and k .
Setting j = n − r and k = r + 1 shows that we cannot satisfy the new clauses when x 1 + … + x n ≥ r + 1. Conversely, if we can satisfy F with x 1 + … + x n ≤ r then we can satisfy (18) and (19) by setting s j k ← [ x 1 + … + x j + k − 1 ≥ k ]
27. Argue as in the previous answer, but imagine that b 0 k \= 1 , b r + 1 1 \= 0 ; prove the hint by induction on j and n − k (beginning with k = n − 1, then k = n − 2, and so on).
28. For example, the clauses for x ¯ 1 + … + x ¯ n ≤ n − 1 when n = 5 are ( x 1 ∨ s 1 1 ) , ( x 2 ∨ s ¯ 1 1 ∨ s 1 2 ) , ( x 3 ∨ s ¯ 1 2 ∨ s 1 3 ) , ( x 4 ∨ s ¯ 1 3 ∨ s 1 4 ) , ( x 5 ∨ s ¯ 1 4 ) . We may assume that n ≥ 4; then the first two clauses can be replaced by ( x 1 ∨ x 2 ∨ s 1 2 ) , and the last two by ( x n − 1 ∨ x n ∨ s ¯ 1 n − 2 ) , yielding n − 2 clauses of length 3 in n − 3 auxiliary variables.
29. We can assume that 1 ≤ r 1 ≤ … ≤ r n \= r < n . Sinz’s clauses (18) and (19) actually do the job nicely if we also assert that s j k is false whenever k = r i + 1 and j = i − r i .
30. The clauses now are ( s ¯ j k ∨ s j + 1 k ) , ( x ¯ j + k ∨ s ¯ j k ∨ s j k + 1 ) , ( s j k ∨ s ¯ j k + 1 ) , ( x j + k ∨ s j k ∨ s ¯ j + 1 k ) , hence they define the quantities s j k \= [ x 1 + … + x j + k − 1 ≥ k ] ; implicitly s 0 k \= s j r + 1 \= 0 and s j 0 \= s n − r + 1 k \= 1 . The new clauses in answer 23 are 1 2 ¯ 1 1 , 2 3 ¯ 1 1 , 3 4 ¯ 1 1 , 1 2 ¯ 2 2 , 2 3 ¯ 2 2 , 3 4 ¯ 2 2 , 1 2 ¯ 3 3 , 2 3 ¯ 3 3 , 3 4 ¯ 3 3 ; 1 1 1 ¯ , 2 1 2 ¯ , 3 1 3 ¯ , 4 1 4 ¯ , 2 1 1 ¯ 1 2 , 3 2 2 ¯ 1 2 , 4 3 3 ¯ 1 2 , 5 4 4 ¯ 1 2 3 1 1 ¯ 2 3 , 4 2 2 ¯ 2 3 , 5 3 3 ¯ 2 3 , 6 4 4 ¯ 2 3 4 3 1 , 5 3 2 , 6 3 3 , 7 3 4 .
With (20) and (21) we can identify b ′ j k with b ¯ j k + 1 − j k , when l k > 1 leaves are below node k . Then b j k is true if and only if the leaves below k have j or more 1s. For example, answer 23 gets the new clauses 7 2 6 ¯ , 6 2 6 ¯ , 67 2 6 ¯ ; 5 2 5 ¯ , 4 2 5 ¯ , 45 1 5 ¯ ; 3 2 4 ¯ , 2 2 4 ¯ , 23 1 4 ¯ ; 1 3 3 ¯ , 6 3 ¯ 2 3 , 1 6 3 ¯ 2 2 , 6 3 ¯ 1 2 , 1 6 3 ¯ 1 2 , 1 6 3 ¯ 1 1 ; 4 2 ¯ 2 4 , 5 2 ¯ 2 4 , 4 2 ¯ 1 3 , 4 5 2 2 2 3 , 5 2 ¯ 1 3 , 4 5 2 ¯ 1 2 2 , 4 5 2 ¯ 1 2 2 , 4 5 2 2 1 2 , 4 5 1 1 ; 2 3 4 1 , 2 3 3 2 , 2 3 2 3 .
Furthermore, (20) and (21) can be unified in the same way with the weaker constraints r ′ ≤ x 1 + … + x n ≤ r . If we want, say, 2 ≤ x 1 + … + x 7 ≤ 4, we can simply replace the final four clauses of the previous paragraph by 4 5 2 ¯ 1 1 1 , 2 3 2 1 , 2 3 1 2 . Under the conventions of (18) and (19), by contrast, these weaker constraints would generate a comparable number of new clauses, namely 1 2 ¯ 1 1 , 1 2 ¯ 2 2 , 1 2 ¯ 3 3 , 1 2 ¯ 4 4 , 1 2 ¯ 5 5 and 1 1 1 ¯ , 2 1 2 ¯ , 3 2 2 ¯ 1 2 , 3 1 1 ¯ 2 3 , 4 2 2 ¯ 2 3 , 4 1 1 ¯ 3 4 , 5 2 2 ¯ 3 4 , 5 1 1 ¯ 4 5 , 6 2 2 ¯ 4 5 , 6 5 1 , 7 5 2 ; but those clauses involve the new variables 1 4 , 1 5 , 2 4 , 2 5 .
31. We can use the constraints on the second line of (10), together with the constraints of exercise 30 that force x 1 + … + x n \= r . Then we seek n for which this problem is satisfiable, while the same problem with x n \= 0 is not. The following small values can be used to check the calculations:
r \= 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 F 3 ( r ) \= 1 2 4 5 9 11 13 14 20 24 26 30 32 36 40 41 51 54 58 63 71 74 82 84 92 95 100 F 4 ( r ) \= 1 2 3 5 6 8 9 10 13 15 17 19 21 23 25 27 28 30 33 34 37 40 43 45 48 50 53 F 5 ( r ) \= 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 24 25 27 28 29 31 33 34 36 37 38 F 6 ( r ) \= 1 2 3 4 5 7 8 9 10 12 13 14 15 17 18 19 20 22 23 24 25 26 29 32 33 35 36
Furthermore, significant speedup is possible if we also make use of previously computed values F t (1), … , F t ( r −1). For example, when t = 3 and r ≥ 5wemust have x a +1 +…+ x a +8 ≤ 4 for 0 ≤ a ≤ n −8, because F 3 (5) = 9. These additional subinterval constraints blend beautifully with those of exercise 30 , because x a +1 + … + x a + p ≤ q for 0 ≤ a ≤ n − p implies s ¯ b + p − q k ∨ s b k − q for 0 ≤ b ≤ n +1 − p + q − r and q < k ≤ r .
We can also take advantage of left-right symmetry by appending the unit clause s ¯ ⌈ ( n − r ) / 2 ⌉ ⌈ r / 2 ⌉ when r is odd; s n / 2 − r / 2 + 1 r / 2 when n and r are both even.
Suitable benchmark examples arise when computing, say, F 3 (27) or F 4 (36). But for large cases, general SAT-based methods do not seem to compete with the best special-purpose backtrack routines. For example, Gavin Theobald and Rodolfo Niborski have obtained the value F 3 (41) = 194, which seems well beyond the reach of these ideas.
[See P. Erdös and P. Turán, J. London Math. Soc. 11 (1936), 261–264; errata, 34 (1959), 480; S. S. Wagstaff, Jr., Math. Comp. 26 (1972), 767–771.]
32. Use (15) and (16), and optionally (17), but omit variable v j unless j ∈ L ( υ ).
33. To double-color a graph with k colors, change (15) to the set of k clauses υ 1 ∨…∨ υ j −1 ∨ υ j +1 ∨…∨ υ k , for 1 ≤ j ≤ k ; similarly, ( 2 k ) clauses of length k − 2 will yield a triple coloring. Small examples reveal that C 2 l +1 for l ≥ 2 can be double-colored with five colors: {1, 2} ({3, 4}{5, 1}) l − {2,3}{4,5}; furthermore, seven colors suffice for triple coloring when l ≥ 3: {1,2,3} ({4,5,6} {7,1,2}) l −2 {3,4,5}{6,7,1}{2,34}{5,6,7}. The following exercise proves that those colorings are in fact optimum.
34. (a) We can obviously find a q -tuple coloring with qχ ( G ) colors. And McGregor’s graph has a four- clique, hence χ ∗ .( G ) ≥ 4.
(b) Any q -tuple coloring with p colors yields a solution to the fractional exact cover problem, if we let λ j \= Σ i \= 1 p [ S j is the set of vertices colored i ]/ q . Conversely, the theory of linear equalities tells us that there is always an optimum solution with rational { λ 1 , . . . , λ N }; such a solution yields a q -tuple coloring when each qλ j is an integer.
(c) χ ∗ ( C n ) = χ ( C n ) = 2 when n is even; and χ ∗ ( C 2 l +1 ) ≤ 2+1 /l = n/α ( C 2 l +1 ), because there’s an l -tuple coloring with n colors as in the previous exercise. Also χ ∗ ( G ) ≥ n/α ( G ) in general: n = Σ υ Σ j λ j [ υ ∈ S j ] = Σ j λ j | S j | ≤ α( G ) Σ j λ j .
(d) For the hint, let S = { υ 1 ,...,υ l } where vertices are sorted by their colors. Since vertex υ j belongs to C i with | C i | ≥ |{ υ j ,...,υ l }|, we have t υ j ≤ 1/( l + 1 − j ).
So χ ( G ) ≤ k = Σ υ t υ \= Σ υ t υ Σ j λ j [ υ ∈ S j ] = Σ j λ j Σ υ t | υ [ υ ∈ S j ] ≤ Σ j λ j H α ( G ) .
[See David S. Johnson, J. Computer and System Sci. 9 (1974), 264–269; L. Lovász, Discrete Math. 13 (1975), 383–390. The concept of fractional covering is due to A. J. W. Hilton, R. Rado, and S. H. Scott, Bull. London Math. Soc. 5 (1973), 302–306.]
35. (a) The double coloring below proves that χ ∗ ( G ) ≤ 7/2; and it is optimum because NV and its neighbors induce the wheel W 5 . (Notice that χ ∗ ( W n ) = 1 + χ ∗ ( C n ).)
(b) By part (c) of the previous exercise, χ ∗ ( G ) ≥ 25/4. Furthermore there is a quadruple coloring with 25 colors:
[Is C 5 ⊠ C 5 ¯ the smallest graph for which χ ∗ ( G ) < χ ( G ) − 1?]
36. A few more binary color constraints analogous to (16) yield the corresponding SAT problem. We can also assume that the upper right corner is colored 0, because that region touches n + 4 = 14 others; at least n + 6 colors are needed. The constraints elsewhere aren’t very tight (see exercise 38(b) ); thus we readily obtain an optimum radio coloring with n + 6 colors for the McGregor graphs of all orders n > 4, such as the one below. An ( n + 7)th color is necessary and sufficient when n = 3 or 4.
37. The 10-coloring shown here is optimum, because Missouri ( MO ) has degree 8.
38. By looking at solutions for n = 10, say, which can be obtained quickly via Algorithm W (Walk SAT ), it’s easy to discover patterns that work in general: (a) Let ( x, y ) have color (2 x + 4 y ) mod 7. (Seven colors are clearly necessary when n ≥ 3.) (b) Let ( x, y, z ) have color (2 x + 6 y ) mod 9. (Nine colors are clearly necessary when n ≥ 4.)
39. Let f ( n ) denote the fewest consecutive colors. SAT solvers readily verify that f ( n ) = (1, 3, 5, 7, 8, 9) for n = (0, 1, 2, 3, 4, 5). Furthermore we can exploit symmetry to show that f (6) > 10: One can assume that 000000 is colored 0, and that the colors of 000001, …, 100000 are increasing; that leaves only three possibilities for each of the latter. Finally, we can verify that f (6) = 11 by finding a solution that uses only the colors {0, 1, 3, 4, 6, 7, 9, 10}.
But f (7) is known only to be ≥ 11 and ≤ 15.
[ L (2, 1) labelings were named by J. R. Griggs and R. K. Yeh, who initiated the theory in SIAM J. Discrete Math. 5 (1992), 586–595. The best known upper bounds, including the fact that f (2 k − k − 1) ≤ 2 k , were obtained by M. A. Whittlesey, J. P. Georges, and D. W. Mauro, who also solved exercise 38(a) ; see SIAM J. Discrete Math . 8 (1995), 499–506.]
40. No; the satisfiable cases are z = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 21. [The statement would have been true if we’d also required ( x m ∨ … ∨ x 2 ) Λ ( y n ∨…∨ y 2 ).]
41. First there are mn AND s to form x i y j . A bin that contains t bits initially will generate ⌊ t/ 2⌋ carries for the next bin, using ( t − 1) / 2 adders. (For example, t = 6 will invoke 2 full adders and one half adder.) The respective values of t for bin [2], bin [3], … , bin [ m + n + 1] are (1, 2, 4, 6, … , 2 m − 2, 2 m − 1, … , 2 m − 1, 2 m − 2, 2 m − 3, … , 5, 3, 1), with n − m occurrences of 2 m − 1. That makes a total of mn − m − n full adders and m half adders; altogether we get mn + 2( mn − m − n ) + m instances of AND, mn − m − n instances of OR, and 2( mn − m − n ) + m instances of X OR .
42. Ternary XOR requires quaternary clauses, but ternary clauses suffice for median:
( t ∨ u ∨ v ∨ x ¯ ) ( t ∨ u ¯ ∨ v ¯ ∨ x ¯ ) ( t ¯ ∨ u ∨ v ¯ ∨ x ¯ ) ( t ¯ ∨ u ¯ ∨ v ¯ ∨ x ¯ ) ( t ∨ u ∨ v ¯ ∨ x ) ( t ∨ u ¯ ∨ v ∨ x ) ( t ¯ ∨ u ∨ v ∨ x ) ( t ¯ ∨ u ¯ ∨ v ¯ ∨ x ) ( t ∨ u ∨ y ¯ ) ( t ∨ v ∨ y ¯ ) ( u ∨ v ∨ y ¯ ) ( t ¯ ∨ u ¯ ∨ y ) ( t ¯ ∨ v ¯ ∨ y ) ( u ¯ ∨ v ¯ ∨ y )
These clauses specify respectively that x ≤ t ⊕ u ⊕ υ , x ≥ t ⊕ u ⊕ υ , y ≤ 〈 tuv 〉, y ≥ 〈 tuv 〉.
43. x = y = 3 works when n = 2, but the cases 3 ≤ n ≤ 7 are unsatisfiable. We can use x = 3(2 n −2 + 1), y = 7(2 n −3 + 1) for all n ≥ 8. (Such solutions aren’t at all rare. For example, ( x, y ) = ( # C4466223 , # E26E7647 ) is one of 293 instances when n = 32.)
44. First scout the territory quickly by looking at all ( N + 1 2 ) \= 660 billion cases with at most six zeros in x or y ; here N \= ( 32 27 ) + ( 27 32 ) + … + ( 32 32 ) . This uncovers the remarkable pair x = 2 32 − 2 26 − 2 22 − 2 11 − 2 8 − 2 4 − 1, y = 2 32 − 2 11 + 2 8 − 2 4 + 1, whose product is 2 64 − 2 58 − 2 54 − 2 44 − 2 33 − 2 8 − 1. Now a SAT solver finishes the job by showing that the clauses for 32 × 32 bit multiplication are unsatisfiable in the presence of the further constraint x ¯ 1 + ⋅ ⋅ ⋅ + x ¯ 32 + y ¯ 1 + ⋅ ⋅ ⋅ + y ¯ 32 + z ¯ 1 + ⋅ ⋅ ⋅ + z ¯ 64 ≤ 15 . (The LIFO version of the clauses worked much faster than FIFO in the author’s experiments with Algorithm L . Symmetry was broken by separate runs with x k …x 1 = 01 k −1 , y k …y 1 = 1 k .)
45. Use the clauses for xy = z in the factorization problem, with m = ⌊ t/ 2⌋, n = ⌊ t/ 2⌋, and x j \= y j for 1 ≤ j ≤ m ; append the unit clause ( y ¯ n ) if m < n .
46. The two largest, 285000288617375 2 and 301429589329949 2 , have 97 bits; the next square binary palindrome, 1178448744881657 2 , has 101. [This problem is not easy for SAT solvers; number theory does much better. Indeed, M. Coriand has discovered a nice way to find all n -bit examples by considering only O (2 n/ 4 ) cases, because the left and right halves of a binary number are nearly forced by the left and right quarters of its square. The first eight square binary palindromes were found by G. J. Simmons, JRM 5 (1972), 11–19; see OEIS sequence A003166 for many further results.]
47. Each wire has a “top” and a “bottom.” There are n + g + 2 h tops of wires, and m + 2 g + h bottoms of wires. Hence the total number of wires is n + g + 2 h = m + 2 g + h , and we must have n + h = m + g .
48. The wires compute q 1 ← q , q 2 ← q , x ← p ⊕ q 1 , y ← q 2 ⊕ r , z ← x ⊕ y . Let p denote “ p stuck at 1” while p ¯ denotes “ p stuck at 0.” The pattern pqr = 000 detects p , q 1 , q 2 , r , x , y , z ; 001 detects p , q 1 , q 2 , r ¯ , x , y ¯ , z ¯ ; 010 detects p , q ¯ 1 , q ¯ 2 , r , x ¯ , y ¯ , z ; 011 detects p , q ¯ 1 , q ¯ 2 , r ¯ , x ¯ , y , z ¯ ; 100 detects p ¯ , q 1 , q 2 , r , x ¯ , y , z ¯ ; 101 detects p ¯ , q 1 , q 2 , r ¯ , x ¯ , y ¯ , z ; 110 detects p ¯ , q ¯ 1 , q ¯ 2 , r , x , y ¯ , z ; 111 detects p ¯ , q ¯ 1 , q ¯ 2 , r ¯ , x , y , z . Notice that the stuck-at faults for q aren’t detectable (because z = ( p ⊕ q ) ⊕ ( q ⊕ r ) = p ⊕ r ); but we can detect faults on its clones q 1 , q 2 . (In Fig. 77 the opposite happens.)
Three patterns such as {100, 010, 001} suffice for all of the detectable faults.
49. One finds, for example, that the faults b 3 2 , c ¯ 1 2 , s ¯ 2 , and q ¯ are detected only by the pattern y 3 y 2 y 1 x 2 x 1 = 01111; a ¯ 3 2 , b ¯ 3 2 , p ¯ , c ¯ 2 2 , z ¯ 5 are detected only by 11011 or 11111.
All covering sets can be found by setting up a CNF with 99 positive clauses, one for each detectable fault; for example, the clause for z ¯ 5 is x 27 ∨ x 31 , while the clause for x 2 2 is x 4 ∨ x 5 ∨ x 12 ∨ x 13 ∨ x 20 ∨ x 21 ∨ x 28 ∨ x 29 . We can find minimum covers from a BDD for these clauses, or by using a SAT solver with additional clauses such as (20) and (21) to limit the number of positive literals. Exactly fourteen sets of five patterns suffice, the most memorable being {01111, 10111, 11011, 11101, 11110}. (Indeed, every minimum set includes at least two of those five patterns.)
50. Primed variables for tarnished wires are x 2 ′ , b 2 ′ , b 3 ′ , s ′ , z 3 ′ , c 2 ′ , z 4 ′ , z 5 ′ . Those wires also have sharped variables x 2 # , b 2 # , … , z 5 # ; and we need sharped variables x 2 1 # , x 2 3 # , x 2 4 # , b 2 1 # , b 2 2 # , b 3 1 # , b 3 2 # , s 1 # , s 2 # c 2 1 # , c 2 2 # for fanout wires. The primed variables are defined by clauses such as ( p ¯ ′ ∨ a 3 ) ∧ ( p ¯ ′ ∨ b ′ 2 ) ∧ ( p ′ ∨ a ¯ 3 ∨ b 2 ′ ¯ ) , which corresponds to p ′ ← a 3 Λ b ′ 2 . Those clauses are appended to the 49 clauses listed after (23) in the text. Then there are two clauses (25) for nine of the ten primed-and-sharped variables; however, in the case of x 2 we use the unit clauses ( x ′ 2 ) ∧ ( x ¯ 2 ) instead, because the variable x 2 # doesn’t exist. There are five fanout clauses (26), namely ( x ¯ 2 1 # ∨ x 2 3 # ∨ x 2 4 # ) ∧ ( b ¯ 2 # ∨ b 2 1 # ∨ b 2 2 # ) ∧ … ∧ ( c ¯ 2 # ∨ c 2 1 # ∨ c 2 2 # ) . There are eleven clauses ( x ¯ 2 3 # ∨ b 2 # ) ∧ ( x ¯ 2 4 # ∨ b 3 # ) ∧ ( b ¯ 2 1 # ∨ s # ) ∧ … ∧ ( b ¯ 3 2 # ∨ z 5 # ) ∧ ( c ¯ 2 2 # ∨ z 5 # ) for tarnished inputs to gates. And finally there’s ( x 2 1 # ) ∧ ( z 3 # ∨ z 4 # ∨ z 5 ) .
51. (The complete set of 196 patterns found by the author in 2013 included the inputs ( x, y ) = (2 32 − 1, 2 31 + 1) and (⌈2 63/2 ⌉, ⌈2 63/2 ⌉) as well as the two number-theoretic patterns mentioned in the text. Long runs of carries are needed in the products.)
52. ( z 1 , 2 ∨ z 2 , 2 ∨ … ∨ z M , 2 ) ∧ ( z ¯ i , 2 ∨ q ¯ i , 1 ) ∧ ( z ¯ i , 2 ∨ p ¯ i , 2 ) ∧ ( z ¯ i , 2 ∨ q ¯ i , 3 ) ∧ ( z ¯ i , 2 ∨ p ¯ i , 4 ) ∧ … ∧ ( z ¯ i , 2 ∨ q ¯ i , 20 ) . The second subscript of z is k in the k th case, 1 ≤ k ≤ P .
53. On the left is the binary expansion of π , and on the right is the binary expansion of e , 20 bits at a time (see Appendix A ).
One way to define f ( x ) for all 20-bit x is to write π / 4 \= Σ k \= 1 ∞ u k / 2 20 k and e / 4 \= Σ l \= 1 ∞ υ l / 2 20 l , where each u k and υ l is a 20-bit number. Let k and l be smallest such that x = u k and x = υ l . Then f ( x ) = [ k ≤ l ].
Equation (27) has actually been contrived to sustain an illusion of magic: Many simple Boolean functions are consistent with the data in Table 2 , even if we require four-term DNF s of three literals each. But only two of them, like (27), have the additional property that they actually agree with the definition of f ( x ) in the previous paragraph for ten more cases, using u k up to k = 22 and υ l up to l = 20! One might almost begin to suspect that a SAT solver has discovered a deep new connection between π and e .
54. (a) The function x ¯ 1 x 9 x 11 x ¯ 18 ∨ x ¯ 6 x ¯ 10 x ¯ 12 ∨ x ¯ 4 x 10 x ¯ 12 matches all 16 rows of Table 2 ; but adding the 17th row makes a 3-term DNF impossible.
(b) 21 rows are impossible, but (27) satisfies 20 rows.
(c) x ¯ 1 x ¯ 5 x ¯ 12 x 17 ∨ x ¯ 4 x 8 x ¯ 13 x ¯ 15 ∨ x ¯ 6 x ¯ 9 x ¯ 12 x 16 ∨ x ¯ 6 x ¯ 13 x ¯ 16 x 20 ∨ x 13 x 14 x ¯ 16 does 28, which is max. (Incidentally, this problem makes no sense for sufficiently large M , because the equation f ( x ) = 1 probably does not have exactly 2 19 solutions.)
55. Using (28)–(31) with p i,j \= 0 for all i and j , and also introducing clauses like (20) and (21) to ensure that q i ,1 + … + q i ,20 ≤ 3, leads to solutions such as
f ( x 1 , … , x 20 ) \= x ¯ 1 x ¯ 7 x ¯ 8 ∨ x ¯ 2 x ¯ 3 x ¯ 4 ∨ x ¯ 4 x ¯ 13 x ¯ 14 ∨ x ¯ 6 x ¯ 10 x ¯ 12 .
(There are no monotone increasing solutions with ≤ 4 terms of any length.)
56. We can define f consistently from only a subset of the variables if and only if no entry on the left agrees with any entry on the right, when restricted to those coordinate positions. For example, the first 10 coordinates do not suffice, because the top entry on the left begins with the same 10 bits as the 14th entry on the right. The first 11 coordinates do suffice (although two entries on the right actually agree in their first 12 bits).
Let the vectors on the left be u k and those on the right be v l , as in answer 53 , and form the 256 × 20 matrix whose rows are u k ⊕ υ l for 1 ≤ k, l ≤ 16. We can solve the stated problem if and only if we can find five columns for which that matrix isn’t 00000 in any row. This is the classical covering problem (but with rows and columns interchanged): We want to find five columns that cover every row.
In general, such an m × n covering problem corresponds to an instance of SAT with m clauses and n variables x j , where x j means “select column j .” The clause for a particular row is the OR of the x j for each column j in which that row contains 1. For example, in Table 2 we have u 1 ⊕ υ 1 = 01100100111101111000, so the first clause is x 2 ∨ x 3 ∨ x 6 ∨ …∨ x 17 . To cover with at most five columns, we add suitable clauses according to (20) and (21); this gives 396 clauses of total length 2894, in 75 variables.
(Of course ( 20 5 ) is only 15504; we don’t need a SAT solver for this simple task! Yet Algorithm D needs only 578 kilomems, and Algorithm C finds an answer in 353 K μ .)
There are 12 solutions: We can restrict to coordinates x j for j in {1, 4, 15, 17, 20}, {1, 10, 15, 17, 20}, {1, 15, 17, 18, 20}, {4, 6, 7, 10, 12}, {4, 6, 9, 10, 12}, {4, 6, 10, 12, 19}, {4, 10, 12, 15, 19}, {5, 7, 11, 12, 15}, {6, 7, 8, 10, 12}, {6, 8, 9, 10, 12}, {7, 10, 12, 15, 20}, or {8, 15, 17, 18, 20}. (Incidentally, BDD methods show that the number of solutions to the covering problem has the generating function 12 z 5 + 994 z 6 + 13503 z 7 + … + 20 z 19 + z 20 , counting by the size of the covering set.)
57. Table 2 specifies a partially defined function of 20 Boolean variables, having 2 20 −32 “ don’t-cares.” Exercise 56 shows how to embed it in a partially defined function of only 5 Boolean variables, in twelve different ways. So we have twelve different truth tables:
And the tenth of these yields f ( x ) \= ( ( x 8 ⊕ ( x 9 ∨ x 10 ) ) ∨ ( ( x 6 ∨ x 12 ) ⊕ x ¯ 10 ) ) ⊕ x 12 .
58. These clauses are satisfiable whenever the other clauses are satisfiable (except in the trivial case when f ( x ) = 0 for all x ), because we don’t need to include both x j and x ¯ j in the same term. Furthermore they reduce the space of possibilities by a factor of (3 / 4) N . So they seem worthwhile. (On the other hand, their effect on the running time appears to be negligible, at least with respect to Algorithm C in small-scale trials.)
59. f ( x ) ⊕ f ^ ( x ) \= x 2 x ¯ 3 x ¯ 6 x ¯ 10 x ¯ 12 ( x ¯ 8 ∨ x 8 ( x 13 ∨ x 15 ) ) is a function of eight variables that has 7 solutions. Thus the probability is 7 / 256 = . 02734375.
60. A typical example with 32 given values of f ( x ), chosen randomly, yielded
f ^ ( x 1 , … , x 20 ) \= x 4 x ¯ 7 x ¯ 12 ∨ x ¯ 6 x 8 x ¯ 11 x 14 x 20 ∨ x ¯ 9 x ¯ 12 x 18 x ¯ 19 ∨ x ¯ 13 x ¯ 16 x ¯ 17 x 19 ,
which of course is way off; it differs from f ( x ) with probability 102752 / 2 18 ≈ . 39. With 64 training values, however,
f ^ ( x 1 , … , x 20 ) \= x 2 x ¯ 13 x ¯ 15 x 19 ∨ x ¯ 3 x ¯ 9 x ¯ 19 x ¯ 20 ∨ x ¯ 6 x ¯ 10 x ¯ 12 ∨ x ¯ 8 x 10 x ¯ 12
comes closer, disagreeing only with probability 404 / 2 11 ≈ . 197 .
61. We can add 24 clauses ( p a , 1 ∨ q a , 1 ∨ p a , 2 ∨ q ¯ a , 2 ∨ p a , 3 ∨ q ¯ a , 3 ∨ … ∨ p b , 1 ∨ q b , 1 ∨ … ∨ p c , 1 ∨ q c , 1 ∨ … ∨ p d , 1 ∨ q d , 1 ∨ … ∨ p ¯ d , 10 ∨ q d , 10 ∨ … ∨ p d , 20 ∨ q d , 20 ), one for each permutation abcd of {1, 2, 3, 4}; the resulting clauses are satisfiable only by other functions f ( x ).
But the situation is more complicated in larger examples, because a function can have many equivalent representations as a short DNF. A general scheme, to decide whether the function described by a particular setting p i , j ′ and q i , j ′ of the p s and q s is unique, would be to add more complicated clauses, which state that p i,j and q i,j give a different solution. Those clauses can be generated by the Tseytin encoding of
∨ i \= 1 M ∧ j \= 1 N ( ( p ¯ i , j ∧ x ¯ j ) ∨ ( q ¯ i , j ∧ x j ) ) ⊕ ∨ i \= 1 M ∧ j \= 1 N ( ( p ¯ ′ i , j ∧ x ¯ j ) ∨ ( q ¯ ′ i , j ∧ x j ) ) .
62. Preliminary experiments by the author, with N = 20 and p = 1 / 8, seem to indicate that more data points are needed to get convergence by this method, but the SAT solver tends to run about 10 times faster. Thus, locally biased data points appear to be preferable unless the cost of observing the hidden function is relatively large.
Incidentally, the chance that x ( k ) \= x ( k −1) was relatively high in these experiments ((7 / 8) 20 ≈ . 069); so cases with y ( k ) \= 0 were bypassed.
63. With Tseytin encoding (24), it’s easy to construct 6 r + 2 n −1 clauses in 2 r + 2 n −1 variables that are satisfiable if and only if α fails to sort the binary sequence x 1 … x n . For example, the clauses when α = [1 : 2][3 : 4][1 : 3][2 : 4][2 : 3] are ( x 1 ∨ l ¯ 1 ) ∧ ( x 2 ∨ l ¯ 1 ) ∧ ( x ¯ 1 ∨ x ¯ 2 ∨ l 1 ) ∧ ( x ¯ 1 ∨ h 1 ) ∧ ( x ¯ 2 ∨ h 1 ) ∧ ( x 1 ∨ x 2 ∨ h ¯ 1 ) ∧ … ∧ ( l 4 ∨ l ¯ 5 ) ∧ ( h 3 ∨ l ¯ 5 ) ∧ ( l ¯ 4 ∨ h ¯ 3 ∨ l 5 ) ∧ ( l ¯ 4 ∨ h 5 ) ∧ ( h ¯ 3 ∨ h 5 ) ∧ ( l 4 ∨ h 3 ∨ h ¯ 5 ) ∧ ( g 1 ∨ g 2 ∨ g 3 ) ∧ ( g ¯ 1 ∨ l 3 ) ∧ ( g ¯ 1 ∨ l ¯ 5 ) ∧ ( g ¯ 2 ∨ l 5 ) ∧ ( g ¯ 2 ∨ h ¯ 5 ) ∧ ( g ¯ 3 ∨ h 5 ) ∧ ( g ¯ 3 ∨ h ¯ 4 ) . They’re unsatisfiable, so α always sorts properly.
64. Here we reverse the policy of the previous answer, and construct clauses that are satisfiable when they describe a sorting network: Let the variable C i , j t stand for the existence of comparator [ i : j ] at time t , for 1 ≤ i < j ≤ n and 1 ≤ t ≤ T . Also, adapting (20) and (21), let variables B j , k t be defined for 1 ≤ j ≤ n −2 and 1 ≤ k ≤ n , with clauses
( B ¯ 2 j , k t ∨ B ¯ 2 j + 1 , k t ) ∧ ( B ¯ 2 j , k t ∨ B j , k t ) ∧ ( B ¯ 2 j + 1 , k t ∨ B j , k t ) ∧ ( B 2 j + 1 , k t ∨ B 2 j + 1 , k t ∨ B ¯ j , k t ) ; ( ∗ )
in this formula we substitute { C 1 , k t , … , C k − 1 , k , t C k , k + 1 t , … , C k , n t } for the n − 1 “leaf nodes” { B n − 1 , k t , … , B 2 n − 3 , k t } These clauses prohibit comparators from clashing at time t , and they make B 1 , k t false if and only if line k remains unused.
If x = x 1 …x n is any binary vector, let y 1 …y n be the result of sorting x (so that ( y 1 …y n ) 2 = 2 vx −1). The following clauses F ( x ) encode the fact that comparators C i , j t transform x ↦ y : ( C ¯ i , j t ∨ V ¯ x , j t ∨ V x , i t − 1 ) ∧ ( C ¯ i , j t ∨ V ¯ x , i t ∨ V x , j t − 1 ) ∧ ( C ¯ i , j t ∨ V x , i t ∨ V ¯ x , i t − 1 ∨ V ¯ x , j t − 1 ) ∧ ( C ¯ i , j t ∨ V ¯ x , j t ∨ V x , i t − 1 ∨ V x , j t − 1 ) ∧ ( C ¯ i , j t ∨ V x , j t ∨ V ¯ x , i t − 1 ) ∧ ( C ¯ i , j t ∨ V x , j t ∨ V ¯ x , j t − 1 ) ∧ ( B 1 , i t ∨ V ¯ x , i t ∨ V x , i t − 1 ) ∧ ( B 1 , i t ∨ V x , j t ∨ V ¯ x , i t − 1 ) , for 1 ≤ i < j ≤ n and 1 ≤ t ≤ T ; here we substitute x j for V x , j 0 and also substitute y j for V x , j T , thereby simplifying the boundary conditions.
Furthermore, we can remove all variables V x , i t when x has i leading 0s and V x , j t when x has j trailing 1s, replacing them by 0 and 1 respectively and simplifying further.
Finally, given any sequence α = [ i 1 : j 1 ] … [ i r : j r ] of initial comparators, T further parallel stages will yield a sorting network if and only if the clauses (∗), together with ∧ x F ( x ) over all x producible by α , are simultaneously satisfiable.
Setting n = 9, α = [1 : 6][2 : 7][3 : 8][4 : 9], and T = 5, we obtain 85768 clauses in 5175 variables, if we leave out the ten vectors x that are already sorted. Algorithm C finds them unsatisfiable after spending roughly 200 megamems; therefore T ^ ( 9 ) > 6 . ( Algorithm L fails spectacularly on these clauses, however.) Setting T ← 6 quickly yields T ^ ( 9 ) ≤ 7 D. Bundala and J. Závodný [ LNCS 8370 (2014), 236–247] used this approach to prove in fact that T ^ ( 11 ) \= 8 and T ^ ( 13 ) \= 8 . Then T. Ehlers and M. Müller extended it [ LNCS 9136 (2015), 167– 176], to prove that T ^ ( 17 ) \= 10 , with the surprising optimum network shown here.
65. (a) The goal is to express the transition equation in CNF. There are ( 8 4 ) clauses like ( x ¯ ′ ∨ x ¯ a ∨ x ¯ b ∨ x ¯ c ∨ x ¯ d ) , one for each choice of four neighbors { a, b, c, d } ⊆ { NW , N , ..., SE }. Also ( 8 7 ) clauses like ( x ¯ ′ ∨ x a ∨ … ∨ x g ) , one for each choice of seven. Also ( 8 6 ) like ( x ¯ ′ ∨ x ∨ x a ∨ … ∨ x f ) , for each choice of six. Also ( 8 3 ) like ( x ′ ∨ x ¯ a ∨ x ¯ b ∨ x ¯ c ∨ x d ∨ … ∨ x h ) , complementing just three. And finally ( 8 2 ) like ( x ′ ∨ x ¯ ∨ x ¯ a ∨ x ¯ b ∨ x c ∨ … ∨ x g ) complementing just two and omitting any one of the others. Altogether 70 + 8 + 28 + 56 + 28 = 190 clauses of average length (70 · 5 + 8 · 8 + 28 · 8 + 56 · 9 + 28 · 9)/190 ≈ 7.34.
(b) Here we let x = x ij , x NW = x ( i −1)( j −1 ), … , x SE = x ( i +1)( j +1) , x ′ \= x i j ′ . There are seven classes of auxiliary variables a k i j , … , g k i , j , each of which has two children; the meaning is that the sum of the descendants is ≥ k . We have k ∈ {2, 3, 4} for the a variables, k ∈ {1, 2, 3, 4} for the b and c variables, and k ∈ {1, 2} for d , e , f , g .
The children of a ij are b ( i |1) j and c ij . The children of b ij are d i ( j −( j &2)) and e i ( j +( j &2)) . The children of c ij are f i ′ j ′ and g ij , where i ′ = i +2 and j ′ = ( j −1) | 1 if i is odd, otherwise i ′ = i and j ′ = j −( j &1). The children of d ij are x ( i −1)( j +1) and x i ( j +1) . The children of e ij are x ( i −1)( j −1) and x i ( j −1) . The children of f ij are x ( i −1) j and x ( i −1)( j +1) . Finally, the children of g ij are x i ″ j ″ and x i ″ j ″, where i ′ = i + 1−(( i &1) ≪1); and ( i ″ , j ″ ) = ( i + 1 , j ⊕ 1) if i is odd, otherwise ( i ″ , j ″ ) = ( i − 1 ,j − 1 + (( j &1) ≪ 1)). (OK — this isn’t elegant. But hey, it works!)
If the children of p are q and r , the clauses that define p k are ( p k ∨ q ¯ k , ∨ r ¯ k ″ ) for k ′ + k ″ = k and ( p ¯ k ∨ q k ′ ∨ r k ″ ) for k ′ + k ″ = k + 1. In these clauses we omit q ¯ 0 or r ¯ 0 ; we also omit q m or r m when q or r has fewer than m descendants.
For example, these rules define d 1 35 and d 2 35 by the following six clauses:
( d 1 35 ∨ x ¯ 26 ) , ( d 1 35 ∨ x ¯ 36 ) , ( d 2 35 ∨ x ¯ 26 ∨ x ¯ 36 ) , ( d ¯ 1 35 ∨ x 26 ∨ x 36 ) , ( d ¯ 2 35 ∨ x 26 ) , ( d ¯ 2 35 ∨ x 36 ) .
The variables b k i j are defined only when i is odd; d k i j and e k i j only when i is odd and j mod 4 < 2 ; f k i , j only when i + j is even. Thus the total number of auxiliary variables per cell ( i, j ), ignoring small corrections at boundary points, is 3 + 4 / 2 + 4 + 2 / 4 + 2 / 4 + 2 / 2 + 2 = 13 of types a through g , not 19, because of the sharing; and the total number of clauses per cell to define them is 21 + 16 / 2 + 16 + 6 / 4 + 6 / 4 + 6 / 2 + 6 = 57, not 77.
Finally we define x ′ ij from a 2 i j , a 3 i j , a 4 i j , by means of six clauses
( x ¯ ′ i j ∨ a ¯ 4 i j ) , ( x ¯ ′ i j ∨ a 2 i j ) , ( x ¯ ′ i j ∨ x i j ∨ a 3 i j ) , ( x ′ i j ∨ a 4 i j ∨ a ¯ 3 i j ) , ( x ′ i j ∨ x ¯ i j ∨ y ¯ i j ) , ( y i j ∨ a 4 i j ∨ a ¯ 2 i j ) ,
where y ij is another auxiliary variable (introduced only to avoid clauses of size 4).
66. All solutions to (a) can be characterized by a BDD of 8852 nodes, from which we can obtain the generating function 38 z 28 + 550 z 29 + … + 150 z 41 that enumerates them (with a total computation time of only 150 megamems or so). Part (b), however, is best suited to SAT, and X 0 must have at least 38 live cells. Typical answers are
67. Either
or
at lower left will produce the X 0 of (37) at time 1. But length 22 is impossible: With r = 4 we can verify that all the live cells in X 4 lie in some 3 × 3 subarray. Then with r = 22 we need to rule out only ( ( 3 9 ) + ( 4 9 ) + ( 5 9 ) ) × 6 \= 2016 possibilities, one for each viable X 4 within each essentially different 3 × 3 subarray.
68. (Solution by Ben Chaffin.) Exhaustive enumeration is feasible with bitwise computations (and without SAT). The longest paths achievable with (6, 7, 8, 9, 10) live starting cells have (8, 9, 10, 11, 11) generations; starting patterns that achieve length 11 are shown. Roughly (69%, 8%, 10%, 4%, 13%) of all starts end up (too dead, too live, immobile, still, out-of-bounds), respectively.
69. Since only 8548 essentially different 4 × 4 bitmaps are possible (see Section 7.2.3), an exhaustive enumeration is no sweat. The small stable patterns arise frequently, so they’ve all been named:
(A glider is also considered to be stable, although it’s not an oscillator.)
70. (a) A cell with three live neighbors in the stator will stay alive.
(b) A 4 × n board doesn’t work; Fig. A–8 shows the 5 × 8 examples.
(c) Again, the smallest-weight solutions with smallest rectangles are shown in Fig. A–8 . Oscillators with these rotors are plentiful on larger boards; the first examples of each kind were found respectively by Richard Schroeppel (1970), David Buckingham (1972), Robert Wainwright (1985).
71. Let the variables X t \= x ijt characterize the configuration at time t , and suppose we require X r \= X 0 . There are q = 8 r automorphisms σ that take X t ↦ X ( t + p ) mod r τ , where 0 ≤ p < r and τ is one of the eight symmetries of a square grid.
Any global permutation of the N = n 2 r variables leads via Theorem E to a canonical form, where we require the solution to be lexicographically less than or equal to the q − 1 solutions that are equivalent to it under automorphisms.
Such lexicographic tests can be enforced by introducing ( q −1)(3 N −2) new clauses of length ≤ 3, as in (169) — and often greatly simplified using Corollary E.
These additional clauses can significantly speed up a proof of unsatisfiability. On the other hand they can also slow down the search, if a problem has abundant solutions.
In practice it’s usually better to insist only on solutions that are partially canonical, by using only some of the automorphisms and by requiring lexicographic order only on some of the variables.
72. (a) The two 7 × 7s, shown in Fig. A–8 , were found by R. Wainwright (trice tongs, 1972) and A. Flammenkamp (jam, 1988).
Fig. A–8. Noteworthy minimal oscillators of periods 2 and 3.
(b) Here the smallest examples are 9 × 13 and 10 × 15; the former has four L-rotors surrounding long stable lines. Readers will also enjoy discovering 10 × 10 and 13 × 13 instances that have full eightfold symmetry. (When encoding such symmetrical problems by using exercise 65(b) , we need only compute the transitions between variables x tij for 1 ≤ i ≤ ⌈ m/ 2⌉ and 1 ≤ j ≤ ⌈ n/ 2⌉; every other variable is identical to one of these. However, the auxiliary variables a ij , … , g ij shouldn’t be coalesced in this way.)
(c,d) Champion heavyweights have small rotors. What a cool four-way snake dance!
73. (a) They don’t have three A neighbors; and they don’t have three B neighbors.
(b) Two examples appear in Fig. A–9 , where they are packed as snugly as possible into a 12 × 15 box. This pattern, found by R. W. Gosper about 1971, is called the phoenix , since its living cells repeatedly die and rise again. It is the smallest mobile flipflop; the same idea yields the next smallest (also seen in Fig. A–9 ), which is 10 × 12.
(c) The nonblank one comes from a 1 × 4 torus; the checkerboard from an 8 × 8. Here are some amazing m × n ways to satisfy the constraints for small m and n :
Notice that infinite one-dimensional examples are implied by several of these motifs; the checkerboard, in fact, can be fabricated by placing
diagonals together.
Fig. A–9. Mobile flipflops: An ideal way to tile the floor of a workspace for hackers.
74. Call a cell tainted if it is A with more than one A neighbor or B with more than one B neighbor. Consider the topmost row with a tainted cell, and the leftmost tainted cell in that row. We can assume that this cell is an A, and that its neighbors are S, T, U, V, W, X, Y, Z in the pattern
. Three of those eight neighbors are type B, and at least four are type A; several cases need to be considered.
Case 1: W = X = Y = Z = A. Then we must have S = U = V = B and T = 0 (blank), because S, T, U, V aren’t tainted. The three left neighbors of V can’t be type A, since V already has three A neighbors; nor can they be type B, since V isn’t tainted. Hence the tainted X, which must have two B neighbors in the three cells below it, cannot also have two or more A neighbors there.
Case 2: T = A or V = A. If, say, T = A then X = Y = Z = A, and neither V nor W can be type B.
Case 3: S ≠ A, U = A. Then W can’t be type B, and S must be tainted.
Case 4: S = A, U ≠ A. At least one of W, X, Y, Z is B; at least three are A; so exactly three are A. The B can’t be Y, which has four A neighbors. Nor can it be W or Z: That would force V to be blank, hence T = U = B; consequently W = A, Z = B. Since W is tainted, at least two of its right neighbors must be A, contradicting Z = B.
Thus X = B in Case 4. Either T or V is also B, while the other is blank; say T is blank. The three left neighbors of V cannot be A. So they must either all be B (tainting the cell left of S) or all blank. In the latter case the upper neighbors of T must be BBA in that order, since T is blank. But that taints the B above T. A symmetric argument applies if V is blank.
Case 5: S = U = A. Then W ≠ A, and at least two of {X, Y, Z} are A. Now Y = Z = A forces T = V = X = B and W blank, tainting V.
Similarly, X = Y = A forces T = W = Z = B and V blank; this case is more difficult. The three lower neighbors of Y must be AAB, in that order, lest a B be surrounded by four A’s. But then the left neighbors of X are BBB; hence so are the left neighbors of V, tainting the middle one.
Finally, therefore, Case 5 implies that X = Z = A. Either T, V, W, or Y is blank; the other three are B. The blank can’t be T, since T’s upper three neighbors can’t be A. It can’t be W or Y, since V and T aren’t tainted. So T = W = Y = B and V is blank. The left neighbors of S cannot be A, because S isn’t tainted. So the cell left of X must be A. Therefore X must have at least four A neighbors; but that’s impossible, because Y already has three.
Diagonally adjacent A’s are rare. (In fact, they cannot occur in rectangular grids of size 15 × 18 or 16 × 17.) But diligent readers will be able to spot them in Fig. A–9 , which exhibits an astonishing variety of different motifs that are possible in large grids.
75. Let the cells alive at times p − 2, p − 1, p be of types X, Y, Z, and consider the topmost row in which a live cell ever appears. Without loss of generality, the leftmost cell in that row is type Z. The cell below that Z can’t be of type Y, because that Y would have three X neighbors and four Y neighbors besides Z and the blank to its left.
Thus the picture must look like
, where the three predecessors of Z and the topmost Y are filled in. But there’s no room for the three predecessors of the topmost X.
76. The smallest known example, a 28 × 33 pattern found by Jason Summers in 2012, is illustrated here using the letters {F, A, B}, {B, C, D}, {D, E, F} for cells that are alive when t mod 3 = 0, 1, 2. His ingenious construction leads in particular to an infinite solution based on a 7 × 24 torus. An amazing infinite 7 × 7 toroidal pattern also exists, but little else is yet known.
77. If the first four cells in row 4 of X 0 (and of X 5 ) contain a , b , c , d , we need a + b ≠ 1, a + b + c ≠ 1, b + c + d ≠ 2. In clause form this becomes a ¯ ∨ b , a ∨ b ¯ , b ∨ c ¯ , c ¯ ∨ d , b ¯ ∨ c ∨ d ¯ .
Similarly, let the last four elements of column 5 be ( f, g, h, i ); then we want f + g + h ≠ 2, g + h + i ≠ 2, h + i ≠ 2. These conditions simplify to f ¯ ∨ g ¯ , f ¯ ∨ h ¯ , g ¯ ∨ ι ¯ , h ¯ ∨ ι ¯ .
78. The “9 2 phage” in Fig. A–10 is a minimal example.
79. (Solution by T. G. Rokicki.) A tremendous battle flares up, raging wildly on all fronts. When the dust finally settles at time 1900, 11 gliders are escaping the scene (1 going in the original NE direction, 3 going NW, 5 going SW, and 2 going SE), leaving behind 16 blocks, 1 tub, 2 loaves, 3 boats, 4 ships, 8 beehives, 1 pond, 15 blinkers, and 1 toad. (One should really watch this with a suitable applet.)
80. Paydirt is hit on 10 × 10 and 11 × 11 boards, with X 8 = X 9 ; see Fig. A–10 . The minimal example, “symeater19,” has a close relative, “symeater20,” which consists simply of two blocks and two carriers, strategically placed. (The first of these, also called “eater 2,” was discovered by D. Buckingham in the early 1970s; the other by S. Silver in 1998.) They both have the additional ability to eat the glider if it is moved one or two cells to the right of the position shown, or one cell to the left.
It is important to realize that the diagonal track of a glider does not pass through the corners of pixels, bisecting them; the axis of a glider’s symmetry actually passes through the midpoints of pixel edges, thereby cutting off small triangles whose area is 1/8 of a full pixel. Consequently, any eater that is symmetric about a diagonal will eat gliders in two adjacent tracks. The two in Fig. A–10 are exceptional because they’re quadruply effective. Furthermore symeater20 will eat from the opposite direction; and either of its carriers can be swapped to another position next to the blocks.
81. Two eaters make “ssymeater14” ( Fig. A–10 ); and “ssymeater22” is narrower.
82. (a) If X → X ′, then x ′ ij = 1 only if we have Σ i ′ \= i − 1 i + 1 Σ j ′ \= j − 1 j + 1 x i ′ j ′ ≥ 3 .
(b) Use the same inequality, and induction on j .
Fig. A–10. Various examples of minimal still lifes that eat gliders and spaceships.
(c) (Proof of the hint by John Conway, 1970.) In the transitions
we must have
in the center of X ′; hence we must have
at the lower left of X . But then the center of X ′ is
.
83. Work with (2 r + 1 − 2 t ) × (2 r + 1 − 2 t ) grids x tij centered at cell ( i 0 , j 0 ), for 0 ≤ t ≤ r = f ( i 0 ,j 0 ); and assume that x tij \= 0 whenever f ( i, j ) > t . For example, if ( i 0 , j 0 ) = (1, 2), only 14 of the x 3 ij can be alive, namely when ( i, j ) = (−2 .. −1, 2), (−2 .. 0, 1), (−2 .. 1, 0), (−2 .. 2, −1). The case ( i 0 , j 0 ) = (1, 2) leads to 5031 readily satisfiable clauses on 1316 variables, including the unit clause x 612 , when the state transitions are encoded as in answer 65 ; all but 106 of those variables are auxiliary.
84. (a) Use a glider, positioned properly with its tip at (0, 0).
(b) Similarly, a spaceship reaches these cells in the minimum possible time.
(c) Consider patterns A n \=
and B n \=
of width 2 n + 1, illustrated here for n = 3. Then B j works when j mod 4 ∈ {1, 2}; A j and B j − 1 work when j mod 4 ∈ {2, 3}; A j − 1 works when j mod 4 ∈ {0, 3}.
(d) The pattern
assembles a suitable glider at time 3.
(e) A SAT solver found the pattern shown here, which launches an appropriate spaceship (plus some construction debris that vanishes at t = 5).
[It appears likely that f ∗ ( i, j ) = f ( i, j ) for all i and j . But the best general result for large i and j at present, based on space-filling constructions such as Tim Coe’s “Max,” is that f ∗ ( i, j ) = f ( i, j ) + O (1). There’s no known way to prove even the special cases that, say, f ∗ ( j, 2 j ) = 6 j for all j ≥ 0. There has, however, been a recent spectacular breakthrough: As of February 2024, Tomas Rokicki has verified equality for all cells ( i , j ) with i – 6 or j – 6.]
85. (a) Let X be a 12 × 12 bitmap. We must show that the clauses T ( X, X ′) of exercise 65 , together with 92 unary clauses x ′ 23 , x ¯ ′ 24 , x ′ 25 , … from the given pattern, are unsatisfiable. (The pattern is symmetrical; but Life’s rules often produce symmetrical states from unsymmetrical ones.) Thus 2 144−8 different conceivable predecessor states need to be ruled out. Fortunately Algorithm C needs fewer than 100 M μ to do that.
(b) Most states have thousands of predecessors (see the following exercise); so Algorithm C can almost always find one in, say, 500 K μ . Therefore one can prove, for example, that no 6 × 6 Gardens of Eden exist, by rapidly finding a predecessor for each of the 2 36 patterns. (Only about 2 36 / 8 patterns actually need to be tried, by symmetry.) Furthermore, if we run through those patterns in Gray code order, changing the polarity of just one assumed unary clause ± x i j ′ at each step, the mechanism of Algorithm C goes even faster, because it tends to find nearby solutions to nearby problems. Thus thousands of patterns can be satisfied per second, and the task is feasible.
Such an approach is out of the question for 10 × 10 bitmaps, because 2 100 ≫ 2 36 . But we can find all 10 × 10 Gardens of Eden for which there is 90 ° -rotational symmetry, by trying only about 2 25 / 2 patterns, again using Gray code. Aha: Eight such patterns have no predecessor, and four of them correspond to the given orphan.
[See C. Hartman, M. J. H. Heule, K. Kwekkeboom, and A. Noels, Electronic J. Combinatorics 20 , 3 (2013), #P16, 1–19. The existence of Gardens of Eden with respect to many kinds of cellular automata was first proved nonconstructively by E. F. Moore, Proc. Symp. Applied Math. 14 (1962), 17–33.]
86. The 80 cells outside the inner 8 × 8 can be chosen in N = 11,984,516,506,952,898 ways. (A BDD of size 53464 proves this.) So the answer is N/ 2 100−64 ≈ 174,398.
87. Instead of using subscripts t and t + 1, we can write the transition clauses for X → X ′ in the form ( @ ∨ A 0 ¯ ∨ A 0 ′ ) , etc. Let Alice’s states be { α 1 ,...,α p } and let Bob’s be { β 1 ,...,β q }. The clauses ( @ ∨ α ¯ i ∨ α ′ i ) and ( @ ¯ ∨ β ¯ i ∨ β ′ i ) say that your state doesn’t change unless you are bumped. If state α corresponds to the command ‘Maybe go to s ’, the clause ( @ ¯ ∨ α ¯ ∨ α ′ ∨ s ′ ) defines the next possible states after bumping. The analogous clause for ‘Critical, go to s ’ or ‘Set υ ← b , go to s ’ is simply ( @ ¯ ∨ α ¯ ∨ s ′ ) ; and the latter also generates the clause ( @ ¯ ∨ α ¯ ∨ s ′ ) if b \= 1 , ( @ ¯ ∨ α ¯ ∨ υ ¯ ′ ) if b = 0. The command ‘If υ go to s 1 , else to s 0 ’ generates ( @ ¯ ∨ α ¯ ∨ υ ¯ ∨ s ′ 1 ) ∧ ( @ ¯ ∨ α ¯ ∨ υ ∨ s ′ 0 ) . And for each variable υ , if the states whose commands set υ are α i 1 , … , α ih , the clauses
( @ ¯ ∨ υ ∨ α i 1 ∨ … ∨ α i h ∨ υ ¯ ′ ) ∧ ( @ ¯ ∨ υ ¯ ∨ α i 1 ∨ … ∨ α i h ∨ υ ′ )
encode the fact that υ isn’t changed by other commands.
Bob’s program generates similar clauses — but they use @, not @ ¯ , and β , not α .
Incidentally, when other protocols are considered in place of (40), the initial state X 0 analogous to (41) is constructed by putting Alice and Bob into their smallest possible states, and by setting all shared variables to 0.
88. For example, let all variables be false except A0 0 , B0 0 , @ 0 , A1 1 , B0 1 , A1 2 , B1 2 , A1 3 , B2 3 , @ 3 , A2 4 , B2 4 , @ 4 , A3 5 , B2 5 , l 5 , A3 6 , B3 6 , l 6 .
89. No; we can find a counterexample to the corresponding clauses as in the previous exercise: A0 0 , B0 0 , A0 1 , B1 1 , A0 2 , B2 2 , b 2 , @ 2 , A1 3 , B2 3 , b 3 , A1 4 , B3 4 , b 4 , A1 5 , B4 5 , b 5 , @ 5 , A2 6 , B4 6 , a 6 , b 6 , @ 6 , A5 7 , B4 7 , a 7 , b 7 , A5 8 , B2 8 , a 8 , b 8 , l 8 , A5 9 , B5 9 , a 9 , b 9 , l 9 .
(This protocol was the author’s original introduction to the fascinating problem of mutual exclusion [see CACM 9 (1966), 321–322, 878], about which Dijkstra had said “Quite a collection of trial solutions have been shown to be incorrect.”)
90. Alice starves in (43) with p = 1 and r = 3 in (47), if she moves to A1 and then Bob remains in B0 whenever he is bumped. The A2 Λ B2 deadlock mentioned in the text for (45) corresponds to (47) with p = 4 and r = 6. And in (46), successive moves to B1, (B2, A1, A2, B3, B1, A4, A5, A0) ∞ will starve poor Bob.
91. A cycle (47) with no maybe/critical states for Alice can certainly starve her. Conversely, given (i), (ii), (iii), suppose Alice is in no maybe/critical state when t ≥ t 0 ; and let t 0 < t 1 < t 2 < … be times with @ t i = 1 but with @ t = 0 for at least one t between t i and t i +1 . Then we must have X t i = X t j for some i < j , because the number of states is finite. Hence there’s a starvation cycle with p = t i and r = t j .
92. For 0 ≤ i < j ≤ r we want clauses that encode the condition X i ≠ X j . Introduce new variables σ ij for each state σ of Alice or Bob, and v ij for each shared variable v . Assert that at least one of these new variables is true. (For the protocol (40) this clause would be (A0 ij ∨…∨ A4 ij ∨ B0 ij ∨…∨ B4 ij ∨ l ij ).) Also assert the binary clauses ( σ ¯ i j ∨ σ i ) ∧ ( σ ¯ i j ∨ σ ¯ j ) for each σ , and the ternary clauses ( υ ¯ i j ∨ υ i ∨ υ j ) ∧ ( υ ¯ i j ∨ υ ¯ i ∨ υ ¯ j ) for each υ .
The transition clauses can also be streamlined, because we needn’t allow cases where X t +1 = X t . Thus, for example, we can omit B0 t +1 from the clause ( @ t ∨ B0 ¯ t ∨ B0 t + 1 ∨ B1 t + 1 ) of (42); and we can omit the clause ( @ t ∨ B1 ¯ t ∨ l ¯ t ∨ B1 t + 1 ) entirely.
[If r is large, encodings with O ( r (log r ) 2 ) clauses are possible via sorting networks, as suggested by D. Kroening and O. Strichman, LNCS 2575 (2003), 298–309. The most practical scheme, however, seems to be to add the ij constraints one by one as needed; see N. Eén and N. Sörensson, Electronic Notes in Theoretical Computer Science 89 (2003), 543–560.]
93. For the Φ in (50), for example, we can use ( x 1 ∨ x 2 ∨ … ∨ x 16 ) ∧ ( x ¯ 1 ∨ A0 ¯ ′ ) ∧ … ∧ ( x ¯ 1 ∨ A6 ¯ ′ ) ∧ ( x ¯ 2 ∨ B0 ¯ ′ ) ∧ … ∧ ( x ¯ 2 ∨ B6 ¯ ′ ) ∧ ( x ¯ 3 ∨ A0 ¯ ′ ) ∧ ( x ¯ 3 ∨ a ′ ) ∧ … ∧ ( x ¯ 16 ∨ B6 ′ ) ∧ ( x ¯ 16 ∨ b ¯ ′ ) .
94. ( X → X ′ → … → X ( r ) ) Λ Φ( X ) Λ Φ( X ′) ∧ … ∧ Φ( X ( r −1) ) ∧ ⌝ Φ( X ( r ) ). [This important technique is called “ k - induction”; see Mary Sheeran, Satnam Singh, and Gunnar Stålmarck, LNCS 1954 (2000), 108–125. One can, for example, add the clause ( A5 ¯ ∨ B5 ¯ ) to (50) and prove the resulting formula Φ by 3-induction.]
95. The critical steps have a = b = 1, by the invariants, so they have no predecessor.
96. The only predecessor of A5 2 ∧ B5 2 ∧ a 2 ∧ b 2 ∧ l ¯ 2 is A5 1 ∧ B4 1 ∧ a 1 ∧ b 1 ∧ l ¯ 1 ; and the only predecessor of that is A5 0 ∧ B3 0 ∧ a 0 ∧ b 0 ∧ l ¯ 0 . The case l 2 is similar.
But without the invariants, we could find arbitrarily long paths to A5 r Λ B5 r . In fact the longest such simple path has r = 33: Starting with A2 0 ∧ B2 0 ∧ a ¯ 0 ∧ b ¯ 0 ∧ l ¯ 0 , we could successively bump Alice and Bob into states A3, A5, A6, A0, A1, A2, A3, B3, B4, A5, B3, A6, B4, A0, B3, A1, A2, A3, A5, A6, A0, A1, A2, B4, A3, A5, A6, A0, B5, A1, A2, A3, A5, never repeating a previous state. (Of course all of these states are unreachable from the real X 0 , because none of them satisfy Φ.)
97. No. Removing each person’s final step in a path to A6 Λ B6 gives a path to A5 Λ B5.
98. (a) Suppose X 0 → … → X r \= X 0 is impure and X i \= X j for some 0 ≤ i < j < r . We may assume that i = 0. If either of the two cycles X 0 → … → X j \= X 0 or X j → … → X r \= X j is impure, it is shorter.
(b) In those states she would have had to be previously in A0 or A5.
(c) Generate clauses ( g ¯ 0 ) , ( g ¯ t ∨ g t − 1 ∨ @ t − 1 ) , ( h ¯ 0 ) , ( h ¯ t ∨ h t − 1 ∨ @ ¯ t − 1 ) , ( f ¯ t ∨ g t ) , ( f ¯ t ∨ h t ) , ( f ¯ t ∨ α 0 ∨ α ¯ t ) , ( f ¯ t ∨ α ¯ 0 ∨ α t ) , ( f ¯ t ∨ υ 0 ∨ υ ¯ t ) ( f ¯ t ∨ υ ¯ 0 ∨ υ t ) , for 1 ≤ t ≤ r ; and ( f 1 ∨ f 2 ∨ … ∨ f r ). Here υ runs through all shared variables, and α runs through all states that can occur in a starvation cycle. (For example, Alice’s states with respect to protocol (49) would be restricted to A3 and A4, but Bob’s are unrestricted.)
(d) With exercise 92 we can determine that the longest simple path, using only states that can occur in a starvation cycle for (49), is 15. And the clauses of (c) are unsatisfiable when r = 15 and invariant (50) is used. Thus the only possible starvation cycle is made from two simple pure cycles; and those are easy to rule out.
99. Invariant assertions define the values of a and b at each state. Hence mutual exclusion follows as in exercise 95 . For starvation-freedom, we can exclude states A0, A6, A7, A8 from any cycle that starves Alice. But we need also to show that the state A5 t ∧ B0 t ∧ l t is impossible; otherwise she could starve while Bob is maybe-ing. For that purpose we can add ¬ ( ( A6 ∨ A7 ∨ A8 ) ∧ ( B6 ∨ B7 ∨ B8 ) ) ∧ ¬ ( A8 ∧ l ¯ ) ∧ ¬ ( B8 ∧ l ) ∧ ¬ ( ( A3 ∨ A4 ∨ A5 ) ∧ B0 ∧ l ) ∧ ¬ ( A0 ∧ ( B3 ∨ B4 ∨ B5 ) ∧ l ¯ ) to the invariant Φ( X ). The longest simple path through allowable states has length 42; and the clauses of exercise 98(c) are unsatisfiable when r = 42. Notice that Alice and Bob never compete when setting the common variable l , because states A7 and B7 cannot occur together.
(See Dijkstra’s Cooperating Sequential Processes , cited in the text.)
100. Bob is starved by the moves B1, (A1, A2, A3, B2, A4, B3, A0, B4, B1) ∞ . But an argument similar to the previous answer shows that Alice cannot be.
[The protocol obviously provides mutual exclusion as in exercise 95 . It was devised independently in the late 1970s by J. E. Burns and L. Lamport, as a special case of an N -player protocol using only N shared bits; see JACM 33 (1986), 337–339.]
101. The following solution is based on G. L. Peterson’s elegant protocol for N processes in ACM Transactions on Programming Languages and Systems 5 (1983), 56–65:
A0. Maybe go to A1. | B0. Maybe go to B1. |
A1. Set a 1 ← 1, go to A2. | B1. Set b 1 ← 1, go to B2. |
A2. If b 2 go to A2, else to A3. | B2. If a 1 go to B2, else to B3. |
A3. Set a 2 ← 1, go to A4. | B3. Set b 2 ← 1, go to B4. |
A4. Set a 1 ← 0, go to A5. | B4. Set b 1 ← 0, go to B5. |
A5. If b 1 go to A5, else to A6. | B5. If a 2 go to B5, else to B6. |
A6. Set a 1 ← 1, go to A7. | B6. Set b 1 ← 1, go to B7. |
A7. If b 1 go to A8, else to A9. | B7. If a 1 go to B8, else to B12. |
A8. If b 2 go to A7, else to A9. | B8. If a 2 go to B9, else to B12. |
A9. Critical, go to A10. | B9. Set b 1 ← 0, go to B10. |
A10. Set a 1 ← 0, go to A11. | B10. If a 1 go to B11, else to B6. |
A11. Set a 2 ← 0, go to A0. | B11. If a 2 go to B10, else to B6. |
B12. Critical, go to B13. | |
(Alice and Bob might need an app to help them deal with this.) | B13. Set b 1 ← 0, go to B14. B14. Set b 2 ← 0, go to B0. |
102. The clauses for, say, ‘B5. If a go to B6, else to B7.’ should be ( @ ∨ B5 ¯ ∨ a ¯ ∨ α 1 ∨ … ∨ α p ∨ B6 ′ ) ∧ ( @ ∨ B5 ¯ ∨ a ∨ α 1 ∨ … ∨ α p ∨ B7 ′ ) ∧ ( @ ∨ B5 ¯ ∨ B6 ′ ∨ B7 ′ ) , where α 1 , …, α p are the states in which Alice sets a .
103. See, for example, any front cover of SICOMP , or of SIAM Review since 1970.
104. Assume that m ≤ n . The case m = n is clearly impossible, because all four corners must be occupied. When m is odd and n = m + k + 1, put m bishops in the first and last columns, then k in the middle columns of the middle row. When m is even and n = m +2 k + 1, put m in the first and last columns, and two in the middle rows of columns m/ 2+2 j for 1 ≤ j ≤ k . There’s no solution when m and n are both even, because the maximum number of independent bishops of each color is ( m + n − 2) / 2. [R. Berghammer, LNCS 6663 (2011), 103–106.]
105. (a) We must have ( x ij , x ′ ij ) = (1, 0) for t pairs ij , and (0, 1) for t other pairs; otherwise x ij \= x ′ ij . Hence there are 2 mn −2 t solutions.
(b) Use 2 mn variables y ij ,y ′ ij for 1 ≤ i ≤ m and 1 ≤ j ≤ n , with binary clauses ( y ¯ i j ∨ y ¯ ′ i j ) , together with m + n +2( m + n − 1) sets of cardinality constraints such as (20) and (21) to enforce the balance condition Σ { y i j + y ¯ ′ i j | i j ∈ L | \= | L | for each row, column, and diagonal line L .
(c) T ( m, n ) = 1 when min( m, n ) < 4, because only the zero matrix qualifies in such cases. Other values can be enumerated by backtracking, if they are small enough. (The asymptotic behavior is unknown.)
n \= 4 5 6 7 8 T ( 4 , n ) \= 3 7 17 35 77 T ( 5 , n ) \= 7 31 109 365 1367 T ( 6 , n ) \= 17 109 877 6315 47607 T ( 7 , n ) \= 35 365 6315 107637 1703883 T ( 8 , n ) \= 77 1367 47607 1703883 66291089
(d) Suppose m ≤ n . Any solution with nonzero first row and column has all entries zero except that y 1 t = − y t 1 = y ( k +1 − t )1 = −y kt \= y k ( k +1− t ) \= − y ( k +1− t ) k \= y tk \= − y 1( k +1− t ) , for some t and k with 1 < t ≤ k/ 2 ≤ m/ 2. So the answer is 2 Σ k \= 4 m ⌊ k / 2 − 1 ⌋ ( m + 1 − k ) ( n + 1 − k ) , which simplifies to q ( q − 1)(4 q ( n − q ) − 5 n + 2 q + 3 +( m mod 2)(6 n − 8 q − 5)) / 3 when q = ⌊ m/ 2⌋.
[The answer in the case ( m, n ) = (25, 30) is 36080; hence a random 25 × 30 image will have an average of 36080 / 256 ≈ 140 . 9 tomographically equivalent “neighbors” that differ from it in exactly eight pixel positions. Figure 79 has five such neighbors, one of which is shown in answer 111 below.]
(e) We can make all entries nonzero except on the main diagonals (see below). This is optimum, because the diagonal lines for a 1 , a 3 , … , a 4 n − 1 , b 1 , b 3 , … , b 4 n − 1 must each contain a different 0. So the answer is 2 n ( n − 1). (But the maximum for odd sized boards is unknown; for m = n = (5, 7, 9) it turns out to be (6, 18, 33).)
(f) The smallest counterexamples are 7 × 7 (see above).
106. In an m × n problem we must have 0 ≤ r i ≤ n , 0 ≤ c j ≤ m , and 0 ≤ a d , b d ≤ min{ d, m, n, m + n − d }. So the total number B of possibilities, assuming that m ≤ n , is ( n + 1) m ( m + 1) n (( m + 1)! ( m +1) n − m m !) 2 , which is ≈ 3 · 10 197 when ( m, n ) = (25, 30). Since 2 750 /B ≈ 2 · 10 28 , we conclude that a “random” 25 × 30 digital tomography problem usually has more than 10 28 solutions. (Of course there are other constraints too; for example, the fact that Σ r i \= Σ c j \= Σ a d \= Σ b d reduces B by at least a factor of ( n + 1)( m + 1) 2 .)
107. (a) ( r 1 ,...,r 6 ) = (11, 11, 11, 9, 9, 10); ( c 1 ,...,c 13 ) = (6, 5, 6, 2, 4, 4, 6, 5, 4, 2, 6, 5, 6); ( a 1 ,...,a 6 ) = (11, 10, 9, 9, 11, 11); ( b 1 ,...,b 12 ) = (6, 1, 6, 5, 7, 5, 6, 2, 6, 5, 7, 5).
(b) There are two others, namely the following one and its left-right reversal:
[ Reference: P. Gerdes, Sipatsi (Maputo: U. Pedagógica, 2009), page 62, pattern #122.]
108. Here are four of the many possibilities:
109. F1. [Initialize.] Find one solution y 1 …y n , or terminate if the problem is unsatisfiable. Then set y n +1 ← 1 and d ← 0.
F2. [Advance d .] Set d to the smallest j > d such that y j \= 1.
F3. [Done?] If d > n , terminate with y 1 …y n as the answer.
F4. [Try for smaller.] Try to find a solution with additional unit clauses to force x j \= y j for 1 ≤ j < d and x d \= 0. If successful, set y 1 …y n ← x 1 … x n .
Return to F2. Even better is to incorporate a similar procedure into the solver itself; see exercise 275 .
110. Algorithm B actually gives these directly:
001111111011101111100101111101111011111110111011011111111100101111101111011111100111011111110111 111111111011111111001100111111001111011111111010111111110111101111111001100111110110111101111111
111. This family of problems appears to provide an excellent (though sometimes formidable) series of benchmark tests for SAT solvers. The suggested example has solutions
and several of the entries in (a) were by no means easy. An even more difficult case arises if we base lexicographic order on a rook path that spirals out from the center (thus favoring solutions that are mostly 0 or mostly 1 in the middle):
Here many of the entries have never yet been solved by a SAT solver, as of 2013, although again IP solvers have no great difficulty. In fact, the “lexicographic pure cutting plane” procedure of E. Balas, M. Fischetti, and A. Zanette [ Math. Programming A130 (2011), 153–176; A135 (2012), 509–514] turns out to be particularly effective on such problems.
112. Reasonably tight upper and lower bounds would also be interesting.
113. Given an N × N × N contingency problem with binary constraints C JK \= X ∗ JK , R IK \= X I ∗ K_ , _P IJ \= X IJ ∗ , we can construct an equivalent n × n digital tomography problem with n = N 2 + N 3 + N 4 as follows: First construct a four-dimensional tensor Y IJKL \= X ( I ⊕ L ) JK , where I ⊕ L = 1 + ( I + L − 1) mod N , and notice that Y ∗ JKL \= Y IJK ∗ \= X ∗ JK , Y I ∗ KL \= X ( I ⊕ L )∗ K , Y IJ ∗ L \= X ( I ⊕ L ) J ∗ . Then define x ij for 1 ≤ i, j ≤ n by the rule x ij \= Y IJKL when i = I − N 2 K + N 3 L , j = NJ + N 2 K + N 3 L , otherwise x ij \= 0. This rule makes sense; for if 1 ≤ I, I ′, J , J ′, K , K ′, L , L ′ ≤ N and I − N 2 K + N 3 L = I ′ − N 2 K ′ + N 3 L ′ and NJ + N 2 K + N 3 L = NJ ′ + N 2 K ′ + N 3 L ′, we have I ≡ I ′ (modulo N ); hence I = I ′ and K ≡ K ′; hence K = K ′, L = L ′, J = J ′.
Under this correspondence the marginal sums are r i \= Y I ∗ KL when i = I − N 2 K + N 3 L , c j \= Y ∗ JKL when j = NJ + N 2 K + N 3 L , a d \= Y IJ ∗ L when d + 1 = I + NJ + 2 N 3 L , b d \= Y IJK ∗ when d − n = I − NJ − 2 N 2 K , otherwise zero. [See S. Brunetti, A. Del Lungo, P. Gritzmann, and S. de Vries, Theoretical Comp. Sci. 406 (2008), 63–71.]
114. (a) From x 7,23 + x 7,24 = x 7,23 + x 7,24 + x 7,25 = x 7,24 + x 7,25 = 1 we deduce x 7,23 = x 7,25 = 0 and x 7,24 = 1, revealing n 7,23 = n 7,25 = 5. Now x 6,23 + x 6,24 = + x 6,24 = x 4,25 + x 4,24 + x 5,24 + x 6,24 + x 6,25 = 1; hence x 4,24 = x 5,24 = 0, revealing n 4,24 = n 5,24 = 2. So x 6,23 = x 6,25 = 0, and the rest is easy.
(b) Let y i,j mean “cell ( i, j ) has been probed safely, revealing n i,j .” Consider the clauses C obtained by appending y ¯ i , j to each clause of the symmetric function [ Σ i ′ \= i − 1 i + 1 Σ j ′ \= j − 1 j + 1 x i ′ , j ′ \= n i , j ] , for all i, j with x i,j \= 0. Also include ( x ¯ i , j ∨ y ¯ i , j ) , as well as clauses for the symmetric function S N ( x ) if we’re told the total number N of mines.
Given any subset F of mine-free cells, the clauses C F \= C ∧ Λ { y i,j | ( i, j ) ∈ F } are satisfiable precisely by the configurations of mines that are consistent with the data {n i,j | ( i, j ) ∈ F }. Therefore cell ( i, j ) is safe if and only if C F ∧ x i,j is unsatisfiable.
A simple modification of Algorithm C can be used to “grow” F until no further safe cells can be added: Given a solution to C F for which neither x i,j nor x ¯ i , j was obtained at root level ( level 0), we can try to find a “flipped” solution by using the complemented value as the decision at level 1. Such a solution will be found if and only if the flipped value is consistent; otherwise the unflipped value will have been forced at level 0. By changing default polarities we can favor solutions that flip many variables at once. Whenever a literal x ¯ i , j is newly deduced at root level, we can force y i,j to be true, thus adding ( i, j ) to F . We reach an impasse when a set of solutions has been obtained for C F that covers both settings of every unforced x i,j .
For problem (i) we start with F = {(1, 1)}, etc. Case (iv) by itself uncovers only 56 cells in the lower right corner. The other results, each obtained in < 6 G μ , are:
Notice that the Cheshire cat’s famous smile defies logic and requires much guesswork!
[For aspects of Minesweeper that are NP-complete and coNP-complete, see Kaye, Scott, Stege, and van Rooij, Math. Intelligencer 22 , 2 (2000), 9–15; 33 , 4 (2011), 5–17.]
115. Several thousand runs of the algorithm in the previous exercise, given that the total number of mines is 10, indicate success probabilities . 490 ± . 007, . 414 ± . 004, . 279 ± . 003, when the first guess is respectively in a corner, in the center of an edge, or in the center.
116. The smallest is the “clock” in answer 69(b) . Other noteworthy possibilities are
as well as the “ phoenix” in Fig. A–9 .
117. (a) Set x 0 = x n +1 \= 0, and let ( a, b, c ) be respectively the number of occurrences of (01, 10, 11) as a substring of x 0 x 1 …x n + 1 . Then a + c = b + c = νx and c = ν (2) x ; hence a = b = νx − ν (2) x is the number of runs.
(b) In this case the complete binary tree will have only n −1 leaves, corresponding to { x 1 x 2 ,...,x n − 1 x n }; therefore we want to replace n by n − 1 in (20) and (21).
The clauses of (20) remain unchanged unless t k ≤ 3. When t k \= 2 they become ( x ¯ 2 k − n + 1 ∨ x ¯ 2 k − n + 2 ∨ b 1 k ) ∧ ( x ¯ 2 k − n + 2 ∨ x ¯ 2 k − n + 3 ∨ b 1 k ) ∧ ( x ¯ 2 k − n + 1 ∨ x ¯ 2 k − n + 2 ∨ x ¯ 2 k + n + 3 ∨ b 2 k ) . When t k \= 3 we have 2 k = n −1, and they become ( b ¯ 1 2 k ∨ b 1 k ) ∧ ( x ¯ ∨ x ¯ 2 ∨ b 1 k ) ∧ ( b ¯ 2 2 k ∨ b 2 k ) ∧ ( b ¯ 1 2 k ∨ x ¯ 1 ∨ x ¯ 2 ∨ b 2 k ) ∧ ( b ¯ 2 2 k ∨ x ¯ 1 ∨ x ¯ 2 ∨ b 3 k ) .
The clauses of (21) remain unchanged except in simple cases when n ≤ 3.
(c) Now the leaves represent x i x i + 1 ¯ \= x ¯ i ∨ x ¯ i + 1 . So we change (20), when t k \= 2, to ( x 2 k − n + 1 ∨ b 1 k ) ∧ ( x 2 k − n + 2 ∨ b 1 k ) ∧ ( x 2 k − n + 3 ∨ b 1 k ) ∧ ( x 2 k − n + 2 ∨ b 2 k ) ∧ ( x 2 k − n + 1 ∨ x 2 k − n + 3 ∨ b 2 k ) . And there are eight clauses when t k \= 3 : ( b ¯ 1 2 k ∨ b 1 k ) ∧ ( x 1 ∨ b 1 k ) ∧ ( x 2 ∨ b 1 k ) ∧ ( b ¯ 2 2 k ∨ b 2 k ) ∧ ( b ¯ 1 2 k ∨ x 1 ∨ b 2 k ) ∧ ( b ¯ 1 2 k ∨ x 2 ∨ b 2 k ) ∧ ( b ¯ 2 2 k ∨ x 1 ∨ b 3 k ) ∧ ( b ¯ 2 2 k ∨ x 2 ∨ b 3 k ) .
118. Let p i,j \= [the pixel in row i and column j should be covered], and introduce variables h i,j when p i,j \= p i,j +1 \= 1, υ i,j when p i,j \= p i +1,j \= 1. The clauses are (i) ( h i,j ∨ h i,j −1 ∨ υ i,j ∨ υ i −1, j ), whenever p i,j \= 1, omitting variables that don’t exist; (ii) ( h ¯ i , j ∨ h ¯ i , j − 1 ) , ( h ¯ i , j ∨ υ ¯ i , j ) , ( h ¯ i , j ∨ υ ¯ i − 1 , j ) , ( h ¯ i , j , − 1 ∨ υ ¯ i , j ) , ( h ¯ i , j , − 1 ∨ υ ¯ i − 1 , j ) , ( υ ¯ i , j ∨ υ ¯ i − 1 , j ) whenever p i,j \= 1, omitting clauses whose variables don’t both exist; and (iii) ( h i,j ∨ h i +1, j ∨ υ i,j ∨ υ i,j +1 ), whenever p i,j + p i,j +1 + p i +1, j+ 1 ≥3, omitting variables that don’t exist. (The example has 10527 clauses in 2874 variables, but it’s quickly solved.)
119. ThereÙs symmetry between l and l ¯ , also between l and 10- l ; so we need consider only l = (1, 2, 3, 4, 5), with respectively (4, 4, 6, 6, 8) occurrences. The smallest result is F / 5 \= { 123 , 234 , 678 , 789 , 246 , 468 , 147 , 369 , 1 ¯ 2 ¯ 3 ¯ , 2 ¯ 3 ¯ 4 ¯ , 3 ¯ 4 ¯ , 4 ¯ 6 ¯ , 6 ¯ 7 ¯ , 6 ¯ 7 ¯ 8 ¯ , 7 ¯ 8 ¯ 9 ¯ , 1 ¯ 3 ¯ , 2 ¯ 4 ¯ 6 ¯ , 3 ¯ 7 ¯ , 4 ¯ 6 ¯ 8 ¯ , 7 ¯ 9 ¯ , 1 ¯ 4 ¯ 7 ¯ , 2 ¯ 8 ¯ , 3 ¯ 6 ¯ 9 ¯ , 1 ¯ 9 ¯ }.
120. True.
121. The main point of interest is that an empty clause is typically discovered in the midst of step A3; partial backtracking must be done when taking back the changes that were made before this interruption.
A3. [Remove l ¯ .] Set p ← F( l ¯ ) (which is F( l ⊕ 1 ) , see (57)). While p ≥ 2 n + 2, set j ← C( p ) , i ← SIZE( j ) , and if i > 1 set SIZE( j ) ← i − 1, p ← F( p ) . But if i = 1, interrupt that loop and set p ← B( p ) ; then while p ≥ 2 n + 2, set j ← C( p ) , i ← SIZE( j ) , SIZE( j ) ← i + 1, p ← B( p ) ; and finally go to A5.
A4. [Deactivate l ’s clauses.] Set p ← F( l ) . While p ≥ 2 n + 2, set j ← C( p ) , i ← START( j ) , p ← F( p ) , and for i ≤ s < i + SIZE( j ) − 1 set q ← F( s ) , r ← B( s ) , B( q ) ← r , F( r ) ← q , and C(L( s )) ← C(L( s )) − 1. Then set a ← a − C( l ) , d ← d + 1, and return to A2.
A7. [Reactivate l ’s clauses.] Set a ← a + C( l ) and p ← B( l ) . While p ≥ 2 n +2, set j ← C( p ) , i ← START( j ) , p ← B( p ) , and for i ≤ s < i + SIZE( j ) − 1 set q ← F( s ) , r ← B( s ) , B( q ) ← F( r ) ← s , and C(L( s )) ← C(L( s )) + 1. (The links dance a little here.)
A8. [Unremove l ¯ .] Set p ← F( l ¯ ) . While p ≥ 2 n + 2, set j ← C( p ) , i ← SIZE( j ) , SIZE( j ) ← i + 1, p ← F( p ) . Then go to A5.
122. Pure literals are problematic when we want all solutions, so we don’t take advantage of them here. Indeed, things get simpler; only the move codes 1 and 2 are needed.
A1 ∗ . [Initialize.] Set d ← 1.
A2 ∗ . [Visit or choose.] If d > n , visit the solution defined by m 1 …m n and go to A6 ∗ . Otherwise set l ← 2 d + 1 and m d ← 1.
A3 ∗ . [Remove l ¯ .] Delete l ¯ from all active clauses; but go to A5 ∗ if that would make a clause empty.
A4 ∗ . [Deactivate l ’s clauses.] Suppress all clauses that contain l . Then set d ← d + 1 and return to A2 ∗ .
A5 ∗ . [Try again.] If m d \= 1, set m d ← 2, l ← 2 d , and go to A3 ∗ .
A6 ∗ . [Backtrack.] Terminate if d = 1. Otherwise set d ← d − 1 and l ← 2 d + ( m d & 1).
A7 ∗ . [Reactivate l ’s clauses.] Unsuppress all clauses that contain l .
A8 ∗ . [Unremove l ¯ .] Reinstate l ¯ in all the active clauses that contain it. Then go back to A5 ∗ .
It’s no longer necessary to update the values C( k ) for k < 2 n + 2 in steps A4 ∗ and A7 ∗ .
123. For example, we might have
p \= 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 L ( p ) \= 3 9 7 8 7 5 6 5 3 4 3 8 2 8 6 9 6 4 7 4 2
and START( j ) = 21 − 3 j for 0 ≤ j ≤ 7; W 2 = 3, W 3 = 7, W 4 = 4, W 5 = 0, W 6 = 5, W 7 = 1, W 8 = 6, W 9 = 2. Also LINK( j ) = 0 for 1 ≤ j ≤ 7 in this case.
124. Set j ← W l ¯ . While j ≠ 0, a literal other than l ¯ should be watched in clause j , so we do the following: Set i ← START( j ) , i ′ ← START( j − 1 ) , j ′ ← LINK( j ) , k ← i + 1. While k < i ′, set l ′ ← L( k ) ; if l ′ isn’t false (that is, if | l ′| > d or l ′ + m | l ′| is even, see (57)), set L( i ) ← l ′, L( k ) ← l ¯ , LINK( j ) ← W l ′ , W l ′ ← j , j ← j ′, and exit the loop on k ; otherwise set k ← k + 1 and continue that loop. If k reaches i ′, however, we cannot stop watching l ¯ ; so we set W l ¯ ← j , exit the loop on j , and go on to step B5.
125. Change steps B2 and B4 to be like A2 ∗ and A4 ∗ in answer 122 .
126. Starting with active ring (6 9 7 8), the unit clause 9 will be found (because 9 appears before 8); the clause 9 ¯ 3 ¯ 6 ¯ will become 6 ¯ 3 ¯ 9 ¯ ; the active ring will become (7 8 6).
127. Before: 11414545; after: 1142. (And then 11425, etc.)
128. Active ring x 1 x 2 x 3 x 4 Units Choice Changed clauses
( 1234 ) − − − − 1 ¯ 21 3 ¯ ( 234 ) 0 − − − 2 ¯ 3 ¯ 12 , 32 4 ¯ ( 34 ) 0 0 − − 3 ¯ 3 ¯ 4 ¯ 23 , 431 ( 4 ) 0 0 0 − 4 , 4 ¯ Backtrack ( 34 ) 0 − − − 2 3 ¯ 2 ¯ 4 ( 34 ) 0 1 − − 4 ¯ 4 ¯ 341 , 1 ¯ 42 ( 3 ) 0 1 − 0 3 , 3 ¯ Backtrack ( 43 ) − − − − 1 4 1 ¯ 2 , 2 ¯ 1 ¯ 3 ( 243 ) 1 − − − 2 ¯ ( 43 ) 1 0 − − 4 4 32 4 ¯ , 1 4 ¯ 2 ¯ ( 3 ) 1 0 − 1 3 , 3 ¯ Backtrack ( 43 ) 1 − − − 2 3 1 ¯ 2 ¯ ( 43 ) 1 1 − − 3 3 4 2 ¯ 3 ¯ , 1 3 ¯ 2 , 4 ¯ 3 ¯ 1 ( 4 ) 1 1 1 − 4 , 4 ¯ Backtrack
129. Set j ← W l , then do the following steps while j ≠ 0: (i) Set p ← START( j ) + 1; (ii) if p = START( j − 1 ) , return 1; (iii) if L( p ) is false (that is, if x | L( p ) | \= L( p ) & 1), set p ← p + 1 and repeat (ii); (iv) set j ← LINK( j ) . If j becomes zero, return 0.
130. Set l ← 2 k + b , j ← W l , W l ← 0, and do the following steps while j ≠ 0: (i) Set j ′ ← LINK( j ) , i ← START( j ) , p ← i + 1; (ii) while L( p ) is false, set p ← p + 1 (see answer 129 ; this loop will end before p = START( j − 1 ) ); (iii) set l ′ ← L( p ) , L( p ) ← l , L( i ) ← l ′; (iv) set p ← W l ′ and q ← W l ¯ ′ , and go to (vi) if p ≠ 0 or q ≠ 0 or x | l ′| ≥ 0; (v) if t = 0, set t ← h ← | l ′| and NEXT( t ) ← h , otherwise set NEXT( | l ′| ) ← h , h ← | l ′|, NEXT( t ) ← h (thus inserting | l ′| = l ′ ≫ 1 into the ring as its new head); (vi) set LINK( j ) ← p , W l ′ ← j (thus inserting j into the watch list of l ′); (vii) set j ← j ′.
[The tricky part here is to remember that t can be zero in step (v).]
131. For example, the author tried selecting a variable x k for which s 2 k · s 2 k +1 is maximum, where s l is the length of l ’s watch list plus ε , and the parameter ε was 0.1. This reduced the runtime for waerden (3, 10; 97) to 139.8 gigamems, with 8.6 mega-nodes. Less dramatic effects occurred with langford (13): 56.2 gigamems, with 10.8 meganodes, versus 99.0 gigamems if the minimum s 2 k · s 2 k +1 was chosen instead.
132. The unsatisfiable clauses ( x ¯ 1 ∨ x 2 ) , ( x 1 ∨ x ¯ 2 ) , ( x ¯ 3 ∨ x 4 ) , ( x 3 ∨ x ¯ 4 ) , …, ( x ¯ 2 n − 1 ∨ x 2 n ) , ( x 2 n − 1 ∨ x ¯ 2 n ) , ( x ¯ 2 n − 1 ∨ x ¯ 2 n ) , ( x 2 n − 1 ∨ x 2 n ) cause it to investigate all 2 n settings of x 1 , x 3 , … , x 2 n − 1 before encountering a contradiction and repeatedly backtracking.
(Incidentally, the successive move codes make a pretty pattern. If the stated clauses are ordered randomly, the algorithm runs significantly faster, but it still apparently needs nonpolynomial time. What is the growth rate?)
133. (a) Optimum backtrack trees for n -variable SAT problems can be calculated with Θ( n 3 n ) time and Θ(3 n ) space by considering all 3 n partial assignments, “bottom up.” In this 9-variable problem we obtain a tree with 67 nodes (the minimum) if we branch first on x 3 and x 5 , then on x 6 if x 3 ≠ x 5 ; unit clauses arise at all other nodes.
(b) Similarly, the worst tree turns out to have 471 nodes. But if we require the algorithm to branch on a unit clause whenever possible, the worst size is 187. (Branch first on x 1 , then x 4 , then x 7 ; avoid opportunities for unit clauses.)
134. Let each BIMP list be accessed by ADDR , BSIZE , CAP , and K fields, where ADDR is the starting address in MEM of a block that’s able to store CAP items, and CAP = 2 K ; ADDR is a multiple of CAP , and BSIZE is the number of items currently in use. Initially CAP = 4, K = 2, BSIZE = 0, and ADDR is a convenient multiple of 4. The 2 n BIMP tables therefore occupy 8 n slots initially. If MEM has room for 2 M items, those tables can be allocated so that the doubly linked lists AVAIL[ k ] initially contain a k \= (0 or 1) available blocks of size 2 k for each k , where 2 M − 8 n = ( a M − 1 …a 1 a 0 ) 2 .
Resizing is necessary when BSIZE = CAP and we need to increase BSIZE . Set a ← ADDR , k ← K , CAP ← 2 k + 1 , and let b ← a ⊕ 2 k be the address of a ’s buddy. If b is a free block of size 2 k , we’re in luck: We remove b from AVAIL[ k ] ; then if a &2 k =0, nothing needs to be done, otherwise we copy BSIZE items from a to b and set ADDR ← b .
In the unlucky case when b is either reserved or free of size < 2 k , we set p to the address of the first block in AVAIL[ k ′ ] , where AVAIL[ t ] is empty for k < t < k ′ (or we panic if MEM ’s capacity is exceeded). After removing p from AVAIL[ k ′ ] , we split off new free blocks of sizes 2 k +1 , … , 2 k ′−1 if k ′ > k + 1. Finally we copy BSIZE items from block a to block p , set ADDR ← p , and put a into AVAIL[ k ] . (We needn’t try to “collapse” a with its buddy, since the buddy isn’t free.)
135. They’re the complements of the literals in BIMP( l ¯ ) .
136. Before, {(1, 2), (4, 2), (4, 5), (5, 1), (5, 7), (6, 9)}; after, {(1, 2), (4, 2), (6, 9)}.
137. If p in a TIMP list points to the pair ( u, v ), let’s write u = U( p ) and v = V( p ) .
(a) Set N ← n − G , x ← VAR[ N ] , j ← INX[ X ] , VAR[ j ] ← x , INX[ x ] ← j , VAR[ N ] ← X , INX[ X ] ← N . Then do the following for l = 2 X and l = 2 X + 1, and for all p in TIMP( l ) : u ← U( p ) , υ ← V( p ) , p ′ ← LINK( p ) , p ″ ← LINK( p ′ ) ; s ← TSIZE( u ¯ ) −1, TSIZE( u ¯ ) ← s , t ← pair s of TIMP( u ¯ ) ; if p ′ ≠ t , swap pairs by setting u ′ ← U( t ) , v ′ ← V( t ) , q ← LINK( t ) , q ′ ← LINK( q ) , LINK( q ′ ) ← p ′, LINK( p ) ← t , U( p ′ ) ← u ′, V( p ′ ) ← v ′, LINK( p ′ ) ← q , U( t ) ← υ , V( t ) ← l ¯ , LINK( t ) ← p ″ , p ′ ← t . Then set s ← TSIZE( υ ¯ ) −1, TSIZE( υ ¯ ) ← s , t ← pair s of TIMP( υ ¯ ) ; if p ″ ≠ t , swap pairs by setting u ′ ← U( t ) , υ ′ ← V( t ) , q ← LINK( t ) , q ′ ← LINK( q ) , LINK( q ′ ) ← p ″ , LINK( p ′ ) ← t , U( p ″ ) ← u ′, V( p ″ ) ← v ′, LINK( p ″ ) ← q , U( t ) ← l ¯ , V( t ) ← u , LINK( t ) ← p .
Notice that we do not make the current pairs of TIMP( l ) inactive. They won’t be accessed by the algorithm until it needs to undo the swaps just made.
(b) In VAR and in each TIMP list, the active entries appear first. The inactive entries follow, in the same order as they were swapped out, because inactive entries never participate in swaps. Therefore we can reactivate the most-recently-swapped-out entry by simply increasing the count of active entries. We must, however, be careful to do this “ virtual un swapping” in precisely the reverse order from which we did the swapping.
Thus, for l = 2 X + 1 and l = 2 X , and for all p in TIMP( l ) , proceeding in the reverse order from (a), we set u ← U( p ) , v ← V( p ) , TSIZE( υ ¯ ) ← TSIZE( υ ¯ ) + 1, and TSIZE( υ ¯ ) ← TSIZE( υ ¯ ) +1.
(The number N of free variables increases implicitly, because N + E = n in step L12. Thus nothing needs to be done to VAR or INX . These efficient techniques based on swapping are examples of “ sparse-set representations”; see 7.2.2–(16) thru (23).)
138. Because υ ¯ ∈ BIMP( u ¯ ) , (62) will be used to make u nearly true. That loop will also make v nearly true, because v ∈ BIMP( u ) is equivalent to u ¯ ∈ BIMP( υ ¯ ) .
139. Introduce a new variable BSTAMP analogous to ISTAMP , and a new field BST( l ) analogous to IST( l ) in the data for each literal l . At the beginning of step L9, set BSTAMP ← BSTAMP + 1, then set BST( l ) ← BSTAMP for l \= u ¯ and all l ∈ BIMP( u ¯ ) . Now, if BST( υ ¯ ) = BSTAMP and BST( υ ) ≠ = BSTAMP , do the following for all w ∈ BIMP( υ ) : If ω is fixed in context NT (it must be fixed true, since ω ¯ implies υ ¯ ), do nothing. Otherwise if BST( ω ¯ ) = BSTAMP , perform (62) with l ← u and exit the loop on w (because u ¯ implies both ω and ω ¯ ). Otherwise, if BST( ω ) ≠ = BSTAMP , append ω to BIMP( u ¯ ) and u to BIMP( ω ¯ ) . (Of course (63) must be invoked when needed.)
Then increase BSTAMP again, and do the same thing with u and υ reversed.
140. Unfortunately, no: We might have Ω( n ) changes to BSIZE on each of Ω( n ) levels of the search tree. However, the ISTACK will never have more entries than the total number of cells in all BIMP tables (namely 2 M in answer 134 ).
141. Suppose ISTAMP ← ( ISTAMP + 1)mod2 e in step L5. If ISTAMP = 0 after that operation, we can safely set ISTAMP ← 1 and IST( l ) ← 0 for 2 ≤ l ≤ 2 n + 1. (A similar remark applies to BSTAMP and BST( l ) in answer 139 .)
142. (The following operations, performed after BRANCH[ d ] is set in step L2, will also output ‘|’ to mark levels of the search where no decision was made.) Set BACKL[ d ] ← F , r ← k ← 0, and do the following while k < d : While r < BACKF[ k ] , output ‘6+( R r &1)’ and set r ← r +1. If BRANCH[ k ] < 0, output ‘|’; otherwise output ‘2 BRANCH[ k ] +( R r &1)’ and set r ← r + 1. While r < BACKL[ k +1 ] , output ‘4 + ( R r & 1)’ and set r ← r +1. Then set k ← k +1.
143. The following solution treats KINX and KSIZE as the unmodified algorithm treats TIMP and TSIZE . It deals in a somewhat more subtle way with CINX and CSIZE : If clause c originally had size k , and if j of its literals have become false while none have yet become true, CSIZE( c ) will be k − j , but the nonfalse literals will not necessarily appear at the beginning of list CINX( c ) . As soon as j reaches k −2, or one of the literals becomes true, clause c becomes inactive and it disappears from the KINX tables of all free literals. The algorithm won’t look at CINX( c ) or CSIZE( c ) again until it unfixes the literal that deactivated c . Thus a big clause is inactive if and only if it has been satisfied (contains a true literal) or has become binary (has at most two nonfalse literals).
We need to modify only the three steps that involve TIMP . The modified step L1, call it L1′, inputs the big clauses in a straightforward way.
Step L7′ removes the formerly free variable X from the data structures by first deactivating all of the active big clauses that contain L : For each of the KSIZE( L ) numbers c in KINX( L ) , and for each of the CSIZE( c ) free literals u in CINX( c ) , we swap c out of u ’s clause list as follows: Set s ← KSIZE( u ) − 1, KSIZE( u ) ← s ; find t ≤ s with KINX( u ) [ t ] = c ; if t ≠ s set KINX( u ) [ t ] ← KINX( u ) [ s ] and KINX( u ) [ s ] ← c . [ Heuristic: If the number of free literals remaining in c is small compared to c ’s original size, for example if say 15 or 20 original literals have become false, the remaining nonfalse literals can usefully be swapped into the first CSIZE( c ) positions of CINX( c ) when c is being deactivated. The author’s experimental implementation does this when CSIZE( c ) is at most θ times the original size, where the parameter θ is normally 25/64.]
Then step L7′ updates clauses for which L has become false: For each of the KSIZE( L ¯ ) numbers c in KINX( L ¯ ) , set s ← CSIZE( c ) − 1 and CSIZE( c ) ← s ; if s = 2, find the two free literals ( u, υ )in CINX( c ) , swap them into the first positions of that list, put them on a temporary stack, and swap c out of the clause lists of u and υ as above.
Finally, step L7′ does step L8′ = L8 for all ( u, v ) on the temporary stack. [The maximum size of that stack will be the maximum of KSIZE( l ) over all l , after step L1′; so we allocate memory for that stack as part of step L1′.]
In step L12′ we set L ← R E , X ← | L |, and reactivate the clauses that involve X as follows: For each of the KSIZE( L ¯ ) numbers c in KINX( L ¯ ) , proceeding in reverse order from the order used in L7′, set s ← CSIZE( c ) , CSIZE( c ) ← s + 1; if s = 2, swap c back into the clause lists of υ and u , where u = CINX( c ) [0] and υ = CINX( c ) [1]. For each of the KSIZE( L ) numbers c in KINX( L ) , and for each of the CSIZE( c ) free literals u in CINX( c ) , again proceeding in reverse order from the order used in L7′, swap c back into the clause list of u . The latter operation simply increases KSIZE( u ) by 1.
ParamILS advises changing α from 3.5 to 0.001(!) in (195).
144. False; h ′( l ) = 0 . 1 if and only if the complement , l ¯ , doesn’t appear in any clause.
145. By symmetry we know that h ( l ) = h ( l ¯ ) = h (10 − l ) for 1 ≤ l ≤ 9 at depth 0, and the BIMP tables are empty. The first five rounds of refinement respectively give ( h (1) ,...,h (5)) ≈ (4 . 10, 4 . 10, 6 . 10, 6 . 10, 8 . 10), (5 . 01, 4 . 59, 6 . 84, 6 . 84, 7 . 98), (4 . 80, 4 . 58 , 6 . 57, 6 . 57, 8 . 32), (4 . 88, 4 . 54, 6 . 72, 6 . 67, 8 . 06), and (4 . 85, 4 . 56, 6 . 63, 6 . 62, 8 . 23), slowly converging to the limiting values
(4 . 85810213, 4 . 55160111, 6 . 66761920, 6 . 63699698, 8 . 16778057) .
But when d = 1, the successively refined values of ( h ( 1 ) , h ( 1 ¯ ) , … , h ( 4 ) , h ( 4 ¯ ) ) are erratic and divergent: (2.10, 9.10, 3.10, 6.60, 3.10, 13.60, 4.10, 11.10), (5.63, 3.37, 9.24, 2.57, 5.48, 5.67, 8.37, 4.87), (1.42, 10.00, 2.31, 10.42, 1.28, 17.69, 1.94, 16.07), (8.12, 1.43, 12.42, 1.30, 7.51, 2.41, 12.02, 1.81), (0.32, 14.72, 0.42, 16.06, 0.30, 26.64, 0.43, 24.84).
They eventually oscillate between limits that favor either positive or negative literals:
(0 . 1017, 20 . 6819, 0 . 1027, 21 . 6597, 0 . 1021, 32 . 0422, 0 . 1030, 33 . 0200) and
(8 . 0187, 0 . 1712, 11 . 9781, 0 . 1361, 11 . 9781, 0 . 2071, 15 . 9374, 0 . 1718) .
[Equations (64) and (65), which were inspired by survey propagation, first appeared in unpublished work of S. Mijnders, B. de Wilde, and M. J. H. Heule in 2010. The calculations above indicate that we needn’t take h ( l ) too seriously, although it does seem to yield good results in practice. The author’s implementation also sets h ′( l ) ← Θ if the right-hand side of (65) exceeds a threshold parameter Θ, which is 20.0 by default.]
146. Good results have been obtained with the simple formula h ( l ) = ε + KSIZE( l ¯ ) + Σ u ∈ BIMP( l ), u free KSIZE( u ¯ ) , which estimates the potential number of big-clause reductions that occur when l becomes true. The parameter ε is typically set to 0.001.
147. ∞, 600, 60, 30, 30.
148. If a problem is easy, we don’t care if we solve it in 2 seconds or in .000002 seconds. On the other hand if a problem is so difficult that it can be solved only by looking ahead more than we can accomplish in a reasonable time, we might as well face the fact that we won’t solve it anyway. There’s no point in looking ahead at 60 variables when d = 60, because we won’t be able to deal with more than 2 50 or so nodes in any reasonable search tree.
149. The idea is to maintain a binary string SIG( x ) for each variable x , representing the highest node of the search tree in which x has participated. Let b j \= [ BRANCH[ j ] =1], and set σ ← b 0 …b d − 1 at the beginning of step L2, σ ← b 0 …b d at the beginning of step L4. Then x will be a participant in step X3 if and only if SIG( x ) is a prefix of σ .
We update SIG( x ) when x = | u | or x = | v | in step L9, by setting SIG( x ) ← σ unless SIG( x ) is a prefix of σ . The initial value of SIG( x ) is chosen so that it is never a prefix of any possible σ .
(Notice that SIG( x ) needn’t change when backtracking. In practice we can safely maintain only the first 32 bits of σ and of each string SIG( x ) , together with their exact lengths, because lookahead computations need not be precise. In answer 143 , updates occur not in step L9 but in step L7′; they are done for all literals u ≠ L ¯ that appear in any big clause containing L ¯ that is being shortened for the first time.)
150. Asserting 7 at level 22 will also 22fix 1 ¯ , because of the clause 1 ¯ 4 ¯ 7 ¯ . Then 1 ¯ will 22fix 3 and 9, which will 22fix 2 ¯ and 6 ¯ , then 8 ¯ ; and clause 258 becomes false. Therefore 7 ¯ becomes proto true; and (62) makes 3, 6, 9 all proto true, contradicting 3 ¯ 6 ¯ 9 ¯ .
151. For example, one such arrangement is
l : 2 8 ¯ 9 3 1 ¯ 6 7 ¯ 4 ¯ 4 7 6 ¯ 1 3 ¯ 9 ¯ 8 2 ¯ o l : 4 2 10 14 6 16 8 12 22 26 18 28 20 24 32 30 .
[Digraphs that are obtainable in this way are called “partial orderings of dimension ≤ 2,” or permutation posets . We’ve actually seen them in exercise 5.1.1–11, where the set of arcs was represented as a set of inversions . Permutation posets have many nice properties, which we shall study in Section 7.4.2. For example, if we reverse the order of the list and complement the offsets, we reverse the directions on the arrows. All but two of the 238 connected partially ordered sets on six elements are permutation posets. Unfortunately, however, permutation posets don’t work well with lookahead when they aren’t also forests. For example, after 10fixing ‘9’ and its consequences, we would want to remove those literals from the R stack when 14fixing ‘3’; see (71). But then we’d want them back when 6fixing ‘ 1 ¯ ’.]
152. A single clause such as ‘12’ or ‘123’ would be an example, except that the autarky test in step X9 would solve the problem be fore we ever get to step X3. The clauses { 12 3 ¯ , 1 2 ¯ 3 , 1 ¯ 2 3 ¯ , 1 ¯ 2 ¯ 3 , 245 , 3 4 ¯ 5 ¯ } do, however, work: Level 0 branches on x 1 , and level 1 discovers an autarky with x 2 and x 3 both true but returns l = 0. Then level 2 finds all clauses satisfied, although both of the free variables x 4 and x 5 are newbies.
[Indeed, the absence of free participants means that the fixed-true literals form an autarky. If TSIZE( l ) is nonzero for any free literal l , some clause is unsatisfied. Otherwise all clauses are satisfied unless some free l has an unfixed literal l ′ ∈ BIMP( l ) .]
153. Make the CAND array into a heap, with an element x of least rating r ( x ) at the top. (See Section 5.2.3; but start indices at 0, with r ( CAND[ k ] ) ≤ min( r ( CAND[ 2 k +1 ] ) , r ( CAND[ 2 k +2 ] )).) Then, while C > C max , delete the top of the heap (namely CAND[ 0 ] ).
154. The child → parent relations in the subforest will be d → c → a , b → a , c ¯ → d ¯ , and either a ¯ → b ¯ or a ¯ → c ¯ . Here’s one suitable sequence, using the latter:
preorder b ¯ a c c d d ¯ c ¯ a ¯ 2. postorder 2 10 4 8 6 16 14 12
155. First construct the dependency graph on the 2 C candidate literals, by extracting a subset of arcs from the BIMP tables. (This computation needn’t be exact, because we’re only calculating heuristics; an upper bound can be placed on the number of arcs considered, so that we don’t spend too much time here. However, it is important to have the arc u → υ if and only if υ ¯ → u ¯ is also present.)
Then apply Tarjan’s algorithm [see Section 7.4.1.2, or SGB pages 512–519]. If a strong component contains both l and l ¯ for some l , terminate with a contradiction. Otherwise, if a strong component contains more than one literal, choose a representative l with maximum h ( l ); the other literals of that component regard l as their parent. Be careful to ensure that l is a representative if and only if l ¯ is also a representative.
The result will be a sequence of candidate literals l 1 l 2 …l S in topological order, with l i → l j only if i > j . Compute the “ height” of each l j , namely the length of the longest path from l j to a sink. Then every literal of height h > 0 has a predecessor of height h − 1, and we let one such predecessor be its parent in the subforest. Every literal of height 0 (a sink) has a null parent. Traversal of this subforest in double order (exercise 2.3.1–18) now makes it easy to build the LL table in preorder while filling the LO table in postorder.
156. If l ¯ doesn’t appear in any clause of F , then A = { l } is clearly an autarky.
157. Well, any satisfying assignment is an autarky. But more to the point is the autarky {1, 2} for F \= { 1 2 ¯ 3 , 1 ¯ 24 , 3 ¯ 4 ¯ } .
158. BIMP( l ) and TIMP( l ) will be empty, so w will be zero when Algorithm X looks ahead on l . Thus l will be forced true, at depth d = 0. (But pure literals that arise in subproblems for d > 0 won’t be detected unless they’re among the preselected candidates.)
159. (a) False (consider A = {1}, F = {1, 2, 1 ¯ 2}); but true if we assume that F | A is computed as a multiset (so that F | A would be {2, 2} ⊆ F in that example).
(b) True: Suppose A = A ′ ∩ A ″ , ∪ A ′ ∩ A ″ = ø, and A ″ or ø A ¯ ″ touches C ∈ F | A ′. Then C ∩ A ′ = ø and C ∩ C ′ ∈ F , where C ′ ⊆ A ¯ ′ . Since A or A touches C ∪ C ′, some a ∈ C ∪ C ′ is in A ; hence a ∈ A ″ .
160. (a) If the gray clauses are satisfiable, let all black literals be true. [Notice, incidentally, that the suggested example coloring works like a charm in (7).]
(b) Given any set A of strictly distinct literals, color l black if l ∈ A , white if l ¯ ∈ A , otherwise gray. Then A is an autarky if and only if condition (a) holds.
[E. A. Hirsch, Journal of Automated Reasoning 24 (2000), 397–420.]
161. (a) If F ′ is satisfiable, so is F . If F is satisfiable with at least one blue literal false, so is F ′. If F is satisfiable with all the blue literals true, make all the black literals true (but keep gray literals unchanged). Then F ′ is satisfied, because every clause of F ′ that contains a black or blue literal is true, hence every clause that contains a white literal is true; the remaining clauses, whose literals are only orange and gray, each contain at least one true gray literal. [The black-and-blue condition is equivalent to saying that A is a conditional autarky , namely an autarky of F | L . Tseytin’s notion of “ extended resolution” is a special case, because the literals of A and L need not appear in F . See S. Jeannicot, L. Oxusoff, and A. Rauzy, Revue d’intelligence artificielle 2 (1988), 41–60, Section 6; O. Kullmann, Theoretical Comp. Sci. 223 (1999), 1–72, Sections 3, 4, and 14.]
(b) Without affecting satisfiability, we are allowed to add or delete any clause C \= ( a ∨ l ¯ 1 ∨ … ∨ l ¯ q ) for which all clauses containing ā also contain l 1 or … or l q . (Such a clause is said to be “blocked” with respect to a , because C produces nothing but tautologies when it is resolved with clauses that contain ā .)
(c) Without affecting satisfiability, we are allowed to add or delete any or all of the clauses ( l ¯ ∨ a 1 ) , … , ( l ¯ ∨ a p ) , if A is an autarky of F | l ; that is, we can do this if A is almost an autarky, in the sense that every clause that touches Ā but not A contains l .
(d) Without affecting satisfiability, we are allowed to add or delete the clause ( l ¯ ∨ a ) whenever every clause that contains ā also contains l .
162. Construct a “ blocking digraph” with l ′ ↪ l when every clause that contains literal l ¯ also contains l ′. (If l is a pure literal, we’ll have l ′ ↪ l for all l ′; this case can be handled separately. Otherwise all in-degrees will be less than k in a k SAT problem, and the blocking digraph can be constructed in O ( k 2 m ) steps if there are m clauses.)
(a) Then ( l ∨ l ′) is a blocked binary clause if and only if l ¯ ↪ l ′ or l ¯ ′ ↪ l . (Hence we’re allowed in such cases to add both l ¯ ↪ l ′ and l ¯ ′ ↪ l to the dependency digraph.)
(b) Also A = { a, a ′} is an autarky if and only if a ↪ a ′ ↪ a . (Moreover, any strong component { a 1 ,...,a t } with t > 1 is an autarky of size t .)
163. Consider the recurrence relations T n \= 1 + max( T n −1 , T n −2 , 2 U n −1 ), U n = 1 + max( T n −1 , T n −2 , U n −1 + V n −1 ), V n = 1 + U n −1 for n > 0, with T −1 = T 0 = U 0 = V 0 = 0. We can prove that T n , U n , V n are upper bounds on the step counts, where U n refers to cases where F is known to have a nonternary clause, and V n refers to cases when s = 1 and R2 was entered from R3: The terms T n −1 and T n −2 represent autarky reductions in step R2; otherwise the recursive call in R3 costs U n −1 , not T n −1 , because at least one clause contains l ¯ s . We also have V n = 1 + U n −1 , not 1 + T n −1 , because the preceding step R3 either had a clause containing l 2 not l 1 or a clause containing l ¯ 1 not l ¯ 2 .
Fibonacci numbers provide the solution: T n \= 2 F n +2 −3 + [ n =0], U n \= F n +3 −2, V n \= F n +2 −1. [Algorithm R is a simplification of a procedure devised by B. Monien and E. Speckenmeyer, Discrete Applied Mathematics 10 (1985), 287–295, who introduced the term “autarky” in that paper. A Stanford student, Juan Bulnes, had discovered a Fibonacci-bounded algorithm for 3SAT already in 1976; his method was, however, unattractive, because it also required Ω( ϕ n ) space .]
164. If k < 3, T n \= n is an upper bound; so we may assume that k ≥ 3. Let U n \= 1 + max( T n −1 , T n −2 , U n −1 + V n −1,1,..., U n −1 + V n −1, k −2 ), V n ,1 \= 1 + U n −1 , and V n,s \= 1 + max( U n −1 , T n −2 , U n −1 + V n −1, s−1 ) for s > 1, where V n,s refers to an entry at R2 from R3. The use of U n −1 in the formula for V n,s is justified, because the previous R3 either had a clause conta ining l s +1 not l s or one containing l ¯ s not l ¯ s + 1 . One can show by induction that V n,s \= s + U n −1 + … + U n −s , U n \= V n,k −1 ; and T n \= U n + U n −k +1 = 2 U n −1 +1 if n ≥ k . For example, the running time when k = 4 is bounded by Tribonacci numbers, whose growth rate 1 . 83929 n comes from the root of x 3 = x 2 + x +1.
165. Clause 1 ¯ 3 ¯ 4 ¯ in the example tells us that 1, 3, 4 ∉ A . Then 13 6 ¯ implies 6 ∉ A . But A = {2, 5} works, so it is maximum. There always is a maximum (not just maximal) positive autarky, because the union of positive autarkies is a positive autarky.
Each clause ( υ 1 ∨ … ∨ υ s ∨ υ ¯ s + 1 ∨ … ∨ υ ¯ s + t ) of F , where the υ ’s are positive, tells us that υ 1 ∉ A and … and υ s ∉ A implies υ s +j ∉ A , for 1 ≤ j ≤ t . Thus it essentially generates t Horn clauses, whose core is the set of all positive literals not in any positive autarky. A simple variant of Algorithm 7.1.1C will find this core in linear time; namely, we can modify steps C1 and C5 in order to get t Horn clauses from a single clause of F .
[By complementing a subset of variables, and prohibiting another subset, we can find the largest autarky A contained in any given set of strictly distinct literals. This exercise is due to unpublished work of O. Kullmann, V. W. Marek, and M. Truszczyński.]
166. Assume first that PARENT( l 0 ) = Λ, so that H ( l 0 ) = 0 at the beginning of X9 (see X6). Since l 0 = LL[ j ] is not fixed in context T , we have R F \= l 0 by (62). And A = { R F , R F +1 ,...,R E −1 } is an autarky, because no clause touched by A or Ā is entirely false or contains two unfixed literals. Thus we’re allowed to force l 0 true (which is what “do step X12 with l ← l 0 ” means).
On the other hand if w = 0 and PARENT( l 0 ) = p , so that H ( l 0 ) = H ( p ) > 0 in X6, the set A = { R F ,...,R E −1 } is an autarky with respect to the clauses of F | p . Hence the additional clause ( l 0 ∨ p ¯ ) doesn’t make the clauses any less satisfiable, by the black and blue principle. (Notice that ( l ¯ 0 ∨ p ) is already a known clause; so in this case l 0 is essentially being made equal to its parent.)
[The author’s implementation therefore goes further and includes the step
VAL [ | l 0 | ] ← VAL [ | p | ] ⊕ ( ( l 0 ⊕ p ) & 1 ) , ( ∗ )
which promotes the truth degree of l 0 to that of p . This step violates the invariant relation (71), but Algorithm X doesn’t rely on (71).]
167. If a literal l is fixed in context T during the lookahead, it is implied by l 0 . In step X11 we have a case where l is also implied by l ¯ 0 ; hence we’re allowed to force its truth, if l isn’t already proto true. In step X6, l ¯ 0 is implied by l 0 , so l 0 must be false.
168. The following method works well in march : Terminate happily if F = n . (At this point in Algorithm L , F is the number of fixed variables, all of which are really true or really false.) Otherwise find l ∈ { LL[ 0 ] ,..., LL[ S − 1 ] } with l mod2 = 0 and maximum ( H ( l ) + . 1 )(H ( l + 1) + . 1 ) . If l is fixed, set l ← 0. (In that case, Algorithm X found at least one forced literal, although U is now zero; we want to do another lookahead before branching again.) Otherwise, if H ( l ) > H ( l + 1), set l ← l + 1. (A subproblem that is less reduced will tend to be more satisfiable.)
169. When a and b are positive, the function f ( x ) = e − ax + e − bx − 1 is convex and decreasing, and it has the unique root ln τ ( a, b ). Newton’s method for solving this equation refines an approximation x by computing x ′ = x + f ( x ) / ( ae − ax + be − bx ). Notice that x is less than the root if and only if f ( x ) > 0; furthermore f ( x ) > 0 implies f ( x ′) > 0, because f ( x ′) > f ( x )+( x ′ − x ) f ′( x ) when f is convex. In particular we have f (1 / ( a + b )) > 0, because f (0) = 1 and 0′ = 1 / ( a + b ), and we can proceed as follows:
K1. [Initialize.] Set j ← k ← 1, x ← 1 / ( a 1 + b 1 ).
K2. [Done?] (At this point ( a j , b j ) is the best of ( a 1 , b 1 ), … ,( a k , b k ), and e − a j x + e − b j x ≥ 1.) Terminate if k = s . Otherwise set k ← k + 1, x ′ ← 1 / ( a k + b k ).
K3. [Find α , β .] If x ′ < x , swap j ↔ k and x ↔ x ′. Then set α ← e − a j x ′ and β ← e − b j x ′. Go to K2 if α + β ≤ 1.
K4. [Newtonize.] Set x ′ ← x ′ + ( α + β −)/( a j α + b j β ), α ′ ← e − a k x ′ , β ← e − b k x ′ , x ′ ← x ′ + ( α ′ + β ′ − 1)/( a k α′ + b k β ′), and return to K3.
(The floating point calculations should satisfy e u ≤ e υ and u + ω ≤ υ + ω when u < υ .)
170. If the problem is unsatisfiable, Tarjan’s algorithm discovers l and l ¯ in the same strong component. If it’s satisfiable, Algorithm X finds autarkies (because ω is always zero), thus forcing the value of all literals at depth 0.
171. It prevents double-looking on the same literal twice at the same search tree node.
172. When Algorithm Y concludes normally, we’ll have T = BASE + LO[ j ] , even though BASE has changed. This relation is assumed to be invariant in Algorithm X .
173. The run reported in the text, using nonoptimized parameters (see exercise 513 ), did 29,194,670 double-looks (that is, executions of step Y2), and exited 23,245,231 times to X13 in step Y8 (thus successfully forcing l 0 false in about 80% of those cases). Disabling Algorithm Y (i) increased the running time from 0.68 teramems to 1.13 teramems, with 24.3 million nodes. Disabling wraparound (ii) increased the time to 0.85 teramems, with 13.3 million nodes. Setting Y = 1, which disabled wraparound only in Algorithm Y , yielded 0.72 teramems, 11.3 meganodes. (Incidentally, the loops of Algorithm X wrapped around 40% of the time in the regular run, with a mean of 0.62 and maximum of 12; those of Algorithm Y had 20% wraparound, with a mean of 0.25; the maximum Y = 8 was reached only 28 times.) Disabling the lookahead forest (iii) gave surprisingly good results: 0.70 teramems, 8.5 meganodes; there were fewer nodes [hence a more discriminating lookahead], but more time spent per node because of duplicated effort, although strong components were not computed. (Structured problems that have numerous binary clauses tend to generate more helpful forests than random 3SAT problems do.) Disabling compensation resolvents (iv) made very little difference: 0.70 teramems, 9.9 meganodes. But disabling windfalls (v) raised the cost to 0.89 teramems and 13.5 meganodes. And branching on a random l ∈ LL (vi) made the running time soar to 40.20 teramems, with 594.7 meganodes. Finally, disabling Algorithm X altogether (vii) was a disaster, leading to an estimated run time of well over 10 20 mems.
The weaker heuristics of exercise 175 yield 3.09 teramems and 35.9 meganodes.
174. Setting Y to a huge value such as PT will never get to step Y2. (But for (ii), (iii), … , (vii) one must change the programs, not the parameters as they stand.)
175. Precompute the weights, by setting K 2 = 1 and K s ← γK s −1 + . 01, for s between 3 and the maximum clause size. (The extra .01 keeps this from being zero.) The third line of (72) must change to “take account of c for all c in KINX( L ¯ ) ,” where that means “set s ← CSIZE( c ) − 1; if s ≥ 2, set CSIZE( c ) ← s and ω ← ω + K s ; otherwise if all literals of c are fixed false, set a flag; otherwise if some literal u of c isn’t fixed (there will be just one), put it on a temporary stack.” Before performing the last line of (72), go to CONFLICT if the flag is set; otherwise, for each unfixed u on the temporary stack, set W i ← u and i ← i +1 and perform (62) with l ← u ; go to CONFLICT if some u on the temporary stack is fixed false. (A “windfall” in this more general setting is a clause for which all but one literal has been fixed false as a consequence of l 0 being fixed true.)
Of course those changes to CSIZE need to be undone; a simulated false literal that has been “virtually” removed from a clause must be virtually put back. Fortunately, the invariant relation (71) makes this task fairly easy: We set G ← F in step X5, and insert the following restoration loop at the very beginning of (72): “While G > F , set u ← R G −1 ; stop if u is fixed in context T ; otherwise set G ← G − 1, and increase CSIZE( c ) by 1 for all c ∈ KINX( u ¯ ) .” The restoration loop should also be performed, with T ← NT , just before terminating Algorithm X in steps X7 or X13.
[The additional step (∗) in answer 166 can’t be used, because (71) is now crucial.]
Algorithm Y should change in essentially the same way as Algorithm X .
[See O. Kullmann, Report CSR 23-2002 (Swansea: Univ. of Wales, 2002), §4.2.]
176. (a) a j −−− a j +1 , a j −−− b j , a j −−− b j +1 , b j −−− c j , b j −−− d j , c j −−− d j , c j −−− e j , d j −−− f j , e j −−− d j +1 , e j −−− f j +1 , f j −−− c j +1 , f j −−− e j +1 .
(b) Let ( t j , u j , υ j , ω j , a j , b j , c j , d j , e j , f j ) have colors (1, 2, 1, 1, 1, 2, 1, 3, 3, 2) when j is even, (2, 1, 2, 2, 3, 2, 3, 1, 1, 2) when j is odd. The lower bounds are obvious.
(c) Vertices a j , e j , f j can’t all have the same color, because b j , c j , d j have distinct colors. Let α j denote the colors of a j e j f j . Then α j \= 112 implies α j +1 \= 332 or 233; α j \= 121 implies α j +1 \= 233 or 323; α j \= 211 implies α j +1 \= 323 or 332; α j \= 123 implies α j +1 \= 213 or 321. Since α 1 = α q +1 , the colors of α 1 must be distinct, and we can assume that α 1 = 123. But then α j will be an odd permutation whenever j is even.
[See Rufus Isaacs, AMM 82 (1975), 233–234. Unpublished notes of E. Grinberg show that he had independently investigated the graph J 5 in 1972.]
177. There are 20 independent subsets of V j \= { a j , b j , c j , d j , e j , f j } when q > 1; eight of them contain none of { b j , c j , d j } while four contain b j . Let A be a 20 × 20 transition matrix, which indicates when R ∪ C is independent for each independent subset R ⊆ V j and C ⊆ V j +1 . Then I q is trace( A q ); and the first eight values are 8, 126, 1052, 11170, 112828, 1159416, 11869768, 121668290. The characteristic polynomial of A , x 12 ( x 2 − 2 x − 1)( x 2 + 2 x − 1)( x 4 − 8 x 3 − 25 x 2 + 20 x + 1), has nonzero roots ± 1 ± 2 and ≈ −2 . 91, −0 . 05, + 0 . 71, + 10 . 25; hence I q \= Θ( r q ), where r ≈ 10 . 24811166 is the dominant root. Note: The number of kernels of L ( J q ) is respectively 2, 32, 140, 536, 2957, 14336, 70093, 348872, for 1 ≤ q ≤ 8, and its growth rate is ≈ 4 . 93 q .
178. With the first ordering, the top 18 k levels of the search tree essentially represent all of the ways to 3-color the subgraph { a j , b j , c j , d j , e j , f j | 1 ≤ j ≤ k }; and there are Θ(2 k ) ways to do that, by answer 176 . But with the second ordering, the top 6 kq levels essentially represent all of the independent sets of the graph; and there are Ω(10 . 2 k ) of those, by answer 177 .
Empirically, Algorithm B needs respectively 1.54 megamems, 1.57 gigamems, and 1.61 teramems to prove unsatisfiability when q = 9, 19, and 29, using the first ordering; but it needs 158 gigamems already for q = 5 with the second! Additional clauses, which require color classes to be kernels (see answer 14 ), reduce that time to 492 megamems.
Algorithm D does badly on this sequence of problems: When q = 19, it consumes 37.6 gigamems, even with the “good” ordering. And when q = 29, its cyclic method of working somehow transforms the good ordering into a bad ordering on many of the variables at depths 200 or more. It shows no sign of being anywhere near completion even after spending a petamem on that problem!
Algorithm L , which is insensitive to the ordering, needs 2.42 megamems, 2.01 gigamems, and 1.73 teramems when q = 9, 19, and 29. Thus it appears to take Θ(2 q ) steps, and to be slightly slower than Algorithm B as q grows, although exercise 232 shows that a clairvoyant lookahead procedure could theoretically do much better.
Algorithm C triumphs here, as shown in Fig. 92 .
179. This is a straightforward exact cover problem. If we classify the solutions according to how many asterisks occur in each coordinate, it turns out that exactly (10, 240, 180, 360, 720, 480, 1440, 270, 200, 480) of them are respectively of type (00088, 00268, 00448, 00466, 02248, 02266, 02446, 04444, 22228, 22246).
By complementation, we see that 4380 choices of 8 clauses are unsatisfiable; hence q 8 \= 1 − 4380 / ( 80 8 ) \= 1 − 4380 / 28987537150 ≈ 0.9999998 .
180. With N variables y j , one for each possible clause C j , the function f ( y 1 ,...,y N ) = [ ∧ { C j | y j \= 1} is satisfiable ] is ∨ x f x ( y ), where f x ( y ) = [x satisfies ∧ { C j | y i \= 1}] is simply ∧ { y ¯ i | x makes C j false}. For instance if k = 2 and n = 3, and if C 1 , C 7 , C 11 are the clauses ( x 1 ∨ x 2 ) , ( x 1 ∨ x ¯ 3 ) , ( x 2 ∨ x ¯ 3 ) , then f 001 ( y 1 , … , y 12 ) \= y ¯ 1 ∧ y ¯ 7 ∧ y ¯ 11 .
Each function f x has a very simple BDD, but of course the OR of 2 n of them will not be simple. This problem is an excellent example where no natural ordering of the clause variables is evident, but the method of sifting is able to reduce the BDD size substantially. In fact, the clauses for k = 3 and n = 4 can be ordered cleverly so that the corresponding 32-variable BDD for satisfiability has only 1362 nodes! The author’s best result for k = 3 and n = 5, however, was a BDD of size 2,155,458. The coefficients of its generating function (exercise 7.1.4–25) are the desired numbers Q m .
The largest such count, Q 35 = 3,449,494,339,791,376,514,416, is so enormous that we could not hope to enumerate the relevant sets of 35 clauses by backtracking.
181. The previous exercise essentially computed the generating function Σ m Q m z m ; now we want the double generating function Σ l,m T l,m ω l z m , where T l,m is the number of ways to choose m different k -clauses in such a way that these clauses are satisfied by exactly l vectors x 1 …x n . To do this, instead of taking the OR of the simple functions f x , we compute the BDD base that contains all of the symmetric Boolean functions S l ( f 0 ... 0 ,...,f 1 ... 1 ) for 0 ≤ l ≤ 2 n , as follows (see exercise 7.1.4–49): Consider the subscript x to be a binary integer, so that the functions are f x for 0 ≤ < 2 n . Start with S l \= 0 for −1 ≤ l ≤ 2 n , except that S 0 = 1. Then do the following for x = 0, … , 2 n − 1 (in that order): Set S l \= f x ? S l − 1 : S l for l = x +1, … , 0 (in that order).
After this computation, the generating function for S l will be Σ m T l,m z m . In the author’s experiments, the sifting algorithm found an ordering of the 80 clauses for k = 3 and n = 5 so that only about 6 million nodes were needed when x had reached 24; afterwards, however, sifting took too long, so it was turned off. The final BDD base had approximately 87 million nodes, with many nodes shared between the individual functions S l . The total running time was about 22 gigamems.
182. T 0 = 32 and T 1 = 28 and T m \= 0 for 71 ≤ m ≤ 80. Otherwise min T m < max T m .
183. Let t m \= Pr( T m \= 1), and suppose that we obtain clauses one by one until reaching an unsatisfiable set. The fact that t m gets reasonably large suggests that we probably have accumulated a uniquely satisfiable set just before stopping. (That probability is 2 − k N Σ m t m /( N − m ), which turns out to be ≈ 0 . 8853 when k = 3 and n = 5.)
However, except for the fact that both Figs. 85 and 86 are bell-shaped curves with roughly the same tendency to be relatively large or small at particular values of m , there is apparently no strong mathematical connection. The probabilities in Fig. 86 sum to 1; but the sum of probabilities in Fig. 85 has no obvious significance.
When n is large, uniquely satisfiable sets are encountered only rarely. The final set before stopping a.s. has at most f ( n ) solutions, for certain functions f ; but how fast does the smallest such f grow? [See D. J. Aldous, J. Theoretical Probability 4 (1991), 197–211, for related ideas.]
184. The probability q ^ m is Q ^ m / N m , where Q ^ m counts the choices ( C 1 ,...,C m ) for which C 1 ∧…∧ C m is satisfiable. The number of such choices that involve t distinct clauses is t ! { m t } times Q t , because { m t } enumerates set partitions; see Eq. 3.3.2–(5).
185. q ^ m \= Σ t \= 0 N { m t } t ! q t ( N t ) / N m ≥ q m Σ t \= 0 N { m t } t ! ( N t ) / N m \= q m .
186. Σ m Σ t { m t } t ! q t ( N t ) N − m can be summed on m , since Σ m { m t } N − m \= 1 / ( N − t ) t ¯ by Eq. 1.2.9–(28). Similarly, the derivative of 1.2.9–(28) shows that Σ m m { m t } N − m \= ( N / ( N − 1 ) + … + N / ( N − t ) ) / ( N − t ) t ¯ .
187. In this special case, q m \= [0 ≤ m<N ] and p m \= [ m = N ]; hence S n,n \= N = 2 n (and the variance is zero). By (78), we also have S ^ n , n \= N H N ; indeed, the coupon collector’s test (exercise 3.3.2–8) is an equivalent way to view this situation.
188. Now q m \= 2 m n m ¯ / ( 2 n ) m ¯ . It follows by (78) that S ^ 1 , n \= Σ m \= 0 n 2 m n m ¯ / ( 2 n − 1 ) m ¯ , because N = 2 n . The identity 2 m n m ¯ / ( 2 n − 1 ) m ¯ \= 2 q m − q m + 1 yields the surprising fact that S ^ 1 , n \= ( 2 q 0 − q 1 ) + ( 2 q 1 − q 2 ) + … 1 + S 1 , n ; and we also have S ^ 1 , n − 1 \= 2 n 2 n − 1 S 1 , n − 1 . Hence, by induction, we obtain the (even more surprising) closed forms
S 1 , n \= 4 n / ( 2 n n ) , S ^ 1 , n \= 4 n / ( 2 n n ) + 1.
So random 1SAT problems become unsatisfiable after π n + O ( 1 ) clauses, on average.
189. With the auto sifting method in the author’s experimental BDD implementation, the number of BDD nodes, given a sequence of m distinct clauses when k = 3 and n = 50, increased past 1000 when m increased from 1 to about 30, and it tended to peak at about 500,000 when m was slightly more than 100. Then the typical BDD size fell to about 50,000 when m = 150, and to only about 500 when m = 200.
BDD methods break down when n is too large, but when they apply we can count the total number of solutions remaining after m steps. In the author’s tests with k = 3, n = 50, and m = 200, this number varied from about 25 to about 2000.
190. For example, S 1 ( x 1 ,...,x n ) can’t be expressed in ( n − 1)CNF: All clauses of length n − 1 that are implied by S 1 ( x 1 ,...,x n ) are also implied by S ≤ 1 ( x 1 ,...,x n ).
191. Let f ( x 0 ,...,x 2 n −1 ) = 1 if and only if x 0 …x 2 n −1 is the truth table of a Boolean function of n variables that is expressible in k CNF. This function f is the conjunction of 2 n constraints c ( t ), for 0 ≤ t = ( t 0 …t 2 n −1 ) 2 < 2 n , where c ( t ) is the following condition: If x t \= 0, then ∨ { x y | 0 ≤ y < 2 n , ( y ⊕ t ) & m = 0} is 0 for some n -bit pattern m that has vm = k . By combining these constraints we can compute the BDD for f when n = 4 and k = 3; it has 880 nodes, and 43,146 solutions.
Similarly we have the following results, analogous to those in Section 7.1.1:
n \= 0 n \= 1 n \= 2 n \= 3 n \= 4 n \= 5 n \= 6 1 CNF 2 4 10 28 82 244 730 2 CNF 2 4 16 166 4 , 170 224 , 716 24 , 445 , 368 3 CNF 2 4 16 256 43 , 146 120 , 510 , 132 4 , 977 , 694 , 100 , 656
And if we consider equivalence under complementation and permutation, the counts are:
1 CNF 2 3 4 5 6 7 8 2 CNF 2 3 6 14 45 196 1 , 360 3CNF 2 3 6 22 253 37 , 098 109 , 873 , 815
192. (a) S ( p ) \= Σ m \= 0 N p m ( 1 − p ) N − m Q m . (b) We have ∫ 0 N ( t / N ) m ( 1 − t / N ) N − m d t \= N B ( m + 1 , N − m + 1 ) \= N N + 1 / ( N m ) , by exercises 1.2.6–40 and 41; hence S ¯ k , n \= N N + 1 Σ m \= 0 N q m \= N N + 1 S k , n . [See B. Bollobás, Random Graphs (1985), Theorem II.4.]
194. A similar question, about proofs of un satisfiability when α > lim sup n →∞ S 3, n /n , is also wide open.
195. E X = 2 n Pr(0 … 0 satisfies all) = 2 n (1 − 2 − k ) m \= exp( n ln 2 + m ln(1 − 2 − k )) < 2 exp(−2 − k −1 n ln 2). Thus S k (⌊(2 k ln 2) n ⌋ ,n ) = Pr( X > 0) ≤ exp(−Ω( n )). [ Discrete Applied Math. 5 (1983), 77–87. Conversely, in J. Amer. Math. Soc. 17 (2004), 947–973, D. Achlioptas and Y. Peres use the second moment principle to show that (2 k ln 2 − O ( k ) )n random k SAT clauses are almost always satisfiable by vectors x with vx ≈ n/ 2. Careful study of “ covering assignments” (see exercise 364 ) leads to the sharp bounds
2 k ln 2 − 1 + ln 2 2 O ( 2 − k 3 ) ≤ lim inf n → ∞ α k ( n ) ≤ lim sup α k ( n ) ≤ 2 k ln 2 − 1 + ln 2 2 + O ( 2 − k 3 ) ;
see A. Coja-Oghlan and K. Panagiotou, Advances in Math. 288 (2016), 985–1068.]
196. The probability is ( ( n − t ) k ¯ / n k ¯ ) α n + O ( 1 ) \= e − k t α ( 1 + O ( 1 / n ) ) that αn + O (1) random k SAT clauses omit t given letters. Let p = 1 − (1 − e − kα ) k . By inclusion and exclusion, the first clause will be easy with probability p (1 + O (1 /n )), and the first two will both be easy with probability p 2 (1 + O (1 /n )). Thus if X \= Σ j \= 1 m [clause j is easy], we have E X = pm + O (1) and E X 2 = p 2 m 2 + O ( m ). Hence, by Chebyshev’s inequality, Pr ( | X − p m ) | ≥ r m \= O ( 1 / r 2 ) .
197. By Stirling’s approximation, ln q ( a, b, A, B, n ) = nf ( a, b, A, B ) + g ( a, b, A, B ) − 1 2 ln 2 πn − ( δ an − δ ( a + b ) n ) − ( δ bn − δ ( b + B ) n ) − ( δ An − δ ( a + A ) n ) − ( δ Bn − δ ( A + B ) n ) − δ ( a + b + A + B ) n , where δ n is positive and decreasing. And we must have f ( a, b, A, B ) ≤ 0, since q ( a, b, A, B, n ) ≤ 1. The O estimate is uniform when 0 < δ ≤ a, b, A, B ≤ M .
198. Consider one of the N M possible sequences of M 3SAT clauses, where N \= 8 ( n 3 ) and M = 5 n . By exercise 196 it contains g = 5(1 − (1 − e −15 ) 3 )n + O ( n 3/4 ) easy clauses, except with probability O ( n −1/2 ). Those clauses, though rare, don’t affect the satisfiability; and all ( M g ) of the ways to insert them among the r = M − g others are equally likely, so they tend to dampen the transition.
Let l ≤ r be maximum so that the first l noneasy clauses are satisfiable, and let p ( l, r, g, m ) be the probability that, when drawing m balls from an urn that contains g green balls and r red balls, at most l balls are red. Then S 3 ( m, n ) = p ( l, r, g, m ) /N M and S 3 ( m ′ ,n ) = Σ p ( l, r, g, m ′) /N M , summed over all N M sequences.
To complete the proof we shall show that
p ( l , r , g , m + 1 ) \= p ( l , r , g , m ) − O ( n − 1 / 2 ) when 3.5 n < m < 4.5 n ;
hence S 3 ( m + 1 ,n ) = S 3 ( m, n ) − O ( n −1/2 ), S 3 ( m, n ) − S 3 ( m ′ ,n ) = O (( m ′ − m ) n −1/2 ). Notice that p ( l, r, g, m ) = p ( l, r, g, m +1) when m < l or m > l + g ; thus we may assume that l lies between 3 . 4 n and 4 . 6 n . Furthermore the difference
d m \= p ( l , r , g , m ) − p ( l , r , g , m + 1 ) \= ( m 1 ) ( r + g − m − 1 r − l − 1 ) ( r + g r ) \= ( m l ) ( r + g − m r − 1 ) ( r + g r ) r − l r + g − m
has a decreasing ratio d m /d m − 1 = ( m/ ( m − l ) )( ( l + g + 1 − m )/( r + g − m )) when m increases from l to l + g . So max d m occurs at m ≈ l ( r + g ) /r , where this ratio is ≈ 1. Now exercise 197 applies with a = l/n , b = ρg/n , A = ( r − l ) /n , B = (1− ρ ) g/n , ρ = l/r .
[D. B. Wilson, in Random Structures & Algorithms 21 (2002), 182–195, showed that similar methods apply to many other threshold phenomena.]
199. (a) Given the required letters { a 1 ,..., a t }, there are m ways to place the leftmost a 1 , then m – 1 ways to place the leftmost a 2 , and so on; then there are at most N ways to fill in each of the remaining m – t slots.
(b) By inclusion and exclusion: There are ( N – k ) m words that omit k of the letters.
(c) N − m ∑ k ( t k ) ( − 1 ) k ∑ j ( m j ) N m − j ( − k ) j \= ∑ j ( m j ) ( − 1 ) j + t N − j A j , where A j \= ∑ k ( t k ) ( − 1 ) t − k k j \= { j t } t ! by Eq. 1.2.6–(53).
200. (a) The unsatisfiable digraph must contain a strong component with a path
l ¯ t → l 1 → … → l t → l t + 1 → … → l l \= l ¯ t ,
where l 1 , ..., l t are strictly distinct. This path yields an s -snare ( C ; t, u ) if we set s to the smallest index such that | l s +1 | = | l u | for some u with 1 ≤ u < s .
(b) No: ( x ∨ y ) ∧ ( y ¯ ∨ x ) ∧ ( x ¯ ∨ y ) and ( x ∨ y ) ∧ ( y ¯ ∨ x ) ∧ ( x ¯ ∨ y ¯ ) are both satisfiable.
(c) Apply exercise 199(a) with t = s +1, N = 2 n ( n – 1); note that m s + 1 ¯ ≤ m s + 1 .
201. (a) Set ( l i , l i +1 ) ← ( x 1 ,x 2 ) or ( x ¯ 2 , x ¯ 1 ) , where 0 ≤ i < 2 t (thus 4 t ways).
(b) Set ( l i , l i +1 , l i +2 ) ← ( x 1 , x 2 , x 3 ) or ( x ¯ 3 , x ¯ 2 , x ¯ 1 ) , where 0 ≤ i < 2 t ; also ( l ¯ , l t , l t + 1 ) or ( l t − 1 , l t , l ¯ 2 t − 1 ) ← ( x 1 , x 2 , x 3 ) or ( x ¯ 3 , x ¯ 2 , x ¯ 1 ) (total 4 t + 4 ways, if t >2).
(c) ( l 1 , l t – 1 , l t ) or ( l ¯ 2 t − 1 , l ¯ t + 1 , l ¯ t ) ← ( x 1 , x t − 1 , x t ) or ( x ¯ t − 1 , x ¯ t , x t ) (4 ways).
(d) l i or l ¯ 2 t − i ← x i or x ¯ t − i , for 1 ≤ i ≤ t (4 ways, if you understand this notation).
(e) By part (a), it is 2 t × 4 t = 8 t 2 .
(f) Parts (b) and (c) combine to give N (3 , 2) = (2 t + 2) × (4 t + 4) + 2 × 4 = 8( t 2 +2 t + 2) when t > 2. From part (d), N ( t, t ) = 8. Also N (2 t – 1 , 2 t ) = 8; this is the number of snakes that specify the same 2 t clauses. (Incidentally, when t = 5 the generating function ∑ q,r N ( q, r ) w q z r is 1 + 200 w 2 z 1 + (296 w 3 + 7688 w 4 ) z 2 + (440 w 4 + 12800 w 5 + 55488 w 6 ) z 3 + (640 w 5 + 12592 w 6 + 66560 w 7 + 31104 w 8 ) z 4 +(8 w 5 + 736 w 6 + 8960 w 7 + 32064 w 8 + 6528 w 9 ) z 5 + (32 w 6 + 704 w 7 + 4904 w 8 + 4512 w 9 ) z 6 + (48 w 7 + 704 w 8 + 1232 w 9 ) z 7 + (64 w 8 + 376 w 9 ) z 8 +80 w 9 z 9 +8 w 9 z 10 .)
(g) The other l ’s can be set in at most 2 2 t − 1 − q ( n − q ) 2 t − 1 − q ¯ \= R / ( 2 q n q ¯ ) ways.
(h) We may assume that r < 2 t . The r chosen clauses divide into connected components, which are either paths or a “central” component that contains either ( x ¯ 0 ∨ x 1 ) and ( x ¯ t − 1 ∨ x t ) or ( x ¯ t ∨ x t + 1 ) and ( x ¯ 2 t − 1 ∨ x 0 ) . Thus q equals r plus the number of components, minus 1 if the central component includes a cycle. If the central component is present, we must set l t ← x t or x ¯ t , and there are at most 8 ways to complete the mapping of that component. And N ( r, r ) = 16( r +1– t ) for t < r < 2 t .
Cases with k > 0 paths can be chosen in at most ( 2 t + 2 2 k ) ways, because we choose the starting and ending points, and they can be mapped in at most 2 k k ! ( 2 t + 2 2 k ) ways; so they contribute ∑ k >0 O ( t 4 k k/ ( k ! 3 n k )) = O ( t 4 /n ) to (2 n ) r p r . The noncyclic central components, which can be chosen in Θ( t 4 ) ways, also contribute O ( t 4 / n ).
202. (a) m ( m − 1 ) ... ( m − r + 1 ) / m r ≥ 1 − ( r 2 ) / m ; (2 n ( n –1)– r ) m – r /(2 n ( n –1)) m – r ≥ 1 – ( m – r ) r /(2 n ( n – 1)) when r ≤ m < 2 n ( n – 1); and both factors are ≤ 1.
(b) The term of (95) for r = 0 is 1 plus a negligible error. The contribution of O ( t 4 / n ) for r > 0 is O ( n 4/5+1/6–1 ), because ∑ r ≥0 (1 + n –1/6 ) – r \= n 1/6 + 1. And the contributions of (96) to (95) for r ≥ t are exponentially small, because in that range we have (1 + n –1/6 ) – t \= exp(– t ln(1 + n –1/6 )) = exp(–Ω( n 1/30 )). Finally, then, by the second moment principle MPR–(22), S 2 (⌊ n + n 5/6 ⌋ ,n ) ≤ 1 – Pr( X > 0) ≤ 1 – (E X ) 2 /(E X 2 ) = 1 – 1/((E X 2 )/(E X ) 2 ) = 1 – 1/(1+ O ( n –1/30 )) = O ( n –1/30 ).
203. (a) E X = d n E X (1 ,..., 1), by symmetry; and E X (1 ,..., 1) = (1 – p ) m , because each set of q clauses is falsified with probability p . So E X = exp(( r ln(1 – p )+1) n ln d ) is exponentially small when r ln(1 – p )+1 < 0; and we know that Pr( X > 0) ≤ E X .
(b) Let θ s \= ( s 2 ) / ( n 2 ) \= s ( s − 1 ) n ( n − 1 ) , and consider a random constraint set, given that X (1,..., 1) = 1. With probability θ s , both u and v have color 1 and the constraint is known to be satisfied. But with probability 1– θ s , it holds with probability ( d 2 − 2 q ) / ( d 2 − 1 q ) . Thus p s \= ( θ s +(1 – θ s )( d 2 – pd 2 – 1)/( d 2 – 1)) m .
(c) We have Pr( X > 0) ≥ d n (1 – p ) m / E( X | X (1,..., 1) = 1), from the inequality and symmetry; and the denominator is Σ s \= 0 n ( n s ) ( d − 0 ) n − s p s . We can replace p s by the simpler value p s ′ \= ( 1 − p + p s 2 / n 2 ) m , because p s < ( θ s + ( 1 − θ s ) ( 1 − p ) ) m \= ( 1 − p + θ s p ) m < p s ′ . And we can divide the simplified sum by d n (1 – p ) m .
(d) We have ∑ s \= 0 3 n / d t s \= e O ( m / d 2 ) ∑ s \= 0 3 n / d ( n s ) ( 1 d ) s ( 1 − 1 d ) n − s , because s 2 /n 2 = O (1 /d 2 ) when s ≤ 3 n/d . This sum is ≥ 1 – ( e 2 /27) n/d by exercise 1.2.10–22; and the crucial assumption that α > 1 2 makes m/d 2 → 0.
(e) Transition between increase and decrease occurs when x s ≈ 1; and we have
x s \= n − s s + 1 1 d − 1 ( 1 + ( 2 s + 1 ) p ( 1 − p ) n 2 + p s 2 ) m ≈ exp ( ln 1 − σ σ + ( 2 p r σ 1 − p + p σ 2 − 1 ) ln d )
when s = σn . Let f ( σ ) = 2 prσ/ (1 – p + pσ 2 ) – 1, and notice that f ′ ( σ ) > 0 for 0 ≤ σ < 1 because p ≤ 1 2 . Furthermore our choice of r makes f ( 1 2 ) < 0 < f ( 1 ) . Setting g ( σ ) \= f ( σ ) / ln σ 1 − σ , we seek values of σ with g ( σ ) = 1/ ln d . There are three such roots, because g (1 /N ) ≈ – f (0)/ ln N ≥ 1/ ln N ; g ( 1 2 ± 1 / N ) ≈ ∓ f ( 1 2 ) N / 4 ; and g (1 – 1 /N ) ≈ f (1)/ ln N .
(f) At the second peak, where s = n – n/d f (1) , we have (see exercise 1.2.6–67)
t s < ( n e d n − s ) n − s ( 1 d ) n ( 1 + p 1 − p ) m \= exp ( ( − ε + O ( 1 / d f ( 1 ) ) ) n ln d ) ,
which is exponentially small. And when s = 3 n / d , t s < ( n e s d ) s e O ( m / d 2 ) \= O ( ( e / 3 ) 3 n / d ) is also exponentially small. Consequently Σ s \= 3 n / d n t s is exponentially small.
[This derivation holds also when the random constraints are k -ary instead of binary, with q = pd k and α> 1 /k . See J. Artificial Intelligence Res. 12 (2000), 93–103.]
204. (a) If the original literals ± x j that involve variable x j correspond to σ 1 X i (1) , ... , σ p X i ( p ) , with signs σ h , add the clauses (– σ h X i ( h ) ∨ σ h + X i ( h +) ) for 1 ≤ h ≤ p to enforce consistency, where h + = 1+( h mod p ). (This transformation, due to C. A. Tovey, works even in degenerate cases. For example, if m = 1 and if the given clause is ( x 1 ∨ x 1 ∨ x ¯ 2 ) , the transformed clauses are ( X 1 ∨ X 2 ∨ X 3 ), ( X ¯ 1 ∨ X 2 ) , ( X ¯ 2 ∨ X 1 ) , ( X 3 ∨ X ¯ 3 ) .)
(b) (Solution by E. Wynn.) The following 44 clauses in 35 variables are satisfiable if and only if each variable is false: a i ∨ b ¯ i ∨ c i , a ¯ i ∨ b ¯ i ∨ c i , b ¯ i ∨ c ¯ i ∨ d ¯ i , c ¯ i ∨ d i ∨ e i , d i ∨ e ¯ i ∨ f i , e ¯ i ∨ f ¯ i ∨ g ¯ i , f ¯ i ∨ g i ∨ h i , f ¯ i ∨ g i ∨ h ¯ i , for i ∈ {1, 2}; b 1 ∨ b 2 ∨ A ¯ , A ∨ B ∨ C ¯ , A ∨ B ¯ ∨ D , A ∨ D ¯ ∨ E , B ¯ ∨ D ¯ ∨ E ¯ , B ∨ C ∨ F ¯ 1 , C ∨ E ¯ ∨ G 1 , C ∨ F 1 ∨ G ¯ 1 ; F j ∨ G j ∨ F ¯ j + 1 , F j ∨ G j ∨ G ¯ j + 1 , for 1 ≤ j ≤ 6; D ∨ E ∨ ā 1 , F 2 ∨ G 2 ∨ ā 2 , F 3 ∨ G 3 ∨ h ¯ 1 , F 4 ∨ G 4 ∨ h ¯ 2 , a 1 ∨ h 1 ∨ d ¯ 1 , a 2 ∨ h 2 ∨ d ¯ 2 , F 5 ∨ G 5 ∨ g ¯ 1 , F 6 ∨ G 6 ∨ g ¯ 2 .
(c) Add the clauses of (b), and the clauses F j ∨ G j ∨ F ¯ j + 1 , F j ∨ G j ∨ G ¯ j + 1 for 7 ≤ j ≤ ⌈3 m/ 2⌉ + 3, to the 4 m clauses of (a). We can stick the literals { F 7 ,G 7 ,... }, which are always false, into the 2-clauses without using any variable five times, obtaining at most (7 m +39) 3-clauses in N ≈ 7 m + 30 variables.
205. (a) After F 0 = { ϵ }, F 1 = F 0 ⊔ F 0 , F 2 = F 0 ⊔ F 1 , F 3 = F 0 ⊔ F 2 , F 4 \= F 3 ⊔ F 3 ′ , F 5 \= F 4 ⊔ F 4 ″ , always putting the new variable into the four shortest possible clauses, we get F 5 = {345, 2 3 ¯ 4 , 1 2 ¯ 3 ¯ , 1 ¯ 2 ¯ 3 ¯ , 3 ′ 4 ¯ 5 , 2 ′ 3 ¯ ′ 4 ¯ , 1 ′ 2 ¯ ′ 3 ¯ ′ , 1 ¯ ′ 2 ¯ ′ 3 ¯ ′ , 3 " 4 " 5 ¯ , 2 " 3 ¯ " 4 " , 1 " 2 ¯ " 3 ¯ " , 1 ¯ " 2 ¯ " 3 ¯ " , 3 ′ " 4 ¯ " 5 ¯ , 2 ′ " 3 ¯ ′ " 4 ¯ ′ ′ , 1 ′ " 2 ¯ ′ " 3 ¯ ′ ′ ′ , 1 ¯ ′ " 2 ¯ ′ " 3 ¯ ′ ′ ′ }.
(b) Let F 0 = { ε }, F 1 = F 0 ⊔ F 0 , F 2 = F 0 ⊔ F 1 , F 3 = F 0 ⊔ F 2 , F 4 = F 0 ⊔ F 3 , F 5 = F 1 ⊔ F 4 , F 6 = F 0 ⊔ F 5 , F 7 = F 0 ⊔ F 6 , F 8 \= F 4 ⊔ F 7 ′ , F 9 = F 0 ⊔ F 8 , F 10 \= F 7 ⊔ F 9 ′ , F 11 \= F 7 ⊔ F 10 ′ , F 12 = F 0 ⊔ F 11 , F 13 \= F 9 ⊔ F 12 ″ , F 14 \= F 10 ⊔ F 12 ( 3 ) , F 15 \= F 12 ⊔ F 14 ( 4 ) , F 16 \= F 13 ⊔ F 14 ( 6 ) , F 17 \= F 14 ⊔ F 15 ( 7 ) , F 18 \= F 16 ⊔ F 17 ( 13 ) . (Here ‘ x (3) ’ stands for ‘ x ′" ’, etc.) Then F 18 consists of 257 unsatisfiable 4-clauses in 234 variables.
(This problem was first solved by J. Stříbrná in her M.S. thesis (Prague: Charles University, 1994), with 449 clauses. The ⊔ method was introduced by S. Hoory and S. Szeider, Theoretical Computer Science 337 (2005), 347– 359, who presented an unsatisfiable 5SAT problem that uses each variable at most 7 times. It’s not known whether 7 can be decreased to 6 when every clause has size 5. See T. Zhang, T. Peitl, and S. Szeider, arXiv:2405.16149 [cs.DM] (2024), 25 pages.)
206. Suppose F and F ′ are minimally unsatisfiable, and delete a clause of F ⊔ F ′ that arose from F ′ ; then we can satisfy F ⊔ F ′ with x true.
Conversely, if F ⊔ F ′ is minimally unsatisfiable, F and F ′ can’t both be satisfiable. Suppose F is unsatisfiable but F ′ is satisfied by L ′ . Removing a clause of F ⊔ F ′ that arose from F ′ is satisfiable only with x true; but then we can use L ′ to satisfy F ⊔ F ′ . Hence F and F ′ are both unsatisfiable. Finally, if F \ C is unsatisfiable, so is ( F ⊔ F ′ ) \ ( C | x ¯ ) , because any solution would satisfy either F \ C or F ′ .
207. The five clauses of C ( x , y , z ; a , b , c ) \= { x a ¯ b , y b ¯ c , z c ¯ a , a b c , a ¯ b ¯ c ¯ } resolve to the single clause xyz . Thus C ( x , y , y ; 1 , 2 , 3 ) ∪ C ( x , y ¯ , y ¯ ; 4 , 5 , 6 ) ∪ C ( x ¯ , z , z ; 7 , 8 , 9 ) ∪ C ( x ¯ , z ¯ , z ¯ ; a , b , c ) is a solution. [K. Iwama and K. Takaki, DIMACS 35 (1997), 315–333, noted that the 16 clauses { x ¯ y ¯ z ¯ } ∪ C ( x, x, x ;1 , 2 , 3) ∪ C ( y, y, y ; 4 , 5 , 6) ∪ C ( z, z, z ; 7 , 8 , 9) involve each variable exactly four times, and proved that no set of twelve clauses does so.]
208. Make m clones of all but one of the 20 clauses in answer 207 , and put the other 3 m cloned literals into the 3 m binary clauses of answer 204(a) . This gives 23 m 3-clauses in which every literal occurs twice, except that the 3 m literals X ¯ i occur only once.
To complete the solution, we “pad” them with additional clauses that are always satisfiable. For example, we could introduce 3 m more variables u i , with new clauses X ¯ i u i u ¯ i + 1 for 1 ≤ i ≤ 3 m and { u 3 j ′ u 3 j + 1 ′ u 3 j + 2 ′ , u ¯ 3 j ′ u ¯ 3 j + 1 ′ u ¯ 3 j + 2 ′ } for 1 ≤ j ≤ m (treating subscripts mod 3 m ), where u i ′ denotes ( i even? u i : ū i ).
209. Since the multiset of kt literals in any t clauses contains at least t different variables, the “ marriage theorem” (Theorem 7.5.1H) implies that we can choose a different variable in each clause, easily satisfying it. [ Discr. Applied Math. 8 (1984), 85–89.]
210. [P. Berman, M. Karpinski, A. D. Scott, Electronic Colloquium on Computational Complexity (2003), TR22.] This answer uses the magic number ε = δ 7 ≈ 1/58, where δ is the smallest root of δ ((1 – δ 7 ) 6 +(1 – δ 7 ) 7 ) = 1. We will assign random values to each variable so that Pr[all clauses are satisfied] > 0.
Let η j \= (1 – ε ) j /((1 – ε ) j +(1 – ε ) 13– j ), and observe that η j ≤ δ (1 – ε ) j for 0 ≤ j ≤ 13. If variable x occurs d + times and x ¯ occurs d – times, let x be true with probability η d – , false with probability 1 – η d – \= η 13– d – ≤ δ (1 – ε ) 13– d – ≤ δ (1 – ε ) d + .
Let bad( C ) = [clause C is falsified by the random assignment], and construct the lopsidependency graph for these events as in exercise 351 . Then, if the literals of C = ( l 1 ∨ … ∨ l 7 ) have contrary appearances in d 1 , ... , d 7 other clauses, we have
Pr(bad( C )) ≤ ( δ (1 – ε ) d 1 ) ... ( δ (1 – ε ) d 7 ) = ε (1 – ε ) d 1+…+ d 7 ≤ ε (1 – ε ) degree( C ) , because C has at most d 1 + … + d 7 neighbors. Theorem L, with parameter θ i \= ε for each event bad( C ), now tells us that Pr[all m clauses are satisfied] ≥ (1 – ε ) m .
[See H. Gebauer, T. Szabó, and G. Tardos, JACM 63 (2016), 43:1–43:32, for asymptotic results that apply to k SAT as k → ∞.]
211. If m clauses in n variables are given, so that 3 m = 4 n , let N = 8 n . Consider N “colors” named jk or j k ¯ , where 1 ≤ j ≤ n and k is one of the four clauses that contains ±x j . Let σ be a permutation on the colors, consisting of 4-cycles that involve the same variable, with the properties that (i) ( jk ) σ = jk ′ for some k ′ and (ii) ( j k ¯ ) σ \= ( j k ) σ ¯ .
There are 4 n vertices of K N named jk , having the respective color lists
L ( j k , 1 ) \= { j k , j k ¯ } , L ( j k , 2 ) \= { j k , ( j k ) σ } , L ( j k , 3 ) \= { j k ¯ , ( j k ) σ } .
The other 3 m vertices of K N are named a k , b k , c k for each clause k . If that clause is, say, x 2 ∨ x ¯ 5 ∨ x 6 , the color lists are
L ( a k , 1 ) \= { 2 k , 5 k ¯ , 6 k } , L ( b k , 1 ) \= L ( c k , 1 ) \= { 2 k , 2 k ¯ , 5 k , 5 k ¯ , 6 k , 6 k ¯ } ; L ( a k , 2 ) \= { ( 2 k ) σ ¯ } , L ( b k , 2 ) \= { ( 5 k ) σ ¯ } , L ( c k , 2 ) \= { ( 6 k ) σ ¯ } ; L ( a k , 3 ) \= { ( 2 k ) σ 2 ¯ , ( 2 k ) σ } , L ( b k , 3 ) \= { ( 5 k ) σ 2 ¯ , ( 5 k ) σ } , L ( c k , 3 ) \= { ( 6 k ) σ 2 ¯ , ( 6 k ) σ } .
Then K N □ K 3 is list-colorable if and only if the clauses are satisfiable. (For example, ( jk, 1) is colored jk ⇔ (( jk ) σ, 1) is colored ( jk ) σ ⇔ ( a k , 1) is not colored jk .)
212. (a) Let x ijk \= 1 if and only if X ij \= k . [ Note: Another equivalent problem is to find an exact cover with options { {P ij, R ik, C jk } | p ij \= r ik \= c jk \= 1}. This is a special case of 3D matching. Incidentally, the 3D matching problem can be formulated as the problem of finding a binary tensor ( x ijk ) such that x ijk ≤ y ijk and x i ∗∗ \= x ∗ j ∗ \= x ∗∗ k \= 1, given ( y ijk ).]
(b) c 31 = c 32 = r 13 = r 14 = 0 forces x 13∗ = 0 ≠ p 13 when r \= c \= ( 1100 0110 0011 1001 ) , p \= ( 1010 1100 0101 0011 ) .
(c) Make L ( I, J ) = {1 ,...,N } for M < I ≤ N , 1 ≤ J ≤ N . It is well known (Theorem 7.5.1L) that a latin rectangle can always be extended to a latin square.
(d) Index everything by the set {1 ,...,N } ∪ ∪ I,J {( I, J, K ) | K ∈ L ( I, J )}. The elements ( I, J, K ) where K = min L ( I, J ) are called headers . Set p ij \= 1 if and only if (i) i = j = ( I, J, K ) is not a header; or (ii) i = ( I, J, K ) is a header, and j = J or j = ( I, J, K ′ ) is not a header; or (iii) j = ( I, J, K ) is a header, and i = I or i = ( I, J, K ′ ) is not a header. Set r ik \= c ik \= 1 if and only if (i) 1 ≤ i, k ≤ N ; or (ii) i = ( I, J, K ) and k = ( I, J, K ′ ), and if i is not a header then ( K ′ = K or K ′ is the largest element < K in L ( I, J )). [ Reference: SICOMP 23 (1994), 170–184.]
213. The hinted probability is (1 – (1 – p ) n ′ (1 – q ) n – n ) m , where n ′ = b 1 + … + b n . Thus if p ≤ q , every x has probability at least (1 – (1 – p ) n ) m of satisfying every clause. This is huge, unless n is small or m is large: If m is less than α n , where α is any constant less than 1/(1 – p ), then when n > –1/ lg(1 – p ) the probability (1 – (1 – p ) n ) m > exp( α n ln(1 – (1 – p ) n )) > exp(–2( α (1 – p )) n ) > 1 – 2( α (1 – p )) n is exponentially close to 1. Nobody needs a SAT solver for such an easy problem.
Even if, say, p = q = k/ (2 n ), so that the average clause size is k , a clause is empty — hence unsatisfiable — with probability e – k + O ( n –1 ); and indeed a clause has exactly r elements with the Poisson probability e – k k r /r !+ O ( n –1 ) for fixed r . So the model isn’t very relevant. [See J. Franco, Information Proc. Letters 23 (1986), 103–106.]
214. (a) T ( z ) = ze z + 2 T ( pz ) ( e (1– p ) z – 1).
(b) If f ( z ) \= Π m \= 1 ∞ ( 1 − e ( p − 1 ) / z / p m ) and τ ( z ) = f ( z ) T ( z ) e – z , we have τ ( z ) = zf ( z ) + 2 τ ( pz ) = zf ( z ) + 2 pzf ( pz ) + 4 p 2 zf ( p 2 z ) + … .
(c) See P. Jacquet, C. Knessl, and W. Szpankowski, Combinatorics, Probability and Computing 23 (2014), 829–841. [The sequence 〈 T n 〉 was first studied by A. T. Goldberg, Courant Computer Science Report 16 (1979), 48–49.]
215. Since any given x 1 ...x l is a partial solution in ( 8 ( n 3 ) − ( l 3 ) ) m of the ( 8 ( n 3 ) ) m possible cases, level l contains P l \= 2 l ( 1 − 1 8 l 3 ¯ / n 3 ¯ ) m nodes on the average. When m = 4 n and n = 50, the largest levels are ( P 31 ,P 32 ,...,P 36 ) ≈ (6 . 4 , 6 . 9 , 7 . 2 , 7 . 2 , 6 . 8 , 6 . 2) × 10 6 , and the mean total tree size P 0 + … + P 50 is about 85.6 million.
If l = 2 tn and m = αn we have P l \= 2 f ( t ) n , where f ( t ) = 2 t + α lg(1 – t 3 ) + O (1 /n ) for 0 ≤ t ≤ 1/2. The maximum f ( t ) occurs when ln 4 = 3 αt 2 /(1 – t 3 ), at which point t \= t α \= β − 1 2 β 4 + 5 8 β 7 + O ( β 10 ) , where β \= ln 4 / ( 3 α ) ; for example, t 4 ≈ 0 . 334. Now
P L + k P L \= exp ( − γ k 2 n + O ( k n ) + O ( k 3 n 2 ) ) , γ \= ( ln 2 ) 6 α ( 1 + 2 t α 3 ) , w h e n L \= 2 t α n ;
by trading tails, the expected total tree size is π n / γ P L ( 1 + O ( 1 / n ) ) .
[This question was first studied by C. A. Brown and P. W. Purdom, Jr., SICOMP 10 (1981), 583–593; K. M. Bugrara and C. A. Brown, Inf. Sciences 40 (1986), 21–37.]
216. If the search tree has q two-way branches, it has fewer than 2 nq nodes; we shall find an upper bound on E q . Consider such branches after values have been assigned to the first l variables x 1 , ... , x l , and also to s additional variables y 1 , ... , y s because of unit-clause forcing; the branch therefore occurs on level t = l + s . The values can be assigned in 2 t ways, and the y ’s can be chosen in ( n − 1 − l s ) ways. For 1 ≤ i ≤ s the m given clauses must contain j i ≥ 1 clauses chosen (with replacement) from the F \= ( t − 1 2 ) that force the value of y i from other known values. The other m – j 1 –…– j s must be chosen from the R \= 8 ( n 3 ) − s F − ( t 3 ) − 2 ( t 2 ) ( n − t ) remaining clauses that aren’t entirely false and don’t force anything further. Thus the expected number of two-way branches is at most
P l t \= 2 t ( n − l − 1 s ) Σ j 1 , … , j s ≥ 1 ( m j 1 , … , j s , m − j ) F j R m − j N m , j \= j 1 + … + j s , N \= 8 ( n 3 ) ,
summed over 0 ≤ l ≤ t < n . Let b = F/N and c = R/N ; the sum on j 1 , ... , j s is
m ! [ z m ] ( e b z − 1 ) s e c z \= Σ r ( s r ) ( − 1 ) s − r ( c + r b ) m \= s ! c m Σ q ( m q ) { q s } ( b c ) q .
These values P lt are almost all quite small when m = 200 and n = 50, rising above 100 only when l ≥ 45 and t = 49; Σ P lt ≈ 4404 . 7.
If l = xn and t = yn , we have b ≈ 3 8 y 2 / n and c ≈ 1 8 ( 3 ( y − x ) y 2 + y 3 + 6 y 2 ( 1 − y ) ) . The asymptotic value of [ z αn ] ( e βz/n –1) δn e γz can be found by the saddle point method: Let ζ satisfy βδe ζ /( e ζ – 1) + γ = αβ/ζ , and let ρ 2 = α/ζ 2 – δe ζ /( e ζ – 1) 2 . Then the answer is approximately ( e ζ − 1 ) δ n e γ ζ n / β n / ( 2 π ρ β ( ζ n / β ) α n + 1 ) .
[For exact formulas and lower bounds, see SICOMP 12 (1983), 717–733. The total time to find all solutions grows approximately as ( 2 ( 7 8 ) α ) n when α < 4 . 5, according to H.-M. Méjean, H. Morel, and G. Reynaud, SICOMP 24 (1995), 621–649.]
217. True, unless both l and l ¯ belong to A or to B (making A or B tautological). For if L is a set of strictly distinct literals that covers both A and B , we know that neither A nor B nor L contains both l and l ¯ ; hence L \ { l , l ¯ } covers ( A \ { l , l ¯ } ) ∪ ( B \ { l , l ¯ } \= C ) .
(This generalization of resolution is, however, useless if C ⊇ A or C ⊇ B , because a large clause is easier to cover than any of its subsets. Thus we generally assume that l ∈ A and l ¯ ∈ B , and that C isn’t tautological, as in the text.)
218. x ? B : A . [ Hence ( x ∨ A ) ∧ ( x ¯ ∨ B ) always implies A ∨ B .]
219. If C ′ or C ″ is tautological ( ℘ ), we define ℘ ⋄ C = C ⋄ ℘ = C . Otherwise, if there’s a unique literal l such that C ′ has the form l ∨ A ′ and C ″ has the form l ¯ ∨ A " , we define C ′ ⋄ C ′ = A ′ ∨ A ″ as in the text. If there are two or more such literals, strictly distinct, we define C ′ ⋄ C ″ = ℘ . And if there are no such literals, we define C ′ ⋄ C ″ = C ′ ∨ C ″ .
[This operation is obviously commutative but not associative. For example, we have ( x ¯ ⋄ y ¯ ) ⋄ ( x ∨ y ) \= ℘ while x ¯ ⋄ ( y ¯ ⋄ ( x ∨ y ) ) \= ∊ .]
220. (a) True: If C ⊆ C ′ and C ′ ⊆ C ″ and C ″ ≠ ℘ then C ′ ≠ ℘ ; hence every literal of C appears in C ′ and in C ″ . [The notion of subsumption goes back to a paper by Hugh McColl, Proc. London Math. Soc. 10 (1878), 16–28.]
(b) True: Otherwise we’d necessarily have ( C ⋄ C ′ ) ∨ α ∨ α ′ ≠ ℘ and C ≠ ℘ and C ′ ≠ ℘ and C ⋄ C ′ ≠ C ∨ C ′ ; hence there’s a literal l with C = l ∨ A , C ′ \= l ¯ ∨ A ′ , and the literals of A ∨ A ′ ∨ α ∨ α ′ are strictly distinct. So the result is easily checked, whether or not α or α ′ contains l or l ¯ . (Notice that we always have C ⋄ C ′ ⊆ C ∨ C ′ .)
(c) False: x ¯ y ⊆ ℘ but x ⋄ x ¯ y \= y ⊈ x \= x ⋄ ℘ . Also ∊ ⊆ x ¯ but x ⋄ ∊ \= x ⊈ ∊ \= x ⋄ x ¯ .
(d) Such examples are possible if C ≠ ∊ : We have x, x ¯ ⊢ y (and also x, x ¯ ⊢ ℘ ), although the only clauses obtainable from x and x ¯ by resolution are x , x ¯ , and ∊ . (On the other hand we do have F ⊢ ∊ if and only if there’s a refutation chain (104) for F .)
(e) Given a resolution chain C 1 ′ , … , C m + r ′ , we can construct another chain C 1 , ... , C m + r in which C i ⊆ C i ′ for 1 ≤ i ≤ m + r . Indeed, if i > m and C i ′ \= C j ′ ⋄ C k ′ , it’s easy to see that either C j ⋄ C j or C k ⋄ C k or C j ⋄ C k will subsume C i ′ .
(f) It suffices by (e) to prove this when α 1 = … = α m \= α ; and by induction we may assume that α = l is a single literal. Given a resolution chain C 1 , ... , C m + r we can construct another one C i ′ , … , C m + r ′ such that C i ′ \= C i ∨ l for 1 ≤ i ≤ m and C i ′ ⊆ C i ∨ l for m +1 ≤ i ≤ m + r , with C i ′ \= C i ′ or C k ′ or C j ′ ⋄ C k ′ whenever C i \= C j ⋄ C k .
221. Algorithm A recognizes ‘1’ as a pure literal, but then finds a contradiction because the other two clauses are unsatisfiable. The resolution refutation uses only the other two clauses. (This is an example of an unnecessary branch. Indeed, a pure literal never appears in a refutation tree, because it can’t be canceled; see the next exercise.)
222. If A is an autarky that satisfies C , it also satisfies every clause on the path to from a source vertex labeled C , because all of the satisfied literals cannot simultaneously vanish. For the converse, see Discrete Appl. Math. 107 (2000), 99–137, Theorem 3.16.
223. (The author has convinced himself of this statement, but he has not been able to construct a formal proof.)
224. At every leaf labeled by an axiom A of F | x ¯ that is not an axiom of F , change the label to A ∪ x ; also include x in the labels of all this leaf’s ancestors. We obtain a resolution tree in which the leaves are labeled by axioms of F . The root is labeled x , if any labels have changed; otherwise it is still labeled ∊ .
[See J. A. Robinson, Machine Intelligence 3 (1968), 77–94.]
225. Let’s say that a regular resolution tree for clause A is awkward if at least one of its nodes resolves on one of the variables in A . An awkward tree T for A can always be transformed into a regular non-awkward tree T ′ for some clause A ′ ⊆ A , where T ′ is smaller than T . Proof: Suppose T is awkward, but none of its subtrees are. Without loss of generality we can find a sequence of subtrees T 0 , ... , T p , T 1 ′ , … , T p ′ , where T 0 = T and T j – 1 for 1 ≤ j ≤ p is obtained from T j and T j ′ by resolving on the variable x j ; furthermore x p ∈ A . We can assume that the labels of T j and T j ′ are A j and A j ′ , where A j \= x j ∪ R j and A j ′ \= x ¯ j ∪ R j ′ ; hence A j − 1 \= R j ∪ R j ′ . Let B p \= A p ; and for j = p – 1, p – 2, ... , 1, let B j \= B j +1 if x j ∉ B j +1 , otherwise obtain B j by resolving B j +1 with A j ′ . It follows by induction that B j ⊆ x p ∪ A j – 1 . Thus B 1 ⊆ x p ∪ A 0 = A , and we’ve derived B 1 with a non-awkward tree smaller than T .
Now we can prove more than was asked: If T is any resolution tree that derives clause A , and if A ∪ B is any clause that contains A , there’s a non-awkward regular resolution tree T r no larger than T that derives some clause C ⊆ A ∪ B . The proof is by induction on the size of T : Suppose A = A ′ ∪ A ″ is obtained at the root of T by resolving the clauses x ∪ A ′ with x ¯ ∪ A " that label the subtrees T ′ and T ″ . Find non-awkward regular trees T r ′ and T r ″ that derive C ′ and C ″ , where C ′ ⊆ x ∪ A ′ ∪ B and C " ⊆ x ¯ ∪ A " ∪ B . If x ∈ C ′ and x ¯ ∈ C ″ , we obtain the desired T r by resolving T r ′ and T r ″ on x . Otherwise we can either let C = C ′ and T r \= T r ′ , or C = C ″ and T r \= T r ″ . [It’s interesting to apply this construction to the highly irregular resolutions in (105).]
226. Initially α is the root, C ( α ) = ∊ , || α || = N , and s = 0. If α isn’t a leaf, we have C ( α ) = C ( α ′ ) ⋄ C ( α ″ ) where x ∈ C ( α ′ ) and x ¯ ∈ C ( a ″ ) for some variable x . The Prover names x , and changes α ← α ′ or α ← α ″ if the Delayer sets x ← 0 or x ← 1, respectively. Otherwise min(|| α ′ || , || α ″ ||) ≤ || α ||/2, and the Prover can keep going.
227. The proof is by induction on the number of variables, n : If F contains the empty clause, the game is over, the Delayer has scored 0, and the root is labeled 0. Otherwise the Prover names x , and the Delayer considers the smallest possible labels ( m, m ′ ) on the roots of refutations for F | x and F | x ¯ . If m > m ′ , the reply x ← 0 guarantees m points; and the reply x ← ∗ is no better, because m ′ + 1 ≤ m . If m < m ′ , the reply x ← 1 guarantees m ′ ; and if m = m ′ , the reply x ← ∗ guarantees m +1. Thus an optimum Delayer can always score at least as many points as the root label of any branch of a refutation tree constructed by the Prover. Conversely, if the Prover always names an optimal x , the Delayer can’t do better.
(This exercise was suggested by O. Kullmann. One can compute the optimum score “bottom up” by considering all 3 n possible partial assignments as in answer 133 .)
228. We need only assume the transitivity clauses T ijk of (100) when i < j and k < j . [Notice further that T ijk is tautological when i = j or k = j , thus useless for resolution.]
229. Using the binary-relation interpretation, these clauses say that j ⊀ j , that the transitive law “ i ≺ j and j ≺ k implies i ≺ k ” holds whenever i ≤ k and j < k , and that every j has a successor such that j ≺ k . The latter axiom combines with the finiteness of m to imply that there must be a cycle j 0 ≺ j 1 ≺ … ≺ j p – 1 ≺ j p \= j 0 .
Consider the shortest such cycle, and renumber the subscripts so that j p \= max{ j 0 ,...,j p }. We cannot have p ≥ 2, because (100 ′ ) implies j p – 2 ≺ j p , yielding a shorter cycle. Hence p = 1; but that contradicts (99).
230. Call the axioms I j , T ijk , and M jm as in the text. If I j 0 is omitted, let x ij \= [ j = j 0 ] for all i and j . If T i 0 j 0 k 0 is omitted, let x ij \= [ j ∈ A ] for all i ∉ A = { i 0 , j 0 , k 0 }; also let x i 0 j = [ j = j 0 ], x j 0 j \= [ j = k 0 ], and (if i 0 ≠ k 0 ) x k 0 j \= [ j = i 0 ]. Finally, if M j 0 m is omitted, let x ij \= [ p i <p j ], where p 1 ...p m \= 1 ... ( j 0 –1)( j 0+1 ) ...mj 0 . (The same construction shows that the clauses of answer 228 are minimally unsatisfiable.)
231. Since G 11 = M 1 m , we can assume that j > 1. Then G ( j – 1) j = G ( j – 1)( j – 1) ⋄ I j – 1 . And if 1 ≤ i < j – 1 we have G ij \= (… (( G ( j – 1) j ⋄ A ijj ) ⋄ A ij ( j +1) ) ⋄ …) ⋄ A ijm , where A i j k \= G i ( j − 1 ) ⋄ T i ( j − 1 ) k \= G i j ∨ x ¯ ( j − 1 ) k . These clauses make it possible to derive B i j \= ( … ( ( G i j ⋄ T i j i ) ⋄ T j i ( j + 1 ) ) ⋄ … ) ⋄ T j i m \= G j j ∨ x ¯ j i for 1 ≤ i < j , from which we obtain G jj \= (… (( M jm ⋄ B 1 j ) ⋄ B 2 j ) ⋄ …) ⋄ B ( j – 1) j . Finally G mm ⋄ I m \= ∊ .
232. It suffices to exhibit a backtrack tree of depth 6 lg q + O (1). By branching on at most 6 variables we can find the color-triplet α 1 in answer 176(c) .
Suppose we know that α j \= α and α j + p = α ′ , where α ′ cannot be obtained from α in p steps; this is initially true with j = 1, α = α ′ = α 1 , and p = q . If p = 1, a few more branches will find a contradiction. Otherwise at most 6 branches will determine α l , where l = j + ⌊ p/ 2⌋; and either α l will be unreachable from α in ⌊ p/ 2⌋ steps, or α ′ will be unreachable from α l in ⌈ p/ 2⌉ steps, or both. Recurse.
233. C 9 = C 6 ⋄ C 8 , C 10 = C 1 ⋄ C 9 , C 11 = C 3 ⋄ C 10 , C 12 = C 7 ⋄ C 10 , C 13 = C 4 ⋄ C 11 , C 14 = C 2 ⋄ C 12 , C 15 = C 13 ⋄ C 14 , C 16 = C 5 ⋄ C 15 , C 17 = C 6 ⋄ C 15 , C 18 = C 8 ⋄ C 15 , C 19 = C 12 ⋄ C 17 , C 20 = C 11 ⋄ C 18 , C 21 = C 16 ⋄ C 19 , C 22 = C 20 ⋄ C 21 .
234. Reply x jk ← ∗ to any query that doesn’t allow the Prover to violate (107). Then the Prover can violate (106) only after every hole has been queried.
235. Let C ( k , A ) \= ( ∨ j \= 0 k ∨ a ∈ A x j a ) , so that C (0 , {1 ,...,m }) = ( x 01 ∨…∨ x 0 m ) and C ( m, ∅) = ∊ . The chain consists of m stages for k = 1, ... , m , where stage k begins by deriving the clauses x ¯ k a ∨ C ( k − 1 , A ) from the clauses of stage k – 1, for all ( m – k )-element subsets A of {1 ,...,m }\ a ; every such clause requires k resolutions with (107). Stage k concludes by deriving C ( k, A ) for all ( m – k )-element subsets A of {1 ,...,m }, each using one resolution from (106) and k – 1 resolutions from the beginning of the stage. (See (103).) Thus stage k involves a total of ( m m − k ) ( k 2 + k ) resolutions.
For example, the resolutions when m = 3 successively yield 11 ¯ 02 03, 12 ¯ 01 03, 13 ¯ 01 02; 01 02 11 12, 01 03 11 13, 02 03 12 13 (stage 1); 21 ¯ 02 11 12, 21 ¯ 02 12, 21 ¯ 03 11 13, 21 ¯ 03 13, 22 ¯ 01 12 11, 22 ¯ 01 11, 22 ¯ 03 12 13, 22 ¯ 03 13, 23 ¯ 01 13 11, 23 ¯ 01 11, 23 ¯ 02 13 12, 23 ¯ 02 12; 01 11 21 22, 01 11 21, 02 12 22 23, 02 12 22, 03 13 23 22, 03 13 23 (stage 2); and 31 ¯ 11 21, 31 ¯ 21, 31 ¯ , 32 ¯ 12 22, 32 ¯ 22, 32, 33 ¯ 13 23, 33 ¯ 23, 33 ¯ ; 32 33, 33, ∊ (stage 3).
[Stephen A. Cook constructed such chains in 1972 (unpublished).]
236. The symmetry of the axioms should allow exhaustive verification by computer for m = 2, possibly also for m = 3. The construction certainly seems hard to beat. Cook conjectured in 1972 that any minimum-length resolution proof would include, for every subset S of {1 ,...,m }, at least one clause C such that ∪ ± x jk ∈ C { k } = S .
237. The idea is to define y jk \= x jk ∨ ( x jm ∧ x mk ) for 0 ≤ j < m and 1 ≤ k < m , thus reducing from m + 1 pigeons to m . First we append 6 m ( m – 1) new clauses
( x j m ∨ z j k ) ∧ ( x m k ∨ z j k ) ∧ ( x ¯ j m ∨ x ¯ m k ∨ z ¯ j k ) ∧ ( x ¯ j k ∨ y j k ) ∧ ( y j k ∨ z j k ) ∧ ( x j k ∨ y ¯ j k ∨ z ¯ j k ) ,
involving 2 m ( m – 1) new variables y jk and z jk . Call these clauses A jk , ... , F jk .
Now if P j stands for (106) and H ijk for (107), we want to use resolution to derive P j ′ \= ( y j 1 ∨ … ∨ y j ( m − 1 ) ) and H i j k ′ \= ( y ¯ i k ∨ y ¯ j k ) . First, P j can be resolved with D j 1 , ... , D j ( m – 1) to get P j ′ ∨ x j m . Next, P m ⋄ H j m m \= x m 1 ∨ … ∨ x m ( m − 1 ) ∨ x ¯ j m can be resolved with G j k \= C j k ⋄ E j k \= x ¯ j m ∨ x ¯ m k ∨ y j k for 1 ≤ k < m to get P j ′ ∨ x ¯ j m . One more step yields P j ′ . (The intuitive “meaning” guides these maneuvers.)
From B j k ⋄ F j k \= x j k ∨ x m k ∨ y ¯ j k , we obtain Q i j k \= x ¯ i k ∨ y ¯ j k after resolving with H ijk and H imk . Then ( Q i j k ⋄ F i k ) ⋄ A i k \= x i m ∨ y ¯ i k ∨ y ¯ j k \= R i j k , say. Finally, ( R j i k ⋄ H i j m ) ⋄ R i j k \= H i j k ′ as desired. (When forming R jik we need Q jik with j > i .)
We’ve done 5 m 3 – 6 m 2 +3 m resolutions to reduce m +1 to m . Repeating until m = 0, with fresh y and z variables each time, yields ∊ after about 5 4 m 4 steps.
[See Stephen A. Cook, SIGACT News 8 , 4 (October 1976), 28–32.]
238. The function (1 – cx ) – x \= exp( cx 2 + c 2 x 3 /2 + …) is increasing and > e cx 2 . Setting c \= 1 2 n , W \= 2 n ln r , and b = ⌈ W ⌉ makes f ≤ r < ρ – b . Also W ≥ w ( α 0 ) when n ≥ w ( α 0 ) 2 and r ≥ 2; hence w ( α 0 ⊢ ∊ ) ≤ W + b ≤ 8 n ln r + 1 as desired. The ‘–2’ in the lemma handles the trivial cases that arise when r < 2.
(It is important to realize that we don’t change n or W in the induction proof. Incidentally, the exact minimum of W + b , subject to r = (1 – W/ (2 n )) – b , occurs when
W \= 2 n ( 1 − e − 2 T ( z ) ) \= 4 n z + 2 n z 3 3 + … , b \= ln r 2 T ( z ) \= ( ln r ) ( 1 2 z − 1 2 − z 4 − … ) ,
where z 2 = (ln r )/(8 n ) and T ( z ) is the tree function. Thus it appears likely that the proof of Lemma B supports the stronger result w ( α 0 ⊢ ∊ ) < 8 n ln r − 1 2 ln r + 1 .)
239. Let α 0 consist of all 2 n nontautological clauses of length n . The shortest refutation is the complete binary tree with these leaves, because every nontautological clause must appear. Algorithm A shows that 2 n – 1 resolutions suffice to refute any clauses in n variables; hence || α 0 ⊢ ∊ || = 2 n – 1, and this is the worst case.
240. If A ′ has t elements and ∂A ′ has fewer than t , the sequence of 5 t integers f ij for its neighbors must include at least 2 t repeats of values seen earlier. (In fact there are at least 2 t + 1 repeats, because 2 t would leave at least t in the boundary; but the calculations are simpler with 2 t , and we need only a rather crude bound.)
The probability p t that some such A ′ exists is therefore less than ( m + 1 t ) ( 5 t 2 t ) ( 3 t m ) 2 t , because there are ( m + 1 t ) ways to select A ′ , ( 5 t 2 t ) to select the repeating slots, and at most (3 t ) 2 t out of m 2 t ways to fill those slots. Also ( m + t t ) \= ( m t ) + ( m t − 1 ) < 2 ( m t ) when t ≤ 1 2 m .
By exercise 1.2.6–67 we have p t ≤ 2 ( m e t ) t ( 5 t e 2 t ) 2 t ( 3 t m ) 2 t \= 2 ( c t / m ) t ,where c = 225 e 3 /4 ≈ 1130. Also p 0 = p 1 = 0. Thus the sum of p t for t ≤ m/ 3000 is less than 2 Σ t \= 2 ∞ ( c / 3000 ) t ≈ .455 ; and the probability of strong expansion exceeds .544.
241. If 0 < | A ′ | ≤ m/ 3000, we can put one of its elements into a hole b k ∈ ∂A ′ . Then we can place the other elements in the same way, since b k isn’t their neighbor.
242. The proof of Theorem B remains valid when these new axioms are added.
243. (a) The probability that F ′ has t elements and V ( F ′ ) has fewer than t is at most ( α n t ) ( n t ) ( t n ) 3 t ≤ ( α e 2 t n ) t . The sum of this quantity for 1 ≤ t ≤ lg n is O ( n –1 ), and so is the sum for lg n ≤ t ≤ n/ (2 αe 2 ).
(b) If the condition in (a) holds, there’s a matching from F ′ into V ( F ′ ), by Theorem 7.5.1H; hence we can satisfy F ′ by assigning to its variables, one by one. If F is unsatisfiable we’ll therefore need to invoke more than n/ (2 αe 2 ) of its axioms.
(c) The probability p t that F ′ has t elements and 2 | V ( F ′ ) | − 3 | F ′ | < 1 2 | F ′ | is at most ( α n t ) ( n λ t ) ( λ t n ) 3 t ≤ ( α e 1 + λ λ 3 − λ ( t / n ) 1 / 4 ) t , where λ \= 7 4 . We have ( e 1+λ λ 3–λ ) 4 < 10 6 ; so p t < c t when t ≤ n ′ , where c < 1, and Σ t \= n ′ / 2 n ′ p t is exponentially small.
(d) Since n ′ < n/ (2 αe 2 ), every refutation a.s. contains a clause C with n ′ /2 ≤ μ ( C ) < n ′ . The minimal axioms F ′ on which C depends have | F ′ | = μ ( C ). Let k be the number of “boundary” variables that occur in just one axiom of F ′ . If v is such a variable, we can falsify C and the axiom containing v , while the other axioms of F ′ are true; hence V must contain v or v ¯ . We have | V ( F ′ ) | \= k + | n o n b o u n d a r y | ≤ k + 1 2 ( 3 | F ′ | − k ) , because each non boundary variable occurs at least twice. Therefore k ≥ 2| V ( F ′ )|– 3| F ′ | ≥ n ′ /4, q.s. (Notice the similarities to the proof of Theorem B.)
244. We have [ A ∪ B ] 0 = [ A ] 0 [ B ] 0 ∪ [ A ] 1 [ B ] 1 and [ A ∪ B ] 1 = [ A ] 0 [ B ] 1 ∪ [ A ] 1 [ B ] 0 , where concatenation of sets has the obvious meaning. These relations hold also when A = ∅ or B = ∅, because [∅] 0 = { ∊ } and [∅] 1 = ∅.
245. (a) When conditioning on ē uv , simply delete the edge u ––– v from G . When conditioning on e uv , also complement l ( u ) and l ( v ). The graph might become disconnected; in that case, there will be exactly two components, one even and one odd, with respect to the sums of their labels. The axioms for the even component are satisfiable and may be discarded.
For example, α ( G ) |{ b, ē } corresponds to
while α ( G ) |{ b, e } corresponds to
. We toss out the left component in the first case, the right one in the other.
(b) If C ∈ α ( v ) we may take V ′ = { v }. And we have μ ( ∊ ) = | V |, because the axioms ∪ v∈V\u α ( v ) are satisfiable for all u ∈ V .
(c) If u ∈ V ′ and v ∉ V ′ , there’s an assignment that falsifies C and some axiom of α ( u ) while satisfying all α ( w ) for w ∈ V ′ \ u , because | V ′ | is minimum. Setting e uv ← ē uv will satisfy α ( u ) without affecting the axioms α ( w ) (which don’t contain e uv ).
(d) By (b), every refutation of α ( G ) must contain a clause C with 1 3 m ≤ μ ( C ) < 2 3 m . The corresponding V ′ has | V ′ | / ( | V ′ | + | ∂ V ′ | ) < ( 2 3 + 8 ) / 9 , hence | ∂ V ′ | > 1 26 | V ′ | .
[Property (i) is interesting but irrelevant for this proof. Notice that α ( G ) has exactly 8 3 n ≈ 2.67 n 3SAT clauses in n = 3 m/ 2 variables when G is cubic; every literal occurs four times. G. Tseytin proved lower bounds for refutations of α ( G ) by regular resolution in 1966, before graphs with property (iii) were known; A. Urquhart obtained them for general resolution in JACM 34 (1987), 209–219, and the simplified argument given here is due to Ben-Sasson and Wigderson. The fact that α ( G ) requires exponentially long refutation chains, although the same axioms can be refuted easily by working with linear equations mod 2, amounts to a proof that backtracking is a poor way to deal with linear equations! Suitable Ramanujan graphs raman (2 ,q, 3 , 0) can be found by the algorithms of the Stanford GraphBase for infinitely many prime numbers q . We can also obtain the same lower bounds with the multigraphs raman (2 ,q, 1 , 0) and raman (2 ,q, 2 , 0). Section 7.4.3 will explore expander graphs in detail.]
246. Let’s write [ a 1 ...a k ] ℓ for what exercise 244 calls [{ a 1 ,...,a k }] ℓ . With new variables x , y , z we can introduce { x a , x b ¯ , x ¯ a ¯ b , y a ¯ , y b , y ¯ a b ¯ , z x , z y , z ¯ x ¯ y ¯ } and resolve those clauses to [ zab ] 1 , which means z = a ⊕ b . So we can assume that ‘ z ← a ⊕ b ’ is a legal primitive operation of “extended resolution hardware,” when z is a new variable. Furthermore we can compute a 1 ⊕…⊕ a k in O ( k ) steps, using z 0 ← 0 (which is the clause [ z 0 ] 1 , namely z ¯ 0 ) and z k ← z k – 1 ⊕ a k when k ≥ 1.
Let the edge variables E ( v )be a 1 , ... , a d , where d is the degree of v . We compute s v ← a 1 ⊕… ⊕ a d by setting s v, 0 ← 0, s v,k ← s v,k – 1 ⊕ a k , and s v ← s v,d . We can resolve s v with the axioms α ( v ) in O (2 d ) steps, to get the singleton clause [ s v ] l(v) ⊕1 , meaning s v \= l ( v ). Summing over v , these operations therefore take O ( N ) steps.
On the other hand, we can also compute z n ← ⊕ v s v and get zero (namely ‘ z ¯ n ’). Doing this cleverly, by omnisciently knowing G , we can in fact compute it in O ( mn ) steps: Start with any vertex v and set z 1 ← s v (more precisely, set z 1 ,k ← s v,k for 0 ≤ k ≤ d ). Given z j for 1 ≤ j < n , with all its subvariables z j,k , we then compute z j +1 ← z j ⊕ s u , where u is the unused vertex with s u, 1 = z j, 1 . We can arrange the edges into an order so that if z j has p edge variables in common with s u , then z j,k \= s u,k for 1 ≤ k ≤ p . Suppose the other variables of z j and s u are respectively a 1 , ... , a q and b 1 , ... , b r ; we want to merge them into the sequence c 1 , ... , c q + r that will be needed later when z j +1 is used. So we set z j +1 , 0 ← 0, z j +1 ,k ← z j +1 ,k – 1 ⊕ c k , z j +1 ← z j +1 ,q + r .
From the clauses constructed in the previous paragraph, resolution can deduce [ z j,k s u,k ] 1 for 1 ≤ k ≤ p , and hence [ z j +1 , 0 z j,p s u,p ] 1 (namely that z j +1 , 0 = z j,p ⊕ s u,p ). Furthermore, if c k \= a i , and if we know that z j +1 ,k – 1 = z j,s ⊕ s u,t where s = p + i – 1 and t = p + k – i , resolution can deduce that z j +1 ,k = z j,s +1 ⊕ s u,t ; a similar formula applies when c k \= b i . Thus resolution yields z j +1 ← z j ⊕ s u as desired. Ultimately we deduce both z n and z ¯ n from the singleton clauses s v \= l ( v ).
247. Eliminating x 2 from {12 , 1 ¯ 2 , 1 ¯ 2 ¯ } gives { 1 ¯ }; eliminating x 1 then gives ∅. So those five clauses are satisfiable.
248. We have F ( x 1 , … , x n ) \= ( x n ∨ A 1 ′ ) ∧ … ∧ ( x n ∨ A p ′ ) ∧ ( x ¯ n ∨ A 1 ″ ) ∧ … ∧ ( x ¯ n ∨ A q ″ ) ∧ A 1 ′ ″ ∧ … ∧ A r ′ ″ \= ( x n ∨ G ′ ) ∧ ( x ¯ n ∨ G ″ ) ∧ G ′ ″ , where G ′ \= A 1 ′ ∧ … ∧ A p ′ , G ″ \= A 1 ″ ∧ … ∧ A q ″ , and G ′″ \= A 1 ′″ ∧ … ∧ A r ′″ depend only on { x 1 ,...,x n – 1 }. Hence F ′ = ( G ′ ∨ G ″ ) ∧ G ′" ; and the clauses of G ′ ∨ G ″ \= ∧ i \= 1 p ∧ j \= 1 q ( A i ′ ∨ A j ″ ) are the resolvents eliminating x n .
249. After learning C 7 \= 2 ¯ 3 ¯ as in the text, we set d ← 2, l 2 ← 2 ¯ , C j \= 2 3 ¯ , learn C 8 \= 3 ¯ , and set d ← 1, l 1 ← 3 ¯ . Then l 2 ← 4 ¯ (say); and l 3 ← 1 ¯ , l 4 ← 2 ¯ . Now C i \= 1234 has been falsified; after l 4 ← 2 and C j \= 1 2 ¯ we learn C 9 = 134, set l 3 ← 1, and learn C 10 \= 134 ⋄ 1 ¯ 3 \= 34 . Finally l 2 ← 4, we learn C 11 = 3; l 1 ← 3, and we learn C 12 = ∊ .
250. l 1 ← 1, l 2 ← 3, l 3 ← 2 ¯ , l 4 ← 4; learn 1 ¯ 2 3 ¯ ; l 3 ← 2, l 4 ← 4; learn 1 ¯ 2 ¯ 3 ¯ and 1 ¯ 3 ¯ ; l 2 ← 3 ¯ , l 3 ← 2 ¯ , l 4 ← 4; learn 1 ¯ 23 ; l 3 ← 2, l 4 ← 4; learn 1 ¯ 2 ¯ 3 , 1 ¯ 3 , 1 ¯ ; l 1 ← 1 ¯ , l 2 ← 3, l 3 ← 4 ¯ , l 4 ← 2; learn 1 3 ¯ 4 ; l 3 ← 4, l 4 ← 2 ¯ , l 4 ← 2.
251. Algorithm I has the property that l ¯ i 1 , ... , l ¯ i k − 1 , l i k are on the stack whenever the new clause l i 1 ∨…∨ l i k has been learned, if i 1 < … < i k \= d and step I4 returns to I2. These literals limit our ability to exploit the new clause; so it appears to be impossible to solve this problem without doing more resolutions than Stålmarck did.
However, we can proceed as follows. Let M i m k " be the clause x m 1 ∨...∨ x m ( k – 1) ∨ x ik ∨… ∨ x i ( m – 1) ∨ x ¯ i m , for 1 ≤ i, k < m . Using ij to stand for x ij , the process for m = 3 begins by putting 11 ¯ , 12 ¯ , 13, 21 ¯ , 22 ¯ , 23, 31 ¯ , 32 ¯ , 33 on the stack. Then step I3 has C i \= I 3 , step I4 has C j \= M 33 ; so step I5 learns I 3 ⋄ M 33 = M 32 . Step I4 now changes 32 ¯ to 32 and chooses C j \= T 232 ; so I5 learns M 32 ⋄ T 232 \= M 232 ″ . Step I4 changes 31 ¯ to 31 and chooses C j \= T 231 ; now we learn M 232 " ⋄ T 231 \= M 231 " . Next, we learn M 231 " ⋄ M 23 \= M 22 ; and after changing 22 ¯ to 22 we also learn M 21 .
The stack now contains 11 ¯ , 12 ¯ , 13, 21. We add 31 ¯ , 32 ¯ , and proceed to learn M 32 ⋄ T 132 \= M 132 " , M 132 " ⋄ T 131 \= M 131 " , M 131 " ⋄ M 13 \= M 12 . The stack now contains 11 ¯ , 12, and we’ve essentially reduced m from 3 to 2.
In a similar way, O ( m 2 ) resolutions will learn M i ( m – 1) for i = m – 1, ... , 1; and they’ll leave x ¯ 11 , ... , x ¯ 1 ( m − 2 ) , x 1( m – 1) on the stack so that the process can continue.
252. No; large numbers of clauses such as x ¯ 12 ∨ x ¯ 23 ∨ … ∨ x ¯ 89 ∨ x 19 are generated by the elimination process. Although these clauses are valid, they’re not really helpful.
Exercise 373 proves, however, that the proof is completed in polynomial time if we restrict consideration to the transitivity clauses of exercise 228 (!).
253. A conflict arises when we follow a chain of forced moves:
t | L t | level | reason |
0 | 1 | Λ | |
1 | 4 | 1 | 46 |
2 | 5 | 2 | Λ |
3 | 2 | ||
4 | 9 | 2 | 369 |
5 | 2 | ||
6 | 2 | ||
7 | 8 | 2 | 678 |
8 | 2 | 2 | 123 |
9 | 2 |
Now 2 ¯ 5 ¯ 8 ¯ → 2 ¯ 5 ¯ 8 ¯ ⋄ 123 \= 13 5 ¯ 8 ¯ → 13 5 ¯ 67 → 3 5 ¯ 67 9 ¯ → 3 5 ¯ 6 9 ¯ → 3 5 ¯ 6 → 4 ¯ 5 ¯ 6 ; so we learn 4 ¯ 5 ¯ 6 (which can be simplified to 5 ¯ 6 , because 4 ¯ is “ redundant” as explained in exercise 257 ).
Setting L 2 ← 5 ¯ , with reason 4 ¯ 5 ¯ 6 or 5 ¯ 6 , now forces 7, 1 ¯ , 3, 9, 2 ¯ , 8 ¯ , 8, all at level 1; this conflict soon allows us to learn the unit clause 6. (Next we’ll inaugurate level 0, setting L 0 ← 6. No “reasons” need to be given at level 0.)
254. Deducing 3, 2, 4, 4 ¯ at level 1, it will find 2 ¯ 4 ¯ ⋄ 4 3 ¯ \= 2 ¯ 3 ¯ and 2 ¯ 3 ¯ ⋄ 2 3 ¯ \= 3 ¯ , learning 3 ¯ . (Or it might learn 3 ¯ after deducing 2 ¯ .) Then it will deduce 3 ¯ , 1 ¯ , 2, 4 ¯ at level 0.
255. For example, { 1 ¯ 2 ¯ 4 ¯ , 2 ¯ 3 ¯ 5 ¯ , 456 , 45 6 ¯ }. [Since the clause c ′ that is learned by the procedure described in the text contains just one literal l from the conflict level d , the trail position for l ¯ has been called a “ unique implication point” (UIP). If l isn’t the decision literal for its level, we could resolve c ′ with l ’s reason and find another UIP; but each new resolution potentially increases the b array and limits the amount of backjumping. Therefore we stop at the first UIP.]
256. If it is false, literals 50, 26, ... , 30 are true; hence also 25 ¯ , 23, and 29, a conflict. Consequently we can obtain ‘∗∗’ by starting with 23 ¯ 26 ¯ … 50 ¯ and resolving with 23 25 27, 25 27 29, and 25 ¯ 30 ¯ … 70 ¯ . [Similarly, and more simply, one can learn (122) by resolving 11 ¯ 16 ¯ … 56 ¯ with 31 61 91, 41 66 91, and 56 61 66.]
257. (a) Suppose l ¯ ′ on level d ′ > 0 is redundant. Then some l ″ in the reason for l ′ is also on level d ′ ; and l ″ is either in c or redundant. Use induction on trail position.
(b) We can assume that the stamp value s used when resolving conflicts is a multiple of 3, and that all stamps are ≤ s . Then we can stamp literal l with S (| l |) ← s +1 if l ¯ is known to be redundant, or s +2 if l ¯ is known to be nonredundant and not in c . (These stamps serve as a “ memo cache” to avoid repeated work.) While building c we can also stamp levels as well as literals, setting LS[ d ′ ] ← s if level d ′ has exactly one of the b i , or s + 1 if it has more than one.
Then for 1 ≤ j ≤ r , b ¯ j is redundant if and only if LS[ lev ( b j ) ] = s + 1 and red ( b ¯ j ) is true, where lev ( l ) = VAL( | l | ) ≫ 1 and where red ( l ¯ ) is the following recursive procedure: “If l is a decision literal, return false. Otherwise let ( l ∨ ā 1 ∨…∨ ā k ) be l ’s reason. For 1 ≤ i ≤ k with lev ( a i ) > 0, if S( | a i | ) = s + 2 return false; if S (| a i | ) < s and either LS[ lev ( a i ) ] < s or red ( ā i ) is false, set S( | a i | ) ← s + 2 and return false. But if none of these conditions hold, set S( | l | ) ← s + 1 and return true.”
[See Allen Van Gelder, LNCS 5584 (2009), 141–146.]
258. That statement is true in Table 3 , but false in general. Indeed, consider the sequel to Table 3 : The decision L 44 \= 57 ¯ causes the watch list of 57 to be examined, thus forcing 15, 78, and 87 (among other literals) in some order because of the clauses 15 57 36, 78 57 36, 87 57 27. Then 96 ¯ will be forced by the clause 96 ¯ 87 ¯ … 15 ¯ ; and the second literal of that clause at the time of forcing will be 15 ¯ , regardless of trail order, if the watched literals of that clause were 96 ¯ and 15 ¯ (making it invisible to 78 ¯ and 87 ¯ ).
259. 1+ ρ 6 + ρ 7 < ρ + ρ 2 when . 7245 < ρ < .7548. (There can in fact be any number of crossover points: Consider the polynomial (1 – ρ – ρ 2 )(1 – ρ 3 – ρ 6 )(1 – ρ 9 – ρ 18 ). )
260. First, to get a random permutation in the heap we can use a variant of Algorithm 3.4.2P: For k ← 1, 2, ... , n , let j be a random integer in [0 ..k – 1] and set HEAP[ k – 1 ] ← HEAP[ j ] , HEAP[ j ] ← k . Then set HLOC(HEAP[ j ]) ← j for 0 ≤ j < n .
Next, set F ← 0 and W l ← 0 for 2 ≤ l ≤ 2 n + 1 and c ← 3. Do the following for each input clause l 0 l 1 ...l k – 1 : Terminate unsuccessfully if k = 0, or if k = 1 and 0 ≤ VAL( | l 0 | ) ≠ l 0 &1. If k = 1 and VAL( | l 0 | ) < 0, set VAL( | l 0 | ) ← l 0 &1, TLOC( | l 0 | ) ← F , F ← F + 1. If k > 1, set MEM[ c + j ] ← l j for 0 ≤ j < k ; also MEM[ c – 1 ] ← k , MEM[ c – 2 ] ← W l 0 , W l 0 ← c , MEM[ c – 3 ] ← W l 1 , W l 1 ← c , c ← c + k +3.
Finally, set MINL ← MAXL ← c +2 (allowing two cells for extra data in the preamble of the first learned clause). Of course we must also ensure that MEM is large enough.
261. (Throughout this answer, l j is an abbreviation for MEM[ c + j ] .) Set q ← 0 and c ← W l ¯ . While c ≠ 0, do the following: Set l ′ ← l 0 . If l ′ ≠ l ¯ (hence l 1 \= l ¯ ), set c ′ ← l – 3 ; otherwise set l ′ ← l 1 , l 0 ← l ′ , l 1 ← l ¯ , c ′ ← l – 2 , l – 2 ← l – 3 , and l – 3 ← c ′ . If VAL( | l 0 | ) ≥ 0 and VAL( | l 0 | ) + l 0 is even (that is, if l 0 is true), perform the steps
i f q ≠ 0 , s e t M E M [ q − 3 ] ← c , e l s e s e t W l ¯ ← c ; t h e n s e t q ← c . ( ∗ )
Otherwise set j ← 2; while j < l – 1 and VAL( | l j | ) ≥ 0 and VAL( | l j | ) + l j is odd, set j ← j +1. If now j < l – 1 , set l 1 ← l j , l j ← l ¯ , l – 3 ← W l 1 , W l 1 ← c . But if j = l – 1 , do(∗) above; jump to C7 if VAL( | l 0 | ) ≥ 0; otherwise set L F ← l 0 , etc. (see step C4) and c ← c ′ .
Finally, when c = 0, do (∗) above to terminate l ¯ ’s new watch list.
262. To delete k = HEAP[ 0 ] in C6: Set h ← h – 1 and HLOC( k ) ← –1. Stop if h = 0. Otherwise set i ← HEAP[ h ] , α ← ACT( i ) , j ← 0, j ′ ← 1, and do the following while j ′ < h : Set α ′ ← ACT(HEAP[ j ′ ]) ; if j ′ +1 < h and ACT(HEAP[ j ′ +1 ]) > α ′ , set j ′ ← j ′ +1 and α ′ ← ACT(HEAP[ j ′ ]) ;if α ≥ α ′ , set j ′ ← h , otherwise set HEAP[ j ] ← HEAP[ j ′ ] , HLOC(HEAP[ j ′ ]) ← j , j ← j ′ , and j ′ ← 2 j + 1. Then set HEAP[ j ] ← i and HLOC( i ) ← j .
In C7, set k ← | l |, α ← ACT( k ) , ACT( k ) ← α + DEL , j ← HLOC( k ) , and if j > 0 perform the “siftup” operation: “Looping repeatedly, set j ′ ← ( j – 1) ≫ 1 and i ← HEAP[ j ′ ] , exit if ACT( i ) ≥ α , else set HEAP[ j ] ← i , HLOC( i ) ← j , j ← j ′ , and exit if j = 0. Then set HEAP[ j ] ← k and HLOC( k ) ← j .”
To insert k in C8, set α ← ACT( k ) , j ← h , h ← h +1; if j = 0 set HEAP[ 0 ] ← k and HLOC( k ) ← 0; otherwise perform the siftup operation.
263. (This answer also sets the level stamps LS[ d ] needed in answer 257 , assuming that the LS array is initially zero.) Let “bump l ” mean “increase ACT( | l | ) by DEL ” as in answer 262 . Also let blit ( l ) be the following subroutine: “If S( | l | ) = s , do nothing. Otherwise set S( | l | ) ← s , p ← lev ( l ). If p > 0, bump l ; then if p = d , set q ← q + 1; else set r ← r +1, b r ← l ¯ , d ′ ← max( d ′ ,p ), and if LS[ p ] ≤ s set LS[ p ] ← s +[ LS[ p ] = s ].”
When step C7 is entered from C4, assuming that d > 0, set d ′ ← r ← 0, q ← −1, s ← s + 3, and do blit ( l j ) for 0 ≤ j < k . Also set t ← max( TLOC( | l 0 | ) ,..., TLOC( | l k – 1 | ) ). Then, while q > 0, set l ← L t , t ← t – 1; if S( | l | ) = s then set q ← q – 1, and if R l ≠ Λ let clause R l be l 0 l 1 ... l k – 1 and do blit ( l j ) for 1 ≤ j < k . Finally set l ′ ← L t , and while S( | l ′ | ) ≠ s set t ← t – 1 and l ′ ← L t .
The new clause can now be checked for redundancies as in answer 257 . To install it during step C9, there’s a subtle point: We must watch a literal that was defined on level d ′ . Thus we set c ← M A X L , M E M [ c ] ← l ¯ ′ , k ← 0, j ′ ← 1; and for 1 ≤ j ≤ r if S( | b j | ) = s set k ← k +1 and do this: If j ′ = 0or lev ( b j ) < d ′ , set M E M [ c + k + j ′ ] ← b ¯ j ; otherwise set M E M [ c + 1 ] ← b ¯ j , j ′ ← 0, M E M [ c − 2 ] ← W l ¯ ′ , W l ¯ ′ ← c , M E M [ c − 3 ] ← W b ¯ j , W b ¯ j ← c . Finally set MEM[ c –1 ] ← k +1, MAXL ← c + k +6.
264. We can maintain a “history code” array, setting H F to 0, 2, 4, or 6 when L F is set, and then using H t +( L t & 1) as the move code that represents trail location t for 0 ≤ t < F . History codes 6, 4, and 0 are appropriate in steps C1, C4, and C6, respectively; in C9, use code 2 if l ′ was a decision literal, otherwise use code 6.
[These move codes do not increase lexicographically when the trail is flushed and restarted; hence they don’t reveal progress as nicely as they do in the other algorithms.]
265. (1) A literal L t on the trail with G ≤ t < F has become true, but the watch list of L ¯ t has not yet been examined. (2) If l 0 is true, so that c is satisfied, step C4 doesn’t remove c from the watch list of l 1 when l 1 becomes false. (This behavior is justified, because c won’t be examined again until l 1 has become free during the backtracking step C8.) (3) A clause that becomes a reason for l 0 remains on the watch list of its false l 1 . (4) During a full run, a clause that triggers a conflict is allowed to keep both of its watched literals false.
In general, a false watched literal must be defined at the highest trail level of all literals in its clause.
266. If U < p , where U is a uniform deviate between 0 and 1, do this: Set j to a random integer with 0 ≤ j < h , and k ← HEAP[ j ] . If j = 0, or if VAL( k ) ≥ 0, use the normal C6. Otherwise branch on k (and don’t bother to remove k from the heap).
267. As in Algorithm L , let there be a sequential table BIMP( l ) for each literal l , containing all literals l ′ such that l ¯ ∨ l ′ is a binary clause. Furthermore, when the propagation algorithm sets L F ← l ′ because l ′ ∈ BIMP( l ) , we may set R l ← – l , instead of using a positive clause number as the “reason.” (Notice that a binary clause therefore need not be represented explicitly in MEM , if it is represented implicitly in the BIMP tables. The author’s implementation of Algorithm C uses BIMP tables only to expedite binary clauses that appear in the original input. This has the advantage of simplicity, since the exact amount of necessary space can be allocated permanently for each table. Learned binary clauses are comparatively rare in practice; thus they can usually be handled satisfactorily with watched literals, instead of by providing the elaborate buddy-system scheme that was important in Algorithm L .)
Here, more precisely, is how the inner loop goes faster with BIMP s. We want to carry out binary propagations as soon as possible, because of their speed; hence we introduce a breadth-first exploration process analogous to (62):
S e t H ← F ; t a k e a c c o u n t o f l ′ f o r a l l l ′ ∈ B I M P ( l 0 ) ; w h i l e H < F , s e t l 0 ← L H , H ← H + 1 , a n d ( ∗ ∗ ) t a k e a c c o u n t o f l ′ f o r a l l l ′ ∈ B I M P ( l 0 ) .
Now “take account of l ′ ” means “if l ′ is true, do nothing; if l ′ is false, go to C7 with conflict clause l ¯ ∨ l ′ ; otherwise set L F ← l ′ , TLOC( | l ′ | ) ← F , VAL( | l ′ | ) ← 2 d + ( l ′ & 1), R l ← – l , F ← F + 1.” We do (∗∗) just before setting c ← c ′ in answer 261 . Furthermore, we set E ← F just after G ← 0 in step C1 and just after F ← F +1 in steps C6 and C9; and if G ≤ E after G ← G + 1 in step C4, we do (∗∗) with l 0 ← l ¯ .
Answer 263 is modified in straightforward ways so that “clause R l ” is treated as if it were the binary clause ( l ∨ l ¯ ′ ) when R l has the negative value – l ′ .
268. If MEM[ c – 1 ] = k ≥ 3 is the size of clause c , and if 1 < j < k , we can delete the literal l in MEM[ c + j ] by setting k ← k – 1, MEM[ c – 1 ] ← k , l ′ ← MEM[ c + k ] , MEM[ c + j ] ← l ′ , and MEM[ c + k ] ← l + f , where f is a flag (typically 2 31 ) that distinguishes a deleted literal from a normal one. (This operation does not need to be done when the current level d is zero; hence we can assume that k ≥ 3 and j > 1 before deletion. The flag is necessary so that global operations on the entire set of clauses, such as the purging algorithm, can pass safely over deleted literals. The final clause in MEM should be followed by 0, an element that’s known to be unflagged.)
269. (a) If the current clause contains a literal l \= L ¯ t that is not in the trivial clause, where t is maximum, resolve the current clause with R l ¯ and repeat.
(b) ( u ¯ 1 ∨ b j ) ∧ ( l j ∨ l ¯ j − 1 ∨ b ¯ j ) for 1 ≤ j ≤ 9, ( l 0 ∨ u ¯ 2 ∨ u ¯ 3 ) ∧ ( l ¯ 9 ∨ l ¯ 8 ∨ b ¯ 10 ) ; l ′ = l 0 .
(c) If r ≥ d ′ + τ , where τ is a positive parameter, learn the trivial clause instead of ( l ¯ ′ ∨ b ¯ 1 ∨ … ∨ b ¯ r ) . (The watched literals should be l ¯ ′ and ū d .)
Notice that this procedure will learn more t han simple backtrack à la Algorithm D does, even when the trivial clause is always substituted (that is, even when τ = –∞), because it provides for backjumping when d ′ < d +1.
270. (a) Consider the clauses 3 2 ¯ , 4 3 ¯ 2 ¯ , 5 4 ¯ 3 ¯ 1 ¯ , 6 5 ¯ 4 ¯ 1 ¯ , 6 ¯ 5 ¯ 4 ¯ , with initial decisions L 1 ← 1, L 2 ← 2. Then L 3 ← 3 with reason R 3 ← 3 2 ¯ ; similarly L 4 ← 4, L 5 ← 5. If L 6 ← 6, the conflict clause 6 ¯ 5 ¯ 4 ¯ allows us to strengthen R 6 to 5 ¯ 4 ¯ 1 ¯ ; but if L 6 ← 6 ¯ , with R 6 ¯ ← 6 ¯ 5 ¯ 4 ¯ , we don’t notice that 6 5 ¯ 4 ¯ 1 ¯ can be strengthened. In either case we can, however, strengthen R 5 to 4 ¯ 3 ¯ 1 ¯ , before learning the clause 2 ¯ 1 ¯ .
(b) After doing blit ( l j ) to the literals of R l , we know that R l \ l is contained in { b ¯ 1 , … , b ¯ r } together with q + 1 unresolved false literals that have been stamped at level d . ( Exercise 268 ensures that p ≠ 0 within each blit .) Thus we can subsume clause R l on the fly if q + r +1 < k and q > 0.
In such cases the procedure of answer 268 can be used to delete l from c = R l . But there’s a complication, because l = l 0 is a watched literal ( j = 0 in that answer), and all other literals are false. After l is deleted, it will be essential to watch a false literal l ′ that is defined at trail level d . So we find the largest j ′ ≤ k such that VAL(MEM[ c + j ′ ]) ≥ 2 d , and we set l ′ ← MEM[ c + j ′ ] . If j ′ ≠ k , we also set MEM[ c + j ′ ] ← MEM[ c + k ] ; we can assume that j ′ > 1. Finally, after setting MEM[ c ] ← l ′ and MEM[ c + k ] ← l + f as in answer 268 , we also delete c from the watch list W l , and insert it into W l ′ .
[This enhancement typically saves 1%–10% of the running time, but sometimes it saves a lot more. It was discovered in 2009, independently by two different groups of researchers: See H. Han and F. Somenzi, LNCS 5584 (2009), 209–222; Y. Hamadi, S. Jabbour, and L. Saïs, Int. Conf. Tools with Artif. Int. (ICTAI) 21 (2009), 328–335.]
271. We shall check for discards only if the current clause C i is not trivial (see exercise 269 ), and if the first literal of C i – 1 does not appear in the trail. (Indeed, experience shows that almost every permissible discard falls into this category.) Thus, let C i – 1 be l 0 l 1 ...l k – 1 where VAL( | l 0 | ) < 0; we want to decide if { l ¯ ′ , b ¯ 1 , … , b ¯ r } ⊆ { l 1 , … , l k − 1 } .
The secret is to use the stamp fields that have already been set up. Set j ← k –1, q ← r + 1, and do the following while q > 0 and j ≥ q : If l j \= l ¯ ′ , or if 0 ≤ VAL( | l j | ) ≤ 2 d ′ + 1 and S( | l j | ) = s , set q ← q – 1; in any case set j ← j – 1. Then discard if q = 0.
272. Reflection isn’t as easy to implement as it may seem, unless C is a unit clause, because C R must be placed carefully in MEM and it must be consistent with the trail. Furthermore, experience shows that it’s best not to learn the reflection of every learned clause, because excess clauses make unit propagation slower. The author has obtained encouraging results, however, by doing the following operations just before returning to C3 in step C9, whenever the length of C doesn’t exceed a given parameter R :
Assign ranks to the literals of C R by letting rank( l ) = ∞ if l is on the trail, rank( l ) = d ″ if l ¯ is on the trail at level d ′ < d ′ , rank( l ) = d otherwise. Let u and v be two of the highest ranking literals, with rank( u ) ≥ rank( v ). Put them into the first two positions of C R , so that they will be watched. Do nothing further if rank( v ) > d ′ . Otherwise, if rank( v ) < d ′ , backjump to level rank( v ) and set d ′ ← rank( v ). Then if rank( u ) = rank( v ) = d ′ , treat C R as a conflict clause by going to step C7 with c ← C R . (That is a rare event, but it can happen.) Otherwise, if u doesn’t appear in the current trail, set L F ← u , TLOC( | u | ) ← F , R u ← C R , F ← F + 1. (Possibly F = E + 2 now.)
(For example, this method with R ← 6 roughly halved the running time of waerden (3 , 10; 97) and waerden (3 , 13; 160) with parameters (193) except for ρ ← . 995.)
A similar idea works with the clauses langford ( n ), and in general whenever the input clauses have an automorphism of order 2.
273. (a) We can convert Algorithm C into a “clause learning machine” by keeping the process going after F reaches n in step C5: Instead of terminating, start over again by essentially going back to step C1, except that the current collection of clauses should be retained, and the OVAL polarities should be reset to random bits. Learned clauses of size K or less, where K is a parameter, should be written to a file. Stop when you’ve found a given number of short clauses, or when you’ve exceeded a given time limit.
For example, here’s what happened when the author first tried to find W (3 , 13): Applying this algorithm to waerden (3 , 13; 158) with K = 3, and with a timeout limit of 30 G μ (gigamems), yielded the five clauses 65 68 70, 68 78 81, 78 81 90, 78 79 81, 79 81 82. So fifteen clauses 65 68 70, 66 69 71, ... , 81 83 84 could be added to waerden (3 , 13; 160), as well as their fifteen reflections 96 93 91, 95 92 90, ... , 80 78 77. Then the algorithm “C R ”of exercise 272 proved this augmented set unsatisfiable after an additional 107 G μ . In a second experiment, using K = 2 with waerden (3 , 13; 159) led to three binary clauses 76 84, 81 86, and 84 88. Shifting and reflecting gave twelve binary clauses, which in company with waerden (3 , 13; 160) were refuted by C R in another 80 G μ . (For comparison, Algorithm C R refuted waerden (3 , 13; 160) unaided in about 120 G μ , compared to about 270 G μ for both Algorithm C and Algorithm L .) Optimum strategies for learning useful clauses from satisfiable subproblems are far from clear, especially because running times are highly variable. But this method does show promise, especially on more difficult problems — when more time can be devoted to the preliminary learning.
(b) Short clauses that can be learned from satisfiable instances of, say, X 0 → X 1 → … → X r – 1 , when X 0 is not required to be an initial state, can be shifted and used to help refute X 0 → X 1 → … → X r .
274. With care, circular reasoning can (and must) be avoided. But the author’s elaborate experiments with such ideas (and with the related notion of “better conflicts”) were disappointing; they didn’t beat the running time of the simpler algorithm. However, an intriguing idea by Allen Van Gelder [ Journal on Satisfiability, Boolean Modeling and Computation 8 (2012), 117–122] shows promise.
275. When a solution has been found, let k be minimum such that x k \= 1 and the value of x k has not been assigned at level 0. If no such k exists, we stop. Otherwise we are entitled to force variables x 1 through x k – 1 all to have their current values, at level 0, because we know that this doesn’t produce an unsatisfiable problem. So we fix those values, and we restart the solution process at level 1 with the tentative decision ‘ x k \= 0’. If a conflict occurs, we’ll know that x k \= 1 at level 0; if not, we’ll have a solution with x k \= 0. In either case we can increase k . (This method is considerably better than that of answer 109 , because every learned clause remains valid .)
276. True. Unit propagation essentially transforms F ∧ L into F | L .
277. Otherwise F ∧ C 1 ∧…∧ C t – 1 ⊢ 1 ∊ fails (unit propagation wouldn’t start).
278. For example, (46 , 5 ¯ 6 , 5 ¯ 4 , 6 , 4 , ∊ ). (Six steps are necessary.)
279. True, because the dependency digraph contains a literal l with l → ∗ l ¯ → ∗ l .
280. (a) They’re satisfied if and only if x 1 ...x n has at least j 0s and at least k 1s. [The problem cook ( k, k ) was introduced by Stephen A. Cook (unpublished) in 1971.]
(b) Take all positive ( j – t )-clauses on {1 ,...,n – 1 – t } for t = 1, 2, ... , j .
(c) Suppose the very first decision is L 0 ← x n . The algorithm will proceed to act as if the input were cook ( j, k ) | x n \= cook ( j, k – 1). Furthermore, with these clauses, every clause that it learns initially will include x ¯ n . Therefore, by induction, the unit clause ( x ¯ n ) will be learned clause number ( n − 2 j − 1 ) . All previously learned clauses are subsumed by this one, hence they’re no longer relevant. The remaining problem is cook ( j , k ) | x ¯ n \= c o o k ( j − 1 , k ) ; so the algorithm will finish after learning ( n − 2 j − 2 ) more.
Similarly, if the first decision is L 0 ← x ¯ n , the ( n − 2 j − 2 ) th learned clause will be ( x n ).
281. Stålmarck’s refutation corresponds to the sequence ( M j k 1 ′ , M j k 2 ′ , ... , M j k ( k − 1 ) ′ , M j ( k – 1) ) for j = 1, ... , k – 1, for k = m , m – 1, ... , 1. ( M j k ( k − 1 ) ′ can be omitted.)
282. First learn the exclusion clauses (17). In the next clauses we shall write a j , b j , ... , as shorthand for a j,p , b j,p , ... , where p is a particular color, 1 ≤ p ≤ 3. Notice that the 12 q edges appear in 4 q triangles, namely { b j ,c j ,d j }, { a j ,a j ′ ,b j ′ }, { f j ,e j ′ ,c j ′ }, {e j ,f j ′ ,d j ′ }, for 1 ≤ j ≤ q , where j ′ is j + 1 (modulo q ). For every such triangle {u, v, w }, learn ( ū p ′ ∨ v p ∨ w p ) and then ( u p ∨ v p ∨ w p ), where p ′ is p + 1 (modulo 3).
Now for j = 1,2, ... , q , learn ( a j ∨ f j ∨ a j ′ ∨ e j ′ ), ( a j ∨ e j ∨ a j ′ ∨ f j ′ ), ( e j ∨ f j ∨ e j ′ ∨ f j ′ ), ( ā j ∨ ē j ∨ ē j ′ ), ( a ¯ j ∨ f ¯ j ∨ f ¯ j ′ ) , ( e ¯ j ∨ f ¯ j ∨ a ¯ j ′ ) , as well as eighteen more:
( u ¯ 1 ∨ v ¯ 1 ∨ u j ′ ) , ( u ¯ 2 ∨ v ¯ 2 ∨ u j ′ ′ ∨ v j ′ ′ ) , i f j ≥ 3 i s o d d ; ( u ¯ 1 ∨ v ¯ 1 ∨ u j ′ ) , ( u ¯ 2 ∨ v ¯ 2 ∨ u ¯ j ′ ′ ) , i f j ≥ 3 i s e v e n ;
here u, v ∈ { a, e, f } and u ′ ,v ′ ∈ { a, e, f } yield 3 × 3 choices of ( u, v, u ′ ,v ′ ). Then we’re ready to learn ( ā j ∨ ē j ), ( a ¯ j ∨ f ¯ j ) , ( e ¯ j ∨ f ¯ j ) for j ∈ {1 , 2} and ( a j ∨ e j ∨ f j ∨ a j ′ ), ( a j ∨ e j ∨ f j ) for j ∈ {1 ,q }. All of these clauses are to be learned for 1 ≤ p ≤ 3.
Next, for j = q , q – 1, ... , 2, learn ( ā j ∨ ē j ), ( a ¯ j ∨ f ¯ j ) , ( e ¯ j ∨ f ¯ j ) for 1 ≤ p ≤ 3 and then ( a j – 1 ∨ e j – 1 ∨ f j – 1 ∨ a j ), ( a j – 1 ∨ e j – 1 ∨ f j – 1 ) for 1 ≤ p ≤ 3. We have now established all clauses in the hint.
The endgame consists of the following for 1 ≤ p ≤ 3: For all choices of p ′ and p ″ with { p, p ′ ,p ″ } = {1 , 2 , 3} (thus two choices), and for j = 2, 3, ... , q , learn three clauses
( a ¯ 1 , p ∨ e ¯ 1 , p ′ ∨ a ¯ j , p ∨ e ¯ j , p " ) , ( a ¯ 1 , p ∨ e ¯ 1 , p ′ ∨ a ¯ j , p ′ ∨ e j , p ) , ( a ¯ 1 , p ∨ e ¯ 1 , p ′ ∨ a ¯ j , p " ∨ e j , p ′ ) , j e v e n ; ( a ¯ 1 , p ∨ e ¯ 1 , p ′ ∨ a ¯ j , p ∨ e ¯ 1 , p ′ ) , ( a ¯ 1 , p ∨ e ¯ 1 , p ′ ∨ a ¯ j , p ′ ∨ e j , p " ) , ( a ¯ 1 , p ∨ e ¯ 1 , p ′ ∨ a ¯ j , p " ∨ e j , p ) , j o d d ;
then learn ( ā 1 ,p ∨ ē 1 ,p ′ ). Finally learn ā 1 ,p .
[Not all of these clauses are actually necessary. For example, the exclusion clauses for b ’s, c ’s, and d ’s aren’t used. This certificate doesn’t assume that the symmetry-breaking unit clauses b 1 , 1 ∧ c 1 , 2 ∧ d 1 , 3 of fsnark ( q ) are present; indeed, those clauses don’t help it much. The actual clauses learned by Algorithm C are considerably longer and somewhat chaotic (indeed mysterious); it’s hard to see just where an “aha” occurs!]
283. A related question is to ask whether the expected length of learned clauses is O (1) as q → ∞. Note : Exercise 7.2.2.3–232 has further information.
284. It’s convenient to represent each unit clause ( l ) in F ∪ C 1 ∪...∪ C t as if it were the binary clause ( l ∨ x ¯ 0 ), where x 0 is a new variable that is always true. We borrow some of the data structures of Algorithm C , namely the trail array L , the reason array R , and the fields TLOC , S , VAL associated with each variable. We set VAL( k ) = 0, 1, or –1 when x k has been forced true, forced false, or not forced, respectively.
To verify the clause C i \= ( a 1 ∨...∨ a k ), we begin with VAL( j ) ← 0 for 0 ≤ j ≤ n , L 0 ← 0, L 1 ← ā 1 , ... , L k ← ā k , E ← F ← k +1, G ← 0, and VAL( | L p | ) ← L p & 1 for 0 ≤ p < F ; then we carry out unit propagation as in Algorithm C , expecting to reach a conflict before G = F . (Otherwise verification fails.)
A conflict arises when a clause c = l 0 ...l k – 1 forces l 0 at a time when l ¯ 0 has already been forced. Now we mimic step C7 (see exercise 263 ), but the operations are much simpler: Mark c , stamp S( | l j | ) ← i for 0 ≤ j < k , and set p ← max ( TLOC( | l 1 | ) ,..., TLOC( | l k – 1 | ) ). Now, while p ≥ E , we set l ← L p , p ← p – 1, and if S( | l | ) = i we also “resolve with the reason of l ” as follows: Let clause R l be l 0 l 1 ...l k – 1 , mark R l , and set S( | l j | ) ← i for 1 ≤ j < k .
[ Wetzler, Heule, and Hunt have suggested an interesting improvement, which will often mark significantly fewer clauses at the expense of a more complicated algorithm: Give preference to already-marked clauses when doing the unit propagations, just as Algorithm L prefers binary implications to the implications of longer clauses (see (62)).]
285. (a) j = 77, s 77 = 12 + 2827, m 77 = 59, b 77 = 710.
(b) j = 72, s 72 = 12 + 2048, m 72 = 99 + 243 + 404 + 536 = 1282, b 72 = 3 + 40 + 57 + 86 = 186. (The RANGE statistic is rather coarse when α \= 1 2 , because many different signatures yield the same value.)
(c) j = 71, s 71 = 12 + 3087, m 71 = 243, b 71 = 40.
286. The maximum, 738, is achieved uniquely by the RANGE -oriented solution with α \= 15 16 , except that we can optionally include also the signatures (6 , 0) and (7 , 0) for which a pq \= 0. [This solution optimizes the worst case of clause selection, because the stated problem implicitly assumes that the secondary heuristic is bad. If we assume, however, that the choice of tie-breakers based on clause activity is at least as good as a random choice, then the expected number 738 + 45 ⋅ 10 59 ≈ 745.6 from α \= 15 16 is not as good as the expected number 710 + 287 ⋅ 57 404 ≈ 750.5 from α \= 9 16 .]
287. When a conflict is detected in step C7 (with d > 0), keep going as in step C3; but remember the first clause C d that detected a conflict at each level d .
Eventually step C5 will find F = n . That’s when clauses get their RANGE scores, if we’re doing a full run because we want to purge some of them. (Sometimes, however, it’s also useful to do a few full runs at the very beginning, or just after a restart, because some valuable clauses might be learned.)
New clauses can be learned in the usual way from the remembered clauses C d , in decreasing order of d , except that “trivial” clauses ( exercise 269 ) are considered only at the lowest such level. We must keep track of the minimum backjump level d ′ , among all of these conflicts. And if several new clauses have the same d ′ , we must remember all of the literals that will be placed at the end of the trail after we eventually jump back.
288. Step C5 initiates a full run, then eventually finds F = n . At this point we’re done, in the unlikely event that no conflicts have arisen. Otherwise we set LS[ d ] ← 0 for 0 ≤ d < n and m j ← 0 for 1 ≤ j < 256. The activity ACT( c ) of each learned clause c has been maintained in MEM[ c – 5 ] , as a 32-bit floating point number. The following steps compute RANGE( c ) , which will be stored in MEM[ c – 4 ] as an integer, for all learned c in increasing order, assuming that c ’s literals are l 0 l 1 ...l s – 1 :
If R l 0 = c , set RANGE( c ) ← 0. Otherwise set p ← r ← 0, and do the following for 0 ≤ k < s : Set v ← VAL( | l k | ) . If v < 2 and v + l k is even, set RANGE( c ) ← 256 and exit the loop on k (because c is permanently satisfied, hence useless). If v ≥ 2 and LS[ lev ( l k ) ] < c , set LS[ lev ( l k ) ] ← c and r ← r + 1. Then if v ≥ 2 and LS[ lev ( l k ) ] = c and l k + v is even, set LS[ lev ( l k ) ] ← c + 1 and p ← p + 1. After k reaches s , set r ← min (16( p + α ( r – p )) , 255), RANGE( c ) ← r , and m r ← m r +1.
Now resolve conflicts (see answer 287 ), giving ACT( c ) ← 0 and RANGE( c ) ← 0 to all newly learned clauses c , and jump back to trail level 0. (A round of purging is a major event, something like spring cleaning. It is possible that d ′ = 0, in which case one or more literals have been appended to trail level 0 and their consequences have not yet been explored.) Find the median range j as defined in (124), where T is half the total current number of learned clauses. If j < 256 and T > s j , find h = T – s j clauses with RANGE( c ) = j and ACT( c ) as small as possible, and bump their range up to j +1. (This can be done by putting the first m j – h of them into a heap, then repeatedly bumping the least active as the remaining h are encountered; see exercise 6.1–22.)
Finally, go again through all the learned clauses c , in order of increasing c , ignoring c if RANGE( c ) > j , otherwise copying it into a new location c ′ ≤ c . (Permanently false literals, which are currently defined at level 0, can also be removed at this time; thus the clause’s size in MEM[ c ′ – 1 ] might be less than MEM[ c – 1 ] . It is possible, but unlikely, that a learned clause becomes reduced to a unit in this way, or even that it becomes empty.) The activity score in MEM[ c – 5 ] should be copied into MEM[ c ′ – 5 ] ; but RANGE( c ) and the watch links in MEM[ c – 2 ] and MEM[ c – 3 ] needn’t be copied.
When copying is complete, all the watch lists should be recomputed from scratch, as in answer 260 , including original clauses as well as the learned clauses that remain.
289. By induction, y k \= (2 – 2 1–k )Δ + (2( k – 2) + 2 2– k ) δ for all k ≥ 0.
290. Set k ← HEAP[ 0 ] ; then if VAL( k ) ≥ 0, delete k from the heap as in answer 262 , and repeat this loop.
291. OVAL( 49 ) will be the even number 36, because of the propagations on level 18 that led to (115).
292. If AGILITY ≥ 2 32 – 2 13 , then (127) either subtracts 2 19 – 1 or adds 1. Hence there’s a minuscule chance that AGILITY will overflow by passing from 2 32 – 1 to 2 32 (zero). (But overflow won’t be a calamity even if — unbelievably — it happens. So this is one “ bug” in the author’s program that he will not try to fix.)
293. Maintain integers u f , v f , and θ f , where θ f has 64 bits. Initially u f = v f = M f = 1. When M ≥ M f in step C5, do this: Set M f ← M f + v f . If u f &– u f = v f , set u f ← u f + 1, v f ← 1, θ f ← 2 32 ψ ; otherwise set v f ← 2 v f and θ f ← θ f + ( θ f ≫4). Flush if AGILITY ≤ θ f .
294. We have, for example, g 1100 \= z 3 ( g 0100 + g 1000 + g 1110 ) , and g 01∗1 = 1. The solution is g 00∗1 = g 01∗0 = g 11∗1 = A/D , g 00∗0 = g 10∗1 = g 11∗0 = B/D , g 10∗0 = C/D , where A = 3 z – z 2 – z 3 , B = z 2 , C = z 3 , D = 9 – 6 z – 3 z 2 + z 3 . Hence the overall generating function is g = (6 A +6 B +2 C +2 D )/(16 D ); and we find g ′ (1) = 33/4, g ″ (1) = 147. Thus mean( g ) = 8 . 25, var( g ) = 87 . 1875, and the standard deviation is ≈ 9 . 3.
295. Consider all 3 ( n 3 ) clauses x ¯ i ∨ x j ∨ x k for distinct { i, j, k }, plus two additional clauses ( x ¯ 1 ∨ x ¯ 2 ∨ x ¯ 3 ) ∧ ( x ¯ 4 ∨ x ¯ 5 ∨ x ¯ 6 ) to make the solution 0 ... 0 unique. Only the two latter clauses cause the variables X t and Y t in the proof of Theorem U to deviate from each other. [C. Papadimitriou, Computational Complexity (1994), Problem 11.5.6. These clauses spell trouble for a lot of other SAT algorithms too.]
296. The hinted ratio 2(2 p + q +1)(2 p + q )/(9( p +1)( p + q +1)) is ≈ 1 when p ≈ q (more precisely when p = q – 7+ O (1 /q )). And f ( q + 1 , q + 1 ) / f ( q , q ) \= 2 ( n − q ) ( 3 q + 3 ) 3 ¯ / ( 27 ( q + 1 ) 2 ( 2 q + 2 ) 2 ¯ ) is ≈ 1 when q ≈ n/ 3. Finally, f ( n / 3 , n / 3 ) \= 3 4 π n ( 3 / 4 ) n ( 1 + O ( 1 / n ) ) by Stirling’s approximation, when n = 3 q .
297. (a) G q ( z ) = ( z/ 3) q C (2 z 2 /9) q = G ( z ) q where G ( z ) \= ( 3 − 9 − 8 z 2 ) / ( 4 z ) , by Eqs. 7.2.1.6–(18) and (24). [See Algorithmica 32 (2002), 620–622.]
(b) G q (1) = 2 – q is the probability that Y t actually reaches 0, for some finite t
(c) If the Y process does stop, G q ( z ) /G q (1) = (2 G ( z )) q describes the distribution of stopping times. Hence G q ′ ( 1 ) / G q ( 1 ) \= 2 q G ′ ( 1 ) \= 3 q is the mean length of the random walk, given that it terminates. (The variance, incidentally, is 24 q . A random Y -walker who doesn’t finish quickly is probably doomed to wander forever.)
(d) The generating function for T , the stopping time of the Y process, is T ( z ) \= Σ q ( n q ) 2 − n G q ( z ) ; and T is finite with probability T ( 1 ) \= ( 3 4 ) n by (b). If we restrict consideration to such scenarios, the mean T ′ (1) /T (1) is n ; and Markov’s inequality tells us that Pr( T ≥ N | the algorithm terminates) ≤ n/N .
(e) The algorithm succeeds with probability p > Pr( T < N ) ≥ (1 – n/N )(3/4) n , when it is given satisfiable clauses. So it fails after K (4/3) n trials with probability less than exp( K (4/3) n ln(1 – p )) < exp(– K (4/3) n p ) < exp(– K/ 2) when N = 2 n .
298. Change 1/3 and 2/3 in (129) to 1 /k and ( k – 1) /k . The effect is to change G ( z ) to ( z/k ) C (( k – 1) z 2 /k 2 ), with G (1) = 1/( k – 1) and G ′ (1) = k/ (( k – 1)( k – 2)). As before, T (1) = 2 – n (1 + G (1)) n and T ′ (1) /T (1) = nG ′ (1)/(1 + G (1)). So the generalized Corollary W gives success probability > 1 – e – K/ 2 when we apply Algorithm P K (2 – 2 /k ) n times with N = ⌊2 n/ ( k – 2)⌋.
299. In this case G ( z ) \= ( 1 − 1 − z 2 ) / z ; thus G (1) = T (1) = 1. But G ′ (1) = ∞, so we must use a different method. The probability of failure if N = n 2 is
1 2 n Σ p , q ( n q ) q 2 p + q ( 2 p + q p ) [ 2 p + q > n 2 ] 2 2 p + q \= Σ t > n 2 2 − n − t t Σ p ( n t − 2 p ) ( t p ) ( t − 2 p ) ≤ Σ t > n 2 2 − n − t t ( t ⌊ t / 2 ⌋ ) Σ p ( n t − 2 p ) ( t − 2 p ) \= n 4 Σ t > n 2 2 − t t ( t ⌊ t / 2 ⌋ ) < n 4 Σ t > n 2 2 π t 3 \= n 8 π ∞ n 2 d x ⌈ x ⌉ 3 / 2 < n 8 π ∞ n 2 d x x 3 / 2 \= 1 2 π .
[See C. Papadimitriou, Computational Complexity (1994), Theorem 11.1.]
300. In this algorithm, variables named with uppercase letters (except C and N ) denote bit vectors of some fixed size (say 64); each bit position represents a separate trial. The notation U r stands for a vector of random bits, each of which is 1 with probability 1 /r , independently of all other bits and all previous U ’s. The maximum number of flips per bit position in this variant of Algorithm P is only approximately equal to N .
P1 ′ . [Initialize.] Set X i ← U 2 for 1 ≤ i ≤ n . Also set t ← 0.
P2 ′ . [Begin pass.] Set Z ← 0 and j ← 0. (Flipped positions are remembered in Z .)
P3 ′ . [Move to next clause.] If j = m , go to P5 ′ . Otherwise set j ← j +1.
P4 ′ . [Flip.] Let C j be the clause ( l 1 ∨… ∨ l k ). Set Y ← L ¯ 1 & … & L ¯ k , where L i denotes X h if l i \= x h and L i denotes X ¯ h if l i \= x ¯ h . (Thus Y has 1s in positions that violate clause C j .) Set Z ← Z | Y and t ← t +( Y & 1). Then for r = k , k – 1, ... , 2 set Y ′ ← Y & U r , L r ← L r ⊕ Y ′ , Y ← Y – Y ′ . Finally set L 1 ← L 1 ⊕ Y and return to P3 ′ .
P5 ′ . [Done?] If Z ≠ –1, terminate successfully: One solution is given by the bits ( X 1 & B ) ... ( X n & B ), where B \= Z ¯ & ( Z + 1 ) . Otherwise, if t > N , terminate unsuccessfully. Otherwise return to P2 ′ .
The shenanigans in step P4 ′ have the effect of flipping the offending bits of each literal with probability 1 /k , thus distributing the 1s of Y in an un biased fashion.
301. In practice we can assume that all clauses have limited size, so that (say) k ≤ 4 in step P4 ′ . The clauses can also be sorted by size.
A traditional random number generator produces bits U 2 ; and one can use U 2 & U 2 to get U 4 . The method of exercise 3.4.1–25 can be used for other cases; for example,
U 2 & ( U 2 | ( U 2 & ( U 2 | ( U 2 & ( U 2 | ( U 2 & ( U 2 | ( U 2 & U 2 ) ) ) ) ) ) ) )
is a sufficiently close approximation to U 3 . The random numbers needed in step P1 ′ must be of top quality; but those used in step P4 ′ don’t have to be especially accurate, because most of their bits are irrelevant. We can precompute the latter, making tables of 2 d values for each of U 2 , U 3 , U 4 , and running through them cyclically by means of table indices U2P , U3P , U4P as in the code below, where UMASK = 2 d +3 – 1. The values of U2P , U3P , and U4P should be initialized to (truly) random bits whenever step P2 ′ starts a new pass over the clauses.
Here is sample code for the inner loop, step P4 ′ , for clauses with k = 3. The octabyte in memory location L +8( i –1) is the address in memory where X h is stored, plus 1 if it should be complemented; for example, if l 2 is x ¯ 3 , the address X +3×8+1 will be in location L + 8, where L is a global register. Register mone holds the constant –1.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
302. Assume that literals are represented internally as in Algorithm A , and that all clauses have strictly distinct literals. An efficient implementation actually requires more arrays than are stated in the text: We need to know exactly which clauses contain any given literal, just as we need to know the literals of any given clause.
W4. [Choose l .] Set g ← [ U ≥ p ], c ← ∞, j ← z ← 0, and do the following while j < k : Set j ← j + 1. Then if c | l j | < c and either c | l j | \= 0 or g = 1, set c ← c | l j | and z ← 0. Then if c | l j | ≤ c , set z ← z + 1, and if zU < 1 also set l ← l j . (Here each random fraction U should be independent of the others.)
W5. [Flip l .] Set s ← 0. For each j such that C j contains l , make clause C j happier as follows: Set q ← k j , k j ← q +1; and if q = 0, set s ← s +1 and delete C j from the f array (see below); or if q = 1, decrease the cost of C j ’s critical variable (see below). Then set c | l | ← s and x | l | ← x ¯ | l | . For each j such that C j contains l ¯ , make clause C j sadder as follows: Set q ← k j –1, k j ← q ; and if q = 0, insert C j into the f array (see below); or if q = 1, increase the cost of C j ’s critical variable (see below). Set t ← t + 1 and return to W2.
To insert C j into f , we set f r ← j , w j ← r , and r ← r + 1 (as in step W1). To delete it, we set h ← w j , r ← r – 1, f h ← f r , w f r ← h .
Whenever we want to update the cost of C j ’s critical variable in step W5, we know that C j has exactly one true literal. Thus, if the literals of C j appear sequentially in a master array M , it’s easy to locate the critical variable x | M i | : We simply set i ← START( j ) ; then while M i is false (namely while x | M i | \= M i & 1), set i ← i +1.
A slight refinement is advantageous when we will be increasing c | M i | : If i ≠ START( j ) , swap M START( j ) ↔ M i . This change significantly shortens the search when c | M i | is subsequently decreased. (In fact, it reduced the total running time by more than 5% in the author’s experiments with random 3SAT problems.)
303. In this case D = 3 – z – z 2 = A/z , and we have g ′ (1) = 3, g ″ (1) = 73/4. Thus mean( g ) = 3 and var( g ) = 12 . 25 = 3 . 5 2 .
304. If νx = x 1 + … + x n \= a , there are a ( n – a ) unsatisfied clauses; hence there are two solutions, 0 ... 0 and 1 ... 1. If x 1 ...x n isn’t a solution, Algorithm P will change a to a ± 1, each with probability 1 2 . Thus the probability generating function g a for future flips is 1 when a = 0 or a = n , otherwise it is z ( g a – 1 + g a +1 )/2. And the overall generating function is g \= Σ a ( n a ) g a / 2 n . Clearly g a \= g n – a .
Exercise MPR–105 determines g a and proves that the mean number of flips, g a ′ ( 1 ) , is a ( n – a ) for 0 ≤ a ≤ n . Thus g ′ ( 1 ) \= 2 − n ∑ a \= 0 n ( n a ) g a ′ ( 1 ) \= 1 2 ( n 2 ) .
Turning now to Algorithm W , again with x 1 + … + x n \= a , the cost of x i is a – 1 when x i \= 1, n – a – 1 when x i \= 0. Therefore g 1 = g n – 1 = z in this case. And for 2 ≤ a ≤ n – 2, a ≠ n/ 2, we will move closer to a solution with probability q and farther from a solution with probability p , where p + q = 1 and p = p ′ /2 ≤ 1/2; here p ′ is the greed-avoidance parameter of Algorithm W . Thus for 2 ≤ a ≤ n/ 2 we have g a \= g n – a = z ( qg a – 1 + pg a +1 ).
If p ′ = 0, so that the walk is 100% greedy, Algorithm W zooms in on the solution, with g a \= z a . Exercise 1.2.6–68 with p = 1/2 tells us that g ′ ( 1 ) \= n / 2 − m ( n m ) / 2 n \= n / 2 − n / 2 π + O ( 1 ) in that case. On the other hand if p ′ = 1, so that the walk is greedy only when a = 1 or a = n – 1, we’re almost in the situation of Algorithm P but with n decreased by 2. Then g ′ ( 1 ) \= 2 − n ∑ a \= 1 n − 1 ( n a ) ( 1 + ( a − 1 ) ( n − 2 ) − ( a − 1 ) 2 ) \= n ( n − 5 ) / 4 + 2 + ( 2 n − 4 ) / 2 n ; greed triumphs.
What happens as p ′ rises from 0 to 1? Let’s decrease n by 2 and use the rule g a \= z ( qg a – 1 + pg a +1 ) for 1 ≤ a ≤ n/ 2, so that the calculations resemble those we did for Algorithm P but with p now ≤ 1/2 instead of p = 1/2. Functions t k and u k can be defined as in MPR–105; but the new recurrences are t k +1 = ( t k – pz 2 t k – 1 ) /q and u k +1 = ( u k – pz 2 u k – 1 ) /q . Hence
T ( w ) \= q − p w q − w + p z 2 w 2 ; U ( w ) \= q − ( 1 − q z ) w q − w + p z 2 w 2 .
Differentiating with respect to z , then setting z = 1, now yields
t k ′ ( 1 ) \= 2 p q ( 1 − ( p / q ) k ) ( q − p ) 2 − 2 p k q − p , u k ′ ( 1 ) \= 2 p q ( 1 − ( p / q ) k ) q ( q − p ) 2 − 2 p ( k − 1 / 2 ) q − p .
It follows that g a ′ ( 1 ) \= a / ( q − p ) − 2 p q ( ( p / q ) m − a − ( p / q ) m / ( q − p ) 2 for 0 ≤ a ≤ n/ 2 when n is even, a/ ( q – p ) – q (( p/q ) m – a – ( p/q ) m )/( q – p ) 2 when n is odd. The overall totals when n = 1000 and p ′ = ( . 001 , . 01 , . 1 , . 5 , . 9 , . 99 , . 999) are respectively ≈ (487 . 9 , 492 . 3 , 541 . 4 , 973 . 7 , 4853 . 4 , 44688 . 2 , 183063 . 4).
305. That little additional clause reverses the picture! Now there’s only one solution, and greediness fails badly when νx > n/ 2 because it keeps trying to move x away from the solution. To analyze the new situation in detail, we need 3( n – 1) generating functions g ab , where a = x 1 + x 2 and b = x 3 + … + x n . The expected number of flips will be g ′ (1), where g \= 2 − n Σ b \= 0 2 Σ b \= 0 n − 2 ( 2 a ) ( n − 2 b ) g a b .
The behavior of Algorithm P is ambiguous, because the unsatisfied clause found in step P2 depends on the clause ordering. The most favorable case arises when a = 2, because we can decrease a to 1 by working on the special clause x ¯ 1 ∨ x ¯ 2 . Any other clause is equally likely to increase or decrease a + b . So the best-case generating functions maximize the chance of reaching a = 2: g 00 = 1, g 01 \= z 2 ( g 00 + g 11 ) , g 02 \= z 2 ( g 01 + g 12 ) , g 10 \= z 2 ( g 00 + g 20 ) , g 11 \= z 2 ( g 10 + g 21 ) , g 12 \= z 2 ( g 11 + g 22 ) , and g 2 b = zg 1 b . The solution has g 1 b = ( z/ (2 – z 2 )) b +1 ; and we find mean( g ) = 183/32 = 5 . 71875.
The worst case arises whenever g 20 ≠ zg 10 and g 21 ≠ zg 11 ; for example we can take g 20 \= z 2 ( g 10 + g 21 ) , g 21 \= z 2 ( g 20 + g 22 ) , together with the other seven equations from the best case. Then g 01 = g 10 = z (4–3 z 2 ) /d , g 02 = g 11 = g 20 = z 2 (2– z 2 ) /d , and g 12 = g 21 = z 3 /d , where d = 8–8 z 2 + z 4 . Overall, g = (1+ z ) 2 (2– z 2 )/(4 d ) and mean( g ) = 11.
(This analysis can be extended to larger n : The worst case turns out to have g ab \= g a + b \= ( z/ 2) a + b t n – a – b /t n , in the notation of the previous exercise, giving n (3 n – 1)/4 flips on average. The best case has g 1 b as before; hence g 0 b ′ \= 3 b + 2 − 2 1 − b , g 16 ′ \= 3 b + 3 , and g 2 b ′ \= 3 b + 4 when z = 1. The best average number of flips therefore turns out to be linear , with mean ( g ) \= 3 2 n − 8 9 ( 3 / 4 ) n .)
The analysis becomes more exciting, but trickier, when we use Algorithm W . Let p = p ′ /2 and q = 1 – p as in the previous answer. Clearly g 00 = 1, g 01 = g 10 = zg 00 , g 02 \= z 2 ( g 01 + g 12 ) , and g 22 = zg 12 ; but the other four cases need some thought. We have
g 11 \= z 4 ( ( 1 2 + q ) ( g 01 + g 10 ) + g 12 + 2 p g 21 ) ,
since the costs for x 1 x 2 x 3 x 4 = 1010 are 1211 and the unsatisfied clauses are ( x ¯ 1 ∨ x 4 ) , ( x ¯ 3 ∨ x 4 ) , ( x ¯ 1 ∨ x 2 ) , ( x ¯ 3 ∨ x 2 ) ; in the former two clauses we flip each literal equally often, but in the latter two we flip x 2 with probability p and the other with probability q . A similar but simpler analysis shows that g 21 \= z 4 ( g 11 + 3 g 22 ) and g 20 \= z 5 ( g 10 + 2 g 21 ) .
The most interesting case is g 12 \= z 3 ( p g 02 + 2 p g 11 + 3 q g 22 ) , where the costs are 2122 and the problematic clauses are ( x ¯ 1 ∨ x 2 ) , ( x ¯ 3 ∨ x 2 ) , ( x ¯ 4 ∨ x 2 ) . If p = 0, Algorithm W will always decide to flip x 2 ; but then we’ll be back in state 12 after the next flip.
Indeed, setting p = 0 yields g 00 = 1, g 01 = g 10 = z , g 02 \= 1 2 z 2 , g 11 \= 3 4 z 2 , g 20 \= 3 5 z 2 + 3 40 z 4 , g 21 \= 3 16 z 3 , and g 12 = g 22 = 0. The weighted total therefore turns out to be g = (40 + 160 z + 164 z 2 +15 z 3 +3 z 4 )/640. Notice that the greedy random walk never succeeds after making more than 4 flips, in this case; so we should set N = 4 and restart after each failure. The probability of success is g (1) = 191/320. (This strategy is actually quite good: It succeeds after making an average of 1577/382 ≈ 4 . 13 flips and choosing random starting values x 1 x 2 x 3 x 4 about 320/191 times.)
If p is positive, no matter how tiny, the success probability for N = ∞ is g (1) = 1. But the denominator of g is 48 – 48 z 2 + 26 pz 2 + 6 pz 4 – 17 p 2 z 4 , and we find that mean( g ) = (1548+2399 p –255 p 2 )/(1280 p –680 p 2 ) = (6192+4798 p ′ –255 p ′2 )/(2560 p ′ – 680 p ′2 Taking p ′ = (.001, .01, .1, .5, .9, .99, .999) in this formula gives, respectively, the approximate values (2421.3, 244.4, 26.8, 7.7, 5.9, 5.7, 5.7).
(Calculations for n = 12 show that g is a polynomial of degree 8 when p = 0, with g (1) ≈ .51 and g ′ (1) ≈ 2.40. Thus, setting N = 8 yields success after about 16.1 flips and 1.95 initializations. When p > 0 we have g ′ (1) ≈ 1.635 p –5 + O ( p –4 ) as p → 0, and the seven values of p ′ considered above yield respectively (5 × 10 16 , 5 × 10 11 , 5 × 10 6 , 1034.3, 91.1, 83.89, 83.95) flips—surprisingly not monotone decreasing in p ′ . These WalkSAT statistics can be compared with 17.97 to 105 flips for Algorithm P .)
306. (a) Since l ( N ) = E N + (1 – qN )( N + l ( N )), we have qNl ( N ) = E N + N – N qN = p 1 + 2 p 2 + ... + N pN + N pN +1 + ... + N p ∞ \= N – ( q 1 + ... + qN –1).
(b) If N = m + k and k ≥ 0 we have E N = m 2 / n , q 1 + … + q N –1 \= km / n , and qN = m / n ; hence l ( N ) = n + k ( n – m )/ m .
(c) If N ≤ n , l ( N ) \= ( N − ( N 2 ) / n ) / ( N / n ) \= n − N − 1 2 ; otherwise l ( N ) \= l ( n ) \= n + 1 2 .
(d) From q N \= p 1 ( N – q 1 –…– q N – 1 ) and q N +1 = p 1 ( N +1 – q 1 – … – q N ) we deduce p N +1 = p 1 (1 – q N ), hence 1 – q N +1 = (1 – p 1 )(1 – q N ). So it’s a geometric distribution, with p t \= p (1 – p ) t –1 for t ≥ 1. (The fact that l (1) = l (2) = … is called the “ memoryless property” of the geometric distribution.)
(e) Choose p 1 , ... , p n arbitrarily, with q n \= p 1 + … + p n ≤ 1. Then, arguing as in (d), p n +1 , p n +2 , ... are defined by 1 – q N \= (1 – 1 /l ( n )) N – n (1 – q n ) for N ≥ n .
(f) Since l ( n +1) – l ( n ) = ( n – ( q 1 + … + q n ))(1 – 1 /q n ) ≤ 0, we must have q n \= 1 and l ( n ) = l ( n + 1). (The case l ( n ) < l ( n + 1) is impossible.)
(g) Let x = p 1 and y = p 2 . By part (f), the conditions are equivalent to 0 < x ≤ x + y < 1 and x (3 – 2 x – y ) > 1. Hence 0 < (2 x –1)(1– x )– xy ≤ (2 x –1)(1– x ); we get the general solution by first choosing 1 2 < x < 1 , then 0 ≤ y < (2 x – 1)(1 – x ) /x .
(h) If N ∗ = ∞ and l ( n ) < ∞, we can find n ′ with q n ′ l ( n ′ ) = p 1 +2 p 2 +…+ n ′ p n ′ + n ′ p n ′ +1 + … + n ′ p ∞ > l ( n ). Hence l ( N ) ≥ q N l ( N ) ≥ q n ′ l ( n ′ ) > l ( n ) for all N ≥ n ′ .
(i) We have q n + k = k/ ( k + 1) for k ≥ 0; hence l ( n + k ) = ( k + 1)( n + H k ) /k . The minimum occurs when l ( n + k ) ≈ l ( n + k – 1), namely when n ≈ k – H k ; thus k = n +ln n + O (1). For example, the optimum cutoff value when n = 10 is N ∗ = 23. (Notice that E ∞ = ∞, yet l = l ( N ∗ ) ≈ 14 . 194 in this case.)
(j) Let p t \= [ t> 1]/2 t –1 . Then l ( N ) = (3 – 2 2– N )/(1 – 2 1– N ) decreases to 3.
(k) Clearly l ≤ L . For N ≤ L we have l ( N ) = ( N – ( q 1 + … + q N – 1 )) /q N ≥ ( N –(1+ … +( N –1)) /L )/( N/L ) = L –( N –1)/2 ≥ ( L +1)/2. And for N = ⌊ L ⌋ + k +1, similarly, l ( N ) ≥ N – (1+ … + ⌊ L ⌋ + kL ) /L = ⌊ L + 1⌋ (1 – ⌊ L ⌋ /(2 L )) ≥ ( L +1)/2.
307. (a) E X = E N 1 +(1 – q N 1 )( N 1 +E X ′ ), where X ′ is the number of steps for the sequence ( N 2 ,N 3 ,... ). For numerical results, start with j ← 0, s ← 0, α ← 1; then, while α > ∊ , set j ← j +1, α ← (1 – q N j ) α , and s ← s + E N j + αN j . (Here ∊ is tiny.)
(b) Let P j \= (1 – q N 1 ) ... (1 – q N j –1 ) = Pr( X > T j ), and note that P j ≤ (1 – p n ) j –1 where n = min{ t | p t > 0}. Since q N l ( N ) = E N +(1 – q N ) N , we have
E X \= q N 1 l ( N 1 ) + ( 1 − q N 1 ) ( q N 2 l ( N 2 ) + ( 1 − q N 2 ) ( q N 3 l ( N 3 ) + … ) ) \= Σ j \= 1 ∞ P j q N j l ( N j ) \= Σ j \= 1 ∞ ( P j − P j + 1 ) l ( N j ) .
(c) E X ≥ Σ j \= 1 ∞ ( P j − P j + 1 ) l ( N ∗ ) \= l .
(d) We can assume that N j ≤ n for all j ; otherwise the strategy would do even worse. For the hint, let { N 1 ,...,N r } contain r m occurrences of m , for 1 ≤ m ≤ n , and suppose t m \= r m + … + r n . If t m < n/ (2 m ), the probability of failure would be (1 – m/n ) t m ≥ 1 – t m m/n > 1/2. Hence we have t m ≥ n/ (2 m ) for all m , and N 1 + … + N r \= t 1 + … + t n ≥ nH n /2.
Now there’s some m such that the first r – 1 trials fail on p ( m ) with probability > 1 2 . For this m we have E X > 1 2 ( N 1 + … + N r − 1 ) ≥ 1 2 ( N 1 + … + N r − n ) .
308. (a) 2 a +1 – 1; and we also have S 2 a + b \= S b +1 for 0 ≤ b < 2 a – 1 (by induction).
(b) The sequence ( u n ,v n ) in (131) has 1 + ρk entries with u n \= k ; and ρ 1 + … + ρn = n – νn by Eq. 7.1.3–(61). From the double generating function g ( w, z ) = Σ n ≥0 w νn z n = (1+ wz )(1+ wz 2 )(1+ wz 4 )(1+ wz 8 ) ... we deduce that Σ k ≥0 z 2 k +1–νk \= zg ( z –1 ,z 2 ).
(c) { n | S n = 2 a } = {2 a +1 k +2 a +1 – 1 – νk | k ≥ 0}; hence Σ n ≥0 z n [ S n = 2 a ] = z 2 a +1 –1 g ( z –1 , z 2 a +1 ) = z 2 a +1 –1 (1 + z 2 a +1 –1 ) (1 + z 2 a +1 –1 ) (1 + z 2 a +3 –1 )....
(d) When 2 a occurs for the 2 b th time, we’ve had 2 a + b – c – [ c > a ] occurrences of 2 c , for 0 ≤ c ≤ a + b . Consequently Σ( a , b , 1) = ( a + b – 1)2 a + b + 2 a +1 .
(e) The exact value is Σ c \= 0 a + b 2 a + b − c 2 c + Σ c \= 1 ρ k 2 a + b + c ; and ρ k ≤ λ k = [lg k ].
(f) The stated formula is E min k {Σ( a , b , k ) | Σ( a , b , k ) ≥ X }, if we penalize the algorithm so that it never succeeds unless it is run with the particular cutoff N = 2 a .
(g) We have Q ≤ (1 – q t ) 2 b ≤ (1 – q t ) 1/ qt < e –1 ; hence E X < ( a + b – 1)2 a + b + 2 a + 1 + Σ k \= 1 ∞ ( a + b + 2 k − 1 ) 2 a + b e − k \= 2 a + b (( a + b ) e/ ( e – 1) + e (3 – e )/( e – 1) 2 +2 1– b ). Furthermore we have 2 a + b < 8 l – 4 l [ b = 0], by exercise 306(k) .
309. No — far from it. If Algorithm C were to satisfy the hypotheses of exercise 306 , it would have to do complete restarts: It would not only have to flush every literal from the trail, it would also have to forget all the clauses that it has learned, and reinitialize the random heap. [But reluctant doubling appears to work well also outside of Vegas.]
310. A method analogous to (131) can be used: Let ( u 1 ′ , v 1 ′ ) \= ( 1 , 0 ) ; then define ( u n + 1 ′ , v n + 1 ′ ) \= ( u n ′ & − u n ′ \= 1 ≪ v n ′ ? (succ( u n ′ ) , 0): ( u n ′ , v n ′ + 1 ) ). Here ‘succ’ is the Fibonacci-code successor function that is defined by six bitwise operations in answer 7.1.3–158. Finally, let S n ′ \= F v n ′ + 2 for n ≥ 1. (This sequence 〈 S n ′ 〉 , like 〈 S n 〉, is “nicely balanced”; hence it is universal as in exercise 308 . For example, when F a appears for the first time, there have been exactly F a +2 – c occurrences of F c , for 2 ≤ c ≤ a .)
311. Because 〈 R n 〉 does surprisingly well in these tests, it seems desirable to consider also its Fibonacci analog: If f n \= succ( f n – 1 ) is the binary Fibonacci code for n , we can call 〈 ρ ′ n 〉 = 〈 ρf n 〉 = (0 , 1 , 2 , 0 , 3 , 0 , 1 , 4 , 0 ,... ) the “Fibonacci ruler function,” and let 〈 R n ′ 〉 \= ( 1 , 2 , 3 , 1 , 5 , 1 , 2 , 8 , 1 , … ) ) be the “ ruler of Fibonaccis,” where R n ′ \= F 2 + ρ ′ n .
The results ( E S ,E S ′ ,E R ,E R ′ ) for m = 1 and m = 2 are respectively (315 . 1 , 357 . 8 , 405 . 8 , 502 . 5) and (322 . 8 , 284 . 1 , 404 . 9 , 390 . 0); thus S beats S ′ beats R beats R ′ when m = 1, while S ′ beats S beats R ′ beats R when m = 2. The situation is, however, reversed for larger values of m : R beats R ′ beats S beats S ′ when m = 90, while R ′ beats R beats S ′ beats S when m = 89.
In general, the reluctant methods shine for small m , while the more “aggressive” ruler methods forge ahead as m grows: When n = 100, S beats R if and only if m ≤ 13, and S ′ beats R ′ if and only if m ≤ 12. The doubling methods are best when m isapower of 2 or slightly less; the Fibonacci methods are best when m is a Fibonacci number or slightly less. The worst cases occur at m = 65 = 2 6 + 1 for S and R (namely 1402.2 and 845.0); they occur at m = 90 = F 11 + 1 for S ′ and R ′ (namely 1884.8 and 805.9).
312. T ( m, n ) = m + b 2 b h 0 ( θ ) /θ + 2 b g ( θ ), where b = ⌈lg m ⌉, θ = 1 – m/n , h a ( z ) = Σ n z n [ S n \=2 a ], and g ( z ) = Σ n ≥1 S n z n = Σ a ≥0 2 a h a ( z ).
313. If l changes to 1, the number of unsatisfied clauses increases by the cost of | l | and decreases by the number of unsatisfied clauses that contain l ; and the latter is at least 1.
Consider the following interesting clauses, which have the unique solution 0000:
x 1 ∨ x ¯ 2 , x ¯ 1 ∨ x 2 , x 2 ∨ x ¯ 3 , x ¯ 2 ∨ x 3 , x 3 ∨ x ¯ 4 , x ¯ 3 ∨ x 4 , x ¯ 1 ∨ x ¯ 4 .
From 0110 the algorithm goes “uphill” to either 1110 or 0111.
314. (Solution by Bram Cohen, 2012.) Consider the 10 clauses 1 ¯ 2 ¯ 34 5 ¯ 67 , 1 ¯ 2 3 ¯ 4 5 ¯ 67 , 123 4 ¯ 5 , 123 4 ¯ 6 , 123 4 ¯ 7 , 1 ¯ 2 ¯ 3 ¯ 4 ¯ , 1 ¯ 2 ¯ 3 ¯ 5 ¯ , 1 ¯ 2 ¯ 3 ¯ 6 ¯ , 1 ¯ 2 ¯ 4 ¯ 5 ¯ , 1 ¯ 2 ¯ 4 ¯ 6 ¯ , and 60 more obtained by the cyclic permutation (1234567). All binary x = x 1 ...x 7 with weight νx = 2 have cost-free flips leading to weight 3, but no such flips to weight 1. Since the only solution has weight 0, Algorithm W loops forever whenever νx > 1. (Is there a smaller example?)
315. Any value with 0 ≤ p < 1/2 works, since each graph component is either K 1 or K 2 .
316. No; max θ (1 – θ ) d for 0 ≤ θ < 1 is d d /( d + 1) d +1 , when θ = 1/( d + 1). [But Theorem J for d > 2 is a consequence of the improved Theorem L in exercise 356(c) .]
317. Number the vertices so that the neighbors of vertex 1 are 2, ... , d ′ , and let G j \= G \ {1 ,...,j }. Then α ( G ) = α ( G 1 ) – Pr( A 1 ∩ Ā 2 ∩ … ∩ Ā m ), and the latter probability is ≤ Pr( A 1 ∩ Ā d ′ +1 ∩…∩ Ā m ) = Pr( A 1 | Ā d ′ +1 ∩…∩ Ā m ) α ( G d ′ ) ≤ pα ( G d ′ ).
Let ρ = ( d – 1)/ d . By induction we have α ( G j ) > ρα ( G j +1 ) for 1 ≤ j < d ′ , because vertex j + 1 has degree < d in G j . If d ′ = 1 then α ( G ) ≥ α ( G 1 ) – ρα ( G 1 ) > ρα ( G 1 ) > 0. Otherwise if d ′ ≤ d , α( G ) ≥ α ( G 1 ) – pα ( G d ′ ) > α( G 1 ) – pρ 1– d ′ α ( G 1 ) ≥ α( G 1 ) – pρ 1– d α ( G 1 ) = ρα ( G 1 ) > 0. Otherwise we must have d ′ = d + 1, with vertex 1 of degree d , and α ( G ) > α ( G 1 ) − p ρ − d α ( G 1 ) \= d − 2 d − 1 α ( G 1 ) ≥ 0 .
318. Let f n = M G ( p ) where G is the graph of a complete t -ary tree with t n leaves; thus G has t k vertices at distance k from the root, for 0 ≤ k ≤ n . Then
f 0 \= 1 − p , f 1 \= ( 1 − p ) t − p , a n d f n + 1 \= f n t − p f n − 1 t 2 f o r n > 1.
By Theorem S, it suffices to show that f n ≤ 0 for some n .
The key idea is to let g 0 = 1 – p and g n + 1 \= f n + 1 / f n t \= 1 − p / g n t . Assuming that g n > 0 for all n , we have g 1 < g 0 and g n − g n + 1 \= p / g n t − p / g n – 1 t > 0 when g n < g n – 1 . Hence lim n →∞ gn = λ exists, with 0 < λ < 1. Furthermore λ = 1 – p / λ t , so that p = λ t (1 – λ ). But then p ≤ t t /( t + 1) t + 1 (see answer 316 with θ = 1 – λ ).
[One must admit, however, that the limit is not often reached until n is extremely large. For example, even if t = 2 and p = .149, we don’t have f n < 0 until n = 45. Thus G must have at least 2 45 vertices before this value of p is too large for Lemma L.]
319. Let x = 1/( d – 1). Since e x > 1 + x = d /( d – 1), we have e > ( d /( d – 1)) d -1 .
320. (a) Let f m ( p ) be the Möbius polynomial when p 1 = … = p m = p . Then we have f m ( p ) = f m –1 ( p ) – pf m –2 ( p ), and one can show by induction that f m (1/(4 cos 2 θ )) = sin(( m + 2) θ )/((2 cos Ν ) m +1 sin θ ). The threshold decreases to 1/4 as m → ∞.
(b) 1 / ( 4 cos 2 π 2 m ) ; the Möbius polynomial g m ( p ) = f m –1 ( p ) – pf m –3 ( p ) satisfies the same recurrence as f m ( p ), and equals 2 cos mθ /(2 cos θ ) m when p = 1/(4 cos 2 θ ).
[In terms of the classical Chebyshev polynomials, g m ( p ) \= 2 p m / 2 T m ( 1 / 2 p ) ) and f m ( p ) \= p ( m + 2 ) / 2 U m + 1 ( 1 / 2 p ) ) .]
321. Let θ \= ( 2 − 2 ) / 2 , θ ′ \= θ ( 1 − θ ) \= ( 2 − 1 ) / 2 , and c = ( p – θ )/(1 – θ). The method of answer 345 gives ( Pr ( A ¯ B ¯ C ¯ D ¯ ) , Pr ( A B ¯ C ¯ D ¯ ) , Pr ( A B C ¯ D ¯ ) , Pr ( A B ¯ C D ¯ ) , Pr ( A B C D ¯ ) , Pr( ABCD )) = (0, θ ′ (1– c ) 3 , 2 θ ′ (1– c ) c , θ 2 (1– c ) 2 +2 θ ′ (1– c ) 3 , θ 2 (1– c ) c +3 θ ′ (1– c ) c 2 , θ 2 c 2 + 4 θ ′ c 3 ). Other cases are symmetric to these six. When p = 3/10 the six probabilities are ≈ (0, .20092, .00408, .08815, .00092, .00002).
322. (a) Let a j = Σ i w i ⌈ ij ∈ A ⌉, b j = Σ k yk ⌈ jk ∈ B ⌉, c l = Σ k yk ⌈ kl ∈ C ⌉, and d l = Σ i w i ⌈ li ∈ D ⌉. Then when X = j and Z = l , the best way to allocate the events is
within W and Y . Hence Pr ( A ¯ ∩ B ¯ ∩ C ¯ ∩ D ¯ ) \= Σ j , l x j z l ( ( a ¯ j + d ¯ l ) − 1 ) ( ( b ¯ j + c ¯ l ) − 1 ) , which is zero if and only if we have a j + d l ≥ 1 or b j + c l ≥ 1 for all j and l with x j z l > 0.
(b) Since Σ j x j ( a j , b j ) = ( p , p ), the point ( p , p ) lies in the convex hull of the points ( a j , b j ). So there must be points ( a , b ) = ( a j ′ , b j ′ ) and ( a ′ , b ′ ) = ( a j ′ , b j ′ ) such that the line from ( a , b ) to ( a ′ , b ′ ) intersects the region {( x , y ) | 0 ≤ x , y ≤ p }; in other words μa + (1 – μ ) a ′ ≤ p and μb + (1 – μ ) b ′ ≤ p . Similarly we can find c , d , c ′ , d ′ , ν .
(c) Fact: If a ≥ 2 3 and b ′ ≥ 2 3 , then μ ≥ 1 2 ; hence a \= b ′ \= 2 3 and a ′ = b = 0. Notice also that there are 16 symmetries, generated by (i) a ↔ b , c ↔ d ; (ii) a ↔ a ′ , b ↔ b ′ , μ ↔ 1 – μ ; (iii) c ↔ c ′ , d ↔ d ′ , ν ↔ 1 – ν ; (iv) a ↔ d , b ↔ c , μ ↔ ν .
If c ≤ c ′ and d ≤ d ′ , or if c ≤ 1 3 and d ≤ 1 3 , we can assume (by symmetry) that the Fact applies; this gives a solution to all the constraints, with c \= d \= c ′ \= d ′ \= 1 3 .
For the remaining solutions we may assume that a , b ′ > 1 3 > a ′ , b . Suppose the line from ( a, b ) to ( a ′ ,b ′ ) intersects the line from (0 , 0) to (1 , 1) at the point ( α, α ); dividing a , b , a ′ , b ′ by 3 α gives a solution in which μ a + ( 1 − μ ) a ′ \= μ b + ( 1 − μ ) b ′ \= 1 3 . Similarly, we can assume that d , c ′ > 1 3 > d ′ , c and that ν c + ( 1 − ν ) c ′ \= ν d + ( 1 − ν ) d ′ \= 1 3 . Consequently a + d ≥ 1 and b ′ + c ′ ≥ 1. Symmetry also allows us to assume that a + d ′ ≥ 1. In particular, a > 2 3 ; and, by the Fact, b ′ < 2 3 . So a ′ + d ≥ 1, d > 2 3 , c ′ < 2 3 .
Now extend the lines that connect ( a, b ) to ( a ′ ,b ′ ) and ( c, d ) to ( c ′ ,d ′ ), by increasing a , b ′ , c ′ , d while decreasing a ′ , b , c , d ′ , until a ′ = 1 – d and a = 1 – d ′ , and until either a = 1 or b = 0, and either d = 1 or c = 0. The only solution of this kind with b ′ + c ′ ≥ 1 occurs when a = d = 1, a ′ = b = c = d ′ = 0, b ′ = c ′ = 1/2, μ \= 1 3 , ν \= 2 3 .
(d) For the first solution, we can let W , X , Y , Z be uniform on {0 , 1 , 2}, {0 , 1}, {0 , 1 , 2}, and {0}, respectively; and let A = {10 , 20}, B = {11 , 12}, C = {00}, D = {00}. (For example, WXY Z = 1110 gives event B .) The second solution turns out to be the same, but with ( X, Y, Z, W ) in place of ( W, X, Y, Z ). Notice that the solution applies also to P 4 , where the threshold is 1 3 . [See STOC 43 (2011), 242.]
323. cbc . In this simple case, we just eliminate all strings in which c is followed by a .
324. For 1 ≤ j ≤ n , and for each v such that v = x j or v ––– x j , let i ≺ j for each i < j such that v = x i . (If several values of i qualify, it suffices to consider only the largest one. Several authors have used the term “ dependence graph” for this partial ordering.) The traces equivalent to α correspond to the topological sortings with respect to ≺, because those arrangements of the letters are precisely the permutations that preserve the empilement.
In (136), for example, with x 1 ...x n \= bcebafdc , we have 1 ≺ 2, 1 ≺ 4, 2 ≺ 4, 4 ≺ 5, 3 ≺ 6, 2 ≺ 7, 3 ≺ 7, 2 ≺ 8, 4 ≺ 8, and 7 ≺ 8. Algorithm 7.2.1.2V produces 105 solutions, 12345678 ( bcebafdc ) through 36127485 ( efbcdbca ).
325. Every such trace α yields an acyclic orientation, if we let u ––→ v when u appears at a lower level in α ’s empilement. Conversely, the topological sortings of any acyclic orientation are all equivalent traces; so this correspondence is one-to-one. [See Ira M. Gessel, Discrete Mathematics 232 (2001), 119–130.]
326. True: x commutes with y if and only if y commutes with x .
327. Each trace α is represented by its height h = h ( α ) ≥ 0, and by h linked lists L j \= L j ( α ) for 0 ≤ j < h . The elements of L j are the letters on level j of α ’s empilement; these letters have disjoint territories, and we keep each list in alphabetic order so that the representation is unique. The canonical string representing α is then L 0 L 1 ...L h – 1 . (For example, in (136) we have L 0 = be , L 1 = cf , L 2 = bd , L 3 = ac , and the canonical representation is becfbdac .) We also maintain the sets U j \= ∪{ T ( a ) | a ∈ L j } as bit vectors; in (136), for example, they are U 0 = # 36 , U 1 = # 1b , U 2 = # 3c , U 3 = # 78 .
To multiply α by β , do the following for k = 0, 1, ... , h ( β ) – 1 (in that order), and for each letter b ∈ L k ( β ) (in any order): Set j ← h ( α ); then while j > 0 and T ( b ) & U j – 1 ( α ) = 0, set j ← j – 1. If j = h ( α ), set L j ( α ) empty, U j ( α ) ← 0, and h ( α ) ← h ( α ) + 1. Insert b into L j ( α ), and set U j ( α ) ← U j ( α )+ T ( b ).
328. Do the following for k = h ( β ) – 1, ... , 1, 0 (in that order), and for each letter b ∈ L k ( β ) (in any order): Set j ← h ( α ) – 1; while j > 0 and T ( b )& U j ( α ) = 0, set j ← j – 1. Report failure if b isn’t in L j ( α ). Otherwise remove b from that list and set U j ( α ) ← U j ( α ) – T ( b ); if U j ( α ) is now zero, set h ( α ) ← h ( α ) – 1.
If there was no failure, the resulting α is the answer.
329. Do the following for k = 0, 1, ... , h ( α ) – 1 (in that order), and for each letter a ∈ L k ( α ) (in any order): Report failure if a isn’t in L 0 ( β ). Otherwise remove a from that list, set U 0 ( β ) ← U 0 ( β ) – T ( a ), and renormalize the representation of β .
Renormalization involves the following steps: Set j ← c ← 1. While U j – 1 ( β ) ≠ 0 and c ≠ 0, terminate if j = h ( β ); otherwise set c ← 0, j ← j +1, and then, for each letter b in L j – 1 ( β ) such that T ( b )& U j – 2 ( β ) = 0, move b from L j – 1 ( β ) to L j – 2 ( β ) and set U j – 2 ( β ) ← U j – 2 ( β )+ T ( b ), U j – 1 ( β ) ← U j – 1 ( β ) – T ( b ), c ← 1. Finally, if U j – 1 ( β ) = 0, set U i – 1 ( β ) ← U i ( β ) and L i – 1 ( β ) ← L i ( β ) for j ≤ i < h ( β ), then set h ( β ) ← h ( β ) – 1.
If there was no failure, the resulting β is the answer.
330. Let the territorial universe be V ∪ E , the vertices plus edges of G , and let T ( a ) = {a } ∪ {{ a, b } | a ––– b }. [G. X. Viennot, in 1985, called this subgraph a starfish .] Alternatively, we can get by with just two elements in each set T ( a ) if and only if G = L ( H ) is the line graph of some other multigraph H . Then each vertex a of G corresponds to an edge u ––– v in H , and we can let T ( a ) = { u, v }.
[ Notes: The smallest graph G that isn’t a line graph is the “ claw” K 1 , 3 . Since sets of independent vertices in the line graph G are sets of disjoint edges in H , also called matchings of H , the Möbius polynomial of G is also known as the “matching polynomial” of H . Such polynomials are important in theoretical chemistry and physics. When all territories have | T ( a )| ≤ 2, all roots of the polynomial M G ∗ ( z ) in (149) are real and positive, by exercise 341 . But M claw ( z, z, z, z ) = 1 – 4 z +3 z 2 – z 3 has complex roots ≈ 0 . 317672 and 1 . 34116 ± 1 . 16154 i .]
331. If α is a string with k > 0 occurrences of the substring ac , there are 2 k ways to decompose α into factors { a, b, c, ac }, and the expansion includes + α and – α each exactly 2 k –1 times. Thus we’re left with the sum of all strings that don’t contain ‘ ac ’.
332. No: If b commutes with a and c , but ac ≠ ca , we’re dealing with strings that contain no adjacent pairs ba or cb ; hence cab qualifies, but it’s equivalent to the smaller string bca . [Certain graphs do define traces with the stated property, as we’ve seen in (135) and (136). Using the next exercise we can conclude that the property holds if and only if no three letters a < b < c have a ― b , b ― c , and a ––– c in the graph G of clashes. Thus the letters can be arranged into a suitable linear order if and only if G is a cocomparability graph; see Section 7.4.2.]
333. To show that Σ α ∈ A , β ∈ B (–1) |β| αβ = 1, let γ = a 1 ...a n be any nonempty string. If γ cannot be factored so that a 1 ...a k ∈ A and a k +1 ...a n ∈ B , then γ doesn’t appear. Otherwise γ has exactly two such factorizations, one in which k has its smallest possible value and the other in which k is one greater; these factorizations cancel each other in the sum. [ Discrete Mathematics 14 (1976), 215–239; Manuscripta Mathematica 19 (1976), 211–243. See also R. Fröberg, Mathematica Scandinavica 37 (1975), 29–39.]
334. Equivalently we want to generate all strings of length n on the alphabet {1 ,...,m } that satisfy the following criterion, which strengthens the adjacent-letter test of exercise 332 : If 1 ≤ i < j ≤ n , x i ― x j , x i + 1 ― x j , ... , x j − 1 ― x j , then x i ≤ x j . [See A. V. Anisimov and D. E. Knuth, Int. J. Comput. Inf. Sci. 8 (1979), 255–260.]
T1. [Initialize.] Set x 0 ← 0 and x k ← 1 for 1 ≤ k ≤ n .
T2. [Visit.] Visit the trace x 1 ...x n .
T3. [Find k .] Set k ← n . While x k \= m set k ← k – 1. Terminate if k = 0.
T4. [Advance x k .] Set x k ← x k + 1 and j ← k – 1.
T5. [Is x k valid?] If x j > x k and x j ― x k , return to T4. If j > 0 and x j < x k and x j ― x k , set j ← j – 1 and repeat this step.
T6. [Reset x k +1 ...x n .] While k < n do the following: Set k ← k +1, x k ← 1; while x k – 1 > x k and x k − 1 ― x k , set x k ← x k + 1. Then go back to T2.
335. Given such an ordering, we have M G \= det( I – A ), where the entry in row u and column v of A is v [ u ≥ v or u ––– v ]. The determinant in the given example is
det ( 1 − b − c 0 0 0 0 1 − b 0 − d 0 0 0 − b 1 − c − d − e 0 0 − b − c 1 − d 0 − f 0 − b − c − d 1 − e − f 0 − b − c − d − e 1 − f ) + det ( − a − b − c 0 0 0 0 1 c − d 0 0 0 0 1 − d − e 0 0 0 0 1 − d 0 − f 0 0 0 − d 1 − e − f 0 0 0 − d − e 1 − f ) ,
after expanding the first column, then subtracting the first row from all other rows in the right-hand determinant. Therefore this rule satisfies recurrence (142).
[The result also follows from MacMahon’s Master Theorem, exercise 5.1.2–20, using the characterization of lexi cographically smallest traces in answer 334 . According to Theorem 5.1.2B, such traces are in one-to-one correspondence with multiset permutations whose two-line representation does not contain v u when v > u and v ― u . Is there a similar determinantal expression when G is not a cocomparability graph?]
336. (a) If α is a trace for G and β is a trace for H , we have μ G ⊕ H ( αβ ) = μ G ( α ) μ H ( β ). Hence M G ⊕ H \= M G M H . (b) In this case μ G ––– H ( αβ ) = μ G ( α ) if β = ∊ , μ H ( β ) if α = ∊ ; otherwise it’s zero. Therefore M G ––– H \= M G + M H – 1.
[These rules determine M G recursively whenever G is a cograph (see exercise 7 – 90 ). In particular, complete bipartite and k -partite graphs have simple Möbius series, exemplified by M G \= (1 – a )(1 – b )(1 – c ) + (1 – d )(1 – e )+(1 – f ) – 2 when G = K 3 , 2 , 1 .]
337. Substituting a 1 + … + a k for a in M G gives M G ′ . (Each trace for G ′ is obtained by putting subscripts on the a ’s of the traces for G .)
338. The proof of Theorem F needs only minor changes: We limit α to traces that contain no elements of A , and we define α ′ and β ′ by letting a be the smallest letter ∉ A in the bottom level of γ ’s empilement. If γ has no such letter, there’s only one factorization, with α = . Otherwise we pair up cancelling factorizations. [Incidentally, the sum of all traces whose sinks are in A must be written in the other order: M G − 1 M G \ A .]
339. (a) “Push down” on piece x j and factor out what comes through the floor.
(b) Factor out the pyramid for the smallest label, and repeat on what’s left.
(c) This is a general convolution principle for labeled objects [see E. A. Bender and J. R. Goldman, Indiana Univ. Math. J. 20 (1971), 753–765]. For example, when l = 3 the number of ways to get a labeled trace of length n from three labeled pyramids is Σ i , j , k ( n i , j , k ) P i P j P k / 3 ! \= n ! Σ i , j , k ( P i / i ! ) ( P j / j ! ) ( P k / k ! ) / 3 ! , with i + j + k = n in both of these sums. We divide by 3! so that the topmost pyramid labels will be increasing.
(d) Sum the identity in (c) for l = 0, 1, 2, ... .
(e) T ( z ) = Σ n ≥0 t n z n = 1/ M G ( z ) by Theorem F, and P ( z ) = Σ n ≥1 p n z n / n . Note: If we retain the letter names, writing for example M G ( z ) = 1–( a + b + c ) z + acz 2 instead of M G ( z ) = 1–3 z + z 2 , the formal power series – ln M G ( z ) exhibits the pyramids of length n in the coefficient of z n , but only in the sense of commutative algebra (not trace algebra). For example, the coefficient of z 3 obtained from Σ k ≥1 (1 – M G ( z )) k /k with trace algebra includes the nonpyramidal term bac/ 6.
340. Let w (( i 1 ... i k )) = (–1) k –1 a i 1 i 2 a i 2 i 3 ... a i k i 1 ; thus w ( π ) = (– a 13 a 34 a 42 a 21 ) (– a 57 a 75 )( a 66 ) in the given example. The permutation polynomial is then det A , by definition of the determinant. (And we get the permanent , if we omit the (–1) k –1 .)
341. The hint is true when n = 2, since the first involution polynomials are w 11 x and w 11 w 22 x 2 – w 12 . And there’s a recurrence: W ( S ) = w ii xW ( S \ i ) – Σ j ≠ i W ( S \{ i, j }).
So we can prove the existence of n + 1 roots s 1 < r 1 < … < r n < s n +1 by induction: Let W n ( x ) be the polynomial for {1 ,...,n }. Then W n +1 ( x ) is w ( n +1)( n +1) xW n ( x ) minus n polynomials w ( n +1) j W ({1 ,...,n } \ j ), each with roots q k ( j ) that are nicely sandwiched between the roots of W n . Furthermore q n − k ( j ) \= − q k ( j ) and r n +1 – k = – r k , for 1 ≤ k ≤ n/ 2. It follows that W n +1 ( r n ) < 0, W n +1 ( r n – 1 ) > 0, and so on, with (–1) k W n +1 ( r n +1 – k ) > 0 for 1 ≤ k ≤ n/ 2. Moreover, W n +1 (0) = 0 when n is even; (–1) k W n +1 (0) > 0 when n = 2 k – 1; and W n +1 ( x ) > 0 for all large x . Hence the desired s k exist. [See Heilmann and Lieb, Physical Review Letters 24 (1970), 1412.]
342. If we replace ( i 1 ... i k ) by a i 1 i 2 a i 2 i 3 ... a i k i 1 (as in answer 340 , but without the (–1) k –1 ), then M G n becomes det( I – A ). Replacing a ij by a ij x j gives the determinant in MacMahon’s Master Theorem. And if x 1 = … = x n \= x , we get the polynomial det( I – xA ), whose roots are the reciprocals of the roots of A ’s characteristic polynomial.
343. The formulas in answer 336 show that M G ( p 1 ,...,p m ) increases whenever any p j decreases, with respect to a cograph G . The only graph on ≤ 4 vertices that isn’t a cograph is P 4 (see exercise 7–90); then M G ( p 1 ,p 2 ,p 3 ,p 4 ) = 1 – p 1 – p 2 – p 3 – p 4 + p 1 p 3 + p 1 p 4 + p 2 p 4 = (1 – p 1 )(1 – p 3 – p 4 ) – p 2 (1 – p 4 ). In this case also we can conclude that M G ( p 1 ,...,p 4 ) > 0 implies ( p 1 ,...,p 4 ) ∈ R( G ). But when G = P 5 , we find M G (1 – ∊, 1 – ∊, ∊, 1 – ∊, 1 – ∊ ) > 0 for 0 ≤ ∊ < ϕ –2 ; yet (1 – ∊, 1 – ∊, ∊, 1 – ∊, 1 – ∊ ) is never in R ( G ) because M G (0 , 0 , ∊, 1 – ∊, 1 – ∊ ) = –(1 – ∊ ) 2 .
344. (a) If some minterm, say B 1 B ¯ 2 B ¯ 3 B 4 , has negative “probability,” then p 1 p 4 × (1 – π 2 – π 3 + π 23 ) < 0; hence M G (0 ,p 2 ,p 3 , 0) < 0 violates the definition of R( G ).
(b) In fact, more is true: π I ∪ J \= π I π J when i ― j j for i ∈ I , j ∈ J , and I ∩ J = ∅.
(c) It’s M G ( p 1 [1 ∈ J ] ,...,p m [ m ∈ J ]), by (140) and (141). This important fact, already implicit in the solution to part (a), implies that β ( G | J ) > 0 for all J .
(d) Writing just ‘ J ’ for ‘ G | J ’, we shall prove that α ( i ∪ J ) /β ( i ∪ J ) ≥ α ( J ) /β ( J ) for i ∉ J , by induction on | J |. Let J ′ \= { j ∈ J | i ― j } . Then we have
α ( i ∪ J ) \= α ( J ) − Pr ( A i ∩ ∩ j ∈ J A ¯ j ) ≥ α ( J ) − Pr ( A i ∩ ∩ j ∈ J ′ A ¯ j ) ≥ α ( J ) − p i α ( J ′ ) ,
because of (133). Also β ( i ∪ J ) = β ( J ) – p i β ( J ′ ). Hence α ( i ∪ J ) β ( J ) – α ( J ) β ( i ∪ J ) ≥ ( α ( J ) – p i α ( J ′ )) β ( J ) – α ( J )( β ( J ) – p i β ( J ′ )) = p i ( α ( J ) β ( J ′ ) – α ( J ′ ) β ( J )), which is ≥ 0 by induction since J ′ ⊆ J .
[This argument proves that Lemma L holds whenever ( p 1 ,...,p m ) leads to a legitimate probability distribution with β ( G ) > 0; hence such probabilities are in R ( G ).]
(e) By induction, we have β ( i ∪ J ) = β ( J ) – θ i β ( J ′ ) Π i ––– j (1 – θ j ) ≥ β ( J ) – θ i β ( J ′ ) Π j ∈ J \ J ′ (1 – θ j ) ≥ (1 – θ i ) β ( J ), because β ( J ) /β ( J ′ ) ≥ Π j ∈ J \ J ′ (1 – θ j ).
345. (Solution by A. D. Scott and A. D. Sokal.) Set p j ′ \= ( 1 + δ ) p j where δ ≤ 0 is the slack of ( p 1 ,...,p m ). Then M G ( p 1 ′ , … , p m ′ ) \= 0 , but it becomes positive if any p ′ j is decreased. Define events B 1 ′ , + , B m ′ by the construction in exercise 344 . Let C 1 , ... , C m be independent binary random variables such that Pr( C j \= 1) = q j , where ( 1 − p j ′ ) ( 1 − q j ) \= 1 − p j . Then the events B j \= B j ′ ∨ C j satisfy the desired conditions: Pr ( B r | B ¯ j i ∩ … ∩ B ¯ j k ) \= Pr ( B i | B ¯ j i ′ ∩ … ∩ B ¯ j k ′ ) \= Pr ( B i ) \= p i ; and Pr ( B 1 ∨ … ∨ B m ) ≥ Pr ( B 1 ′ ∨ … ∨ B m ′ ) \= 1 .
346. (a) By (144), K a,G is the sum of all traces on the probabilities of G \ a whose sources are neighbors of a . Decreasing p j doesn’t decrease any trace.
(b) Suppose vertex a = 1 has neighbors 2, ... , j . If we’ve recursively computed M G \ a ∗ and M G \ a , finding that ( p j +1 , ... , p m ) ∈ R( G \ a ∗ ) and ( p 2 , ... , p m ) ∈ R( G \ a ), then we know K a,G ; and the monotonicity property in (a) implies that ( p 1 , ... , p m ) ∈ R( G ) if and only if aK a,G < 1.
The graph
in exercise 335 can, for example, be processed as follows:
M a b c d e f \= M b c d e f ( 1 − a M d e f M b c d e f ) \= ( 1 − a ′ ) ( 1 − b ′ ) … ( 1 − f ′ ) , a ′ \= a ( 1 − b ′ ) ( 1 − c ′ ) , M b c d e f \= M c d e f ( 1 − b M c e f M c d e f ) \= ( 1 − b ′ ) ( 1 − c ′ ) … ( 1 − f ′ ) , b ′ \= b ( 1 − c ″ ) ( 1 − c ′ ) ( 1 − d ′ ) , M c d e f \= M d e f ( 1 − c M f M d e f ) \= ( 1 − c ′ ) ( 1 − d ′ ) ( 1 − e ′ ) ( 1 − f ′ ) , c ′ \= c ( 1 − d ′ ) ( 1 − e ′ ) , M c e f \= M e f ( 1 − c M f M e f ) \= ( 1 − c ″ ) ( 1 − e ′ ) ( 1 − f ′ ) , c ″ \= c ( 1 − e ′ ) , M d e f \= M e f ( 1 − d M e M f ) \= ( 1 − d ′ ) ( 1 − e ′ ) ( 1 − f ′ ) , d ′ \= d ( 1 − e ″ ) ( 1 − e ′ ) ( 1 − f ′ ) , M e f \= M f ( 1 − e M ∊ M f ) \= ( 1 − e ′ ) ( 1 − f ′ ) , e ′ \= e ( 1 − f ′ ) , M e \= M ∊ ( 1 − e M ∊ M ∊ ) \= ( 1 − e ″ ) , e ″ \= e , M f \= M ∊ ( 1 − f M ∊ M ∊ ) \= ( 1 − f ′ ) , f ′ \= f ,
with M ∊ \= 1. (The equations on the left are derived top-down, then the equations on the right are evaluated bottom-up. We have ( a,b,...,f )∈ R ( G ) if and only if f ′ < 1, e ′ < 1, e ′ < 1, ... , a ′ < 1.) Even better is to traverse this graph in another order, using the rule M G ⊕ H \= M G M H ( exercise 336 ) when subgraphs aren’t connected:
M c d a b e f \= M d a b e f ( 1 − c M b M f M d a b e f ) \= ( 1 − c ′ ) ( 1 − d 1 ) + ( 1 − f ′ ) , c ′ \= c ( 1 − a ′ ) ( 1 − d ′ ) ( 1 − e ′ ) , M d a b e f \= M a b M e f ( 1 − d M a M e M a b M e f ) \= ( 1 − d ′ ) ( 1 − a ′ ) ( 1 − b ′ ) ( 1 − e ′ ) ( 1 − f ′ ) , ( s e e b e l o w )
M a b \= M b ( 1 − a M ϵ M b ) \= ( 1 − a ′ ) ( 1 − b ′ ) , a ′ \= a ( 1 − b ′ ) , M a \= M ϵ ( 1 − a M ϵ M ϵ ) \= ( 1 − a ″ ) , a ″ \= a , M b \= M ϵ ( 1 − b ( M ϵ M ϵ ) \= ( 1 − b ′ ) , b ′ \= b ,
where d ′ = dM a M ∊ /( M ab M ef ) = d (1 – a ″ )(1 – e ″ )/((1 – a ′ )(1 – b ′ )(1 – e ′ )(1 – f ′ )), and M ef , M e , M f , M are as before. In this way we can often solve the problem in linear time. [See A. D. Scott and A. D. Sokal, J. Stat. Phys. 118 (2005), 1151–1261, §3.4.]
347. (a) Suppose v 1 ––– v 2 –––…––– v k ––– v 1 is an induced cycle. We can assume that v 1 ≻ v 2 . Then, by induction on j , we must have v 1 ≻ … ≻ v j for 1 < j ≤ k ; for if v j +1 ≻ v j we would have v j +1 ––– v j – 1 by (∗). But now v k ––– v 1 implies that k = 3.
(b) Let the vertices be {1 ,...,m }, with territory sets T ( a ) ⊆ U for 1 ≤ a ≤ m ; and let U be a tree such that each U | T ( a ) is connected. Let U a be the least common ancestor of T ( a ) in U . (Thus the nodes of T ( a ) appear at the top of the subtree rooted at U a .) Since U a ∈ T ( a ), we have a ––– b when U a \= U b .
Writing s ≻ U t for the ancestor relation in U , we now define a ≻ b if U a ≻ U U b or if U a \= U b and a < b . Then (∗) is satisfied: If t ∈ T ( a ) ∩ T ( b ), we have U a ≻ U t and U b ≻ U t , hence U a ≻ ¯ U U b or U b ≻ ¯ U U a , hence a ≻ b or b ≻ a . And if a ≻ b ≻ c and t ∈ T ( a ) ∩ T ( c ), we have U a ≻ ¯ U U b ≻ ¯ U U c ; consequently U b ∈ T ( a ) ∩ T ( b ), because U b lies on the unique path between t and U a in U and T ( a ) is connected.
(c) Processing the nodes in any order such that a is eliminated before b whenever U a is a proper ancestor of U b will then lead only to subproblems in which the algorithm needs no “double-primed” variables.
For example, using ( a,b,...,g ) instead of (1 , 2,..., 7) in order to match the notation in exercise 346 , suppose U is the tree rooted at p having the edges p ––– q , p ––– r , r ––– s , r ––– t , and let T ( a ) = { p, q, r, t }, T ( b ) = { p, r, s }, T ( c ) = { p, q }, T ( d ) = { q }, T ( e ) = { r, s }, T ( f ) = { s }, T ( g ) = { t }. Then a ≻ b ≻ c ≻ d , c ≻ e ≻ f , e ≻ g . The algorithm computes M abcdefg = (1 – a ′ ) M bcdefg , M bcdefg = (1 – b ′ ) M cdefg , etc., where a ′ = aM f /M bcdefg , b ′ = bM dfg /M cdefg = b ( M d M f M g )/( M cd M ef M g ), etc.
In general, the tree ordering guarantees that no “double-primed” variables are needed. Thus the formulas reduce to v ′ = v/ Π u –– v , v≻u (1 – u ′ ) for each vertex v .
(d) For example, we have p 1 = a , ... , p 7 = g , θ 1 = a ′ , ... , θ 7 = g ′ in (c). The values of the θ ’s, which depend on the ordering ≻, are uniquely defined by the given equations; and we have M G ( p 1 , ... , p m ) = (1 – θ 1 ) ... (1 – θ m ) in any case. [W. Pegden, Random Structures & Algorithms 41 (2012), 546–556.]
348. There is at least one singularity at z = ρe iθ for some θ . If 0 < r < ρ , the power series f ( z ) \= Σ n \= 0 ∞ f ( n ) ( r e i θ ) ( z − r e i θ ) n / n ! has radius of convergence ρ – r . If z = ρ isn’t a singularity, the radius of convergence for θ = 0 would exceed ρ – r . But | f ( n ) ( r e i θ ) | \= | Σ m \= 0 ∞ m n ¯ a n ( r e i θ ) m − n | ≤ f ( n ) ( r ) . [ Mathematische Annalen 44 (1894), 41–42.]
349. Typical generating functions are g 0000001 = 1; g 0110110 = z ( g 0100110 + g 0101110 + g 0110110 + g 0111110 )/4 (in Case 1) or g 0110110 = z ( g 0000110 + g 0010110 + g 0100110 + g 0110110 )/4 (in Case 2). These systems of 128 linear equations have solutions whose denominators involve one or more of the polynomials 4– z ,2– z ,16–12 z + z 2 ,4–3 z ,64–80 z +24 z 2 – z 3 , 8 – 8 z + z 2 in Case 1 (see exercise 320 ); the denominators in Case 2 are powers of 4 – z .
Setting g ( z ) = Σ x g x ( z )/128 leads to g ( z ) = 1/((2 – z )(8 – 8 z + z 2 )) in Case 1, with mean 7 and variance 42; g ( z ) = (1088 – 400 z +42 z 2 – z 3 )/(4 – z ) 6 in Case 2, with mean 1139/729 ≈ 1 . 56 and variance 1139726/729 2 ≈ 2 . 14.
[The upper bound E 1 + … + E 6 is achieved by the distribution of Case 1, because it matches the extreme distribution (148) of the path graph P 6 . Incidentally, if Case 1 is generalized from n = 7 to arbitrary n , the mean is n ( n – 1)/6 and the variance is ( n + 3)( n +2) n ( n – 1)/90.]
350. (a) The generating function for N is Π k \= 1 n ( 1 − ξ k ) / ( 1 − ξ k z ) ; so the mean and variance, in general, are Σ k \= 1 n ξ k / ( 1 − ξ k ) and Σ k \= 1 n ξ k / ( 1 − ξ k ) 2 . In particular, the means are (i) n ; (ii) n/ (2 n – 1); (iii) n/ (2 n – 1); (iv) H 2 n − H n + 1 2 n \= ln 2 + O ( 1 / n ) ; (v) 1 2 ( 1 n + 1 + 1 2 n − 1 2 n + 1 ) \= 1 2 n + O ( 1 / n 2 ) . The variance in case (i) is 2 n ; otherwise it’s asymptotically the same as the mean, times 1 + O (1 /n ).
(b) In this case the mean and variance are ξ/ (1 – ξ ) and ξ/ (1 – ξ ) 2 , where ξ = Pr( A m ) = 1 – (1 – ξ 1 ) ... (1 – ξ n ). This value ξ is (i) 1 – 2 – n ; (ii) 1 − ( 1 − 1 2 n ) n \= 1 − e − 1 / 2 + O ( 1 / n ) ; (iii) 1 – (1 – 2 – n ) n = n/ 2 n + O ( n 2 /4 n ); (iv) 1/2; (v) 1/(2 n + 2). Hence the respective means are (i) 2 n – 1; (ii) e 1/2 – 1+ O (1 /n ); (iii) n/ 2 n + O ( n 2 /4 n ); (iv) 1; (v) 1/(2 n + 1). And the variances are (i) 4 n – 2 n ; (ii) e – e 1/2 + O (1 /n ); (iii) n/ 2 n + O ( n 2 /4 n ); (iv) 2; (v) 1/(2 n +1)+1/(2 n +1) 2 .
(c) Since G is K n, 1 , exercises 336 and 343 imply that ( ξ 1 ,...,ξ n ,ξ ) ∈ R( G ) if and only if ξ < 1 2 . This condition holds in cases (ii), (iii), and (v).
351. (Solution by Moser and Tardos.) We require i ––– j if there’s a setting of the variables such that A i is false and A j is true, provided that some change to the variables of Ξ j might make A i true. And vice versa with i ↔ j .
(The Local Lemma can be proved also for directed lopsidependency graphs; see Noga Alon and Joel H. Spencer, The Probabilistic Method (2008), §5.1. But the theory of traces, which we use to analyze Algorithm M , is based on undirected graphs, and no algorithmic extension to the directed case is presently known.)
352. Answer 344(e) , with M G \= β ( i ∪ J ), M G \ i \= β ( J ), proves that M G \ i /M G ≥ 1– θ i .
353. (a) There are n + 1 sorted strings in Case 1, namely 0 k 1 n – k for 0 ≤ k ≤ n . There are F n +2 solutions in Case 2 (see, for example, exercise 7.2.1.1–91).
(b) At least 2 n M G (1/4), where G is the path P n – 1 . By exercise 320 we have M G (1/4) = f n – 1 (1/4) = ( n +1)/2 n ; so Case 1 matches the lower bound.
(c) There are no lopsidependencies. Hence the relevant G is the empty graph on m = n –1 vertices; M G (1/4) = (3/4) n –1 by exercise 336 ; and indeed, F n +2 ≥ 3 n –1 2 2– n .
354. Differentiate (151) and set z ← 1.
355. If A = A j is an isolated vertex of G , then 1 – p j z is a factor of the polynomial M G ∗ ( z ) in (149), hence 1 + δ ≤ 1 /p j ; and E j \= p j /(1 – p j ) ≤ 1 /δ . Otherwise M G ( p 1 , … , p j − 1 , p j ( 1 + δ ) , p j + 1 , … , p m ) \= M G ∗ ( 1 ) − δ p j M G / A ∗ ∗ ( 1 ) > M G ∗ ( 1 + δ ) \= 0 ; so E j \= p j M G / A ∗ ∗ ( 1 ) / M G ∗ ( 1 ) > 1 / δ .
356. (a) We prove the hint by induction on | S |. It’s obvious when S = ∅; otherwise let X = S ∩ ∪ i ∈ U j U j and Y = S \ X . We have
Pr ( A i | A ¯ S ) \= Pr ( A i ∩ A ¯ X ∩ A ¯ Y ) Pr ( A ¯ X ∩ A ¯ Y ) ≤ Pr ( A i ∩ A ¯ Y ) Pr ( A ¯ X ∩ A ¯ Y ) ≤ Pr ( A i ) Pr A ¯ Y ) Pr ( A ¯ X ∩ A ¯ Y ) \= Pr ( A i ) Pr ( A ¯ X | A ¯ Y )
by (133). Suppose i belongs to the cliques U j 0 , ... , U j r where j = j 0 . Let X 0 = ∅ and X k \= ( S ∩ U j k ) \ X k –1 , Y k \= Y ∪ X 1 ∪ … ∪ X k – 1 for 1 ≤ k ≤ r . We have Pr( A l | Ā Y k ) ≤ θ lj k for all l ∈ X k , since | Y k | < | S | when X k ≠ = ∅; hence Pr( Ā X k | Ā Y k ) ≥ (1 + θ ij k – Σ j k ). Thus Pr( Ā X | Ā Y ) = Pr( Ā X 1 | Ā Y 1 ) Pr( Ā X 2 | Ā Y 2 ) ... Pr( Ā X r | Ā Y r ) ≥ Π k ≠ j,i ∈ U k (1 + θ ik – Σ k ), by the chain rule (exercise MPR-14); the hint follows.
Finally let W k \= U 1 ∪…∪ U k for 1 ≤ k ≤ t . The hint implies that
Pr ( A ¯ 1 ∩ … ∩ A ¯ m ) \= Pr ( A ¯ W 1 ) Pr ( A ¯ W 2 | A ¯ W 1 ) … Pr ( A ¯ W t | A ¯ W t − 1 ) ≥ ( 1 − Σ 1 ) ( 1 − Σ 2 ) … ( 1 − Σ t ) > 0.
(b) The extreme events B 1 , ... , B m of Theorem S satisfy the hint of (a). Thus Pr ( B i | ∩ k ∉ U j B ¯ k ) ≤ θ i j for all i ∈ U j ; hence q i \= Pr ( B i | ∩ k ≠ i B ¯ k ) ≤ θ i j / ( 1 + θ i j − Σ j ) . Furthermore E i \= q i /(1 – q i ) in (152), because q i \= p i M G \ i ∗ /M G \ i .
(c) Let U 1 , ... , U t be the edges of G , with θ ik \= θ i when U k \= { i, j }. Then Σ k \= θ i + θ j < 1, and the sufficient condition in (a) is that Pr( A i ) ≤ θ i Π j ≠ k , i ––– j (1– θ j ) whenever i ––– k . (But notice that Theorem M does not hold for such larger p i .)
[K. Kolipaka, M. Szegedy, and Y. Xu, LNCS 7408 (2012), 603–614.]
357. If r > 0, we have x = r/ (1– p ), y = r/ (1– q ). But r = 0 is possible only on the axes of Fig. 94 : Either ( p, q ) = (0 , 1), x = 0, 0 < y ≤ 1, or ( p, q ) = (1 , 0), 0 < x ≤ 1, y = 1.
358. Suppose x ≥ y (hence p ≥ q and X > 0). Then p ≤ r if and only if 1 – y ≤ y .
359. Instead of computing π l by formula (154), represent it as two numbers ( π l + , π l ′ ) , where π l + is the product of the nonzero factors and π l ′ is the number of zero factors. Then the quantity π l ¯ needed in (156) is π l ¯ + [ π l ¯ ′ \= 0 ] ; and the quantity π l /(1 – η C → l ) is π l + [ π l ′ \= 1 ] if η C → l \= 1, otherwise it’s π l + [ π l ′ \= 0 ] / ( 1 − η C → l ) . A similar method can be used to separate out the zero factors of Π l ∈ C γ l → C in (157).
360. We may assume that η 3 = 0. Since π l \= 1 implies that η C → l \= γ l ¯ → C \= 0 , we have η C → 1 \= η C → 2 ¯ \= η C → 3 \= η C → 4 ¯ \= γ 1 ¯ → C \= γ 2 → C \= γ 3 ¯ → C \= γ 4 → C \= 0 for all C . Consequently, as in (159), all but three of the values η C → l are zero; let x , y , z denote the others. Also let η 1 ¯ \= a , η 2 \= b , η 4 \= c , η 3 ¯ \= d . Then π 1 ¯ \= ( 1 − a ) ( 1 − x ) , π 2 = (1– b )(1– y ), π 4 = (1– c )(1– z ), and π 3 \= 1 − d . A fixed point is obtained if x = d ( b + cd (1– b )+ ad 2 (1– b )(1– c ))/(1 – d 3 (1– a )(1– b )(1– c )), etc. If d is 0 or 1 then x = y = z = d . [Are there any other fixed points, say with π 1 ≠ 1?]
361. The π ’s and γ ’s will also be either 0 or 1, and we exclude the case π l \= π l ¯ \= 0 ; thus each variable v is either 1, 0, or ∗, depending on whether ( π v , π v ¯ ) is(0 , 1), (1 , 0), or (1 , 1).
Any assignment of 1, 0, or ∗ to the variables is permissible, provided that every clause has at least one literal that’s true or two that are ∗. (Such partial assignments are called “covering,” and they’re usually possible even with unsatisfiable clauses; see exercise 364 .) All survey messages η C → l ′ \= η C → l are zero except when clause C has l as its only non-false literal. The reinforcement message η l can be either 0 or 1, except that it must be 1 if l is true ( π l \= 0) and all messages η C → l are 0.
If we also want η l ′ \= η l , we take κ = 1 in (158), and η l \= 1 – π l .
362. Create a linked list L , containing all literals that are to be forced true, including all literals that are in 1-clauses of the original problem. Do the following steps while L is nonempty: Remove a literal l from L ; remove all clauses that contain l ; and remove l ¯ from all the clauses that remain. If any of those clauses has thereby been reduced to a single literal, ( l ′ ), check to see if l ′ or l ¯ ′ is already present in L . If l ¯ ′ is present, a contradiction has arisen; we must either terminate unsuccessfully or restart step S8 with increased ψ . But if l ¯ ′ and l ′ are both absent, put l ′ into L .
363. (a) True; indeed, this is an important invariant property of Algorithm C .
(b) W (001) = 1, W (∗∗∗) = p 1 p 2 p 3 , otherwise W ( x ) = 0.
(c) Statements (i) and (iii) are true, but not (ii); consider x = 10∗, x ′ = 00∗, and the clause 123.
(d) All eight subsets of { 1 , 2 ¯ , 3 ¯ } are stable except { 2 ¯ , 3 ¯ } , because x 1 is constrained in 100. The other seven are partially ordered as shown. (This diagram illustrates L 7 , the smallest lattice that is lower semimodular but not modular.)
(e)
x 2 x 3 = 00 | 01 | 0∗ | 10 | 11 | 1∗ | ∗0 | ∗1 | ∗∗ | |
x 1 = 0 | 0 | q 1 q 2 | 0 | q 1 q 3 | q 1 q 2 q 3 | q 1 q 2 p 3 | 0 | q 1 p 2 q 3 | q 1 p 2 p 3 |
x 1 = 1 | q 2 q 3 | q 1 q 2 q 3 | q 1 q 2 p 3 | q 1 q 2 q 3 | q 1 q 2 q 3 | q 1 q 2 p 3 | q 1 p 2 q 3 | q 1 p 2 q 3 | q 1 p 2 p 3 |
x 1 = ∗ | 0 | p 1 q 2 q 3 | p 1 q 2 p 3 | p 1 q 2 q 3 | p 1 q 2 q 3 | p 1 q 2 p 3 | p 1 p 2 q 3 | p 1 p 2 q 3 | p 1 p 2 p 3 |
(f) One solution is { 1 ¯ 2 ¯ 3 4 ¯ 5 ¯ , 1 ¯ 4 , 2 ¯ 5 , 3 ¯ 4 5 ¯ , 3 ¯ 4 ¯ 5 } . (For these clauses the partial assignment {3} is stable, but it is “unreachable” below {1 , 2 , 3 , 4 , 5}.)
(g) If L = L ′ \ l and L ′ ∈ ℒ but L / ∉ ℒ, introduce the clause ( x 1 ∨ ∨ k ∈ L ′ x ¯ k ) .
(h) True, because L ′ = L \ l ′ and L ″ = L \ l ″ , where | l ′ | and | l ″ | are unconstrained with respect to L . A variable that’s unconstrained with respect to L is also unconstrained with respect to any subset of L .
(i) Suppose L ′ = L ′(0) ≺ … ≺ L ′( s ) \= {1 ,...,n } and L ″ = L ″(0) ≺ … ≺ L ″( t ) \= {1 ,...,n }. Then L ′( s – i ) ∩ L ″( t – j ) is stable for 0 ≤ i ≤ s and 0 ≤ j ≤ t , by induction on i + j using (h).
(j) It suffices to consider the case L = {1 ,...,n }. Suppose the unconstrained variables are x 1 , x 2 , x 3 . Then, by induction, the sum is q 1 q 2 q 3 + p 1 + p 2 + p 3 – ( p 1 p 2 + p 1 p 3 + p 2 p 3 )+ p 1 p 2 p 3 = 1, using “ inclusion and exclusion” to compensate for terms that are counted more than once. A similar argument works with any number of unconstrained variables.
Notes: See F. Ardila and E. Maneva, Discrete Mathematics 309 (2009), 3083– 3091. The sum in (j) is ≤ 1 when each p k + q k ≤ 1 for 1 ≤ k ≤ n , because it is monotone. Because of (i), the stable sets below L form a lower semimodular lattice, with
L ′ ∧ L ″ \= L ′ ∩ L ″ a n d L ′ ∨ L ″ \= ∩ { L ′ ′ ′ | L ′ ′ ′ ⊇ L ′ ∪ L ″ a n d L ′ ′ ′ ⊑ L } .
E. Maneva and A. Sinclair noted in Theoretical Comp. Sci. 407 (2008), 359–369 that a random satisfiability problem is satisfiable with probability ≤ E W ( X ), the expected total weight of partial assignments having the given distribution, because of identity (j); this led them to sharper bounds than had previously been known.
364. (a) True if and only if all clauses have length 2 or more.
(b) 001 and ∗∗∗ are covering; these are the partial assignments of nonzero weight, when q 1 = … = q n \= 0 in the previous exercise. Only 001 is a core.
(c) ∗∗∗ is the only covering and the only core; W (0101) = W (0111) = q 3 .
(d) In fact, every stable partial assignment L ′ has a unique covering assignment L with L ⊑ L ′ , namely L = ∩{ L ″ | L ″ ⊑ L ′ , obtained by successively removing unconstrained literals (in any order)}.
(e) If L ′ and L ″ are adjacent we have L ′ ∩ L ″ ⊑ L ′ and L ′ ∩ L ″ ⊑ L ″ .
(f) Not necessarily. For example, the clauses { 1 ¯ 2 ¯ 34 , 1 ¯ 2 3 ¯ 4 , 1 ¯ 2 3 ¯ 4 , 1 2 ¯ 3 ¯ 4 , 1 2 ¯ 3 4 ¯ , 12 3 ¯ 4 ¯ } define S ¯ 2 ( x 1 , x 2 , x 3 , x 4 ) ; there are two clusters but only an empty core.
[A. Braunstein and R. Zecchina introduced the notion of covering assignments in J. Statistical Mechanics (June 2004), P06007:1–18.]
365. If L is any of the six solutions in (8), and if q is odd, then qL – d is a covering assignment for 0 ≤ d < q and 8 q – d ≤ n < 9 q – d . (For example, if L \= { 1 ¯ , 2 ¯ , 3 , 4 , 5 ¯ , 6 ¯ , 7 , 8 } the partial assignment 3 L − 1 \= { 2 ¯ , 5 ¯ , 8 , 11 , 14 ¯ , 17 ¯ , 20 , 23 } works for n ∈ [23 .. 25].) Thus all n > 63 are “covered.” [Do all nonempty coverings of waerden (3 , 3; n ) have this form?]
366. Eliminating variable 1 ( x 1 ) by resolution yields the erp rule x ¯ 1 ← ( x 2 ∨ x ¯ 3 ) ∧ ( x 3 ∨ x 4 ) , and new clauses { 2 3 ¯ 4 , 2 3 ¯ 4 ¯ , 234 , 2 ¯ 34 } . Then eliminating 2 ( x 2 ) yields x 2 ← ( x 3 ∨ x 4 ) ∧ ( x ¯ 3 ∨ x 4 ) and new clauses { 34 , 3 ¯ 4 } . Now 4 ( x 4 ) is pure; so x 4 ← 1, and F ′ = ∅ is satisfiable. (Going backwards in the erp rules will then make x 4 ← 1, x 2 ← 1, x 1 ← 0, regardless of x 3 .)
367. (We can choose whichever of the two assignments is most convenient, for example by picking the shortest, since either one is a valid erp rule.) Any solution will either satisfy all the clauses on the right side of x ¯ or all the clauses on the right side of x , or both. For if a solution falsifies both C i \ x and C i ′ \ x ¯ , it falsifies C i ⋄ C i ′ .
In either case the value of x will satisfy all of the clauses C 1 , ..., C p , C 1 ' , … , C q ' .
368. If ( l ) is a clause, subsumption removes all other clauses that contain l . Then resolution (with p = 1) will remove l ¯ from all q of its clauses, and ( l ) itself.
369. Let C i \= ( l ∨ α i ) and C j ′ \= ( l ¯ ∨ β j ) . Each omitted clause C i ⋄ C j ′ \= ( α i ∨ β j ) , where 1 < i ≤ p and r < j ≤ q , is redundant, because it is a consequence of the non-omitted clauses ( α i ∨ l ¯ 1 ) , … , ( α i ∨ l ¯ r ) , ( l 1 ∨ … ∨ l r ∨ β j ) via hyperresolution. [This technique is called “ substitution,” because we essentially replace | l | by its definition.]
370. ( a ∨ b ) ∧ ( a ∨ b ¯ ∨ c ¯ ) ∧ ( a ¯ ∨ b ∨ c ) \= ( a ∨ c ¯ ) ∧ ( b ∨ c ) . (See the discussion following 7.1.1–(27). In general, advanced preprocessors use the theory of DNF minimization, in its dual form, to find irredundant minimum forms for CNF. Such techniques are not implemented, however, in the examples of preprocessing considered in this section.)
371. One scenario starts by eliminating variable 1, replacing eight clauses by eight new ones: 23 4 ¯ 7 ¯ , 2 ¯ 3 ¯ 47 , 23 5 ¯ 9 ¯ , 2 ¯ 3 ¯ 59 , 3 4 ¯ 5 7 ¯ , 3 ¯ 4 5 ¯ 7 , 4 5 ¯ 7 9 ¯ , 4 ¯ 5 7 ¯ 9 . Then 8 is eliminated, replacing another eight by eight: 2 4 ¯ 5 6 ¯ , 2 ¯ 4 5 ¯ 6 , 25 6 ¯ 7 ¯ , 2 ¯ 5 ¯ 67 , 25 7 ¯ 9 ¯ , 2 ¯ 5 ¯ 79 , 46 7 ¯ 9 ¯ , 4 ¯ 6 ¯ 79 . Then come self-subsumptions: 23 4 ¯ 7 ¯ ↦ 23 7 ¯ (via 234), 3 4 ¯ 5 7 ¯ ↦ 35 7 ¯ (345), 357 ↦ 35 ( 35 7 ¯ ); and 35 subsumes 345, 35 7 ¯ . Further self-subsumptions yield 23 5 ¯ 9 ¯ ↦ 23 9 ¯ , 2 ¯ 3 ¯ 59 ↦ 2 ¯ 3 ¯ 9 , 2 ¯ 5 ¯ 79 ↦ 2 ¯ 79 , 2 ¯ 4 5 ¯ 6 ↦ 2 ¯ 46 , 246 ↦ 46; and 46 subsumes 456, 46 7 ¯ 9 ¯ , 2 ¯ 46 . Similarly, 2 ¯ 5 ¯ 67 ↦ 2 ¯ 67 , 4 ¯ 5 7 ¯ 9 ↦ 4 ¯ 59 , 2 ¯ 3 ¯ 47 ↦ 2 ¯ 3 ¯ 7 , 3 ¯ 4 5 ¯ 7 ↦ 3 ¯ 5 ¯ 7 , 3 ¯ 5 ¯ 7 ¯ ↦ 3 ¯ 5 ¯ ; and 3 ¯ 5 ¯ subsumes 3 ¯ 4 ¯ 5 ¯ , 3 ¯ 5 ¯ 7 . Then 2 4 ¯ 5 6 ¯ ↦ 2 4 ¯ 6 ¯ , 2 ¯ 4 ¯ 6 ¯ ↦ 4 ¯ 6 ¯ ; and 4 ¯ 6 ¯ subsumes 4 ¯ 5 ¯ 6 ¯ , 2 4 ¯ 6 ¯ , 4 ¯ 6 ¯ 79 . Also 25 6 ¯ 7 ¯ ↦ 2 6 ¯ 7 ¯ , 4 5 ¯ 7 9 ¯ ↦ 4 5 ¯ 9 ¯ , 25 7 ¯ 9 ¯ ↦ 2 7 ¯ 9 ¯ .
Round 2 of variable elimination first gets rid of 4, replacing six clauses by just four using exercise 369 : 23 6 ¯ , 2 ¯ 3 ¯ 6 , 569 , 5 ¯ 6 ¯ 9 ¯ . Then variable 3 goes away; ten clauses become eight, again via exercise 369 : 2 5 ¯ 6 ¯ , 2 ¯ 56 , 2 5 ¯ 7 ¯ , 2 ¯ 57 , 2 5 ¯ 9 ¯ , 2 ¯ 59 , 5 6 ¯ 9 ¯ , 5 ¯ 69 . And the ten clauses that now contain 2 or 2 ¯ resolve into just four: 56 7 ¯ 9 ¯ , 5 6 ¯ 7 ¯ 9 , 5 ¯ 67 9 ¯ , 5 ¯ 6 ¯ 79 .
After eliminating 7 and 9, only four clauses remain, namely 56, 5 6 ¯ , 5 ¯ 6 , 5 ¯ 6 ¯ ; and they quickly produce a contradiction.
372. (This problem is surprisingly difficult.) Are the clauses { 1 ¯ 5 ¯ , 1 ¯ 6 ¯ , 2 ¯ 5 ¯ , 2 ¯ 6 ¯ , 3 ¯ 7 ¯ , 3 ¯ 8 ¯ , 4 ¯ 7 ¯ , 4 ¯ 8 ¯ , 123, 124, 134, 234, 567, 568, 578, 678} as “small” as possible?
373. Using the notation of (102), elimination of x 1 m , x 2 m , ... , x mm produces new clauses M i m k ′ for 1 ≤ i, k < m as well as M m ( m – 1) . Then elimination of x m ( m – 1) gives ( M i ( m – 1) ∨ M m ( m – 2) ) for 1 ≤ i < m . This clause self-subsumes to M i ( m – 1) , using M i m 1 ′ , … M i m ( m − 2 ) ′ . And M i ( m – 1) subsumes each M i m k ′ , so we’ve reduced m to m –1. 374. As in (57), variables are numbered 1 to n , and literals from 2 to 2 n + 1. But we will now number the clauses from 2 n + 2 to m + 2 n + 1. The literals of clauses will be stored in cells, somewhat as in Algorithm A , but with additional links: Each cell p contains not only a literal L( p ) , a clause number C( p ) , and forward/backward pointers F( p ) and B( p ) to other cells with the same literal, but also left/right pointers S( p ) and D( p ) to other cells in the same clause . (Think “sinister” and “dexter.”) Cells 0 and 1 are reserved for special use; cell l , for 2 ≤ l < 2 n + 2, serves as the head of the doubly linked list of cells that contain the literal l ; cell c , for 2 n +2 ≤ c < m +2 n + 2, serves as the head of the doubly linked list of cells that contain the elements of clause c ; and cell p , for m +2 n +2 ≤ p < M , either is available for future use or holds literal and clause data for a currently active clause.
Free cells are accessed via a global pointer AVAIL . To get a new p ⇐ AVAIL when AVAIL ≠ 0, we set p ← AVAIL , AVAIL ← S(AVAIL) ; but if AVAIL = 0, we set p ← M and M ← M + 1 (assuming that M never gets too large). To free one or more cells from p ′ to p ″ that are linked together via left links, we set S( p ′ ) ← AVAIL and AVAIL ← p ″ .
The number of active clauses containing literal l , TALLY( l ) , can therefore be computed as follows: Set t ← 0, p ← F( l ) ; while not lit ( p ), set t ← t + 1 and p ← F( p ) ; set TALLY( l ) ← t ; here ‘ lit ( p )’ stands for ‘ p < 2 n +2’. The number of literals in clause c , SIZE( c ) , can be computed by a similar loop, using ‘ cls ( p )’ to stand for ‘ p < m +2 n +2’: Set t ← 0, p ← S( c ) ; while not cls ( p ), set t ← t + 1 and p ← S( p ) ; set SIZE( c ) ← t . After initialization, the TALLY and SIZE statistics can be updated dynamically as local changes are made. ( TALLY( l ) and SIZE( c ) can be maintained in L( l ) and C( c ) .)
To facilitate resolution, the literals of each clause are required to increase from left to right; in other words, we must have L( p ) < L( q ) whenever p = S( q ) and q = D( p ) , unless cls ( p ) or cls ( q ). But the clauses within literal lists need not appear in any particular order. We might even have C(F( p )) > C( q ) but C(F( p ′ )) < C( q ′ ) , when C( p ) = C( p ′ ) and C( q ) = C( q ′ ) .
To facilitate subsumption, each literal l is assigned a 64-bit signature SIG( l ) = (1 ≪ U 1 ) | (1 ≪ U 2 ), where U 1 and U 2 are independently random 6-bit numbers. Then each clause c is assigned a signature that is the bitwise OR of the signatures of its literals: Set t ← 0, p ← S( c ) ; while not cls ( p ), set t ← t | SIG(L( p )) and p ← S( p ) ; set SIG( c ) ← t . (See the discussion of Bloom’s superimposed coding in Section 6.5.)
(a) To resolve c with c ′ , where c contains l and c ′ contains l ¯ , we essentially want to do a list merge. Set p ← 1, q ← S( c ) , u ← L( q ) , q ′ ← S( c ′ ) , u ′ ← L( q ′ ) , and do the following while u + u ′ > 0: If u = u ′ , copy( u ) and bump( q, q ′ ); if u = ū ′ = l , bump( q, q ′ ); if u = ū ′ ≠ l , terminate unsuccessfully; otherwise if u > u ′ , copy( u ) and bump( q ); otherwise copy( u ′ ) and bump( q ′ ). Here ‘copy( u )’ means ‘set p ′ ← p , p ⇐ AVAIL , S( p ′ ) ← p , L( p ) ← u ’; ‘bump( q )’ means ‘set q ← S( q ) ; if cls ( q ) set u ← 0, otherwise set u ← L( q ) ’; ‘bump( q ′ )’ is similar, but it uses q ′ and u ′ ; and ‘bump( q, q ′ )’ means ‘bump( q ) and bump( q ′ )’. Unsuccessful termination occurs when clauses c and c ′ resolve to a tautology; we set p ← 0, after first returning cells p through S( 1 ) to free storage if p ≠ 1. Successful termination with u = u ′ = 0 means that the resolved clause consists of the literals in cells from p through S( 1 ) , linked only via S pointers.
(b) Find a literal l in C with minimum TALLY( l ) . Set p ← F( l ) , and do the following while not lit ( p ): Set c ′ ← C( p ) ; if c ′ ≠ c and ∼ SIG( c ′ ) & SIG( c ) = 0 and SIZE( c ′ ) ≥ SIZE( c ) , do a detailed subsumption test; then set p ← F( p ) . The detailed test begins with q ← S( c ) , u ← L( q ) , q ′ ← S( c ′ ) , u ′ ← L( q ′ ) , and does the following steps while u ′ ≥ u > 0: bump( q ′ ) while u ′ > u ; then bump( q, q ′ ) if u ′ = u . When the loop terminates, c subsumes c ′ if and only if u ≤ u ′ .
(c) Use (b), but set p ← F ( l \= x ¯ ? x : l ) , and use (( SIG( c ) & ∼ SIG( x ¯ ) ) | SIG( x ) ) in place of SIG( c ) . Also modify the detailed test, by inserting ‘if u \= x ¯ then u ← x ’ just after each occurrence of ‘ u ← L( q ) ’.
[The algorithm in (b) was introduced by A. Biere, LNCS 3542 (2005), 59–70, §4.2. “ False hits,” in which the detailed test is performed but no actual (self-)subsumption is detected, tend to occur less than 1% of the time in practice.]
375. Let each literal l have another field STAMP( l ) , initially zero; and let s be a global “time stamp” that is initially zero. To make the test, set s ← s + 1 and σ ← 0; then set STAMP( u ) ← s and σ ← σ | SIG( u ) for all u such that ( l ¯ u ¯ ) is a clause. If σ ≠ 0, set σ ← σ | SIG( l ) and run through all clauses c that contain l , doing the following: If SIG( c ) & ∼ σ = 0, and if each of c ’s literals u ≠ l has STAMP( u ) = s , exit with C 1 = c and r = SIZE( c ) – 1. If C 1 has thereby been found, set s ← s + 1 and STAMP( ū ) ← s for all u ≠ l in c . Then a clause ( l ¯ ∨ β j ) implicitly has j ≤ r in the notation of exercise 369 if and only if β j is a single literal u with STAMP( u ) = s .
Given a variable x , test the condition first for l = x ; if that fails, try l \= x ¯ .
376. Highest priority is given to the common operations of unit conditioning and pure literal elimination, which are “low-hanging fruit.” Give each variable x two new fields, STATE( x ) and LINK( x ) . A “ to-do stack,” containing all such easy pickings, begins at TODO and follows LINK s until reaching Λ. The nonzero states are called FF (forced false), FT (forced true), EQ (eliminated quietly), and ER (eliminated by resolution). Variable x is on the to-do stack only if STATE( x ) is FF , FT , or EQ .
Whenever a unit clause ( l ) is detected, with STATE( | l | ) = 0, we set STATE( | l | ) ← ( l &1? FF : FT ), LINK( | l | ) ← TODO , and TODO ← | l |. But if STATE( | l | ) = ( l &1? FT : FF ), we terminate, because the clauses are unsatisfiable.
Whenever a literal with TALLY( l ¯ ) = 0 is detected, we do the same thing if STATE( | l | ) = 0. But if STATE( | l | ) = ( l & 1? FT : FF ), we simply set STATE( | l | ) ← EQ instead of terminating. (In that case TALLY( l ) is also 0.)
To clear the to-do stack, we do the following while TODO ≠ Λ: Set x ← TODO and TODO ← LINK( x ) ; if STATE( x ) = EQ , do nothing (no erp rule is needed to eliminate x ); otherwise set l ← ( STATE( x ) = FT ? x : x ¯ ), output the erp rule l ← 1, and use the doubly linked lists to delete all clauses containing l and to delete l ¯ from all clauses. (Those deletions update TALLY and SIZE fields, so they often contribute new entries to the todo stack. Notice that if clause c loses a literal, we must recompute SIG( c ) . If clause c disappears, we set SIZE( c ) ← 0, and never use c again.)
Subsumption and strengthening are next in line. We give each clause c a new field LINK( c ) , which is nonzero if and only if c appears on the “ exploitation stack.” That stack begins at EXP and follows LINK s until reaching the nonzero sentinel value Λ ′ . All clauses are initially placed on the exploitation stack. Afterwards, whenever a literal l ¯ is deleted from a clause c , either during unit conditioning or self-subsumption, we test if LINK( c ) = 0; if so, we put c back on the stack by setting LINK( c ) ← EXP and EXP ← c .
To clear the exploitation stack, we first clear the to-do stack. Then, while EXP ≠ Λ ′ , we set c ← EXP , EXP ← LINK( c ) , and do the following if SIZE( c ) ≠ 0: Remove clauses subsumed by c ; clear the to-do stack; and if SIZE( c ) is still nonzero, strengthen clauses that c can improve, clear the to-do stack, and set TIME( c ) ← T (see below).
All of this takes place before we even think about the elimination of variables. But rounds of variable elimination form the “outer level” of computation. Each variable x has yet another field, STABLE( x ) , which is nonzero if and only if we need not attempt to eliminate x . This field is initially zero, but set nonzero when x is eliminated or its elimination has been abandoned. It is reset to zero whenever a variable is later “touched,” namely when x or x ¯ appears in a deleted or self-subsumed clause. (In particular, every variable that appears in a new clause produced by resolution will be touched, because it will appear in at least one of the clauses that were replaced by new ones.)
If a round has failed to eliminate any variables, or if it has eliminated them all, we’re done. But otherwise there’s still work to do, because the new clauses can often be subsumed or strengthened. (Indeed, some of them might actually be duplicates.) Hence two more fields are introduced: TIME( l ) for each literal and TIME( c ) for each clause, initially zero. Let T be the number of the current elimination round. We set TIME( l ) ← T for all literals l in all clauses that are replaced by resolution, and TIME( c ) ← T is also set appropriately as mentioned above.
Introduce yet another field, EXTRA( c ) , initially zero. It is reset to zero whenever TIME( c ) ← T , and set to 1 whenever c is replaced by a new clause. For every literal l such that STATE( | l | ) = 0 and TIME( l ) = T at the end of round T , set EXTRA( c ) ← EXTRA( c ) + 4 for all clauses c that contain l , and EXTRA( c ) ← EXTRA( c ) | 2 for all clauses c that contain l ¯ . Then run through all clauses c for which SIZE( c ) > 0 and TIME( c ) < T . If SIZE( c ) = EXTRA( c ) ≫ 2, remove clauses subsumed by c and clear the exploitation stack. Also, if EXTRA( c ) &3 ≠ 0, we may be able to use c to strengthen other clauses — unless EXTRA( c ) & 1 = 0 and EXTRA( c ) ≫ 2 < SIZE( c ) – 1. Self-subsumption using l need not be attempted when EXTRA( c ) & 1 = 0 unless TIME( l ¯ ) = T and EXTRA( c ) ≫ 2 = SIZE( c ) – [ TIME( l ) = T ]. Finally, reset EXTRA( c ) to zero (even if TIME( c ) = T ). [See Niklas Eén and Armin Biere, LNCS 3569 (2005), 61–75.]
377. Each vertex v of G corresponds to variables v 1 , v 2 , v 3 in F ; each edge u ––– v corresponds to clauses ( ū 1 ∨ v 2 ), ( ū 2 ∨ v 3 ), ( u ¯ 3 ∨ v ¯ 1 ) , ( u 2 ∨ v ¯ 1 ) , ( u 3 ∨ v ¯ 2 ) , ( u ¯ 1 ∨ v ¯ 3 ) . The longest paths in the dependency digraph for F have the form t 1 → u 2 → v 3 → w ¯ 1 or t 1 → u ¯ 3 → v ¯ 2 → w ¯ 1 , where t ––– u ––– v ––– w is a walk in G .
[A similar method reduces the question of finding an oriented cycle of length r in a given digraph to the question of finding a failed literal in some dependency digraph. The cycle detection problem has a long history; see N. Alon, R. Yuster, and U. Zwick, Algorithmica 17 (1997), 209–223. So any surprisingly fast algorithm to decide whether or not failed literals exist — that is, faster than n 2ω/(ω+1) when m = O ( n ) and matrix multiplication takes O ( n ω ) — would lead to surprisingly fast algorithms for other problems.]
378. The erp rule l ← l ∨ ( l ¯ 1 ∧ … ∧ l ¯ q ) will change any solution of F \ C into a solution of F . [See M. Järvisalo, A. Biere, and M. Heule, LNCS 6015 (2010), 129–144.]
(In practice it’s sometimes possible to remove tens of thousands of blocked clauses. For example, all of the exclusion clauses (17) in the coloring problem are blocked, as are many of the clauses that arise in fault testing. Yet the author has yet to see a single example where blocked clause elimination is actually helpful in combination with transformations 1–4, which are already quite powerful by themselves.)
379. (Solution by O. Kullmann.) In general, any set F of clauses can be replaced by another set F ′ , whenever there’s a variable x such that the elimination of x from F yields exactly the same clauses as the elimination of x from F ′ . In this case the elimination of a has this property.
380. (a) Reverse self-subsumption weakens it to ( a ∨ b ∨ c ∨ d ), then to ( a ∨ b ∨ c ∨ d ∨ e ), which is subsumed by ( a ∨ d ∨ e ). [In general one can show that reverse self-subsumption from C leads to a subsumed clause if and only if C is certifiable from the other clauses.]
(b) Again we weaken to ( a ∨ b ∨ c ∨ d ∨ e ); but now we find this blocked by c
(c) No erp rule is needed in (a), but we need c ← c ∨ ( a ¯ ∧ b ¯ ) in (b). [Heule, Jäarvisalo, and Biere, LNCS 6397 (2010), 357–371, call this “ asymmetric elimination.”]
381. By symmetry, we’ll remove the final clause. (Without it, the given clauses state that x 1 ≤ x 2 ≤ … ≤ x n ; with it, they state that all variables are equal.) Assume more generally that, for 1 ≤ j < n , every clause other than ( x ¯ j ∨ x j + 1 ) that contains x ¯ j also contains either x n or x ¯ i for some i < j . For 1 ≤ j < n – 1 we can then weaken ( x 1 ∨ … ∨ x j ∨ x ¯ n ) to ( x 1 ∨ … ∨ x j + 1 ∨ x ¯ n ) . Finally, ( x 1 ∨ … ∨ x n − 1 ∨ x ¯ n ) can be eliminated because it is blocked by x n – 1 .
Although we’ve eliminated only one clause, n – 1 erp rules are actually needed to undo the process: x 1 ← x 1 ∨ x n ; x 2 ← x 2 ∨ ( x ¯ 1 ∧ x n ) ; x 3 ← x 3 ∨ ( x ¯ 1 ∧ x ¯ 2 ∧ x n ) ; ... ; x n − 1 ← x n − 1 ∨ ( x ¯ 1 ∧ … ∧ x ¯ n − 2 ∧ x n ) . (Those rules, applied in reverse order, can however be simplified to x j ← x j ∨ x n for 1 ≤ j < n , because x 1 ≤ … ≤ x n in any solution.)
[See Heule, Järvisalo, Biere, EasyChair Proc. in Computing 13 (2013), 41–46.]
382. See M. J. H. Heule, M. Järvisalo, and A. Biere, LNCS 6695 (2011), 201–215.
383. (a) In a learning step, let Φ ′ = Φ and Ψ ′ = Ψ ∪ C . In a forgetting step, let Φ ′ = Φ and Ψ = Ψ ′ ∪ C . In a hardening step, let Φ ′ = Φ ∪ C and Ψ = Ψ ′ ∪ C . In a softening step, let Φ = Φ ′ ∪ C and Ψ ′ = Ψ ∪ C . In all four cases it is easy to verify that (sat(Φ) ⇔ sat(Φ ∪ Ψ)) implies (sat(Φ) ⇔ sat(Φ ′ ) ⇔ sat(Φ ′ ∪ Ψ ′ )), where sat( G ) means “ G is satisfiable,” because sat( G ∪ G ′ ) ⇒ sat( G ). Thus the assertions are invariant.
(b) Each erp rule allows us to go one step backward, until reaching F .
(c) The first (softening) step is fine, because both Φ = ( x ) and Φ \ ( x ) = 1 are satisfiable, and because the erp rule unconditionally makes x true. But the second (learning) step is flawed, because sat(Φ ∪ Ψ) does not imply sat(Φ ∪ Ψ ∪ C ) when Φ ∪ Ψ = ( x ) and C \= ( x ¯ ) . (This example explains why the criterion for learning is not simply ‘sat(Φ) ⇒ sat(Φ ∪ C )’ as it essentially is for softening.)
(d) Yes, because C is also certifiable for Φ ∪ Ψ.
(e) Yes, after softening it. No erp rule is needed, because Φ \ C ⊢ C .
(f) A soft clause can be discarded whether or not it is subsumed. To discard a hard clause that is subsumed by a soft clause, first harden the soft one. To discard a hard C that is subsumed by a hard C ′ , weaken C and then discard it. (The weakening step is clearly permissible, and no erp rule is needed.)
(g) If C contains x ¯ and C ′ contains x and C \ x ¯ ⊆ C ′ \ x , we can learn the soft clause C ⋄ C ′ = C ′ \ x , then use it to subsume C ′ as in (f).
(h) Forget all soft clauses that contain x or x ¯ . Then let C 1 , ... , C p be the hard clauses containing x , and C 1 ′ , … , C q ′ those containing x ¯ . Learn all the (soft) clauses C i ⋄ C j ′ , and harden them, noting that they don’t involve x . Weaken each C i , with erp rule x ← x ∨ C ¯ i , and forget it; also weaken and forget each C j ′ , with erp rule x ← x ∧ C j ′ . (One can show that either of the erp rules in (161) would also suffice.)
(i) Whenever Φ∪Ψ is satisfiable, so is Φ∪Ψ∪{( x ∨ z ) , ( y ∨ z ) , ( x ¯ ∨ y ¯ ∨ z ¯ ) }, because we can always set z ← x ¯ ∨ y ¯ .
[ Reference: M. Järvisalo, M. Heule, and A. Biere, LNCS 7364 (2012), 355–370. Notice that, by exercise 368 , parts (f) and (h) justify the use of unit conditioning.]
384. Whenever we have a solution to Φ \ C that falsifies C , we will show that Φ is satisfied by making l true; hence softening C is permissible, with erp rule l ← l ∨ C ¯ .
To prove that claim, notice that a problem could arise only in a hard clause C ′ that contains l ¯ . But if all other literals of C ′ are false in the given solution, then all literals of C ⋄ C ′ are false, contradicting the assumption that ( Φ \ C ) ∧ C ⋄ C ′ ¯ ⊢ 1 ∊ .
(Such clauses C are “ resolution certifiable” with respect to Φ\ C . Blocked clauses are a very special case. Similarly, we can safely learn any clause that is resolution certifiable with respect to Φ ∪ Ψ.)
385. (a) True, because C ¯ ∧ l ⊢ 1 ∊ when l ∈ C .
(b) 1 ¯ is implied, not certifiable; 1 ¯ 2 is certifiable, not absorbed; 1 ¯ 23 is absorbed.
(c, d) If C is any clause and l is any literal, then F ∧ C ¯ ⊢ 1 l implies F ′ ∧ C ¯ ⊢ 1 l , because unit propagation in F carries over to unit propagation in F ′ .
386. (a) The trail contained exactly score( F, C, l ) literals when decision l ¯ was made at level d during the helpful round. The clause learned from the ensuing conflict causes at least one new literal to be implied at level d ′ < d .
(b) The score can’t decrease when F grows.
(c) Each l ∈ C needs at most n helpful rounds to make score( F, C, l ) = ∞.
(d) Suppose, for example, F \= ( a ∨ d ¯ ) ∧ ( a ∨ b ∨ e ∨ l ) ∧ ( a ¯ ∨ c ) ∧ ( b ¯ ) ∧ ( c ∨ d ∨ e ¯ ∨ l ) and C = ( a ∨ b ∨ c ∨ d ∨ l ). The helpful sequences of decisions are ( a ¯ , c ¯ , l ¯ ) , ( c ¯ , l ¯ ) , ( d ¯ , a ¯ , c ¯ , l ¯ ) , ( d ¯ , c ¯ , l ¯ ) , and they occur with probabilities 1 10 1 6 1 4 , 1 10 1 4 , 1 10 1 8 1 6 1 4 , 1 10 1 8 1 4 .
In general if a decision is to be made and j elements of C ¯ are not yet in the trail, the probability that suitable decisions will be made at random is at least
f ( n , j ) \= min ( j − 1 2 n f ( n − 1 , j − 1 ) , j − 2 2 ( n − 1 ) f ( n − 2 , j − 2 ) , … , 1 2 ( n − j + 2 ) f ( n − j + 1 , 1 ) , 1 2 ( n − j + 1 ) ) \= ( j − 1 ) ! 2 j n j ¯ .
(e) The waiting time to absorb each clause C i is upper-bounded by a geometric distribution whose mean is ≤ 4 n | C i | , repeated at most | C i | n times.
References: K. Pipatsrisawat and A. Darwiche, Artif. Intell. 175 (2011), 512–525; A. Atserias, J. K. Fichte, and M. Thurley, J. Artif. Intell. Research 40 (2011), 353–373.
387. We may assume that G and G ′ have no isolated vertices. Letting variable vv ′ mean that v corresponds to v ′ , we need the clauses ( u v ′ ¯ ∨ v v ′ ¯ ) for u < v and ( v u ′ ¯ ∨ v v ′ ¯ ) for u ′ < v ′ . Also, for each u < v with u ––– v in G , we introduce auxiliary variables uu ′ vv ′ for each edge u ′ ––– v ′ in G ′ , with clauses ( u u ′ v v ′ ¯ ∨ u u ′ ) ∧ ( u u ′ v v ′ ¯ ∨ v v ′ ) ∧ (∨ { uu ′ vv ′ | u ′ ––– v ′ in G ′ }). The variables vv ′ and uu ′ vv ′ can be restricted to cases where degree( u ) ≤ degree( u ′ ) and degree( v ) ≤ degree( v ′ ).
388. (a) Can the complete graph K k be embedded in G ? (b) Can G be embedded in the complete k -partite graph K n ,..., n , where G has n vertices? (c) Can the cycle C n be embedded in G ? where G has n vertices?
389. This is similar to a graph embedding problem, with G ′ the 4 × 4 (king ∪ knight) graph and with G defined by edges T ––– H , H ––– E , E ––– ⊔ , ... , N ––– G ; however, we allow v ′ = w ′ when v ≠ w , and labels must match. The adjacent M s can be avoided by changing ‘ PROGRAMMING ’ to either ‘ PROGRAMXING ’ or ‘ PROGRAXMING ’.
Algorithm C needs fewer than 10 megamems to find the first solution below. Furthermore, if the blank space can also be moved, the algorithm will rather quickly also find solutions with just five knight moves (the minimum), or 17 of them (the max):
390. Let d ( u, v ) be the distance between vertices u and v . Then d ( v, v ) = 0 and
d ( u , v ) ≤ j + 1 ⇔ d ( u , w ) ≤ j f o r s o m e w ∈ N ( v ) \= { w | w — v }
if u ≠ v . In parts (a), (d), we introduce variables v j for each vertex v and 0 ≤ j ≤ k . In part (c) we do this for 0 ≤ j < n . But parts (b), (e), (f) use just n variables, { v | v ∈ V }.
(a) Clauses ( s 0 ) ∧ ∧ v ∈ V \ s ( ( v ¯ 0 ) ∧ ∧ j \= 0 k − 1 ( v ¯ j + 1 ∨ ∨ w ∈ N ( v ) w j ) ) are satisfied only if v j ≤ [ d ( s, v ) ≤ j ]; hence the additional clause ( t k ) is also satisfied only if d ( s, t ) ≤ k . Conversely, if d ( s, t ) ≤ k , all clauses are satisfied by setting v j ← [ d ( s, v ) ≤ j ].
(b) There’s a path from s to t if and only if there’s a subset H ⊆ V such that s ∈ H , t ∈ H , and every vertex v of the induced graph G | H has degree 2 – [ v = s ] – [ v = t ]. [The vertices on a shortest path from s to t yield one such H . Conversely, given H , we can find vertices v j ∈ H such that s = v 0 ––– v 1 –––…––– v k \= t .]
We can represent that criterion via clauses on the binary variables v = [ v ∈ H ] by asserting ( s ) ∧ ( t ), together with clauses to ensure that Σ( v ) = 2 – [ v = s ] – [ v = t ] for all v ∈ H , where Σ( v ) = Σ w ∈ N ( v ) w is the degree of v in G | H . The number of such clauses for each v is at most 6| N ( v )|, because we can append v ¯ to each clause of (18) and (19) with r = 2, and | N ( v )| additional clauses will rule out Σ( v ) < 2. Altogether there are O ( m ) clauses, because Σ v ∈ V | N ( v )| = 2 m .
[Similar but simpler alternatives, such as (i) to require Σ( v ) ∈ {0 , 2} for all v ∈ V \{ s, t }, or (ii) to require Σ( v ) ≥ 2 for all v ∈ H \{ s, t },do not work: Counterexamples are (i) s
t and (ii) s
t . Another solution, more cumbersome, associates a Boolean variable with each edge of G .]
(c) Let s be any vertex; use (a) with k = n – 1, plus ( v n – 1 ) for all v ∈ V \ s .
(d) Clauses ( s 0 ) ∧ ∧ j \= 0 k − 1 ∧ v ∈ V ∧ w ∈ N ( v ) ( v ¯ j ∨ w j + 1 ) are satisfied only if we have v j ≥ [ d ( s, v ) ≤ j ]; hence the additional unit clause ( t ¯ k ) cannot also be satisfied when d ( s, t ) ≤ k . Conversely, if d ( s, t ) > k we can set v j ← [ d ( s, v ) ≤ j ].
(e) ( s ) ∧ ( ∧ v ∈ V ∧ w ∈ N ( v ) ( v ¯ ∨ w ) ) ∧ ( t ¯ ) .
(f) Letting s be any vertex, use ( s ) ∧ ( ∧ v ∈ V ∧ w ∈ N ( v ) ( v ¯ ∨ w ) ) ∧ ( ∨ v ∈ V \ s v ¯ ) .
[Similar constructions work with digraphs and strong connectivity. Parts (d)–(f) of this exercise were suggested by Marijn Heule. Notice that parts (a) and (c)–(f) construct renamed Horn clauses, which work very efficiently (see exercise 444 ).]
391. (a) Let d – 1 = ( q l – 1 ...q 0 ) 2 . To ensure that ( x l – 1 ...x 0 ) 2 < d we need the clauses ( x ¯ i ∨ ∨ { x ¯ j | j > i , q j \= 1 } ) 52 whenever q i \= 0. The same holds for y .
To enforce x ≠ y , introduce the clause ( a l – 1 ∨ … ∨ a 0 ) in auxiliary variables a l – 1 ...a 0 , together with ( a ¯ j ∨ x j ∨ y i ) ∧ ( a ¯ j ∨ x ¯ j ∨ y ¯ i ) for 0 ≤ j < l (see (172)).
(b) Now x ≠ y is enforced via clauses of length 2 l , which state that we don’t have x = y = k for 0 ≤ k < d . For example, the appropriate clause when l = 3 and k = 5 is ( x ¯ 2 ∨ y ¯ 2 ∨ x 1 ∨ y 1 ∨ x ¯ 0 ∨ y ¯ 0 ) .
(c) Use the clauses of (b) for 0 ≤ k < 2 d – 2 l , plus clauses of length 2 l – 2 for d ≤ k < 2 l stating that we don’t have ( x l – 1 ...x 1 ) 2 = ( y l – 1 ...y 1 ) 2 = k – 2 l –1 . (The encodings in (b) and (c) are identical when d = 2 l .)
[See A. Van Gelder, Discrete Applied Mathematics 156 (2008), 230–243.]
392. (a) [Puzzle ( ii ) was introduced by Sam Loyd in the Boston Herald , 13 November 1904; page 27 of his Cyclopedia (1914) states that he’d created a puzzle like ( i ) at age 9! Puzzle ( iv ) is by H. E. Dudeney, Strand 42 (1911), 108, slightly modified. Puzzle ( iii ) is from the Grabarchuks’ Big, Big, Big Book of Brainteasers (2011), #196; puzzle ( v ) was designed by Serhiy O. Grabarchuk in 2015.]
(b) [Puzzle ( vi ) is an instance of the odd-even transposition sort, exercise 5.3.4– 37. Eight order-reversing connections would be impossible with only eight columns, instead of the nine in ( vii ), because the permutation has too many inversions.]
(c) Let d j \= Σ i \= 1 j ( | T i | − 1 ) and d = d t . We introduce variables v i for 1 ≤ i ≤ d , and the following clauses for 1 ≤ j ≤ t and d j – 1 < i ≤ d j : ( v ¯ i , ∨ v ¯ i ) for 1 ≤ i ′ ≤ d j – 1 ; the clauses of answer 390(b) on variables v i , where s is the ( i – d j – 1 )th element of T j and t is the last element. These clauses ensure that the sets V j \= { v | v d j –1 +1 ∨...∨ v d j } are disjoint, and that V j contains a connected component S j ⊇ T j .
We also assert ( v ¯ i ) for 1 ≤ i ≤ d , whenever T j is a singleton set { v }.
[For the more general “Steiner tree packing” problem, see M. Grötschel, A. Martin, and R. Weismantel, Math. Programming 78 (1997), 265–281.]
393. A construction somewhat like that of answer 392(c) can be used with five different 8 × 8 graphs, one for the moves of each white-black pair S j . But we need to keep track of the edges used, not vertices, in order to prohibit edges that cross each other. Additional clauses will rule that out.
394. Call these clauses langford ′" ( n ). [Steven Prestwich described a similar method in Trends in Constraint Programming (Wiley, 2007), 269–274.] Typical results are:
variables clauses Algorithm D Algorithm L Algorithm C | ||||||
langford ′" (9) | 206 | 1157 | 131 M μ | 18 M μ | 22 M μ | (UNSAT) |
langford ′" (13) | 403 | 2935 | 1425 G μ | 44 G μ | 483 G μ | (UNSAT) |
langford ′" (16) | 584 | 4859 | 713 K μ | 42 M μ | 343 K μ | (SAT) |
langford ′" (64) | 7352 | 120035 | (huge) | (big) | 71 M μ | (SAT) |
395. The color of each vertex v gets binary axiom clauses ( v ¯ j + 1 ∨ v j ) for 1 ≤ j < d –1, as in (164). And for each edge u ––– v in the graph, we want d clauses ( u ¯ j − 1 ∨ u j ∨ v ¯ j − 1 ∨ v j ) for 1 ≤ j ≤ d , omitting ū 0 and v ¯ 0 when j = 1, u d and v d when j = d .
[The surprising usefulness of order encoding in graph coloring was first noticed by N. Tamura, A. Taga, S. Kitagawa, and M. Banbara in Constraints 14 (2009), 254–272.]
396. First we have ( x ¯ j + 1 ∨ x j ) and x ^ j + 1 ¯ ∨ x ^ j for 1 ≤ j < d . Then we have “channeling” clauses to ensure that j ≤ x < j + 1 ⇔ jπ ≤ xπ < jπ + 1 for 0 ≤ j < d :
( x ¯ j ∨ x j + 1 ∨ x ^ j π ) ∧ ( x ¯ j ∨ x j + 1 ∨ x ^ j π + 1 ¯ ) ∧ ( x ^ j π ¯ ∨ x ^ j π + 1 ∨ x j ) ∧ ( x ^ j π ¯ ∨ x ^ j π + 1 ∨ x ¯ j + 1 ) .
(These clauses should be either shortened or omitted in boundary cases, because x 0 and x ^ 0 are always true, while x d and x ^ d are always false. We obtain 6 d –8 clauses for each x .)
With such clauses for every vertex of a graph, together with clauses based on adjacent vertices and cliques, we obtain encodings for n -coloring the n × n queen graph that involve 2( n 3 – n 2 ) variables and 5 3 n 4 + 4 n 3 + O ( n 2 ) clauses, compared to n 3 – n 2 variables and 5 3 n 4 − n 3 + O ( n 2 ) clauses with single cliques and (162) alone. Typical running times with Algorithm C and single cliques are 323 K μ , 13 . 1M μ , 706 G μ for n = 7, 8, 9; with double clique-ing they become 252 K μ , 1 . 97 M μ , 39 . 8G μ , respectively.
The double clique hints turn out to be mysteriously ineffective when π is the standard organ-pipe permutation (0 π, 1 π,..., ( d –1) π ) = (0 , 2 , 4,..., 5 , 3 , 1) instead of its inverse. Random choices of π when n = 8 yielded significant improvement almost half the time, in the author’s experiments; but they had negligible effect in 1/3 of the cases.
Notice that the example π for d = 4 yields x 1 \= x ¯ 0 , x 3 \= x 3 , x ^ 1 \= x ¯ 2 , x ^ 3 \= x 1 . Hence the direct encoding is essentially present as part of this redundant representation, and the hints ( u ¯ 3 ∨ v ¯ 3 ) ∧ ( u 1 ∨ v 1 ) ∧ ( u ^ 3 ¯ ∨ v ^ 3 ¯ ) ∧ ( u ^ 1 ∨ v ^ 1 ) for 2-cliques { u, v } are equivalent to (16). But the hints ( u 2 ∨ v 2 ∨ w 2 ) ∧ ( u ¯ 2 ∨ v ¯ 2 ∨ w ¯ 2 ) ∧ ( u ^ 2 ∨ v ^ 2 ∨ w ^ 2 ) ∧ ( u ^ 2 ¯ ∨ v ^ 2 ¯ ∨ w ^ 2 ¯ ) that apply when { u, v, w } is a triangle give additional logical power.
397. There are ( p – 2) d binary clauses ( y ¯ j i + 1 ∨ y j i ) for 1 ≤ i < p – 1, together with the (2 p – 2) d clauses ( x ¯ i j ∨ x i j + 1 ∨ y j i ) ∧ ( x ¯ i − 1 j ∨ x i − 1 j + 1 ∨ y ¯ j i ) for 1 ≤ i < p , all for 0 ≤ j < d . The hint clauses ( x 0 p − 1 ∨ … ∨ x p − 1 p − 1 ) ∧ ( x ¯ 0 d − p + 1 ∨ … ∨ x ¯ p − 1 d − p + 1 ) are also valid.
(This setup corresponds to putting p pigeons into d holes, so we can usually assume that p ≤ d . If p ≤ 4 it is better to use ( p 2 ) d clauses as in exercise 395 . Notice that we obtain an interesting representation of permutations when p = d . In that case y is the inverse permutation; hence (2 d – 2) p additional clauses corresponding to y j \= i ⇒ x i \= j are also valid, as well as two hint clauses for y .)
A related idea, but combined with direct encoding of the x ’s, was presented by I. Gent and P. Nightingale in Proceedings of the International Workshop on Modelling and Reformulating Constraint Satisfaction Problems 3 (2004), 95–110.
398. We could construct (3 p – 4) d binary clauses that involve y j i , as in exercise 397 . But it’s better just to have (3 p –6) d clauses for the at-most-one constraints x 0 k + x 1 k + … + x ( p – 1) k ≤ 1, 0 ≤ k < d .
399. (a) d 2 – t preclusion clauses (binary); or 2 d support clauses (total length 2( d + t )).
(b) If unit propagation derives v ¯ j from ( u ¯ i ∨ v ¯ j ) , we knew u i ; hence (17) gives ū i for all i ′ ≠ i , and v ¯ j follows from the support clause that contains it.
(c) If unit propagation derives v ¯ j from its support clause, we knew ū i for all i ≠ j ; hence (15) gives u j , and v ¯ j follows from (16). Or if unit propagation derives u i from that support clause, we knew v j and ū i for all i ′ ∉ { i, j }; hence ū j from (16), u i from (15).
(d) A trivial example has no legal pairs; then unit propagation never gets started from binary preclusions, but the (unit) support clauses deduce all. A more realistic example has d = 3 and all pairs legal except (1 , 1) and (1 , 2), say; then we have ( 15 ) ∧ ( 17 ) ∧ ( u ¯ 1 ∨ v ¯ 1 ) ∧ ( u ¯ 1 ∨ v ¯ 2 ) ∧ ( v ¯ 3 ) ⊬ 1 u ¯ 1 but (15) ∧ (17) ∧ ( ū 1 ∨ v 3 ) ∧ ( v ¯ 3 ) ⊢ 1 ū 1 .
[Preclusion was introduced by S. W. Golomb and L. D. Baumert, JACM 12 (1965), 521–522. The support encoding was introduced by I. P. Gent, European Conf. on Artificial Intelligence 15 (2002), 121–125, based on work of S. Kasif, Artificial Intelligence 45 (1990), 275–286.]
400. This problem has n variables q 1 , ... , q n with n values each; thus there are n 2 Boolean values, with q ij \= [ q i \= j ] = [there’s a queen in row i and column j ]. The constraint between q i and q j is that q i ∉ { q j ,q j + i – j, q j – i + j }; so it turns out that there are n at-least-one clauses, plus ( n 3 – n 2 )/2 at-most-one clauses, plus either n 3 – n 2 support clauses or n 3 − n 2 + ( n 3 ) preclusion clauses. In this problem each support clause has at least n – 2 literals, so the support encoding is much larger.
Since the problem is easily satisfiable, it makes sense to try WalkSAT. When n = 20, Algorithm W typically finds a solution from the preclusion clauses after making fewer than 500 flips; its running time is about 500 K μ , including about 200 K μ just to read the input. With the support clauses, however, it needs about 10 times as many flips and consumes about 20 times as many mems, before succeeding.
Algorithm L is significantly worse: It consumes 50 M μ with preclusion clauses, 11 G μ with support clauses. Algorithm C is the winner, with about 400 K μ (preclusion) versus 600 K μ (support).
Of course n = 20 is pretty tame; let’s consider n = 100 queens, when there are 10,000 variables and more than a million clauses. Algorithm L is out of the picture; in the author’s experiments, it showed no indication of being even close to a solution after 20 T μ ! But Algorithm W solves that problem in 50 M μ , via preclusion, after making only about 5000 flips. Algorithm C wins again, polishing it off in 29 M μ . With the support clauses, nearly 100 million literals need to be input, and Algorithm W is hopelessly inefficient; but Algorithm C is able to finish after about 200 M μ .
The preclusion clauses actually allow us to omit the at-most-one clauses in this problem, because two queens in the same row will be ruled out anyway. This trick improves the run time when n = 100 to 35 M μ for Algorithm W .
We can also append support clauses for the columns as well as the rows. This idea roughly halves the search space, but it gives no improvement because twice as many clauses must be handled. Bottom line: Support clauses don’t support n queens well.
(However, if we seek all solutions to the n queens problem instead of stopping with the first one, using a straightforward extension of Algorithm D (see exercise 122 ), the support clauses proved to be definitely better in the author’s experiments.)
401. (a) y j = x 2 j –1 . (b) z j = x 3 j –1 . In general w = ⌊( x + a ) /b ⌋ ⇔ w j = x bj – a .
402. (a) ∧ j \= 1 ⌊ d / 2 ⌋ ( x ¯ 2 j − 1 ∨ x 2 j ) ; (b) ∧ j \= 1 ⌊ d / 2 ⌋ ( x ¯ 2 j − 1 ∨ x 2 j − 1 ) ; omit x ¯ 0 and x d .
403. (a) ∧ j \= 1 d − 1 ( x ¯ j ∨ y ¯ j ∨ z j ) ; (b) ∧ j \= 1 d − 1 ( ( x ¯ j ∨ z j ) ∧ ( y ¯ j ∨ z j ) ) ; (c) ∧ j \= 1 d − 1 ( ( x ¯ j ∨ z ¯ j ) ∧ ( y ¯ j ∨ z ¯ j ) ) ; (d) ∧ j \= 1 d − 1 ( x j ∨ y j ∨ z ¯ j ) .
404. ∧ j \= 0 d − a ( x ¯ j ∨ x j + a ∨ y ¯ j ∨ y j + a ) . (As usual, omit literals with superscript 0 or d .)
405. (a) If a < 0 we can replace ax by ( − a ) x ¯ and c by c + a – ad , where x ¯ is given by (165). A similar reduction applies if b < 0. Cases with a , b , or c = 0 are trivial.
(b) We have 13 x + 8 y ¯ ≤ 63 ⇔ not 13 x + 8 y ¯ ≥ 64 ⇔ not ( P 0 or ... or P d – 1 ) ⇔ not P 0 and ... and not P d –1 , where P j \= ‘ x ≥ j and y ¯ ≥ ⌈ ( 64 − 13 j ) / 8 ⌉ ’. This approach yields ∧ j \= 0 7 ( x ¯ j ∨ y 8 − ⌈ ( 64 − 13 j ) / 8 ⌉ ) , which simplifies to ( x ¯ 1 ∨ y 1 ) ∧ ( x ¯ 2 ∨ y 3 ) ∧ ( x ¯ 3 ∨ y 4 ) ∧ ( x ¯ 4 ∨ y 6 ) ∧ ( x ¯ 5 ) . (Notice that we could have defined P j \= ‘ y ¯ ≥ j and x ≥ ⌈(64 – 8 j )/13⌉’ instead, thereby obtaining the less efficient encoding ( x ¯ 5 ) ∧ ( y 7 ∨ x ¯ 5 ) ∧ ( y 6 ∨ x ¯ 4 ) ∧ ( y 5 ∨ x ¯ 4 ) ∧ ( y 4 ∨ x ¯ 3 ) ∧ ( y 3 ∨ x ¯ 2 ) ∧ ( y 2 ∨ x ¯ 2 ) ∧ ( y 1 ∨ x ¯ 1 ) ; it’s better to discriminate on the variable with the larger coefficient.)
(c) Similarly, 13 x ¯ + 8 y ≤ 90 gives ( x 5 ∨ y ¯ 7 ) ∧ ( x 4 ∨ y ¯ 5 ) ∧ ( x 3 ∨ y ¯ 4 ) ∧ ( x 2 ∨ y ¯ 2 ) ∧ ( x 1 ) . (The ( x, y ) pairs legal for both (b) and (c) are (1 , 1), (2 , 3), (3 , 4), (4 , 6).)
(d) ∧ j \= max ( 0 , ⌈ c + 1 − b ( d − 1 ) ) / a ⌉ ) min ( d − 1 , ⌈ ( c + 1 ) / a ⌉ ) ( x ¯ j ∨ y ¯ ⌈ ( c + 1 − a j ) / b ⌉ ) , when a ≥ b > 0 and c ≥ 0.
406. (a) ( ∧ j \= ⌈ ( a + 1 ) / ( d − 1 ) ⌉ ⌊ a + 1 ⌋ ( x ¯ j ∨ y ¯ ⌈ ( a + 1 ) / j ⌉ ) ) ∧ ( ∧ j \= ⌈ ( a + 1 ) / ( d − 1 ) ⌉ ⌈ a + 1 ⌉ − 1 ( x ¯ ⌈ ( a + 1 ) / j ⌉ ∨ y ¯ j ) ) .
(b) ( ∧ j \= l + 1 ⌊ a − 1 ⌋ + 1 ( x ¯ j ∨ y ⌊ ( a − 1 ) / ( j − 1 ) ⌋ + 1 ) ) ∧ ( ∧ j \= l + 1 ⌈ a − 1 ⌉ ( x ⌊ ( a − 1 ) / j − 1 ⌋ + 1 ∨ y j ) ) ∧ ( x l ) ∧ ( y l ), where l = ⌊ ( a – 1)/( d – 1)⌋ + 1. [Both formulas belong to 2SAT.]
407. (a) We always have ⌊ x / 2 ⌋ + ⌈ x / 2 ⌉ \= x , ⌊ x / 2 ⌋ + ⌊ y / 2 ⌋ ≤ x + y 2 ≤ ⌊ x / 2 ⌋ + ⌊ y / 2 ⌋ + 1 , and ⌈ x / 2 ⌉ + ⌈ y / 2 ⌉ − 1 ≤ x + y 2 ≤ ⌈ x / 2 ⌉ + ⌈ y / 2 ⌉ . (Similar reasoning proves the correctness of Batcher’s odd-even merge network; see Eq. 5.3.4–(3).)
(b) Axiom clauses like (164) needn’t be introduced for u and v , or even for z ; so they aren’t counted here, although they could be added if desired. Let a d = d 2 – 1 be the number of clauses in the original method; then the new method has fewer clauses when a ⌈ d /2⌉ + a ⌊ d /2⌋+1 + 3( d – 2) < a d , namely when d ≥ 7. (The new method for d = 7 involves 45 clauses, not 48; but it introduces 10 new auxiliary variables.) Asymptotically, we can handle d = 2 t + 1 with 3 t 2 t + O (2 t ) = 3 d lg d + O ( d ) clauses and d lg d + O ( d ) auxiliary variables.
(c) x + y ≥ z ⇔ ( d – 1 – x )+( d – 1 – y ) ≤ (2 d – 2 – z ); so we can use the same method, but complemented (namely with x j ↦ x ¯ d − j , y j ↦ y ¯ d − j , z j ↦ z ¯ 2 d − 1 − j ).
[See N. Tamura, A. Taga, S. Kitagawa, and M. Banbara, Constraints 14 (2009), 254–272; R. Asín, R. Nieuwenhuis, A. Oliveras, and E. Rodríguez-Carbonell, Constraints 16 (2011), 195–221.]
408. (a) No; makespan 11 is best, achievable as follows (or via left-right reflection):
(b) If j is the last job processed by machine i , that machine must finish at time ≤ Σ k \= 1 n w i k + Σ k \= 1 m w k j − w i j , because j uses some other machine whenever i is idle. [See D. B. Shmoys, C. Stein, and J. Wein, SICOMP 23 (1994), 631.]
(c) Clearly 0 ≤ s ij ≤ t – w ij . And if ij ≠ i ′ j ′ but i = i ′ or j = j ′ , we must have either s ij + w ij ≤ s i ′ j ′ or s i ′ j ′ + w i ′ j ′ ≤ s ij whenever w ij w i ′ j ′ ≠ 0.
(d) When w ij > 0, introduce Boolean variables s i j k for 1 ≤ k ≤ t – w ij , with the axiom clauses ( s ¯ i j k + 1 ∨ s i j k ) for 1 ≤ k < t – w ij . Then include the following clauses for all relevant i , j , i ′ , and j ′ as in (c): For 0 ≤ k ≤ t + 1 – w ij – w i ′ j ′ , assert ( p ¯ i j i ′ j ′ ∨ s i j − k ∨ s i ′ j ′ k + w i j ) if ij < i ′ j ′ or ( p ¯ i ′ j ′ i j ∨ s i j − k ∨ s i ′ j ′ k + w i j ) if ij > i ′ j ′ , omitting s ¯ i j 0 in the first of these ternary clauses and omitting s i ′ j ′ t + 1 − w i ′ j ′ in the last.
[This method, introduced by N. Tamura, A. Taga, S. Kitagawa, and M. Banbara in Constraints 14 (2009), 254–272, was able to solve several open shop scheduling problems in 2008 that had resisted attacks by all other approaches.]
Since the left-right reflection of any valid schedule is also valid, we can also save a factor of two by arbitrarily choosing one of the p variables and asserting ( p iji ′ j ′ ).
(e) Any schedule for W and T yields a schedule for ⌊ W/k ⌋ and ⌈ T/k ⌉, if we examine time slots 0, k , 2 k , ... . [With this observation we can narrow down the search for an optimum makespan by first working with simpler problems; the number of variables and clauses for ⌊ W/k ⌋ and T/k is about 1 /k times the number for W and T , and the running time also tends to obey this ratio. For example, the author solved a nontrivial 8×8 problem by first working with ⌊ W/ 8⌋ and getting the respective results (U , S , U) for t = (128 , 130 , 129), where ‘U’ means “unsatisfiable” and ‘S’ means “satisfiable”; running times were about (75 , 10 , 1250) megamems. Then with ⌊ W/ 4⌋ it was (S , U , U) with t = (262 , 260 , 261) and runtimes (425 , 275 , 325); with ⌊ W/ 2⌋ it was (U , S , U) with t = (526 , 528 , 527) and runtimes (975 , 200 , 900). Finally with the full W it was (U , S , S) with t = (1058 , 1060 , 1059) and runtimes (2050 , 775 , 300), establishing 1059 as the optimum makespan while doing most of the work on small subproblems.]
Notes: Further savings are possible by noting that any clauses learned while proving that t is satisfiable are valid also when t is decreased. Difficult random problems can be generated by using the following method suggested by C. Guéret and C. Prins in Annals of Operations Research 92 (1999), 165–183: Start with work times w ij that are as near equal as possible, having constant row and column sums s . Then choose random rows i ≠ i ′ and random columns j ≠ j ′ , and transfer δ units of weight by setting w ij ← w ij – δ , w i ′ j ← w ij ′ + δ , w ij ′ ← w ij ′ + δ , w i ′ j ′ ← w i ′ j ′ – δ , where δ ≤ w ij and δ ≤ w i ′ j ′ ; this operation clearly preserves the row and column sums. Choose δ at random between p · min{ w ij ,w i ′ j ′ } and min { w ij ,w i ′ j ′ }, where p is a parameter. The final weights are obtained after making r such transfers. Guéret and Prins suggested choosing r = n 3 , and p = . 95 for n ≥ 6; but other choices give useful benchmarks too.
409. (a) If S ⊆ {1,..., r }, let Σ S = Σ j ∈ S a j . We can assume that job n runs on machines 1, 2, 3 in that order. So the minimum makespan is 2 w 2 n + x , where x is the smallest Σ S that is ≥ ⌈( a 1 + … + a r )/2⌉. (The problem of finding such an S is well known to be NP-hard [R. M. Karp, Complexity of Computer Computations (New York: Plenum, 1972), 97–100]; hence the open shop scheduling problem is NP-complete.)
(b) Makespan w 2 n + w 4 n is achievable if and only if Σ S = ( a 1 + … + a r )/2 for some S . Otherwise we can achieve makespan w 2 n + w 4 n + 1 by running jobs 1, ... , n in order on machine 1 and letting s 3( n – 1) = 0, s 4 n = w 2 n ; also s 2 j = w 2 n + w 4 n , if machine 1 is running job j at time w 2 n . The other jobs are easily scheduled.
(c) ⌊3 n/ 2⌋ – 2 time slots are clearly necessary and sufficient. (If all row and column sums of W are equal to s , can the minimum makespan be ≥ 3 2 s ?)
(d) The “tight” makespan s is always achievable: By renumbering the jobs we can assume that a j ≤ b j for 1 ≤ j ≤ k , a j ≥ b j for k < j ≤ n , b 1 = max{ b 1 ,...,b k }, a n \= max{ a k +1 ,...,a n }. Then if b n ≥ a 1 , machine 1 can run jobs (1 ,...,n ) in order while machine 2 runs ( n, 1 ,...,n – 1); otherwise (2 ,...,n, 1) and (1 ,...n ) suffice.
If a 1 + … + a n ≠ b 1 + … + b n , we can increase a n or b n to make them equal. Then we can add a “dummy” job with a n +1 = b n +1 = max{ a 1 + b 1 ,...,a n + b n }. – s , and obtain an optimum schedule in O ( n ) steps as explained above.
Results (a), (b), (d) are due to T. Gonzalez and S. Sahni, who introduced and named the open shop scheduling problem in JACM 23 (1976), 665–679. Part (c) is a subsequent observation and open problem due to Gonzalez (unpublished).
410. Using half adders and full adders as we did in (23) allows us to introduce intermediate variables w j such that ( x 2 x 1 x 0 ) 2 +( x 2 x 1 x 0 00) 2 +( x 2 x 1 x 0 000) 2 + ( y ¯ 2 y ¯ 1 y ¯ 0 000 ) 2 ≤ ( w 7 w 6 ...w 0 ) 2 , and then to require ( w ¯ 7 ) ∧ ( w ¯ 6 ) . In slow motion, we successively compute ( c 0 z 0 ) 2 ≥ x 0 + x 2 , ( c 1 z 1 ) 2 ≥ x 0 + x 1 + y ¯ 0 , ( c 2 z 2 ) 2 ≥ c 0 + z 1 , ( c 3 z 3 ) 2 ≥ x 1 + x 2 + y ¯ 1 , ( c 4 z 4 ) 2 ≥ c 1 + c 2 + z 3 , ( c 5 z 5 ) 2 ≥ x 1 + y ¯ 2 + c 3 , ( c 6 z 6 ) 2 ≥ c 4 + z 5 , ( c 7 z 7 ) 2 ≥ c 5 + c 6 ; then w 7 w 6 ...w 0 = c 7 z 7 z 6 z 4 z 2 z 0 x 1 x 0 . In slower motion, each step ( c i z i ) 2 ≥ u + v expands to z i ≥ u ⊕ v , c i ≥ u ∧ v ; each step ( c i z i ) 2 ≥ t + u + v expands to s i ≥ t ⊕ u , p i ≥ t ∧ u , z i ≥ v ⊕ s i , q i ≥ v ∧ s i , c i ≥ p i ∨ q i . And at the clause level, t ≥ u ∧ v ⇔ ( t ∨ u ¯ ∨ v ¯ ) ; t ≥ u ∨ v ⇔ ( t ∨ u ¯ ) ∧ ( t ∨ v ¯ ) ; t ≥ u ⊕ v ⇔ ( t ∨ u ¯ ∨ v ) ∧ ( t ∨ u ∨ v ¯ ) . [Only about half of (24) is needed when inequalities replace equalities. Exercise 42 offers improvements.]
We end up with 44 binary and ternary clauses, together with c ¯ 7 ∧ z ¯ 7 . Unit propagation, and the removal of clauses with the pure literals z 0 , z 2 , z 4 , z 6 , now reduce the result. But the order encoding of exercise 405 is clearly much better. The log encoding becomes attractive only with larger integers, as in the following exercise. [See J. P. Warners, Information Processing Letters 68 (1998), 63–69.]
411. Use m + n new variables to represent an auxiliary number w = ( w m + n ...w 1 ) 2 . Form clauses as in exercise 41 for the product xy = w ; but retain only about half of the clauses, as in answer 410 . The resulting 9 mn – 5 m – 10 n clauses are satisfiable if w = xy ; and we have w ≥ xy whenever they are satisfiable. Now add 3 m +3 n – 2 further clauses as in (169) to ensure that z ≥ w . The case z ≤ xy is similar.
412. Mixed-radix representations are also of interest in this connection. See, for example, N. Eén and N. Sörensson, J. Satisfiability, Bool. Modeling and Comp. 2 (2006), 1–26; T. Tanjo, N. Tamura, and M. Banbara, LNCS 7317 (2012), 456–462.
413. There’s only one, namely ∧ σ 1 ,...,σ n ∈{–1,1} ( σ 1 x 1 ∨ σ 1 y 1 ∨...∨ σ n x n ∨ σ n y n ). Proof: Some clause must contain only positive literals, because f (0,..., 0) = 0. This clause must be ( x 1 ∨ y 1 ∨…∨ x n ∨ y n ); otherwise it would be false in cases where f is true. A similar argument shows that every clause ( σ 1 x 1 ∨ σ 1 y 1 ∨…∨ σ n x n ∨ σ n y n ) must be present. And no clause for f can contain both x j and y ¯ j , or both x ¯ j and y j .
414. Eliminating first a n –1 , then a n –2 , etc., yields 2 n –1 clauses. (The analogous result for x 1 . . . x n < y 1 . . . y n is 2 n + 2 n –1 + 1. A preprocessor will probably eliminate a n –1 .)
415. Via (166), construct clauses for 1 ≤ k ≤ n to encode ‘ a k –1 implies x k < y k + a k ’:
( ∧ j \= 1 d − 1 ( a ¯ k − 1 ∨ x ¯ k j ∨ y k j ) ) ∧ ( ∧ j \= 0 d − 1 ( a ¯ k − 1 ∨ a k ∨ x ¯ k j ∨ y k j + 1 ) ) , omitting x ¯ k 0 and y k d ;
also omit ā 0 . For the relation x 1 . . . x n ≤ y 1 . . . y n we can omit the d clauses that contain the (pure) literal an. But for x 1 . . . x n < y 1 . . . y n , we want a n = 0; so we omit a n and the d – 1 clauses ( a ¯ n − 1 ∨ x ¯ n j ∨ y n j ) . [The clauses (169) are due to K. Sakallah, Handbook of Satisfiability (2009), Chapter 10, (10.32).]
416. The other clauses are ∧ i \= 1 m ( ( u i ∨ v ¯ i ∨ a ¯ 0 ) ∧ ( u ¯ i ∨ v i ∨ a ¯ 0 ) ) and ( a 0 ∨ a 1 ∨ ... ∨ a n ). [See A. Biere and R. Brummayer, Proceedings, International Conference on Formal Methods in Computer Aided Design 8 (IEEE, 2008), 4 pages [FMCAD08].]
417. The four clauses ( s ¯ ∨ t ¯ ∨ u ) ∧ ( s ¯ ∨ t ∨ v ) ∧ ( s ∨ t ¯ ∨ u ¯ ) ∨ ( s ∨ t ∨ v ¯ ) ensure that s is true if and only if t ? u: v is true. But we need only the first two of these, as in (173), when translating a branching program, because the other two are blocked in the initial step. Removing them makes the other two blocked on the second step, etc.
418. A suitable branching program for h n when n = 3, beginning at I 11 , is I 11 \= ( 1 ¯ ? 21 : 22 ) , I 21 \= ( 2 ¯ ? 31 : 32 ) , I 22 \= ( 2 ¯ ? 32 : 33 ) , I 31 \= ( 3 ¯ ? 0 : 42 ) , I 32 \= ( 3 ¯ ? 42 : 43 ) , I 33 \= ( 3 ¯ ? 43 : 1 ) , I 42 \= ( 1 ¯ ? 0 : 1 ) , I 43 \= ( 2 ? 0 : 1 ) . It leads via (173) to the following clauses for row i , 1 ≤ i ≤ m : ( r i ,1,1 ); ( r ¯ i , k , j ∨ x i k ∨ r i , k + 1 , j ) ∧ ( r ¯ i , k , j ∨ x ¯ i k ∨ r i , k + 1 , j + 1 ) , for 1 ≤ j ≤ k ≤ n ; ( r ¯ i , n + 1 , 1 ) ∧ ( r i , n + 1 , n + 1 ) and ( r ¯ i , n + 1 , j + 1 ∨ x i j ) for 1 ≤ j < n . Also the following clauses for column j , 1 ≤ j ≤ n : ( c i ,1,1 ); ( c ¯ j , k , i ∨ x k j ∨ c j , k + 1 , i ) ∧ ( c ¯ j , k , i ∨ x ¯ k j ∨ c j , k + 1 , i + 1 ) , for 1 ≤ i ≤ k ≤ m ; ( c ¯ j , m + 1 , 1 ) ∧ ( c j , m + 1 , m + 1 ) and ( c ¯ j , m + 1 , i + 1 ∨ x i j ) for 1 ≤ i < m .
419. (a) There are exactly n –2 solutions: x ij = [ j = 1][ i ≠ m – 1] + [ j = 2][ i = m – 1] + [ j = k ][ i = m –1], for 2 < k = n .
(b) There are exactly m –2 solutions: x ¯ i j \= [ j > 1 ] [ i \= m − 1 ] + [ j \= 1 ] [ i \= m − 2 ] + [ j \= 1 ] [ i \= k ] , for 1 = k < m –2 or k = m .
420. Start via (24) with ( x ¯ 1 ∨ x 2 ∨ s ) ∧ ( x 1 ∨ x ¯ 2 ∨ s ) ∧ ( x 1 ∨ x 2 ∨ s ¯ ) ∧ ( x ¯ 1 ∨ x ¯ 2 ∨ s ¯ ) ; ( x 1 ∨ c ¯ ) ∧ ( x 2 ∨ c ¯ ) ∧ ( x ¯ 1 ∨ x ¯ 2 ∨ c ) ; ( s ¯ ∨ x 3 ∨ t ) ∧ ( s ∨ x ¯ 3 ∨ t ) ∧ ( s ∨ x 3 ∨ t ¯ ) ∧ ( s ¯ ∨ x ¯ 3 ∨ t ¯ ) ; ( s ∨ c ¯ ′ ) ∧ ( x 3 ∨ c ¯ ′ ) ∧ ( s ¯ ∨ x ¯ 3 ∨ c ′ ) ; ( c ¯ ) ∧ ( c ¯ ′ ) . Propagate ( c ¯ ) and ( c ¯ ′ ) , obtaining ( x ¯ 1 ∨ x ¯ 2 ) ∧ ( s ¯ ∨ x ¯ 3 ) ; remove subsumed clauses ( x ¯ 1 ∨ x ¯ 2 ∨ s ¯ ) , ( s ¯ ∨ x ¯ 3 ∨ t ¯ ) ; remove blocked clause ( s ∨ x 3 ∨ t ¯ ) ; remove clauses containing the pure literal t ; rename s to a 1 .
421. Start via (173) with ( a ¯ 5 ∨ x 1 ∨ a 4 ) ∧ ( a ¯ 5 ∨ x ¯ 1 ∨ a 4 ) ∧ ( a ¯ 5 ∨ x ¯ 1 ∨ a 3 ) ∧ ( a ¯ 4 ∨ x ¯ 2 ∨ a 2 ) ∧ ( a ¯ 3 ∨ x 2 ∨ a 2 ) ∧ ( a ¯ 3 ∨ x ¯ 2 ) ∧ ( a ¯ 2 ∨ x ¯ 3 ) ∧ ( a 5 ) . Propagate ( a 5 ).
422. (a) x 1 implies x ¯ 2 , then a 1 , then x ¯ 3 ; x 2 implies x ¯ 1 , then a 1 , then x ¯ 3 .
(b) x 1 implies a 3 , then x ¯ 2 , then a 2 , then x ¯ 3 ; x 2 implies ā 3 , then x ¯ 1 , a 4 , a 2 , x ¯ 3 .
423. No; consider x 1 ? ( x 2 ? x 3 : x 4 ): ( x 2 ? x 4 : x 3 ) with L \= ( x ¯ 3 ) ∧ ( x ¯ 4 ) . (But Abío, Gange, Mayer-Eichberger, and Stuckey have shown [ LNCS 9676 (2016), 1–17] that weak forcing is always achieved if ( ā j ∨ a l ∨ a h ) is added to (173). Furthermore, a forcing encoding can always be constructed, via the extra clauses defined in exercise 436 . Notice that, in the presence of failed literal tests, weak forcing corresponds to forcing.)
424. The clause 1 ¯ 3 ¯ 4 ¯ is redundant (in the presence of 1 ¯ 2 ¯ 3 ¯ and 2 3 ¯ 4 ¯ ); it cannot be omitted, because { 2 ¯ 3 ¯ , 2 3 ¯ , 12 } ⊬ 1 3 ¯ . The clause 2 3 ¯ 4 ¯ is also redundant (in the presence of 1 ¯ 3 ¯ 4 ¯ and 12); it can be omitted, because { 1 ¯ 4 ¯ , 34 , 1 } ⊢ 1 4 ¯ , { 1 ¯ 3 ¯ , 34 , 1 } ⊢ 1 3 ¯ , and { 1 ¯ 2 ¯ , 1 ¯ , 12 } ⊢ 1 2 .
425. If x is in the core, F ⊢ 1 x , because Algorithm 7.1.1C does unit propagation. Otherwise F is satisfied when all core variables are true and all noncore variables are false.
426. (a) True. Suppose the clauses involving a m are ( a m ∨ α i ) for 1 ≤ i ≤ p and ( ā m ∨ β j ) for 1 ≤ j ≤ q ; then G contains the pq clauses ( α i ∨ β j ) instead. If F | L ⊢ 1 l we want to prove that G | L ⊢ 1 l . This is clear if unit propagation from F | L doesn’t involve a m . Otherwise, if F | L ⊢ 1 a m , unit propagation has falsified some α i ; every subsequent propagation step from F | L that uses ( ā m ∨ β j ) can use ( α i ∨ β j ) in a propagation step from G | L . A similar argument applies when F | L ⊢ 1 ā m .
(Incidentally, the elimination of an auxiliary variable also preserves “honesty.”)
(b) False. Let F = ( x 1 ∨ x 2 ∨ a 1 ) ∧ ( x 1 ∨ x 2 ∨ ā 1 ), L \= x ¯ 1 or x ¯ 2 .
427. Suppose n = 3 m , and let f be the symmetric function [ νx<m or νx> 2 m ]. The prime clauses of f are the N \= ( n m , m , m ) ∼ 3 n + 3 / 2 ( 2 π n ) ORs of m positive literals and m negative literals. There are N ′ \= ( n m − 1 , m , m + 1 ) \= m m + 1 N ways to specify that x i 1 \= … = x i m \= 1 and x i m +1 \= … = x i 2 m –1 \= 0; and this partial assignment implies that x j \= 1 for j ∉ { i 1 ,...,i 2 m – 1 }. Therefore at least one of the m + 1 clauses ( x ¯ i 1 ∨ … ∨ x ¯ i m ∨ x i m + 1 ∨ … ∨ x i 2 m − 1 ∨ x j ) must be present in any set of prime clauses that forces f . By symmetry, any such set must include at least N ′ /m prime clauses.
On the other hand, f is characterized by O ( n 2 ) forcing clauses (see answer 436 ).
428. (a) ( y ∨ z j 1 ∨…∨ z jd ) for 1 ≤ j ≤ n ; ( x ¯ i j ∨ z ¯ i k ∨ z ¯ j k ) for 1 ≤ i < j ≤ n , 1 ≤ k ≤ d .
(b) Imagine a circuit with 2 N ( N + 1) gates g lt , one for each literal l of G nd and for each 0 ≤ t ≤ N , meaning that literal l is known to be true after t rounds of unit propagation, if we start with given values of the x ij variables only. Thus we set g l 0 ← 1 if l = x ij and x ij is true, or if l \= x ¯ i j and x ij is false; otherwise g l 0 ← 0. And
g l ( t + 1 ) ← g l t ∨ ∨ { g l 1 t ∧ … ∧ g l ¯ k t | ( l ∨ l 1 ∨ … ∨ l k ) ∈ G n d } , f o r 0 ≤ t < N .
Given values of the x ij , the literal y is implied if and only if the graph has no d -coloring; and at most N rounds make progress. Thus there’s a mo notone chain for g y N \= f ¯ n d .
[This exercise was suggested by S. Buss and R. Williams in 2014, based on a similar construction by M. Gwynne and O. Kullmann.]
429. Let Σ k be the sum of the assigned x ’s in leaves descended from node k . Unit propagation will force b j k ← 1 for 1 ≤ j ≤ Σ k , moving from leaves toward the root. Then it will force b j k ← 0 for j = Σ k + 1, moving downwards from the root, because r = Σ 2 +Σ 3 and because (21) starts this process when k = 2 or 3.
430. Imagine boundary conditions as in answer 26 , and assume that x j 1 , ... , x j r have been assigned 1, where j 1 < … < j r . Unit propagation forces s j k + 1 − k k ← 1 for 1 ≤ k ≤ r ; then it forces s j k − k k ← 0 for r ≥ k ≥ 1. So unassigned x ’s are forced to zero.
431. Equivalently x 1 + … + x m + y ¯ 1 + … + y ¯ n ≤ n ; so we can use (18)–(19)or (20)–(21).
432. The clauses of answer 404(b) can be shown to be forcing. But not those of 404(a) when a > 1; for example, if a = 2 and we assume x ¯ 2 , unit propagation doesn’t yield y 2 .
433. Yes. Imagine, for example, the partial assignment x = 1∗∗∗10∗∗1, y = 10∗00∗1∗∗. Then y 3 must be 1; otherwise we’d have 10010001 ≤ x ≤ y ≤ 100001111. In this situation unit propagation from the clauses that correspond to 1 ≤ 〈 a 1 01〉, a 1 ≤ 〈 a 2 x ¯ 2 0 〉 , a 2 ≤ 〈 a 3 x ¯ 3 y 3 〉 , a 3 ≤ 〈 a 4 x ¯ 4 0 〉 , a 4 ≤ a 5 00 forces a 1 = 1, a 2 = 1, a 4 = 0, a 3 = 0, y 3 = 1.
In general if a given partial assignment is consistent with x ≤ y , we must have x ↓ ≤ y ↑, where x ↓ and y ↑ are obtained from x and y by changing all unassigned variables to 0 and 1, respectively. If that partial assignment forces some y j to a particular value, the value must be 1; and we must in fact have x ↓ > y ′ ↑, where y ′ is like y but with y j \= 0 instead of y j \= ∗. If x j ≠ 1, unit propagation will force a 1 = … = a j – 1 = 1, a k \= … = a j \= 0, y j \= 1, for some k ≥ j .
Similar remarks apply when x i is forced, because x ≤ y ⇔ y ¯ ≤ x ¯ .
434. (a) Clearly p k is equivalent to x ¯ 1 ∧ … ∧ x ¯ k , q k is equivalent to x ¯ k ∧ … ∧ x ¯ n , and r k implies that a run of exactly l 1s begins at x k .
(b) When l = 1, if x k \= 1 unit propagation will imply p ¯ j for j ≥ k and q ¯ j for j ≤ k , hence r ¯ j for j ≠ k ; then r k is forced, making x j \= 0 for all j ≠ k . Conversely, x j \= 0 forces r ¯ j ; if this holds for all j ≠ k , then r k is forced, making x k \= 1.
But when l = 2 and n = 3, the clauses fail to force x 2 = 1 by unit propagation. They also fail to force x 1 = 0 when we have l = 2, n = 4, and x 3 = 1.
435. The following construction with O ( nl ) clauses is satisfactory when l is small: Begin with the clauses for p k and q k (but not r k ) in exercise 434(a) ; include also ( x ¯ k ∨ p k − l ) for l < k ≤ n , and ( x ¯ k ∨ q k + l ) for 1 ≤ k ≤ n – l . Append ( p ¯ k − l ∨ q ¯ k + l ∨ x k ) for 1 ≤ k ≤ n , omitting p ¯ j for j < 1 and omitting q ¯ j for j > n . Finally, append
( x k ∨ x ¯ k + 1 ∨ x k + d ) f o r 0 ≤ k < n a n d 1 < d < 1 , ( ∗ )
omitting x j when j < 1 or j > n .
To reduce to O ( n log l ) clauses, suppose 2 e +1 < l ≤ 2 e +2 , where e ≥ 0. The clauses (∗) can be replaced by ( x ¯ k ∨ y ¯ k ( e ) ∨ z ¯ k ( e ) ) for 1 ≤ k ≤ n , if x ¯ k − d implies y k ( e ) for 1 ≤ d ≤ ⌊ l/ 2⌋ and x ¯ k + d implies z k ( e ) for 1 ≤ d ≤ ⌈ l/ 2⌉. And to achieve the latter, we introduce clauses ( y ¯ k ( t ) ∨ y k ( t + 1 ) ) , ( y ¯ k − 2 t ( t ) ∨ y k ( t + 1 ) ) , ( z ¯ k ( t ) ∨ z k ( t + 1 ) ) , ( z ¯ k + 2 t ( t ) ∨ z k ( t + 1 ) ) , ( x k − 1 ∨ y k ( 0 ) ) , ( x k + 2 e − 1 − ⌊ l / 2 ⌋ ∨ y k ( 0 ) ) , ( x k + 1 ∨ z k ( 0 ) ) , ( x k − 2 e + 1 + ⌈ l / 2 ⌉ ∨ z k ( 0 ) ) , for 1 ≤ k ≤ n and 0 ≤ t < e , always omitting x j or y ¯ j or z ¯ j when j < 1 or j > n .
436. Let the variables q k for 0 ≤ k ≤ n and q ∈ Q represent the sequence of states, and let the variables t kaq represent a transition when 1 ≤ k ≤ n and when T contains a triple of the form ( q ′ ,a,q ). The clauses, F , are the following, for 1 ≤ k ≤ n : (i) ( t ¯ k a q ∨ x k a ) ∧ ( t ¯ k a q ∨ q k ) , when t kaq exists, where x k 0 denotes x ¯ k and x k 1 denotes x k ; (ii) ( q ¯ k − 1 ∨ ∨ { t k a q ′ | ( q , a , q ′ ) ∈ T } ) , for q ∈ Q ; (iii) ( q ¯ k ∨ ∨ { t k a q | ( q ′ , a , q ) ∈ T } ) , for q ∈ Q ; (iv) ( x ¯ k a ∨ ∨ { t k a q | ( q ′ , a , q ) ∈ T } ) , for a ∈ A ; (v) ( t ¯ k a q ′ ∨ ∨ { q k − 1 | ( q , a , q ′ ) ∈ T } ) , when t kaq′ exists. And (vi) ( q ¯ 0 ) for q ∈ Q \ I , ( q ¯ n ) for q ∈ Q \ O .
It is clear that if F ⊢ 1 x ¯ k a no string x 1 ...x n ∈ L can have x k \= a . Conversely, assume that F ⊬ 1 x ¯ k a , and in particular that F ⊬ 1 ∊ . To prove the forcing property, we want to show that some string of L has x k \= a . It will be convenient to say that a literal l is ‘n.f.’ (not falsified) if F ⊬ 1 l ¯ ; thus x k a is assumed to be n.f.
By (iv), there’s a ( q ′ ,a,q ) ∈ T such that t kaq is n.f. Hence q k is n.f., by (i). If k = n we have q ∈ O by (vi); otherwise some t ( k +1) bq ′ is n.f., by (ii), hence x k + 1 b is n.f. Moreover, (v) tells us that there’s ( q ″ ,a,q ) ∈ T with q k − 1 ″ n.f. If k = 1 we have q ″ ∈ I ; otherwise some t ( k –1) cq ″ is n.f., by (iii), and x k − 1 c is n.f. Continuing this line of reasoning yields x 1 ...x n ∈ L with x k \= a (and with x k +1 = b if k < n , x k – 1 = c if k > 1).
The same proof holds even if we add unit clauses to F that assign values to one or more of the x ’s. Hence F is forcing. [See F. Bacchus, LNCS 4741 (2007), 133–147.]
For example, the language L 2 of exercise 434 yields 20 n + 4 clauses with 7 n +3 auxiliary variables: F \= ∧ k \= 1 n ( ( t ¯ k 00 ∨ x ¯ k ) ∧ ( t ¯ k 00 ∨ 0 k ) ∧ ( t ¯ k 11 ∨ x k ) ∧ ( t ¯ k 11 ∨ 1 k ) ∧ ( t ¯ k 12 ∨ x k ) ∧ ( t ¯ k 12 ∨ 2 k ) ∧ ( t ¯ k 02 ∨ x ¯ k ) ∧ ( t ¯ k 02 ∨ 2 k ) ( 0 ¯ k − 1 ∨ t k 00 ∨ t k 11 ) ∧ ( 1 ¯ k − 1 ∨ t k 12 ) ∧ ( 2 ¯ k − 1 ∨ t k 02 ) ∧ ( 0 ¯ k ∨ t k 00 ) ∧ ( 1 ¯ k ∨ t k 11 ) ∧ ( 2 ¯ k ∨ t k 02 ∨ t k 12 ) ∧ ( x k ∨ t k 00 ∨ t k 02 ) ∧ ( x ¯ k ∨ t k 11 ∨ t k 12 ) ∧ ( t ¯ k 00 ∨ 0 k − 1 ) ∧ ( t ¯ k 11 ∨ 0 k − 1 ) ∧ ( t ¯ k 12 ∨ 1 k − 1 ) ∧ ( t ¯ k 02 ∨ 2 k − 1 ) ) ∧ ( 1 ¯ 0 ) ∧ ( 2 ¯ 0 ) ∧ ( 0 ¯ n ) ∧ ( 1 ¯ n ) .
The clauses produced by this general-purpose construction can often be significantly simplified by preprocessing to eliminate auxiliary variables. (See exercise 426 .)
437. Each variable x k now becomes a set of | A | variables x ka for a ∈ A , with clauses like (15) and (17) to ensure that exactly one value is assigned. The same construction is then valid, with the same proof, if we simply replace ‘ x k a ’ by ‘ x ka ’ throughout. ( Notice that unit propagation will often derive partial information such as x ¯ ka , meaning that x k ≠ a , although the precise value of x k may not be known.)
438. Let l ≤ j = l 1 + ··· + l j . Exercise 436 does the job via the following automaton: Q = {0, 1,..., l ≤ t + t − 1}, I = {0}, O = { l ≤ t + t − 1}; T = {( l ≤ j + j, 0 , l ≤ j + j ) | 0 ≤ j < t } ∪ {( l ≤ j + j + k, 1, l ≤ j + j + k + 1) | 0 ≤ j < t, 0 ≤ k < l j +1 } ∪ {( l ≤ j + j − 1, 0, l ≤ j + j − [ j = t ]) | 1 ≤ j ≤ t }.
439. We obviously want the clauses ( x ¯ j ∨ x ¯ j + 1 ) for 1 ≤ j < n ; and we can use, say, (18) and (19) with r = t , to force 0s whenever the number of 1s reaches t . The difficult part is to force 1s from partial patterns of 0s; for example, if n = 9 and t = 4, we can conclude that x 4 = x 6 = 1 as soon as we know that x 3 = x 7 = 0.
An interesting modification of (18) and (19) turns out to work beautifully, namely with the clauses ( t ¯ j k ∨ t j + 1 k ) for 1 ≤ j < 2 t − 1 and 1 ≤ k ≤ n − 2 t + 1, together with ( x 2 j + k − 1 ∨ t ¯ 2 j − 1 k ∨ t 2 j − 1 k + 2 ) for 1 ≤ j ≤ t and 0 ≤ k ≤ n − 2 t + 1, omitting t ¯ 2 j − 1 0 and t 2 j − 1 n − 2 t + 2 .
440 . It’s convenient to introduce ( n + 1 2 ) | N | variables P ik for all P ∈ N and for 1 ≤ i ≤ k ≤ n , as well as ( n + 1 3 ) | N | 2 variables QR ijk for Q, R ∈ N and for 1 ≤ i < j ≤ k ≤ n , although almost all of them will be eliminated by unit propagation. The clauses are: (i) ( QR ¯ ijk ∨ Q i ( j − 1 ) ) ∧ ( QR ¯ ijk ∨ R jk ) ; (ii) ( P ¯ k k ∨ ∨ { x k a | P → a ∈ U } ) ; (iii) ( P ¯ i k ∨ ∨ { Q R i j k | i < j ≤ k , P → Q R ∈ W } ) , if i < k ; (iv) ( x ¯ k a ∨ ∨ { P k k | P → a ∈ U } ) ; (v) ( P ¯ i k ∨ ∨ { P R i ( k + 1 ) l | k < l ≤ n , R ∈ N } ∨ ∨ { Q R hik | 1 ≤ h < i , Q ∈ N } ) , if i > 1 or k < n ; (vi) ( Q R ¯ ijk ∨ ∨ { P i k | P → Q R ∈ W } ) ; (vii) ( P ¯ 1 n ) for P ∈ N \ S .
The forcing property is proved by extending the argument in answer 436 : Assume that x k a is n.f.; then some P kk with P → a is also n.f. Whenever P ik is n.f. with i > 1 or k < n , some PR i ( k +1) l or QP hik is n.f.; hence some “larger” P i l ′ or P h k ′ is also n.f. And if P 1 n is n.f., we have P ∈ S .
Furthermore we can go “downward”: Whenever P ik is n.f. with i < k , there’s QR ijk such that Q i ( j − 1) and R jk are n.f.; on the other hand if P kk is n.f., there’s a ∈ A such that x k a is n.f. Our assumption that x k a is n.f. has therefore shown the existence of x 1 ...x n ∈ L with x k \= a .
[See C.-G. Quimper and T. Walsh, LNCS 4741 (2007), 590–604.]
441. See O. Bailleux, Y. Boufkhad, and O. Roussel, LNCS 5584 (2009), 181–194.
442. (a) F | L q − \= F | l 1 | . . . | l q − 1 | l ¯ q contains ϵ if and only if F | l 1 | ... | l q −1 contains ϵ or the unit clause ( l q ).
(b) If F ⊬ 1 l and F | l ¯ ⊢ 1 ϵ , the failed literal elimination technique will reduce F to F | l and continue looking for further reductions. Thus we have F ⊢ 2 l if and only if unit propagation plus failed literal elimination will deduce either ϵ or l .
(c) Use induction on k ; both statements are obvious when k = 0. Suppose we have F ⊢ k + 1 l ¯ via l 1 , … , l p \= l ¯ , with F | L q − ⊢ k ϵ for 1 ≤ q ≤ p . If p > 1 we have F | l | L q − ⊢ k ϵ for 1 ≤ q < p ; it follows that F | l ⊢ k +1 l p − 1 and F | l ⊢ k + 1 l ¯ p − 1 . If p = 1 we have F | l | L q − ⊢ k ϵ for 1 ≤ q < p ; it follows that F | l ⊢ k +1 l p −1 and F | l ⊢ k + 1 l ¯ p − 1 . If p = 1 we have F | l ⊢ k ϵ . Hence F | l ⊢ k +1 ϵ in both cases.
Now we want to prove that F | l ⊢ k +1 ϵ and F ⊢ k +2 ϵ , given F ⊢ k +1 l ′ and F ⊢ k + 1 l ¯ ′ . If F | L q − ⊢ k ϵ for 1 ≤ q ≤ p , with l p \= l ′ , we know that F | L q − ⊢ k + 1 ϵ . Furthermore we can assume that F ⊬ k + 1 l ¯ ; hence l ≠ l ¯ q for 1 ≤ q ≤ p , and l ≠ l p . If l = l q for some q < p , then F | l | L r − ⊢ k ϵ for 1 ≤ r < q and F | L r − ⊢ k ϵ for q < r ≤ p ; otherwise F | l | L q − ⊢ k ϵ for 1 ≤ q ≤ p . In both cases F | l ⊢ k +1 l ′ and F ⊢ k +2 l ′ . Essentially the same proof shows that F | l ⊢ k + 1 l ¯ ′ and F ⊢ k + 2 l ¯ ′ .
(d) True, by the last relation in part (c).
(e) If all clauses of F have more than k literals, L k ( F ) is empty; hence L 0 ( R ′ ) = L 1 ( R ′ ) = L 2 ( R ′ ) = ∅. But L k ( R ′ ) \= { 1 ¯ , 2 , 4 } for k ≥ 3; for example, R ′ ⊢ 3 1 ¯ because R ′ | 1 ⊢ 2 ϵ , because R ′ | 1 ⊢ 2 3 and R ′ | 1 ⊢ 2 3 ¯ .
(f) Unit propagation can be done in O ( N ) steps if N is the total length of all clauses; this handles the case k = 1.
For k ≥ 2, procedure P k ( F ) calls P k − 1 ( F | x 1 ), P k − 1 ( F | x ¯ 1 ) , P k − 1 ( F | x 2 ), etc., until either finding P k − 1 ( F | l ¯ ) \= { ϵ } or trying both literals for each variable of F . In the latter case, P k returns F . In the former case, if P k − 1 ( F | l ) is also {ϵ}, P k returns {ϵ}; otherwise it returns P k ( F | l ). The set L k contains all literals for which we’ve reduced F to F | l , unless P k ( F ) = { ϵ }. (In the latter case, every literal is in L k .)
To justify this procedure we must verify that the order of testing literals doesn’t matter. If F | l ¯ ⊢ k ϵ and F | l ¯ ′ ⊢ k ϵ , we have F | l | l ¯ ′ ⊢ k ϵ and F | l ′ | l ¯ ⊢ k ϵ by (c); hence P k ( F | l ) = P k ( F | l | l ′ ) = P k ( F | l ′ | l ) = P k ( F | l ′ ).
[See O. Kullmann, Annals of Math. and Artificial Intell. 40 (2004), 303–352.]
443. (a) If F | L ⊢ ϵ then F | L ⊢ l for all literals l ; so if F ∈ PC k we have F | L ⊢ k l and F | L ⊢ k l ¯ and F | L ⊢ k ϵ , proving that PC k ⊆ UC k .
Suppose F ∈ UC k and F | L ⊢ l . Then F | L | l ¯ ⊢ ϵ , and we have F | L | l ¯ ⊢ k ϵ . Consequently F | L ⊢ k +1 l , proving that UC k ⊆ PC k +1 .
The satisfiable clause sets ∅, {1}, {1, 1 ¯ 2}, {12, 1 ¯ 2}, {12, 1 ¯ 2, 1 2 ¯ , 1 ¯ 2 ¯ 3}, {123, 1 ¯ 23, 1 2 ¯ 3, 1 ¯ 2 ¯ 3}, {123, 1 ¯ 23, 1 2 ¯ 3, 1 ¯ 2 ¯ 3, 12 3 ¯ , 1 ¯ 2 3 ¯ , 1 2 ¯ 3 ¯ , 1 ¯ 2 ¯ 3 ¯ 4}, ... , show that PC k ≠ UC k ≠ PC k +1 .
(b) F ∈ PC 0 if and only if F = ∅ or ϵ ∈ F . (This can be proved by induction on the number of variables in F , because ϵ ∉ F implies that F has no unit clauses.)
(c) If F has only one clause, it is in UC 0 . More interesting examples are {1 2 ¯ , 1 ¯ 2}; {1234, 1 ¯ 2 ¯ 3 ¯ 4 ¯ }; {123 4 ¯ , 12 3 ¯ 4, 1 2 ¯ 34, 1 ¯ 234}; {12, 1 ¯ 2 ¯ , 34 5 ¯ , 3 ¯ 4 ¯ 5}; etc. In general, F is in UC 0 if and only if it contains all of its prime clauses.
(d) True, by induction on n : If F | L ⊢ l then F | L | l ¯ ⊢ ϵ , and F | L | l ¯ has ≤ n − 1 variables; so F | L | l ¯ ∈ PC n − 1 ⊆ UC n − 1 . Hence we have F | L | l ¯ ⊢ n − 1 ϵ and F | L ⊢ n l .
(e) False, by the examples in (c).
(f) R ′ ∈ UC 2 \ PC 2 . For example, we have R ′ | 1 ⊢ 2 2 and R ′ | 1 ⊢ 2 2 ¯ .
[See M. Gwynne and O. Kullmann, arXiv:1406.7398 [cs.CC] (2014), 67 pages.]
444. (a) Complementing a variable doesn’t affect the algorithm’s behavior, so we can assume that F consists of unrenamed Horn clauses. Then all clauses of F will be Horn clauses of length ≥ 2 whenever step E2 is reached. Such clauses are always satisfiable, by setting all remaining variables false; so step E3 cannot find both F ⊢ 1 l and F ⊢ 1 l ¯ .
(b) For example, {12, 2 ¯ 3, 1 2 ¯ 3 ¯ , 1 ¯ 23}.
(c) Every unsatisfiable F recognized by SLUR must be in UC 1 . Conversely, if F ∈ UC 1 , we can prove that F is satisfiable and in UC 1 whenever step E2 is reached.
[Essentially the same argument proves that a generalized algorithm, which uses ⊢ k instead of ⊢ 1 in steps E1 and E3, always classifies F if and only if F ∈ UC k . See M. Gwynne and O. Kullmann, Journal of Automated Reasoning 52 (2014), 31–65.]
(d) If step E3 interleaves unit propagation on F | l with unit propagation on F | l ¯ , stopping when either branch is complete and ϵ was not detected in the other, the running time is proportional to the number of cells used to store F , using data structures like those of Algorithm L . (This is an unpublished idea of Klaus Truemper.)
[SLUR is due to J. S. Schlipf, F. S. Annexstein, J. V. Franco, and R. P. Swami-nathan, Information Processing Letters 54 (1995), 133–137.]
445. (a) Since the lexicographic constraints (169) are forcing, a succinct certificate is ( x ¯ 1 m , x ¯ 2 m , . . . , x ¯ ( m − 1 ) m , x ¯ 2 ( m − 1 ) , x ¯ 3 ( m − 1 ) , x ¯ 3 ( m − 1 ) , ... , x ¯ ( m − 1 ) ( m − 1 ) , x ¯ 3 ( m − 2 ) , x ¯ 4 ( m − 2 ) , ... , x ¯ ( m − 1 ) ( m − 2 ) , x ¯ ( m − 1 ) 2 , ∅). The first m − 1 steps can be replaced by ‘ x 0 m ’.
(b) ( x ¯ ( m − 1 ) 1 , x ¯ ( m − 2 ) 2 , . . . , x ¯ 1 ( m − 1 ) , ∅ ) .
(c) ( x 01 , x 12 , ... , x ( m − 2)( m − 1) , ∅).
446. Z ( m, n ) − 1, because a 4-cycle corresponds to a quad.
447. For general m and n we can add the m 3 ¯ n 3 ¯ / 3 ! constraints ( x ¯ i j ∨ x ¯ i ′ j ∨ x ¯ i ′ j ′ ∨ x ¯ i ′ ′ j ′ ∨ x ¯ i ′ ′ j ′ ′ ∨ x ¯ i j ′ ′ ) to (184), for 1 ≤ i < i ′ < i ″ ≤ m and distinct { j, j ′ ,j ″ } ⊆ {1,..., n }. The 19-edge graph illustrated here works when m = n = 8; and Algorithm C finds girth ≥ 8 unsatisfiable with 20 edges, after only 400 megamems of calculation (using lexicographic row/column symmetry).
448. Each pair of points can occur together in at most one line. If the lines contain respectively l 1 , ... , l n points, we therefore have ( l 1 2 ) + ⋅ ⋅ ⋅ + ( l n 2 ) ≤ ( m 2 ) \= 3 n . A Steiner triple system achieves equality, with l 1 = ··· = l n \= 3. Since ( l − 1 2 ) + ( l ′ + 1 2 ) < ( l 2 ) + ( l ′ 2 ) when l ≥ l ′ + 2, we can’t have l 1 + ··· + l n > 3 n . Thus Z ( m, n ) = 3 n +1.
[If m is even and ( m 2 ) \= 3 n , we can’t cover all the pairs with triples, because no point can be in more than ( m − 2) / 2 triples. Daniel Horsley proved in 2015 that Z ( m, n ) = 3 n + ⌊1 − m/ 14⌋ in such cases.]
449. It’s wise to try first for symmetric solutions with x ij \= x ji , roughly halving the number of variables; then the matrices below are found quickly. Such solutions are impossible when n = 9, 12, 13 (and also when n = 15 and 16 if we insist on five 1s in the top row). The case n = 13 corresponds to the projective plane of order 3; indeed, a projective plane of order q is equivalent to a maximum quad-free matrix with m = n = q 2 + q + 1 and Z ( n, n ) = ( q + 1) n + 1.
450. To prove the hint, add the unary clause ( x ¯ 15 ) to the others; this problem is rapidly found to be unsatisfiable, hence no line has more than 4 points. On the other hand, a line with fewer than 3 points is impossible because Z (9, 10) = 32. The same arguments show that every point belongs to either 3 or 4 lines. Thus exactly four lines contain four points, and exactly four points lie on such lines.
If p ∈ l and l is a 4-point line, every other line containing p must contain 2 of the remaining 6 points. And the four 4-point lines contain at least 4 × 4 − ( 4 2 ) \= 10 points altogether. Hence, pigeonwise, we see that each of the four 4-point lines contains exactly one of the four 4-line points.
Now we may call the 4-line points { a, b, c, d }, and the 4-point lines { A, B, C, D }. The other points may be called { ab, ac, ad, bc, bd, cd }, with A = { a, ab, ac, ad }, B = {b, ab, bc, bd }, C = { c, ac, bc, cd }, D = { d, ad, bd, cd }. The other lines can be called {AB,AC,AD,BC,BD,CD }; and we have AB = { a, b, cd }, AC = { a, c, ad }, etc.
451. One of the colors can be placed uniquely, by the previous exercise. So we’re left with the simple problem of two-coloring the remaining 66 squares and avoiding both 0-quads and 1-quads. That problem is unsatisfiable with ∑ x ij odd. The author then constructed a 33 + 33 + 33 solution by hand, using the fact that each color class must be unable to use the deleted square. [See M. Beresin, E. Levine, and J. Winn, The College Mathematics Journal 20 (1989), 106–114 and the cover; J. L. Lewis, JRM 28 (1997), 266–273.]
452. Any such solution must have exactly 81 cells of each color, because R. Nowakowski proved in 1978 that Z (18, 18) = 82. The solution exhibited here was found by B. Steinbach and C. Posthoff [ Multiple-Valued Logic and Soft Computing 21 (2013), 609–625], exploiting 90° rotational symmetry.
453. (a) If R ⊆ {1,..., m } and C ⊆ {1,..., n }, let V ( R, C )= { u i | i ∈ R }∪{ v j | j ∈ C }. If X is decomposable, there’s no path from a vertex in V ( R, C ) to a vertex not in V ( R, C ); hence the graph isn’t connected. Conversely, if the graph isn’t connected, let V ( R, C )be one of its connected components. Then 0 < | R |+| C | < m + n , and we’ve decomposed X .
(b) False in general, unless every row and column of X ′ contains a positive element. Otherwise, clearly true by the definition of lexicographic order.
(c) True: A direct sum is certainly decomposable. Conversely, let X be decomposable via R and C . We may assume that 1 ∈ R or 1 ∈ C ; otherwise we could replace R by {1,..., m } \ R and C by {1,..., n } \ C . Let i ≥ 1 and j ≥ 1 be minimal such that i ∉ R and j ∉ C . Then x i′j \= 0 for 1 ≤ i ′ < i and x ij′ \= 0 for 1 ≤ j ′ < j . The lexicographic constraints now force x i′j′ \= 0 for 1 ≤ i ′ < i , j ′ ≥ j ; also for i ′ ≥ i , 1 ≤ j ′ < j . Consequently X = X ′ ⊕ X ″ , where X ′ is ( i − 1) × ( j − 1) and X ″ is ( m + 1 − i ) × ( n + 1 − j ). (Degenerate cases where i = 1 or j = 1 or i = m + 1 or j = n + 1 need to be considered, but they work fine. This result allows us to “read off” the block decomposition of a lexicographically ordered matrix.)
Reference: A. Mader and O. Mutzbauer, Ars Combinatoria 61 (2001), 81–95.
454. We have f ( x ) ≤ f ( xτ ) ≤ f ( xτ τ ) ≤ ··· ≤ f ( xτ k ) ≤ ··· ; eventually xτ k = x .
455. (a) Yes, because C only causes 1001 and 1011 to be nonsolutions. (b) No, because F might have been satisfied only by 0011. (c) Yes as in (a), although (187) might no longer be an endomorphism of F ∧ C as it was in that case. (d) Yes; if 0110 is a solution, so are 0101 and 1010. [Of course this exercise is highly artificial: We’re unlikely to know that a weird mapping such as (187) is an endomorphism of F unless we know a lot more about the set of solutions.]
456. Only (1 + 2 · 7)(1 + 2)(1 + 8) = 405, out of 65536 possibilities (about 0.62%).
457. We have min 0 ≤ k ≤ 16 ( k k 16 16− k ) = 6 6 16 10 ≈ 51.3 × 10 15 . For general n , the minimum occurs when k = 2 n /e + O (1); and it is 2 2 n ( n − x ) where x = 1/( e ln 2)+ O (2 − n ) < 1.
458. The operation of assigning values to each variable of an autarky, so that all clauses containing those variables are satisfied, while leaving all other variables unchanged, is an endomorphism. (For example, consider the operation that makes a pure literal true.)
459. sweep( X ij ) = −∞ when i = 0 or j = 0. And for 1 ≤ i ≤ m and 1 ≤ j ≤ n we have sweep( X ij ) = max( x ij + sweep( X ( i − 1)( j − 1) ), sweep( X ( i − 1) j ), sweep( X i ( j − 1) )).
[Let the 1s in the matrix be x i 1 j 1 , ... , x i r j r , with 1 ≤ i 1 ≤ ··· ≤ i r ≤ m and with j q +1 < j q when i q +1 = i q . Richard Stanley has observed (unpublished) that sweep( X ) is the number of rows that occur when the Robinson– Schensted– Knuth algorithm is used to insert the sequence n − j 1 , ... , n − j r into an initially empty tableau.]
460. We introduce auxiliary variables s i j t that will become true if sweep( X ij ) > t . They are implicitly true when t < 0, false when t = k . The clauses are as follows, for 1 ≤ i ≤ m , 1 ≤ j ≤ n , and 0 ≤ t ≤ min( i − 1, j − 1, k ): ( s ¯ ( i − 1 ) j t ∨ s i j t ) , if i > 1 and t < k ; ( s ¯ i ( j − 1 ) t ∨ s i j t ) , if j > 1 and t < k ; and ( x ¯ i j ∨ s ¯ ( i − 1 ) ( j − 1 ) t − 1 ∨ s i j t ) . Omit s ¯ 0 ( j − 1 ) t − 1 and s ¯ ( i − 1 ) 0 t − 1 and s ¯ ( i − 1 ) ( j − 1 ) − 1 and s i j k from that last clause, if present.
461. ∧ i \= 1 m − 1 ∧ j \= 1 n − 1 ( x i j ∨ c ¯ ( i − 1 ) j ∨ c i j ) ∧ ∧ i \= 1 m ∧ j \= 1 n − 1 ( c ¯ ( i − 1 ) j ∨ x ¯ i j ∨ x i ( j + 1 ) ) , omitting c ¯ 0 j . These clauses take care of τ 1 ; interchange i ↔ j , m ↔ n for τ 2 .
462. Let X ˜ i j denote the last m + 1 − i rows and the last n + 1 − j columns of X ; and let t ij \= sweep( X ( i − 1)( j − 1) ) + sweep ( X ˜ ( i + 1 ) ( j + 1 ) ) . For τ 1 we must prove 1 + t i ( j +1) ≤ k , given that 1 + t ij ≤ k . It’s true because sweep( X ( i − 1) j ) = sweep( X ( i − 1)( j − 1) ) when column j begins with i − 1 zeros, and we have sweep ( X ˜ ( i + 1 ) ( j + 2 ) ) ≤ sweep ( X ˜ ( i + 1 ) ( j + 1 ) ) .
Let X ′ = Xτ 3 have the associated sweep sums t i j ′ . We must prove that t i j ′ ≤ k and 1 + t ( i + 1 ) ( j + 1 ) ′ ≤ k , if 1 + t ij ≤ k , 1 + t i ( j +1) ≤ k , 1 + t ( i +1) j ≤ k , and t ( i +1)( j +1) ≤ k . The key point is that sweep ( X i j ′ ) \= max(sweep( X ( i − 1) j ), sweep( X i ( j − 1) )), since x i j ′ \= 0 . Also sweep ( X ˜ ( i + 1 ) ( j + 1 ) ′ ) ≤ 1 + sweep ( X ˜ ( i + 2 ) ( j + 1 ) ) .
(Notice that τ 1 and τ 2 might actually decrease the sweep, but τ 3 preserves it.)
463. If row i + 1 is entirely zero but row i isn’t, τ 2 will apply. Therefore the all-zero rows occur at the top. And by τ 1 , the first nonzero row has all its 1s at the right.
Suppose rows 1 through i have r 1 , ... , r i 1s, all at the right, with r i > 0. Then r 1 ≤ ··· ≤ r i , by τ 2 . If i < n we can increase i to i + 1, since we can’t have x ( i +1) j > x ( i +1)( j +1) when j ≤ n − r i , by τ 1 ; and we can’t have it when j > n − r i , by τ 3 .
Thus all the 1s are clustered at the right and the bottom, like the diagram of a partition but rotated 180°; and the sweep is the size of its “ Durfee square” (see Fig. 91 in Section 7.2.1.4). Hence the maximum number of 1s, given sweep k , is k ( m + n − k ).
[Under the partial ordering ( i, j ) ≺ ( i ′ , j ′ ) when i < i ′ and j < j ′ , binary matrices of sweep ≤ k correspond to sets of cells with all chains of length ≤ k . Significant lattice and matroid properties of such “ Sperner k -families” have been studied by C. Greene and D. J. Kleitman, J. Combinatorial Theory A20 (1976), 41–68.]
464. By answer 462 , τ 1 can be strengthened to τ 1 ″ , which sets x i ( j +1) ← 1 but leaves x ij \= 1. Similarly, τ 2 ″ can be strengthened to τ ″ 2 . These endomorphisms preserve the sweep but increase the weight, so they can’t apply to a matrix of maximum weight. [One can prove, in fact, that max-weight binary matrices of sweep k are precisely equivalent to k disjoint shortest paths from the leftmost cells in row m to the rightmost cells in row 1. Hence every integer matrix of sweep k is the sum of k matrices of sweep 1.]
465. If not, there’s a cycle x 0 → x 1 → ··· → x p \= x 0 of length p > 1, where x i τ uv i ↦ x i +1 . Let uv be the largest of { uv 1 ,..., uv p − 1 }. Then none of the other τ ’s in the cycle can change the status of edge uv . But that edge must change status at least twice.
(See also the more general result in Theorem 7.2.2.1S.)
466. Notice first that v 11 must be true, if m ≥ 2. Otherwise h 11 , v 21 , h 22 , v 32 , ... would successively be forced by unit propagation, until reaching a contradiction at the edge of the board. And v 31 must also be true, if m ≥ 4, by a similar argument. Thus the entire first column must be filled with verticals, except the bottom row when m is odd.
Then we can show that the remainder of row 1 is filled with horizontals, except for the rightmost column when n is even. And so on.
The unique solution when m and n are both even uses v ij if and only if i + j is even and 1 ≤ j ≤ min( i, m − i, n/ 2), or i + j is odd and v i ( n +1 − j ) is used. When m is odd, add a row of horizontals below the ( m − 1) × n solution. When n is odd, remove the rightmost column of verticals in the m × ( n + 1) solution.
467. The 8 × 7 covering is the reflection of the 7 × 8 covering (shown here) about its southwest-to-northeast diagonal. Both solutions are unique.
468. (a) Typical running times with Algorithm C for sizes 6 × 6, 8 × 8, ... , 16 × 16 are somewhat improved: 39 K μ , 368 K μ , 4.3M μ , 48M μ , 626 M μ , 8G μ .
(b) Now they’re even better, but still growing exponentially: 30 K μ , 289 K μ , 2.3M μ , 22M μ , 276 M μ , 1.7G μ .
469. For instance ( v 11 ), ( v 31 ), ( v 51 ), ( h 12 ), ( h 14 ), ( v 22 ), ( v 42 ), ( h 23 ), ( v 33 ), ϵ .
470. There can’t be a cycle x 0 → x 1 → ··· → x p \= x 0 of length p > 1, because the largest vertex whose mate is changed always gets smaller and smaller mates.
471. We must pair 2 n with 1, then 2 n − 1 with 2, ... , then n + 1 with n .
472. We can number the vertices from 1 to mn in such a way that every 4-cycle switches as desired. For example, we can make ( i, j ) < ( i, j + 1) ⇔ ( i, j ) < ( i +1, j ) ⇔ ( i, j ) mod 4 ∉ {(0, 0), (0, 1), (1, 1), (1, 2), (2, 2), (2, 3), (3, 3), (3, 0)}. One such numbering in the 4 × 4 case is shown here.
473. For every even-length cycle v 0 −−− v 1 −−−···−−− v 2 r − 1 −−− v 0 with v 0 = max v i and v 1 > v 2 r − 1 , assert ( v 0 v 1 ¯ ∨ v 1 v 2 ∨ v 2 v 3 ¯ ∨ ⋅ ⋅ ⋅ ∨ v 2 r − 1 v 0 ) .
474. (a) (2 n ) · (2 n − 2) · ... · 2 = 2 n n !. (b) (17 3 ¯ )( 1 ¯ 7 ¯ 3)(25 2 ¯ 5 ¯ )(4 4 ¯ )(6)( 6 ¯ ).
(c) Using 0, 1 , ... , f for the 4-tuples 0000, 0001, ... , 1111, we must have f ( 0 ) = f ( 9 ) = f ( 5 ); f ( 2 ) = f ( b ) = f ( 7 ); f ( 4 ) = f ( 8 ) = f ( d ); and f ( 6 ) = f ( a ) = f ( f ); in other words, the truth table of f must have the form abcdeagceagcfehg , where a, b, c, d, e, f, g, h ∉ {0, 1}. So there are 2 8 f ’s.
(d) Change ‘=’ to ‘≠’ in (c). There are no such truth tables, because (191) contains odd cycles; all cycles of an antisymmetry must have even length.
(e) The 128 binary 7-tuples are partitioned into sixteen “ orbits” { x, xσ, xσ 2 , ... }, with eight of size 12 and eight of size 4. For example, one of the 4s is {0011010, 0010110, 0111110, 0110010}; one of the 12s is {0000000, 0011101,..., 1111000}. Hence there are 2 16 functions with this symmetry, and 2 16 others with this antisymmetry.
475. (a) 2 n +1 n !. (There are 2 n +1 n ! /a , if f has a automorphisms+antiautomorphisms.)
(b) ( x z ¯ ) ( x ¯ z ) , because (surprisingly) ( x ∨ y ) ∧ ( x ⊕ z ) \= ( z ¯ ∨ y ) ∧ ( z ¯ ⊕ x ¯ ) .
(c) In general if σ is any permutation having a cycle of length l , and if p is a prime divisor of l , some power of σ will have a cycle of length p . (Repeatedly raise σ to the q th power for all primes q ≠ p , until all cycle lengths are powers of p . Then, if the longest remaining cycle has length p e , compute the p e −1 st power.)
(d) Suppose f ( x 1 , x 2 , x 3 ) has the symmetry ( x 1 x ¯ 2 x 3 ) ( x ¯ 1 x 2 x ¯ 3 ) . Then f (0, 0, 0) = f (1, 1, 0) = f (0, 1, 1), f (1, 1, 1) = f (0, 0, 1) = f (1, 0, 0), so ( x 1 x ¯ 2 ) ( x ¯ 1 x 2 ) is a symmetry.
(e) A similar argument shows that ( u x ) ( v w ) ( u ¯ x ¯ ) ( v ¯ w ¯ ) is a symmetry.
(f) If σ is an antisymmetry of f , then σ 2 is a symmetry. If f has a nontrivial symmetry, it has a symmetry of prime order p , by (c). And if p ≠ 2, it has one of order 2, by (d) and (e), unless n > 5.
(g) Let f ( x 1 ,..., x 6 ) = 1 only when x 1 ...x 6 ∈ {001000, 001001, 001011, 010000, 010010, 010110, 100000, 100100, 100101}. (Another interesting example, for n = 7, has f = 1 ⇔ x 1 ...x 7 is a cyclic shift of 0000001, 0001101, or 0011101; 21 symmetries.)
476. We want clauses that specify r -step chains in n variables, having a single output x n + r . For 0 < t < t ′ < 2 n , introduce new variables Δ tt′ = x ( n + r ) t ⊕ x ( n + r ) t′ . (See (24).) Then for each signed involution σ , not the identity, we want a clause that says “ σ is not a symmetry of f ,” namely (∨{Δ tt′ | t < t ′ and t ′ = tσ }). (Here t is considered to be the same as its binary representation ( t 1 ...t n ) 2 , as in exercise 477 .)
Also, if σ has no fixed points — this is true if and only if σ takes x i ↦ x ¯ i for at least one i — we have further things to do: In case (b), we want a clause that says “ σ is not an antisymmetry,” namely ( ∨ { Δ ¯ t t ′ | t < t ′ and t ′ \= t σ } ) . But in case (a), we need further variables a j for 1 ≤ j ≤ T , where T is the number of signed involutions that are fixedpoint-free. We append the clause ( a 1 ∨···∨ a T ), and also ( a ¯ j ∨ Δ t t ′ ) for all t < t ′ such that t ′ = tσ when σ corresponds to index j . Those clauses say, “there’s at least one signed involution that is an antisymmetry.”
There are no solutions when n ≤ 3. Answers for (a) are ((( x 1 ⊕ x 2 ) ∨ x 3 ) ∧ x 4 ) ⊕ x 1 and ( ( ( x ¯ 1 ⊕ x 2 ) ∧ x 3 ) ⊕ x 4 ) ∧ x 5 ) ⊕ x 1 ; in both cases the signed involution (1 1 ¯ )(2 2 ¯ ) is obviously an antisymmetry. Answers for (b) are (( x 1 ⊕ x 2 ) ∨ x 3 ) ∧ ( x 4 ∨ x 1 ) and ((( x 1 ∧ x 2 ) ⊕ x 3 ) ∧ x 4 ) ⊕ ( x 5 ∨ x 1 ). [Is there a simple formula that works for all n ?]
477. Use the following variables for 1 ≤ h ≤ m , n < i ≤ n + r , and 0 < t < 2 n : x it \= ( t th bit of truth table for x i ); g hi \= [ g h \= x i ]; s ijk \= [ x i \= x j ◦ i x k ], for 1 ≤ j < k < i ; f ipq \= ◦ i ( p, q ) for 0 ≤ p, q ≤ 1, p + q > 0. (We don’t need f i 00 , because every operation in a normal chain takes (0, 0) ↦ 0.) The main clauses for truth table computations are ( s ¯ ijk ∨ ( x i t ⊕ a ) ∨ ( x j t ⊕ b ) ∨ ( x k t ⊕ c ) ∨ ( f ibc ⊕ a ¯ ) ) , for 0 ≤ a , b , c ≤ 1 and 1 ≤ j < k < i .
Simplifications arise in special cases: For example, if b = c = 0, the clause is omitted if a = 0, and the term f i 00 is omitted if a = 1. Furthermore if t = ( t 1 ... t n ) 2 , and if j ≤ n , the (nonexistent) variable x jt actually has the known value t j ; again we omit either the whole clause or the term ( x jt ⊕ b ), depending on b and t . For example, there usually are eight main clauses that involve s ijk ; but there’s only one that involves s i 12 when t < 2 n −2 , namely ( s ¯ i 12 ∨ x ¯ i 1 ) , because the truth tables for x 1 and x 2 begin with 2 n −2 0s. (All such simplifications would be done by a preprocessor if we had defined additional variables f i 00 and x jt , and fixed their values with unit clauses.)
There also are more mundane clauses, namely ( g ¯ h i ∨ x ¯ i t ) or ( g ¯ h i ∨ x i t ) according as g h ( t 1 ,..., t n ) = 0 or 1, to fix the outputs; also ( ∨ i \= n + 1 n + r g h i ) and ( ∨ k \= 1 i − 1 ∨ j \= 1 k − 1 s ijk ) , to ensure that each output appears in the chain and that each step has two operands.
Additional clauses are optional, but they greatly shrink the space of possibilities: ( ∨ k \= 1 m g k i ∨ ∨ i ′ \= i + 1 n + r ∨ j \= 1 i − 1 s i ′ j i ∨ ∨ i ′ \= i + 1 n + r ∨ j \= i + 1 i ′ − 1 s i ′ i j ) ensures that step i is used at least once; ( s ¯ ijk ∨ s ¯ i ′ j i ) and ( s ¯ ijk ∨ s ¯ i ′ k i ) for i < i ′ ≤ n + r avoid reapplying an operand.
Finally, we can rule out trivial binary operations with the clauses ( f i 01 ∨ f i 10 ∨ f i 11 ), ( f i 01 ∨ f ¯ i 10 ∨ f ¯ i 11 ) , ( f ¯ i 01 ∨ f i 10 ∨ f ¯ i 11 ) . (But beware: These clauses, for n < i ≤ n + r , will make it impossible to compute the trivial function g 1 = 0 in fewer than three steps!)
Further clauses such as ( s ¯ i j k ∨ f i 10 ∨ x ¯ i t ∨ x j t ) are true, but unhelpful in practice.
478. We can insist that the ( j, k ) pairs in steps n + 1, ... , n + r appear in colexicographic order; for example, a chain step like x 8 = x 4 ⊕ x 5 need never follow x 7 = x 2 ∧ x 6 . The clauses, for n < i < n + r , are ( s ¯ i j k ∨ s ¯ ( i + 1 ) j ′ k ′ ) if 1 ≤ j ′ < j < k = k ′ < i or if 1 ≤ j < k and 1 ≤ j ′ < k ′ < k < i . (If ( j, k ) = ( j ′ , k ′ ), we could insist further that f i 01 f i 10 f i 11 is lexicographically less than f ( i +1)01 f ( i +1)10 f ( i +1)11 . But the author didn’t go that far.)
Furthermore, if p<q and if each output function is unchanged when x p is swapped with x q , we can insist that x p is used before x q as an operand. Those clauses are
( s ¯ ijq ∨ ∨ n < i ′ < i ∨ i ≤ j ′ < k ′ < i ′ [ j ′ \= p or k ′ \= p ] s i ′ j ′ k ′ ) whenever j ≠ p .
For example, when answer 477 is applied to the full-adder problem, it yields M r clauses in N r variables, where ( M 4 , M 5 ) = (942, 1662) and ( N 4 , N 5 ) = (82, 115). The symmetry-breaking strategy above, with ( p, q ) = (1, 2) and (2, 3), raises the number of clauses to M r ′ , where ( M 4 ′ , M 5 ′ ) \= ( 1025 , 1860 ) . Algorithm C reported ‘unsat’ after (1015, 291) kilomems using ( M 4 , M 4 ′ ) clauses; ‘sat’ after (250, 268) kilomems using ( M 5 , M 5 ′ ) . With larger problems, such symmetry breakers give significant speedup when proving unsatisfiability, but they’re often a handicap in satisfiable instances.
479. (a) Using the notation of the previous answer, we have ( M 8 , M 8 ′ , N 8 ) \= ( 14439 , 17273 , 384 ) and ( M 9 , M 9 ′ , N 9 ) \= ( 19719 , 24233 , 471 ) . The running times for the ‘sat’ cases with M 9 and M 9 ′ clauses were respectively (16, 645, 1259) and (66, 341, 1789) megamems — these stats are the (min, median, max) of nine runs with different random seeds. The ‘unsat’ cases with M 8 and M 8 ′ were dramatically different: (655631, 861577, 952218) and (8858, 10908, 13171). Thus s (4) = 9 in 7.1.2–(28) is optimum.
(b) But s (5) = 12 is not optimum, despite the beauty of 7.1.2–(29)! The M 11 = 76321 clauses in N 11 = 957 variables are ‘sat’ in 680 G μ , yielding an amazing chain:
x 6 \= x 1 ⊕ x 2 , x 10 \= x 6 ∨ x 7 , x 7 \= x 1 ⊕ x 3 , x 11 \= x 4 ⊕ x 9 , x 14 \= x ¯ 8 ∧ x 11 , x 8 \= x 4 ⊕ x 5 , x 12 \= x 9 ⊕ x 10 , z 1 \= x 15 \= x 10 ⊕ x 14 , x 9 \= x 3 ⊕ x 6 , z 0 \= x 13 \= x 5 ⊕ x 11 , z 2 \= x 16 \= x 12 ∧ x ¯ 15 .
And ( M 10 ′ , N 10 ) \= ( 68859 , 815 ) turns out to be ‘unsat’ in 1773 gigamems; this can be reduced to 309 gigamems by appending the unit clause ( g 3(15) ), since C ( S 4 , 5 ) = 10.
Hence we can evaluate x 1 +···+ x 7 in only 5 + 11 + 2 + 1 = 19 steps, by computing ( u 1 u 0 ) 2 = x 5 + x 6 + x 7 , ( v 2 v 1 z 0 ) 2 = x 1 + x 2 + x 3 + x 4 + u 0 , ( w 2 z 1 ) 2 = u 1 + v 1 , z 2 = v 2 ⊕ w 2 .
(c) The solver finds an elegant 8-step solution for ( M 8 , N 8 ) = (6068, 276) in 6 M μ :
x 4 \= x 1 ∨ x 2 , x 6 \= x 3 ⊕ x 4 x 8 \= x 3 ⊕ x 5 , S 1 \= x 10 \= x 6 ∧ x 8 , x 5 \= x 1 ⊕ x 2 , S ¯ 0 \= x 7 \= x 3 ∨ x 4 , S 3 \= x 9 \= x ¯ 6 ∧ x 8 , S 2 \= x 11 \= x 7 ⊕ x 8 .
The corresponding ( M 7 ′ , N 7 ) \= ( 5016 , 217 ) problem is ‘unsat’ in 97 M μ .
(d) The total cost of evaluating the S ’s independently is 3 + 7 + 6 + 7 + 3 = 26, using the optimum computations of Fig. 9 in Section 7.1.2. Therefore the author was surprised to discover a 9-step chain for S 1 , S 2 , and S 3 , using the footprint heuristic:
x 5 \= x 1 ⊕ x 2 , x 8 \= x 5 ⊕ x 7 , S 2 \= x 11 \= x ¯ 8 ∧ x 9 , x 6 \= x 1 ⊕ x 3 , x 9 \= x 6 ∨ x 7 , S 3 \= x 12 \= x 8 ∧ x ¯ 10 , x 7 \= x 3 ⊕ x 4 , x 10 \= x 2 ⊕ x 9 , S 1 \= x 13 \= x 8 ∧ x 10.
This chain can solve problem (d) in 13 steps; but SAT technology does it in 12(!):
x 5 \= x 1 ⊕ x 2 , x 9 \= x 6 ∨ x 7 , S 1 \= x 13 \= x 8 ∧ x 10 , x 6 \= x 1 ⊕ x 3 , x 10 \= x 2 ⊕ x 9 , S 4 \= x 14 \= x 1 ∧ x ¯ 11 , x 7 x 8 \= \= x 3 ⊕ x 4 , x 5 ⊕ x 7 , x 11 S 3 \= x 12 \= \= x 5 ∨ x 9 , x 8 ∧ x ¯ 10 , S ¯ 0 S 2 \= \= x 15 \= x 4 ∨ x 11 , x 16 \= x ¯ 8 ∧ x 11 .
The nonexistence of an 11-step solution can be proved via Algorithm C by a long computation (11034 gigamems), during which 99,999,379 clauses are learned(!).
(e) This solution (found in 342 G μ ) matches the lower bound in exercise 7.1.2–80:
x 7 \= x 1 ⊕ x 2 , x 11 \= x 4 ⊕ x 10 , x 8 \= x 3 ⊕ x 4 , x 12 \= x 5 ⊕ x 10 , x 9 \= x 1 ⊕ x 5 , x 13 \= x 8 ∨ x 11 , x 10 \= x 6 ⊕ x 8 , x 14 \= x 7 ⊕ x 12 , x 15 \= x ¯ 9 ∧ x 12 , x 16 \= x 13 ⊕ x 15 , x 17 \= x 14 ∧ x 16.
(f) This solution (found in 7471 G μ ) also matches that lower bound:
x 7 \= x 1 ∧ x 2 , x 11 \= x 5 ⊕ x 6 , x 15 \= x 8 ⊕ x 13 , x 8 \= x 1 ⊕ x 2 , x 12 \= x 4 ⊕ x 11 , x 16 \= x 10 ⊕ x 14 , x 9 \= x 3 ⊕ x 4 , x 13 \= x 9 ⊕ x 11 , x 17 \= x 7 ⊕ x 16 , x 10 \= x 5 ∧ x 6 , x 14 \= x 9 ∨ x 12 , x 18 \= x 15 ∨ x 17 ,
Here x 18 is the normal function S ¯ 0 , 4 \= S 1 , 2 , 3 , 5 , 6 . We beat exercise 7.1.2–28 by one step.
(g) A solution in t (3) = 12 steps is found almost instantaneously (120 megamems); but 11 steps are too few (‘unsat’ in 301 gigamems).
480. (a) Let x 1 x 2 x 3 x 4 = x l x r y l y r . The truth tables for z l and z r are 0011010010001000 and 01∗∗1∗00∗011∗011, where the ∗s (“ don’t-cares”) are handled by simply omitting the corresponding clauses ( g ¯ h i ∨ ± x i t ) in answer 477 .
Less than 1 gigamem of computation proves that a six-step circuit is ‘unsat’. Here’s a seven-stepper, found in just 30 M μ : x 5 = x 2 ⊕ x 3 , x 6 = x 3 ∨ x 4 , x 8 = x 1 ⊕ x 6 , x 7 = x 1 ∨ x 5 , x 9 = x 6 ⊕ x 7 , z l \= x 10 = x 7 ∧ x 8 , z r \= x 11 = x 3 ⊕ x 9 . (See exercise 7.1.2–60 for a six-step solution that is based on a different encoding.)
(b) Now we have the truth tables z l \= 00110100010010000100100010000011, z r \= 01∗∗1∗001∗00∗0111∗00∗011∗01101∗∗, if x 4 x 5 = y l y r . One of many 9-step solutions is found in 6.9 gigamems: x 6 = x 1 ⊕ x 2 , x 7 = x 2 ⊕ x 5 , x 8 = x 4 ⊕ x 6 , x 9 \= x ¯ 4 ∧ x 7 , x 10 = x 1 ⊕ x 9 , x 11 = x 8 ∨ x 9 , x 12 = x 3 ⊕ x 10 , z r \= x 13 = x 3 ⊕ x 11 , z l \= x 14 \= x 11 ∧ x ¯ 12 .
The corresponding clauses for only 8 steps are proved ‘unsat’ after 190 G μ of work. (Incidentally, the encoding of exercise 7.1.2–60 does not have a 9-step solution.)
(c) Let c n be the minimum cost of computing the representation z l z r of ( x 1 + ··· + x n ) mod 3. Then ( c 1 , c 2 , c 3 , c 4 ) = (0, 2, 5, 7), and c n + 3 ≤ c n + 9. Hence c n ≤ 3 n − 4 for all n ≥ 2. [This result is due to A. Kojevnikov, A. S. Kulikov, and G. Yaroslavtsev, whose paper in LNCS 5584 (2009), 32–44, also inspired exercises 477 – 479 .]
Conjecture: For n ≥ 3 and 0 ≤ a ≤ 2, the minimum cost of evaluating the (single) function [( x 1 + ··· + x n ) mod 3 = a ] is 3 n − 5 − [( n + a ) mod 3 = 0]. (It’s true for n ≤ 5. Here’s a 12-step computation when n = 6 and a = 0, found in 2014 by Armin Biere: x 7 = x 1 ⊕ x 2 , x 8 = x 3 ⊕ x 4 , x 9 = x 1 ⊕ x 5 , x 10 = x 3 ⊕ x 5 , x 11 = x 2 ⊕ x 6 , x 12 = x 8 ⊕ x 9 , x 13 = x 8 ∨ x 10 , x 14 = x 7 ⊕ x 13 , x 15 \= x ¯ 12 ∧ x 13 , x 16 \= x ¯ 11 ∧ x 14 , x 17 = x 11 ⊕ x 15 , S ¯ 0 , 3 , 6 \= x 18 \= x 16 ∨ x 17 . The case n = 6 and a ≠ 0, which lies tantalizingly close to the limits of today’s solvers, is still unknown. What is C ( S 1 , 4 ( x 1 ,..., x 6 ))?)
481. (a) Since z ⊕ z ′ = 〈 x 1 x 2 x 3 〉 and z ′ = x 1 ⊕ x 2 ⊕ x 3 , this circuit is called a “ modified full adder.” It costs one less than a normal full adder, since z ′ = ( x 1 ⊕ x 2 ) ⊕ x 3 and z = ( x 1 ⊕ x 2 ) ∨ ( x 1 ⊕ x 3 ). (And it’s the special case u = 0 of the more general situation in exercise 7.1.2–28.) Part (b) describes a “modified double full adder.”
(b) The function z 2 has 20 don’t-cares, so there are many eight-step solutions (although 7 are impossible); for example, x 6 = x 1 ⊕ x 5 , x 7 = x 2 ⊕ x 5 , z 3 = x 8 = x 3 ⊕ x 6 , x 9 = x 4 ⊕ x 6 , x 10 = x 1 ∨ x 7 , x 11 \= x ¯ 3 ∧ x 9 , z 2 = x 12 = x 6 ⊕ x 11 , z 1 = x 13 = x 10 ⊕ x 11 .
(c) Letting y 2 k − 1 y 2 k = ⟦ x 2 k − 1 x 2 k ⟧, it suffices to show that the binary representation of Σ n = ν ⟦ y 1 y 2 ⟧ + ··· + ν ⟦ y 2 n − 1 y 2 n ⟧ + y 2 n +1 can be computed in at most 8 n steps. Four steps are enough when n = 1. Otherwise, letting c 0 = y 2 n +1 , we can compute z ’s bits with ν ⟦ y 4 k − 3 y 4 k −2 ⟧ + ν ⟦ y 4 k −1 y 4 k ⟧ + c k −1 = 2 ν ⟦ z 2 k −1 z 2 k ⟧ + c k for 1 ≤ k ≤ ⌊ n/ 2⌋. Then Σ n = 2( ν ⟦ z 1 z 2 ⟧ + ··· + ν ⟦ z n −1 z n ⟧) + c n/ 2 if n is even, Σ n = 2( ν ⟦ z 1 z 2 ⟧ +···+ ν ⟦ z n −2 z n −1 ⟧+ z n ) + c ′ if n is odd, where ν ⟦ y 2 n −1 y 2 n ⟧ + c ⌊n/ 2⌋ = 2 z n + c ′ , at a cost of 4 n in both cases. The remaining sum costs at most 8⌊ n/ 2⌋ by induction. [See E. Demenkov, A. Kojevnikov, A. S. Kulikov, and G. Yaroslavtsev, Information Processing Letters 110 (2010), 264–267.]
482. (a) Σ j \= 1 k ( 2 y i − 1 ) is odd when k is odd, and it’s ±1 when k = 1.
(b) Adapting Sinz’s cardinality clauses as in exercises 29 and 30 , we only need the auxiliary variables a j \= s j j − 1 , b j \= s j j , and c j \= s j j + 1 , because s j j + 2 \= 0 and s j + 2 j \= 1 . The clauses are then ( b ¯ j ∨ a j + 1 ) ∧ ( c ¯ j ∨ b j + 1 ) ∧ ( b j ∨ c ¯ j ) ∧ ( a j + 1 ∨ b ¯ j + 1 ) , for 1 ≤ j < t /2 − 1; and ( y ¯ 2 j − 2 ∨ a j ) ∧ ( y ¯ 2 j − 1 ∨ a ¯ j ∨ b j ) ∧ ( y ¯ 2 j ∨ b ¯ j ∨ c j ) ∧ ( y ¯ 2 j + 1 ∨ c ¯ j ) ∧ ( y 2 j − 2 ∨ c ¯ j − 1 ) ∧ ( y 2 j − 1 ∨ c j − 1 ∨ b ¯ j ) ∧ ( y 2 j ∨ b j ∨ a ¯ j + 1 ) ∧ ( y 2 j + 1 ∨ a j + 1 ) for 1 ≤ j < t/ 2, omitting ā 1 , c 0 , and the two clauses that contain y 0 .
(c) Use the construction in (b) with y j \= x jd for 1 ≤ d ≤ n/ 3 and independent auxiliary variables a j,d , b j,d , c j,d . Also, assuming that n ≥ 720, break symmetry by asserting the unit clause ( x 720 ). (That’s much better than simply asserting ( x 1 ).)
This problem was shown to be satisfiable if and only if n < 1161 by B. Konev and A. Lisitsa [ Artificial Intelligence 224 (2015), 103–118], thereby establishing the case C = 2 of a well-known conjecture by Paul Erdős [ Michigan Math. J. 4 (1957), 291–300, Problem 9]. Algorithm C can prove unsatisfiability for n = 1161 in less than 600 gigamems, using the parameters of exercise 512 .
483. Using a direct encoding as in (15), with v jk meaning that v j has color k , we can generate the clauses ( v ¯ j k ) for 1 ≤ j < k ≤ d and ( v ¯ j ( k + 1 ) ∨ ∨ i \= k j − 1 v i k ) for 2 ≤ k < j ≤ n . A similar but slightly simpler scheme works with the order encoding, when v jk means that v j has color > k . [See Ramani, Markov, Sakallah, and Aloul, Journal of Artificial Intelligence Research 26 (2006), 289–322. The vertices might be ordered in such a way that degree( v 1 ) ≥ ··· ≥ degree( v n ), for example.]
It’s not difficult to color the Mycielski graph M c with c colors (which is the minimum), without any symmetry breaking. For example, the 3071-vertex graph M 12 leads to 2,446,271 clauses in 36852 variables (total length 4.9 million); yet 12-color solutions are found by Algorithms C , W , and L respectively in 2.6, 523, and 12200 megamems. The symmetry breaking clauses actually would retard that calculation, because those clauses are much longer. On the other hand, when we try to succeed with only c − 1 colors, those clauses are extremely helpful: The runtime needed by Algorithm C to show that M 6 isn’t 5-colorable goes down from 124 G μ to 32 M μ ! Furthermore, Algorithm L does better here: Its runtime for that problem goes down from 7.5 G μ to 28 M μ .
484. (a) A type (iii) move will work if and only if v 1 −−− v 4 , v 2 −−− v 4 , v 2 −−− v 3 .
(b) For 0 ≤ t < n − 1 we have the clause ( ∨ k \= 1 n − t − 1 q t , k ∨ ∨ l \= 1 n − t − 3 s t , l ) , as well as the following for 1 ≤ i < j < n − t , 1 ≤ k < n − t , 1 ≤ l < n − t − 2: ( q ¯ t , k ∨ x t , k , k + 1 ) ; ( q ¯ t , k ∨ x ¯ t + 1 , i , j ∨ x t , i ′ , j ′ ) ; ( s ¯ t , l ∨ x t , l , l + 3 ) ; ( s ¯ t , l ∨ x ¯ t + 1 , i , j ∨ x t , i ′ ′ , j ′ ′ ) ; here i ′ = i + [ i ≥ k ], j ′ = j + [ j ≥ k ], and { i ″ , j ″ } are the min and max of { i + [ i ≥ l + 3] + 3[ i = l ], j +[ j ≥ l + 3] + 3[ j = l ]}. Finally there’s a unit clause ( x ¯ 0 , i , j ) for all 1 ≤ i < j ≤ n with v i — v j .
(These clauses essentially compute [ G is quenchable], which is a monotone Boolean function of the ( n 2 ) elements above the diagonal in the adjacency matrix of G . The prime implicants of this function correspond to certain spanning trees, of which there are respectively 1, 1, 2, 6, 28, 164, 1137, ... , when n = 1, 2, 3, 4, 5, 6, 7, ... .)
485. Let t ′ = t + 1. Instances of commutativity are: ( q t,k , q t′, k′ ) ↔ ( q t, k + 1 , q t′, k ) if k < k ′ ; ( s t,l′ , s t′, l′ ) ↔ ( s t′,l′+1 , s t′, l ) if l + 2 < l ′ ; ( q t,k′ , s t′, l′ ) ↔ ( s t,l′+1 , q t′, k ) if k < l ′ ; ( s t,l , q t′, k′ ) ↔ ( q t,k′+1 , s t′, l ) if l + 2 < k ′ ; ( s t,l , s t′, l ) ↔ ( q t,l +3 , s t′,l ). These can be broken by appending the clauses ( q ¯ t , k ′ + 1 ∨ q ¯ t ′ , k ) , ( s ¯ t , l ′ + 1 ∨ s ¯ t ′ , l ) , ... , ( q ¯ t , l + 3 ∨ s ¯ t ′ , l ) .
Endomorphisms are also present in the two cases ( q t,k , q t′,k ) ↔ ( q t,k +1 , q t′,k ) and ( s t,k +1 , q t′,k ) ↔ ( q t,k +1 , s t′,k ), provided that both pairs of transitions are legal. These are exploited by the clauses ( q ¯ t , k + 1 ∨ q ¯ t ′ , k ∨ x ¯ t , k , k + 1 ) and ( q ¯ t , k + 1 ∨ s ¯ t ′ , k ∨ x ¯ t , k + 1 , k + 4 ) .
486. This game is a special case of graph quenching, so we can use the previous two exercises. Algorithm C finds a solution after about 1.2 gigamems, without the symmetry-breaking clauses; this time goes down to roughly 85 mega mems when those clauses are added. Similarly, the corresponding 17-card problem after A ♣ × J ♣ is found to be unsatisfiable, after 15 G μ without and 400 M μ with. ( A ♣ × × 10 ♣ fails too.)
Those SAT problems have respectively (1242, 20392, 60905), (1242, 22614, 65590), (1057, 15994, 47740), (1057, 17804, 51571) combinations of (variables, clauses, cells), and they are not handled easily by Algorithms A , B , D , or L . In one solution both q 0 , 11 and s 0 , 7 are true, thus providing two ways to win(!), when followed by q 1 , 15 , s 2 , 13 , q 3 , 12 , s 4 , 10 , s 5 , 7 , q 6 , 7 , s 7 , 5 , q 8 , 5 , s 9 , 4 , q 10 , 5 , s 11 , 3 , q 12 , 3 , s 13 , 1 , s 14 , 1 , q 15 , 1 , q 16 , 1 .
Notes: This mildly addictive game is an interesting way to waste time in case you ever get lost with a pack of cards on a desert island. If you succeed in reducing the original 18 piles to a single pile, you can continue by dealing 17 more cards and trying to reduce the new 18 piles. And if you succeed also at that, you have 17 more cards for a third try, since 52 = 18 + 17 + 17. Three consecutive wins is a Grand Slam.
In a study of ten thousand random deals, just 4432 turned out to be winnable. Computer times (with symmetry breaking) varied wildly, from 1014 K μ to 37 G μ in the satisfiable cases (median 220 M μ ) and from 46 K μ to 36 G μ in the others (median 848 M μ ). The most difficult winnable and unwinnable deals in this set were respectively
9 ♠ 7 ♣ 3 ♣ K ◊ 7 ♠ 3 ♡ 2 ◊ 8 ♣ 6 ♡ J ◊ 8 ♠ 2 ♡ 6 ♠ 4 ◊ 5 ♠ 4 ♡ 10 ◊ Q ♠ and A ♡ Q ♡ 2 ◊ 9 ◊ 7 ♣ 7 ◊ 8 ♡ K ♣ 3 ◊ 10 ♣ 3 ♣ 3 ♠ Q ♠ 8 ♣ 2 ♣ K ♠ 6 ◊ 5 ♣ .
Students in Stanford’s graduate problem seminar investigated this game in 1989 [see K. A. Ross and D. E. Knuth, Report STAN-CS-89-1269 (Stanford Univ., 1989), Problem 1]. Ross posed an interesting question, still unsolved: Is there a sequence of (say) nine “ poison cards,” such that all games starting with those cards are lost?
The classic game Idle Year is also known by many other names, including Tower of Babel, Tower of London, Accordion, Methuselah, and Skip Two. Albert H. Morehead and Geoffrey Mott-Smith, in The Complete Book of Solitaire and Patience Games (1949), 61, suggested that moves shouldn’t be too greedy.
487. Every queen in a set of eight must attack at least 14 vacant cells. Thus | ∂S | gets its minimum value 8 × 14 = 112 when the queens occupy the top row. Solutions to the 8 queens problem, when queens are independent, all have | ∂S | ≤ 176. The maximum | ∂S | is 184, achieved symmetrically for example in Fig. A–11(a) . (This problem is not at all suitable for SAT solvers, because the graph has 728 edges. The best way to proceed is to run through all ( 64 8 ) possibilities with the revolving-door Gray code (Algorithm 7.2.1.3R), because incremental changes to | ∂S | are easy to compute when a queen is deleted or inserted. The total time by that method is only 601 gigamems.)
The maximum of | ∂ out S | is obviously 64 − 8 = 56. The minimum, which corresponds to Turton’s question, is 45; it can be achieved symmetrically as in Fig. A–11(b) , leaving 64 − 8 − 45 = 11 cells unattacked (shown as black queens). In this case SAT solvers win: The revolving-door method needs 953 gigamems, but SAT methods show the impossibility of 44 after only 2.2 G μ of work. With symmetry reduction as in the following exercise, this goes down to 900 M μ although there are 789 variables and 4234 clauses. [Bernd Schwarzkopf, in Die Schwalbe 76 (August 1982), 531, computed all solutions of minimum | ∂ out S |, given | S |, for n × n boards with n ≤ 8. Extensions of Turton’s problem to larger n have been surveyed by B. Lemaire and P. Vitushinskiy in two articles, written in 2011 and accessible from [www.ffjm.org](http://www.ffjm.org) . Optimum solutions for n > 16 are conjectured but not yet known.]
All sets S of eight queens trivially have | ∂ in S | = 8.
488. Let variables w ij and b ij represent the presence of white or black queens on cell ( i, j ), with clauses ( w ¯ i j ∨ b ¯ i ′ j ′ ) when ( i, j ) = ( i ′ , j ′ ) or ( i, j ) −−− ( i ′ , j ′ ). Also, if each army is to have at least r queens, add clauses based on (20) and (21) to ensure that ∑ w ij ≥ r and ∑ b ij ≥ r . Optionally, add clauses based on Theorem E to ensure that k of the w variables for the top row are lexicographically greater than or equal to the corresponding k variables in fifteen symmetrical variants. (For instance, if k = 3, we might require w 11 w 12 w 13 ≥ b 1 n b 2 n b 3 n , thus partially breaking the symmetries.)
Fig. A–11. Optimum queen placements of various kinds.
The maximum army sizes for 3 ≤ n ≤ 13 are known to be (1, 2, 4, 5, 7, 9, 12, 14, 17, 21, 24); see OEIS sequence A250000. An extra black queen can actually be included in the cases n = 3, 4, 6, 8, 10, 11, and 13. Solutions appear in Fig. A–11 ; the construction shown in Fig. A–11(d) generalizes to armies of 2 q ( q + 1) queens whenever n = 4 q + 1, while the one in part (c) belongs to another family of constructions that achieve the higher asymptotic density 7 48 n 2 .
When n = 8 and r = 9, Algorithm C typically finds a solution in about 10 megamems ( k = 0), or about 30 megamems ( k = 3); but with r = 10 it typically proves unsatisfiability in about 1800 M μ ( k = 0) or 850 M μ ( k = 3) or 550 M μ ( k = 4) or 600 M μ ( k = 5). Thus the symmetry breaking constraints are helpful for unsatisfiability in this case, but not for the easier satisfiability problem. On the other hand, the extra constraints do turn out to be helpful for both the satisfiable and unsatisfiable variants when n is larger. The “sweet spot” turns out to be k = 6 when n = 10 and n = 11; unsatisfiability was proved in those cases, with r = 15 and r = 18, after about 185 G μ and 3500 G μ , respectively. [B. M. Smith, K. E. Petrie, and I. P. Gent obtained similar results using CSP methods in LNCS 3011 (2004), 271–286.]
(This problem was posed by S. Ainley in his Mathematical Puzzles (1977), problem C1. He mentioned solutions for n ≤ 30 that have never yet been beaten, although he obtained them by hand. See also Martin Gardner, Math Horizons 7 , 2 (November 1999), 12–16, for generalizations to coexisting armies of sizes r and s . D. M. Kane has proved, among other things, that the maximum value of s , if r = 3 q 2 + 3 q + 1, is asymptotically n 2 − (6 q + 3) n + O (1) [arXiv:1703.04538 [math.CO] (2017), 19 pages].)
489. T 0 = 1, T 1 = 2, T n \= 2 T n −1 +(2 n − 2) T n −2 (see Eq. 5.1.4–(40)). The generating function ∑ n T n z n /n ! and the asymptotic value are given in exercise 5.1.4–31.
490. Yes. For example, using the signed permutation 4 ¯ 13 2 ¯ , we’re allowed to assume that some solution satisfies x ¯ 4 x 1 x 3 x ¯ 2 ≤ x ¯ 4 ′ x 1 ′ x 3 ′ x ¯ 2 ′ for every endomorphism — because the solution with lexicographically smallest x ¯ 4 x 1 x 3 x ¯ 2 has this property. Notice that the signed permutation 1 ¯ 2 ¯ ... n ¯ converts ‘≤’ to ‘≥’.
491. Let σ be the permutation (1234 1 ¯ 2 ¯ 3 ¯ 4 ¯ ). Then σ 4 = (1 1 ¯ )(2 2 ¯ )(3 3 ¯ )(4 4 ¯ ); and by Theorem E we need only search for solutions that satisfy x 1 x 2 x 3 x 4 ≤ x ¯ 1 x ¯ 2 x ¯ 3 x ¯ 4 . We’re therefore allowed to append the clause ( x ¯ 1 ) without affecting satisfiability.
(We actually are allowed to assert that x 1 = x 2 = x 4 = 0, because 0000 and 0010 are the lex-leaders of the two 8-cycles when σ is written as a permutation of states.)
In general if an automorphism σ is a permutation of literals having a cycle that contains both v and v ¯ , for some variable v , we can simplify the problem by assigning a fixed value to v and then by restricting consideration to automorphisms that don’t change v . (See the discussion of Sims tables in Section 7.2.1.2.)
492. Suppose x 1 ... x n satisfies all clauses of F ; we want to prove that ( x 1 . . . x n ) τ \= x 1 ′ . . . x n ′ also satisfies them all. And that’s easy: If ( l 1 ∨···∨ l k ) is a clause, we have l 1 ′ \= l 1 τ , . . . , l n ′ \= l n τ ; and we know that ( l 1 τ ∨···∨ l k τ ) is true because it’s subsumed by a clause of F . [See S. Szeider, Discrete Applied Math. 130 (2003), 351–365.]
493. Using the global ordering p 1 ...p 9 = 543219876 and Corollary E, we can add clauses to assert that x 5 = 0 and x 4 x 3 x 2 x 1 ≤ x 6 x 7 x 8 x 9 . A contradiction quickly follows, even if we stipulate only the weaker relation x 4 ≤ x 6 , because that forces x 6 = 1.
494. Exercise 475(d) shows that ( u v ) ( u ¯ v ¯ ) is a symmetry of the underlying Boolean function, although not necessarily of the clauses F . [This observation is due to Aloul, Ramani, Markov, and Sakallah in the cited paper.] The other symmetries allow us to assert (i) ( x ¯ i ∨ x j ) ∧ ( x ¯ j ∨ x ¯ k ) , (ii) ( x ¯ i ∨ x ¯ j ) ∧ ( x ¯ j ∨ x ¯ k ) , (iii) ( x ¯ i ∨ x ¯ j ) ∧ ( x ¯ j ∨ x k ) .
495. Suppose, for example, that m = 3 and n = 4. The variables can then be called 11, 12, 13, 14, 21, ... , 34; and we can give them the global ordering 11, 12, 21, 13, 22, 31, 14, 23, 32, 24, 33, 34. To assert that 21 22 23 24 ≤ 31 32 33 34, we use the involution that swaps rows 2 and 3; this involution is (21 31)(22 32)(23 33)(24 34) when expressed in form (192) with signs suppressed. Similarly we can assert that 12 22 13 ≤ 13 23 33 because of the involution (12 13)(22 23)(32 33) that swaps columns 2 and 3. The same argument works for any adjacent rows or columns. And we can replace ‘≤’ by ‘≥’, by complementing all variables.
For general m and n , consider any global ordering for which x ij precedes or equals x i j when 1 ≤ i ≤ i ′ ≤ m and 1 ≤ j ≤ j ′ ≤ n . The operation of swapping adjacent rows makes the global lexicographic order increase if and only if it makes the upper row increase lexicographically; and the same holds for columns. [See Anna Lubiw, SICOMP , 16 (1987), 854–879. The matrix entries needn’t be only 0s and 1s.]
496. No; that reasoning would “prove” that m pigeons cannot fit into m holes. The fallacy is that his orderings on rows and columns aren’t simultaneously consistent with a single global ordering, as in the previous exercise.
497. A BDD with 71,719 nodes makes it easy to calculate the total, 818,230,288,201, as well as the generating function 1 + z +3 z 2 +8 z 3 +25 z 4 + ··· + 21472125415 z 24 + 31108610146 z 25 + ··· + 10268721131 z 39 + 6152836518 z 40 + ··· + 24 z 60 + 8 z 61 + 3 z 62 + z 63 + z 64 . (The relatively small coefficients of z 39 and z 40 help account for the fact that ≥ was chosen in (185)–(186); problems with sparse solutions tend to favor ≥.)
[Pólya’s theorem in Section 7.2.3 shows that exactly 14,685,630,688 inequivalent matrices exist; compare this to 2 64 ≈ 1.8447 × 10 19 without any symmetry reduction.]
498. Consider the global ordering x 01 , x 11 , ... , x m 1 ; x 12 , x 22 , ... , x m 2 , x 02 ; x 23 , x 33 , ... , x m 3 , x 03 , x 13 ; ... ; x ( m −1) m , x mm , x 0 m , ... , x ( m −2) m . There’s a column symmetry that fixes all elements preceding x ( j −1) j and takes x ( j −1) j ↦ x ( j −1) k .
499. No. The unusual global ordering in answer 498 is not consistent with ordinary lexicographic row or column ordering. [Nor can the analogous clauses ( x i i ∨ x ¯ i j ) for 1 ≤ i ≤ m and i < j ≤ n be appended to (185) and (186). No quad-free matrix for m = n = 4 and r = 9 satisfies all those constraints simultaneously.]
500. If F 0 has a solution, then it has a solution for which l is true. But ( F 0 ∪ F 1 ) | l might be unsolvable. (For example, let F 0 \= ( x ¯ 1 ∨ x 2 ) ∧ ( x ¯ 2 ∨ x 1 ) , which has the symmetry 1 ¯ 2 ¯ ; so we can take S \= ( x ¯ 1 ) , l \= x ¯ 1 . Combine that with F 1 = ( x 1 ).)
501. Let x ij denote a queen in cell ( i, j ), for 1 ≤ i ≤ m and 1 ≤ j ≤ n . Also let r ij \= [ x i 1 + ··· + x ij ≥ 1] and r ′ ij = [ x i 1 + ··· + x i ( j +1) ≥ 2], for 1 ≤ i ≤ m and 1 ≤ j < n . Using (18) and (19) we can easily construct about 8 mn clauses that define the r ’s in terms of the x ’s and also ensure that x i 1 + ··· + x in ≤ 2. Thus r i ( n − 1 ) ′ \= [ x i 1 + ⋅ ⋅ ⋅ + x i n \= 2 ] ; call this condition r i .
Similar conditions c j , a d , and b d are readily established for column j , and for the diagonals with i + j = d + 1 or i − j = d − n , for 1 ≤ i ≤ m ,1 ≤ j ≤ n , and 1 ≤ d < m + n . Then condition (ii) corresponds to the mn clauses ( x ij ∨ r i ∨ c j ∨ a i + j −1 ∨ b i − j + n ).
Finally we have clauses from (20) and (21) to ensure that ∑ x ij ≤ r .
When m = n , the lower bound r ≥ n − [ n mod 4 = 3] has been established by A. S. Cooper, O. Pikhurko, J. R. Schmitt, and G. S. Warrington [ AMM 121 (2014), 213–221], who also used backtracking to show that r ≥ 12 on an 11 × 11 board. SAT methods, with symmetry breaking, yield that result much more quickly (after about 9 teramems of computation); but this problem, like the tomography problem of Fig. 79 , is best solved by integer programming techniques when m and n are large.
If we call the upper left corner white, solutions with m = n = r −1 and all queens on white squares appear to exist for all n > 2, and they are found almost instantly. However, no general pattern is apparent. In fact, when n is odd it appears possible to insist that the queens all appear in odd-numbered rows and in odd-numbered columns.
Here are examples of optimum placements on smallish boards. The solutions for 8 × 9, 8 × 10, 8 × 13, 10 × 10, and 12 × 12 also work for sizes 8 × 8, 9 × 10, 8 × 12, 9 × 9, and 11 × 11, respectively.
This placement of ten queens on a 10 × 10 board can be described by the “ magic sequence” ( a 1 ,..., a 5 ) = (1, 3, 7, 5, 9), because the queens appear in positions ( a i , a i +1 ) and ( a i +1 , a i ) for 1 ≤ i < n/ 2 as well as in ( a 1 , a 1 ) and ( a n/ 2 , a n/ 2 ). The magic sequences (1, 3, 9, 13, 15, 5, 11, 7, 17) and (9, 3, 1, 19, 5, 11, 15, 25, 7, 21, 23, 13, 17) likewise describe optimum placements for n = 18 and 26. No other magic sequences are known; none exist when n = 34.
502. For each j , construct independent cardinality constraints for the relation x 1 ( j ) + ⋅ ⋅ ⋅ + x n ( j ) ≤ r j , using say (20) and (21), where x k ( j ) \= ( s j k ? x ¯ k : x k ) .
503. The Hamming distance d ( x, y ) = ν ( x ⊕ y ) between binary vectors of length n satisfies d ( x , y ) + d ( x ¯ , y ) \= n . Thus there is no x with d ( x, s j ) ≥ r j + 1 for all j if and only if there is no x with d ( x ¯ , s j ) ≤ n − 1 − r j for all j . [See M. Karpovsky, IEEE Transactions IT-27 (1981), 462–472.]
504. (a) Assume that n ≥ 4. For strings of length 2 n we have d ( z , w ) + d ( z , w ¯ \= 2 n ) ; hence d ( z, w ) ≤ n and d ( z , w ¯ ) ≤ n if and only if d ( z , w ) \= d ( z , w ¯ ) \= n . Every string z with z 2 k −1 ≠ z 2 k for 1 ≤ k ≤ n satisfies d ( z, w j ) = n for 1 ≤ j ≤ n . Conversely, if d ( z, w j ) = d ( z, w k ) = n and 1 ≤ j < k ≤ n , then z 2 j −1 + z 2 j = z 2 k −1 + z 2 k . Thus if z 2 j −1 = z 2 j for some j we have z = 00 ... 0 or 11 ... 1, contradicting d ( z, w 1 ) = n .
(b) For each string x ^ \= x ¯ 1 x 1 x ¯ 2 x 2 . . . x ¯ n x n that satisfies part (a) we have d ( x ^ , y ) \= 2 l ¯ 1 + 2 l ¯ 2 + 2 l ¯ 3 + n − 3 , which is ≤ n + 1 if and only if ( l 1 ∨ l 2 ∨ l 3 ) is satisfied.
(c) Let s j \= w j and r j \= n for 1 ≤ j ≤ 2 n ; let s 2 n + k = y k and r 2 n + k = n +1 for 1 ≤ k ≤ m , where y k is the string in (b) for the k th clause of F . This system has a closest string x ^ \= x ¯ 1 x 1 x ¯ 2 x 2 . . . x ¯ n x n if and only if x 1 ... x n satisfies every clause. [A similar construction in which all strings have length 2 n + 1 and all r j are equal to n + 1 is obtained if we append the bit [ n < j ≤ 2 n ] to each s j . See M. Frances and A. Litman, Theory of Computing Systems 30 (1997), 113–119.]
(d) Boilerplate 11000000, 00110000, 00001100, 00000011, 00111111, 11001111, 11110011, 00000011, at distance ≤ 4; for the clauses, 01011000, 00010110, 01000101, 10010001, 10100100, 00101001, 10001010, and possibly 01100010, at distance ≤ 5.
505. (For k = 0, 1, ... , n − 1 one can set j to a uniform integer in [0.. k ] and INX [ k + 1] ← j ; also if j = k set VAR [ k ] ← k + 1, otherwise i ← VAR [ j ], VAR [ k ] ← i , INX [ i ] ← k , VAR[ j ] ← k + 1.) With nine random seeds, typical runtimes for D3 are (1241, 873, 206, 15, 748, 1641, 1079, 485, 3321) M μ . They’re much less variable for the unsatisfiable K0, namely (1327, 1349, 1334, 1330, 1349, 1322, 1336, 1330, 1317) M μ ; and even for the satisfiable W2: (172, 192, 171, 174, 194, 172, 172, 170, 171) M μ .
506. (a) Almost true: That sum is the total number of clauses of length ≥ 2, because every such clause of length k contributes 1 / ( k 2 ) to the weights of ( k 2 ) edges.
(b) Each of the 12 2 − 2 = 142 cells of the mutilated 12 × 12 board contributes one positive clause ( v 1 ∨···∨ v k ) and ( k 2 ) negative clauses ( v ¯ i ∨ v ¯ j ) , when that cell can be covered by k potential dominoes { v 1 ,..., v k }. So the weight between u and v is 2, 4/3, or 7/6 when dominoes u and v overlap in a cell that can be covered in 2, 3, or 4 ways. Exactly 6 cells can be covered in just 2 ways (and exactly 10 2 in 4 ways).
(The largest edge weights in all of Fig. 95 are 37/6, between 20 pairs of vertices in K6. At the other extreme, 95106 of the 213064 edges in X3 have the tiny weight 1/8646, and 200904 of them have weight at most twice that much.)
507. Consider, for example, the clauses ( u ∨ t ¯ ) , ( v ∨ t ¯ ) , ( u ¯ ∨ v ¯ ∨ t ) , ( u ∨ t ¯ ′ ) , ( v ∨ t ¯ ′ ) , ( u ¯ ∨ v ¯ ∨ t ′ ) from (24). Looking ahead from t = 1 yields the windfall ( t ¯ ∨ t ′ ) , and looking ahead from t ′ = 1 yields ( t ¯ ′ ∨ t ) . Henceforth Algorithm L knows that t equals t ′ .
508. According to (194), the purging parameters were Δ p = 1000 and δ p = 500; thus we have learned approximately 1000 k + 500 ( k 2 ) clauses when doing the k th purging phase. After 1000 L clauses this works out to be ≈ ( 16 L + 9 − 3 ) /2 phases, which is ≈ 34.5 when L = 323. (And the actual number was indeed 34.)
509. One remedy for overfitting is to select training examples at random. In this case such randomness is already inherent, because of the different seeds used while training.
510. (a) From Fig. 96 or Fig. 97 or Table 7 we know that T1 < T2 < L6 in the median rankings; thus T2 obscures L6 and T1.
(b) Similarly, L8 < M3 < Q2 < X6 < F2 < X4 < X5; X6 obscures L8 and X4.
(c) X7 obscures K0, K2, and (indirectly) A2, because K2 obscures K0 and A2.
511. (a) Nine random runs finished in only (4.9, 5.0, 5.1, 5.1, 5.2, 5.2, 5.3, 5.4, 5.5) M μ (!).
(b) Nine random runs now each were aborted after a teramem of trials. (No theoretical explanation for this discrepancy, or for the wildness of P4 in Fig. 97 , is known.)
(c) (0.2,..., 0.5,..., 3.2) M μ without; (0.3,..., 0.5,..., 0.7) M μ with.
512. A training run with ParamILS in 2015 suggested the parameters
α \= 0.7 , ρ \= 0.998 , ϱ \= 0.99995 , Δ p \= 100000 , δ p \= 2000 , τ \= 10 , w \= 1 , p \= 0 , P \= 0.05 , ψ \= 0.16667 , ( * )
which produce the excellent results in Fig. A–12 .
513. After training on rand (3, 1062, 250, 314159), ParamILS chose the values α = 3.5 and Θ = 20.0 in (195), together with distinctly different values that favor double lookahead, namely β = .9995, Y = 32. [The untuned values α = 3.3, β = .9985, Θ = 25.0, and Y = 8 had been used by the author when preparing exercise 173 .]
Fig. A–12. Running times for Algorithm C , with and without special parameter tuning.
514. ParamILS suggests p = .85 and N = 5000 n ; that gives a median time ≈ 690 M μ . (But those parameters give horrifically bad results on most other problems.)
515. Use variables S ijk meaning that cell ( i, j ) in the solution holds k , and Z ij meaning that cell ( i, j ) is blank in the puzzle. The 729 S variables are constrained by 4 × 81 × ( 1 + ( 9 2 ) ) \= 11 , 988 clauses like (13). From condition (i), we need only 41 variables Z ij . Condition (ii) calls for 15 clauses such as ( Z 11 ∨· · ·∨ Z 19 ), ( Z 11 ∨· · ·∨ Z 51 ∨ Z 49 ∨· · ·∨ Z 19 ), ( Z 15 ∨···∨ Z 55 ), ( Z 44 ∨ Z 45 ∨ Z 46 ∨ Z 54 ∨ Z 55 ), when equal Z ’s are identified via (i). Condition (iii), similarly, calls for 28 clauses such as ( Z ¯ 11 ∨ Z ¯ 12 ∨ Z ¯ 13 ) , ( Z ¯ 11 ∨ Z ¯ 21 ∨ Z ¯ 31 ) , ( Z ¯ 45 ∨ Z ¯ 55 ) . Condition (vi) is enforced by 34,992 clauses epitomized by ( S ¯ 111 ∨ Z ¯ 11 ∨ S ¯ 122 ∨ Z ¯ 12 ∨ S ¯ 412 ∨ Z ¯ 41 ∨ S ¯ 421 ∨ Z ¯ 42 ) .
For conditions (iv) and (v), we introduce auxiliary variables V ijk \= S ijk ∧ Z ¯ i j , meaning that k is visible in ( i, j ); R ik \= V i 1 k ∨ ··· ∨ V i 9 k , meaning that k is visible in row i ; C jk \= V 1 jk ∨··· ∨ V 9 jk , meaning that k is visible in column j . Also B bk \= ∨ 〈 i,j 〉= b V ijk , meaning that k is visible in box b ; here 〈 i, j 〉 = 1 + 3 ⌊( i − 1)/3⌋ + ⌊( j − 1)/3⌋. Then P ijk \= Z i j ∧ R ¯ i k ∧ C ¯ j k ∧ B ¯ 〈 i , j 〉 k means that k is a possible way to fill cell ( i, j ) without conflict. These 1701 auxiliary variables are defined with 8262 clauses.
Condition (iv) is enforced by nine 9-ary clauses for each i and j , stating that we mustn’t have exactly one of { P ij 1 ,..., P ij 9 } true. Condition (v) is similar, enforced by three sets of 81 × 9 clauses of length 9; for example, one of those clauses is
( P 417 ∨ P 427 ∨ P 437 ∨ P 517 ∨ P ¯ 527 ∨ P 537 ∨ P 617 ∨ P 627 ∨ P 637 ) .
(“We aren’t obviously forced to put 7 into box 4 by using cell (5, 2).”)
Finally, some of the symmetry is usefully broken by asserting the unary clauses ( S 1 k k ) ∧ ( Z ¯ 11 ) ∧ ( Z 12 ) . Altogether there are 2,471 variables, 58,212 clauses, 351,432 cells.
(This problem was suggested by Daniel Kroening. There are zillions of solutions, and about one in every five or six appears to be completable uniquely to the setting of the S variables. Thus we can obtain as many “hard sudoku” puzzles as we like, by adding additional unary clauses such as ( S 553 ) ∧ ( Z ¯ 17 ) more-or-less at random, then weeding out ambiguous cases via dancing links. The clauses are readily handled by Algorithms L or C , but they’re often too difficult for Algorithm D . That algorithm did, however, find the uniquely completable solution (a) below after only 9.3 G μ of work.)
If we beef up condition (iii), insisting now that no box contains a row or column with more than one blank, condition (vi) becomes superfluous. We get solutions such as (b) below, remarkable for having no forced moves in spite of 58 visible clues, yet uniquely completable. That puzzle is, however, quite easy; only 2, 4, 7 are unplaced.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(a) | (b) | (c) | (d) |
We might also try to strengthen conditions (iv) and (v) by requiring at least three ways to make each choice, not just two. Then we get solutions like (c) above. Unfortunately, however, that one is completable in 1237 ways! Even if we also strengthen condition (iii) as in (b), we get solutions like (d), which can be completed in 12 ways. No uniquely completable sudoku puzzles are known to have such ubiquitous threefold ambiguity.
516. This conjecture can be expressed in several equivalent forms. R. Impagliazzo and R. Paturi [ J. Comp. Syst. Sci. 62 (2001), 367–375] defined s k \= inf{ lg τ | we can know an algorithm to solve k SAT in τ n steps}, and stated the exponential time hypothesis : s 3 > 0. They also defined s ∞ = lim k →∞ s k , and proved that s k ≤ (1 − d/k ) s ∞ for some positive constant d . They conjectured that s ∞ = 1; this is the strong exponential time hypothesis . An alternative formulation [C. Calabro, R. Impagliazzo, and R. Paturi, IEEE Conf. on Comput. Complexity 21 (2006), 252–260] was found later: “If τ < 2, there is a constant α such that no knowable randomized algorithm can solve every SAT problem with ≤ αn clauses in fewer than τ n steps, where n is the number of variables.”
517. (a) (Solution by Günter Rote.) Replace the j th ternary clause ( l j ∨ l j ′ ∨ l j ′ ′ ) by three ternary equations l j + a j + c j \= 1, l ¯ j ′ + a j + b j \= 1 , l ¯ j ′ ′ + c j + d j \= 1 , where a j , b j , c j , and d j are new variables.
(b) Remove equations of length > 3 by using the fact that l 1 + ··· + l k \= 1 if and only if l 1 + ··· + l j + t = 1 and l j + 1 + ⋅ ⋅ ⋅ + l k + t ¯ \= 1 , where t is a new variable. Also, if a , b , c , and d are new variables with a + b + d \= a + c + d ¯ \= 1 , beef up short equations using l + l ′ = 1 ⇔ l + l ′ + a = 1 and l \= 1 ⇔ l ¯ + b + c \= 1 .
[Thomas J. Schaefer proved the NP-completeness of 1-in-3 SAT as a special case of considerably more general results, in STOC 10 (1978), 216–226.]
518. (a) A \= ( x y y y x y y y x ) , where x \= − 1 0 1 0 , y \= 1 1 − 1 1 .
(b) Twice in the n variable rows and n variable columns; once in the 3 m output rows and 3 m input columns; never in the 3 m input rows and 3 m output columns.
(c) By (a), each way to choose 2s in different rows and columns contributes zero to the permanent unless, in every clause, the subset of chosen inputs is nonempty and matches the chosen outputs. In the latter case it contributes 16 m 2 n . [See A. Ben-Dor and S. Halevi, Israel Symp. Theory of Computing Systems 2 (IEEE, 1993), 108–117.]
519. The unsatisfiable problem corresponding to D1 and D2 has median running time 2099 M μ (losing to both factor_fifo and factor_lifo ). The satisfiable one corresponding to D3 and D4 is unstable (as in Fig. 97 ), with median 903 M μ (winning over both).
520. (Solution by Sven Mallach, 2015, using solvers X and Y, where X was CPLEX 12.6 and Y was GUROBI 6, both used with emphasis on mixed-integer-program feasibility, constant objective function, and solution limit 1.) With a time cutoff of 30 minutes on a single-threaded Xeon computer, neither X nor Y could solve any of the 46 problems A1, A2, C1, C2, C3, C4, C5, C6, C8, D1, D2, E1, E2, F1, F2, G1, G2, G5, G6, G7, G8, K7, K8, M5, M7, M8, O1, O2, P0, P1, P2, Q7, S3, S4, T5, T6, T7, T8, W2, W4, X1, X3, X5, X6, X7, X8. (In particular, this list includes P0, S4, and X1, which are extremely easy for Algorithm C .) On the other hand both X and Y solved the langford problems L3 and L4 — which were the toughest for Algorithm C — in less than a second.
Algorithm C performs about 20 G μ per minute on a comparable Xeon. In these experiments it significantly outperformed the geometric methods except on problems K0, K1, K2, L3, L4, and P4 (and some easy cases such as B2).
Of course we must keep in mind that the particular clauses in Table 6 aren’t necessarily the best ways to solve the corresponding combinatorial problems with an IP solver, just as they aren’t necessarily the best encodings for a SAT solver. We are comparing here only black-box clause-solving speeds.
521. A variety of simple schemes have been surveyed by S. Jabbour, J. Lonlac, L. Saïs, and Y. Salhi, Int. J. Artificial Intelligence Tools 27 ,8 (2018), 1850033:1–19.
522. For cycles of length T we can introduce 27 T variables xyz t for 1 ≤ x, y, z ≤ 3 and 0 ≤ t < T , signifying that vertex ( x, y, z ) occupies slot t in the path. Binary exclusion clauses ¬ x y z t ∨ ¬ x ′ y ′ z t ′ ′ , when xyz = x ′ y ′ z ′ and t ≠ t ′ or when xyz ≠ x ′ y ′ z ′ and t = t ′ , ensure that no vertex appears twice in the path, and that no two vertices occupy the same slot. A valid path is specified via the adjacency clauses
¬ x y z t ∨ ∨ { x ′ y ′ z ( t + 1 ) mod T ′ | 1 ≤ x ′ , y ′ , z ′ ≤ 3 and | x ′ − x | + | y ′ − y | + | z ′ − z | \= 1 } .
We represent the shadows by introducing 36 variables a ! b ∗, ba !∗, a !∗ b , b ∗ a !, ∗ a ! b , ∗ ba ! for 1 ≤ a ≤ 2 and 1 ≤ b ≤ 3; here a !∗ b (for example) means that the shadow of ( x, z ) coordinates has a transition between ( a, b ) and ( a +1, b ). These variables appear in ternary clauses such as (¬ xyz t ∨¬( x +1) yz t ∨ x !∗ z ) ∧ (¬ xyz t′ ∨ ¬( x +1) yz t′ ∨ x ! y ∗) whenever x < 3 and t ′ ≡ t ± 1 (modulo T ). To exclude loops we append clauses like
¬1!1∗ ∨ ¬2!1∗ ∨ ¬31!∗ ∨ ¬32!∗ ∨ ¬2!3∗ ∨ ¬22!∗ ∨ ¬1!2∗ ∨ ¬11!∗;
this one excludes the loop in the example illustration. There are 39 such loop-defeating clauses, one for each of the 13 simple cycles in each shadow.
Finally we can break symmetry by asserting the unary clauses 121 T −1 , 111 0 , 112 1 without loss of generality, after verifying that no solution can avoid all eight corners.
Clearly T must be an even number, because the graph is bipartite; also T < 27. If the method of exercise 12 is used for the exclusions, we obtain a total of 6264 clauses, 822 variables, and 17439 cells when T = 16; there are 9456 clauses, 1242 variables, and 26199 cells when T = 24. These clauses are too difficult for Algorithm D . But Algorithm L resolves them almost instantaneously for any given T ; they turn out to be satisfiable if and only if T = 24, and in that case there are two essentially different solutions. One of these cycles, due to John Rickard (who introduced this problem at Cambridge University, circa 1990), is beautifully symmetric, and it is illustrated on the cover of Peter Winkler’s book Mathematical Mind-Benders (2007). It can be represented by the delta sequence (322 3 ¯ 133 1 ¯ 2 ¯ 112 3 ¯ 2 ¯ 2 ¯ 3 1 ¯ 3 ¯ 12 1 ¯ 1 ¯ 2 ¯ ), where ‘ k ’ and ‘ k ¯ ’ change coordinate k by +1 or −1. The other is unsymmetric and represented by (3321 2 ¯ 1 3 ¯ 1 ¯ 221 2 ¯ 323 1 ¯ 1 ¯ 3 ¯ 1 2 ¯ 1 ¯ 3 ¯ 2 ¯ ).
523. (Solution by Peter Winkler.) With coordinates ( x, y, z ) for 1 ≤ x ≤ m , 1 ≤ y ≤ n , 1 ≤ z ≤ 2, any cycle with loopless shadows must contain at least two steps ( x, y, 1) −−− ( x, y, 2) and ( x ′ , y ′ , 1) −−− ( x ′ , y ′ , 2). We can assume that x < x ′ and that x ′ − x is minimum. The m × 2 shadow contains ( x, 1) −−− ( x, 2) and ( x ′ , 1) −−− ( x ′ , 2), together with (say) the path ( x, 1) −−−· · ·−−− ( x ′ , 1), but without the edge ( x ″ , 2) −−− ( x ″ +1, 2) for some x ″ with x ≤ x ″ < x ′ . The unique shortest path from ( x, y ) to ( x ′ , y ′ ) in the m × n shadow contains some edge ( x ″ , y ″ ) −−− ( x ″ +1, y ″ ); hence ( x ″ , y ″ , 1) −−− ( x ″ +1, y ″ , 1) must occur twice in the cycle.
524. This problem involves clauses very much like those for a cyclic path, but simpler; we have T = 27 and no “wrap-around” conditions. With typically 1413 variables, 10410 clauses, and 28701 cells, Algorithm L shines again, needing only a gigamem or two to handle each of several cases that break symmetry based on starting and ending points. There are four essentially different solutions, each of which can be assumed to start at 111; one ends at 333, another at 133, another at 113, and the other at 223. Using the delta sequence notation above, they are: 332 3 ¯ 2331 3 ¯ 2 ¯ 33 2 ¯ 3 ¯ 1332 3 ¯ 233 (which is reflected ternary code); 31 3 ¯ 133 1 ¯ 1 ¯ 211 3 ¯ 1 ¯ 3 1 ¯ 3 ¯ 231 3 ¯ 133 1 ¯ 1 ¯ ; 32 3 ¯ 231 3 ¯ 2 ¯ 3 2 ¯ 3 ¯ 132 3 ¯ 233 2 ¯ 2 ¯ 1 ¯ 22 1 ¯ 2 ¯ 2 ¯ ; 1122 1 ¯ 1 ¯ 2 ¯ 13 1 ¯ 211 2 ¯ 2 ¯ 1 ¯ 1 ¯ 31122 1 ¯ 1 ¯ 2 ¯ 1.
[Such paths, and more generally spanning trees that have loopless shadows, were invented in 1983 by Oskar van Deventer, who called them “ hollow mazes”; see The Mathemagician and Pied Puzzler (1999), 213–218. His Mysterians puzzle is based on an amazing Hamiltonian path on P 5 □ P 5 □ P 5 that has loopless shadows.]
525. The author’s best solution, as of July 2015, had 100 variables, 400 clauses, and 1200 literals (cells); it was derived from Tseytin’s examples of exercise 245 , applied to a more-or-less random 4-regular graph of girth 6 on 50 vertices. Tseytin’s construction, with one odd vertex and 49 even ones, yields 400 clauses of 4SAT, which are quite challenging indeed. It can be simplified to a 3SAT problem by insisting further that every even vertex must have degree exactly 2 in the subgraph specified by true edges. (See K. Markström, J. Satisfiability, Boolean Modeling and Comp. 2 (2006), 221–227).
That simplified problem still turned out to be fairly challenging: It was proved unsatisfiable by Algorithm L in 3.3 T μ and by Algorithm C in 1.9 T μ . (But by applying the endomorphisms of exercise 473 , which broke symmetry by adding 142 clauses of length 6, the running time went down to just 263 M μ and 949 M μ , respectively.)
Another class of small-yet-difficult problems is worth mentioning, although it doesn’t fit the specifications of this exercise [see I. Spence, ACM J. Experimental Algorithmics 20 (2015), 1.4:1–1.4:14]: Every instance of 3D matching whose representation as an exact cover problem has 3 n items and 5 n options, with five options for each item and three items in each option, can be represented as a SAT problem in 3 n variables, 10 n binary clauses, and 2 n quinary clauses, hence only 30 n total literals. This 5SAT problem has the same number of literals as the 3SAT problem discussed above, when n = 40; yet it is considerably more difficult if the matching problem is unsatisfiable. (The problem of this kind that defeated all the SAT solvers in the 2014 competition corresponds to an instance of 3D matching that is solved almost instantaneously by the dancing links method: Algorithm 7.2.2.1X needs fewer than 60 M μ to prove it unsatisfiable. On the other hand, if we encode that 3D matching problem with 3 n quinary at-least-one and 3 n · 10 binary at-most-one clauses, as in (13), instead of using only 2 n for at-least-one and n · 10 for at-most-one, Algorithm L will be almost as good as dancing links.)
526. We prove by induction on | F | that it’s possible to leave at most w ( F ) clauses unsatisfied, where w ( F ) = ∑ C ∉ F 2 −|C| : If all clauses of the multiset F are empty we have w ( F ) = | F |, and the result holds. Otherwise suppose the variable x appears in F . Let l = x if w ( { C | x ∈ C ∈ F } ) ≥ w ( { C | x ¯ ∈ C ∈ F } ) ; otherwise l \= x ¯ . A simple calculation shows that w ( F | l ) ≤ w ( F ). [ J. Computer and System Sciences 9 (1974), 256–278, Theorem 3.]