I wrote a code in Mathematica that returns the number of families (collections) of subsets of $\{1,2,...,n\}$ whose union is not the whole set. The code can only return values for $n = 1,2,3,4$. The respective values are $2,6,40, 1376$. These are the first four terms of Sloane's A051185 which counts the number of intersecting families. Is this a coincidence or is there some reason why these two counts are equal?
4 Answers
A051185 is the number of (pairwise-) intersecting families. Two subsets of $\{1,\ldots, n\}$ intersect iff the union of their complements is not $\{1,\ldots,n\}$. But you want not just the pairwise unions but the union of
all sets in your family to not be the whole set. So you should get a different result for $n=3$: the family $\{\{1,2\}, \{1,3\}, \{2,3\}\}$ is pairwise intersecting, so it should be included in A051185, but its complements $\{\{3\},\{2\},\{1\}\}$ should not be included in your count.
In fact, I get $38$, not $40$, for $n=3$ and $942$, not $1376$, for $n=4$.

- 448,999
-
Yes, thank you. You are quite right. My code was counting only the families with no PAIRS of subsets having a union equal to the whole set. In other words, the families in which every pair was missing something. So by complementation it was counting the number of intersecting families, A051185. I agree now with 2,6,38,942,... for the number of families whose union is the whole set. Thanks again – Geoffrey Critzer Dec 18 '16 at 21:02
If I understand correctly what you're trying to count, your code is wrong. I think the sequence you're after is this one: https://oeis.org/A005530

- 76,357
-
Yes thank you! You are correct that my code was wrong. I agree (at least for the first four terms as I don't understand anything written in the entry ) with A005530. – Geoffrey Critzer Dec 18 '16 at 21:08
The problem is equivalent to count the number of covers of a finite set.
It is mentioned at the beginning of the paper Minimal Covers of Finite Sets by Hearne and Wagner that the number is given as the following (where "$n=1$" should be a typo):
Alternatively, the number of possible covers for a set of $N$ elements are
$$ C(N)=\frac{1}{2}\sum_{k=0}^N(-1)^k\binom{N}{k}2^{2^{N-k}}, $$ the first few of which are $1, 5, 109, 32297,\cdots$ (OEIS A003465: Number of ways to cover an n-set. ).
-
Yes thank you. I agree. I see now that the equation above counts the covers using the principle of inclusion exclusion. Here I want to include the empty set in the families (covers). So I will ignore the factor of 1/2 in the equation to find A000371. Then the number of families whose union does not equal the whole set is 2^2^n - A000371 = A005530 as stated above by Alex Kruckman. – Geoffrey Critzer Dec 18 '16 at 22:36
Here is an approach using the Polya Enumeration Theorem (PET) using the same technique as at this MSE link.
We start with the complementary problem counting families that cover all of $[n].$ We get the following generating function for these subsets:
$$\prod_{q=1}^n (1+A_q).$$
Selecting a subset from these of size $k$ is done with the unlabeled set operator $\mathfrak{P}:$
$$Z(P_k)\left(\prod_{q=1}^n (1+A_q)\right).$$
This operator has OGF
$$Z(P_k) = [w^k] \exp\left(\sum_{d\ge 1} (-1)^{d+1} a_d \frac{w^d}{d}\right)$$
The substitution into the cycle index uses
$$a_d = \prod_{q=1}^n (1+A_q^d).$$
We use inclusion-exclusion to compute the terms where not all $A_q$ a present. These are obtained by first subtracting those where a single $A_q$ or more are not present, i.e. by setting that $A_q$ to zero. Then we add in those where a pair of two $A_q$ or more are not present, again by setting these $A_q$ to zero and so on. The remaing $A_q$ are set to one. Hence if $p$ or more of the $A_q$ were not present the substitution becomes
$$a_d = 2^{n-p}.$$
We thus obtain for the substituted cycle index
$$[w^k] \exp\left(\sum_{d\ge 1} (-1)^{d+1} 2^{n-p} \frac{w^d}{d}\right) \\ = [w^k] \exp\left(2^{n-p} \sum_{d\ge 1} (-1)^{d+1} \frac{w^d}{d}\right) \\ = [w^k] \exp\left(2^{n-p} \log(1+w) \right) = [w^k] (1+w)^{2^{n-p}} = {2^{n-p}\choose k}.$$
This means we have by inclusion-exclusion for the problem of the set being covered
$$\sum_{p=0}^n {n\choose p} (-1)^p {2^{n-p}\choose k}.$$
Summing over all possible $k$ (can be anywhere from zero to $2^n$) we finally obtain
$$\sum_{p=0}^n {n\choose p} (-1)^p \sum_{k=0}^{2^n} {2^{n-p}\choose k} = \sum_{p=0}^n {n\choose p} (-1)^p 2^{2^{n-p}}.$$
This yields for the original problem whose answer is being sought
$$\bbox[5px,border:2px solid #00A000]{ 2^{2^n} - \sum_{p=0}^n {n\choose p} (-1)^p 2^{2^{n-p}}.}$$
which is the sequence OEIS A005530
$$2, 6, 38, 942, 325262, 25768825638, \\ 129127208425774833206, \ldots$$
as observed in a companion post.
The Maple code for this (which will compute the first four values) was like this (shown here to clarify what interpretation of the problem is being used):
with(combinat); ENUM := proc(n) option remember; local set, res, covered; res := 0; for set in powerset(powerset(n)) do covered := `union`(op(set)); if nops(covered) < n then res := res + 1; fi; od; res; end; X := n-> 2^(2^n) -add(binomial(n,p)*(-1)^p*2^(2^(n-p)), p=0..n);
Addendum. Some thought produces the following simple Perl script which adhereres to first principles (problem definition), yet is capable of computing the first five values of the sequence in less than three seconds, which appears to be the natural boundary of what is possible. We solve the complementary problem as above.
#! /usr/bin/perl -w # sub recurse { my ($src, $seen, $pos, $n, $cref) = @_; my $chk; for($chk = 0; $chk < $n; $chk++){ last if $seen->[$chk] == 0; } if($chk == $n){ $$cref += 1 << ((1<<$n)-$pos); return; } return if $pos >= (1 << $n); recurse($src, $seen, $pos+1, $n, $cref); foreach my $el (@{ $src->[$pos] }){ $seen->[$el]++; } recurse($src, $seen, $pos+1, $n, $cref); foreach my $el (@{ $src->[$pos] }){ $seen->[$el]--; } 1; } MAIN : { my $n = shift || 4; my $srcset = []; for(my $idx = 2**$n-1; $idx >= 0; $idx--){ my @data; for(my ($bitpos, $idx2) = (0, $idx); $bitpos < $n; $bitpos++){ my $bit = $idx2 % 2; push @data, $bitpos if $bit == 1; $idx2 = ($idx2-$bit)/2; } push @$srcset, \@data; } my (@vis) = (0) x $n; my $result = 0; recurse($srcset, \@vis, 0, $n, \$result); $result = 2**(2**$n) - $result; print "$result\n"; 1; }

- 61,317
http://www.win.tue.nl/~aeb/preprints/linked.pdf
under proposition 1.1.
My final guess is that it only returns values for $n=1,2,3,4$ because these are the only classes where your constraint is satisfied, so your code is probably equivalent to Sloane's integer sequence. I would say it's a coincidence in that you were not explicitly aware of this equivalence, but not a coincidence in that the equivalence probably exists between your algorithm and Sloane's.
– Dec 18 '16 at 20:13