A setX of numbers is calledsum-freeif the sum of two elements of X never belongs toX. For instance, the set{5, . . . ,9}is sum-free; the set {4, . . . ,9} is not (4 + 4 = 8, 4 + 5 = 9). Can we partition the set{1, . . . , n} into two sum-free subsets? This is possible ifn= 4: both{1,4} and{2,3} are sum-free. But ifn= 5 then such a partition does not exist. Exercise 3.4. Prove this claim.
What about partitioning {1, . . . , n} into three sum-free subsets? This can be done for values ofnthat are much larger than 4. For instance, ifn= 9 then we can take the subsets
3.3. SCHUR NUMBERS 39
Listing 3.4: Exotic pets puzzle, Part 1 1 % E x o t i c p e t s puzzle , P a r t 1
2
3 f i r s t _ n a m e ( a b n e r ; b r u c e ; c h u c k ; d u a n e ).
4 l a s t _ n a m e ( e n g e l s ; f o s t e r ; g u n t e r ; h a l e v y ).
5 pet ( i g u a n a ; j a c k a l ; k i n g _ c o b r a ; l l a m a ).
6 % a c h i e v e d : f i r s t _ n a m e /1 , l a s t _ n a m e /1 , pet /1 are the s e t s
7 % of f i r s t names , l a s t names , and pet s p e c i e s .
8
9 { f u l l _ n a m e ( F , L ) : l a s t _ n a m e ( L )} = 1 : - f i r s t _ n a m e ( F ).
10 { o w n s ( F , P ) : pet ( P )} = 1 : - f i r s t _ n a m e ( F ).
11 % a c h i e v e d : a u n i q u e l a s t n a m e and u n i q u e pet s p e c i e s are
12 % c h o s e n for e a c h f i r s t n a m e .
13
14 F1 = F2 : - f u l l _ n a m e ( F1 , L ) , f u l l _ n a m e ( F2 , L ).
15 F1 = F2 : - o w n s ( F1 , P ) , o w n s ( F2 , P ).
16 % a c h i e v e d : the c h o s e n n a m e s and p e t s are p a i r w i s e d i s t i n c t .
17 18 : - f u l l _ n a m e ( abner , e n g e l s ). 19 : - f u l l _ n a m e ( abner , f o s t e r ). 20 % a c h i e v e d : Abner ’ s l a s t n a m e is n e i t h e r E n g e l s nor F o s t e r . 21 22 : - o w n s ( chuck , i g u a n a ). 23 : - o w n s ( duane , i g u a n a ). 24 % a c h i e v e d : i g u a n a b e l o n g s n e i t h e r to C h u c k nor to D u a n e . 25 26 : - f u l l _ n a m e ( X , f o s t e r ) , o w n s ( X , j a c k a l ). 27 : - f u l l _ n a m e ( X , f o s t e r ) , o w n s ( X , k i n g _ c o b r a ). 28 % a c h i e v e d : Mr . F o s t e r o w n s n e i t h e r j a c k a l nor k i n g c o b r a . 29 30 : - o w n s ( duane , l l a m a ).
31 % a c h i e v e d : Duane ’ s pet is not l l a m a .
32
33 : - f u l l _ n a m e ( duane , e n g e l s ).
34 % a c h i e v e d : Duane ’ s l a s t n a m e is not E n g e l s .
35
36 : - o w n s ( abner , k i n g _ c o b r a ).
37 % a c h i e v e d : Abner ’ s pet is not k i n g c o b r a .
38
39 : - f u l l _ n a m e ( abner , g u n t e r ).
Listing 3.5: Exotic pets puzzle, Part 2 1 % E x o t i c p e t s puzzle , P a r t 2 2 3 : - f u l l _ n a m e ( bruce , f o s t e r ). 4 % a c h i e v e d : Bruce ’ s l a s t n a m e is not F o s t e r . 5 6 : - f u l l _ n a m e ( X , h a l e v y ) , o w n s ( X , i g u a n a ).
7 % a c h i e v e d : Mr . Halevy ’ s pet is not i g u a n a .
8
9 a n s w e r ( X , Y ) : - f u l l _ n a m e ( X , Y ) , o w n s ( X , j a c k a l ).
10
11 # s h o w a n s w e r /2.
Listing 3.6: Schur numbers 1 % P a r t i t i o n {1 ,.. , n } i n t o r sum - f r e e s u b s e t s . 2 3 % i n p u t : p o s i t i v e i n t e g e r s n , r . 4 5 % in ( I , K ) m e a n s t h a t I b e l o n g s to the K - th s u b s e t . 6 7 { in ( I , 1 . . r )} = 1 : - I = 1.. n . 8 % a c h i e v e d : set {1 ,... , n } is p a r t i t i o n e d i n t o r s u b s e t s . 9 10 : - in ( I , K ) , in ( J , K ) , in ( I + J , K ).
11 % a c h i e v e d : the s u b s e t s are sum - f r e e .
Exercise 3.5. Partition {1, . . . ,10} into three sum-free subsets.
The clingo program shown in Listing 3.6 solves the general problem of partitioning
{1, . . . , n} into r sum-free subsets (possibly empty) whenever this is possible. The largest value ofn for which such a partition exists is traditionally denoted byS(r). For instance,
S(2) = 4, and by solving Exercise 3.5 you proved that S(3)≥ 10. The numbers S(r) are calledSchur numbers. We can say that by running this program we estimate Schur numbers.
Exercise 3.6. How many models do you think this program has forr = 2 and n= 4? Exercise 3.7. What is the number of stable models of the rule in Line 7?
Exercise 3.8. About a set X of numbers we say that it is almost sum-free if the sum of twodifferent elements of X never belongs to X. For instance, the set {1,2,4} is almost