Find the correspondence between natural numbers and subsets with the inclusion-exclusion principle

165 Views Asked by At

Quoting Wikipedia:

the inclusion–exclusion principle is a counting technique which generalizes the familiar method of obtaining the number of elements in the union of two finite sets.

Wikipedia provides the following example:

How many integers in {1,...,100} are not divisible by 2, 3 or 5?

With the solution being 26 (= 100 − (50 + 33 + 20) + (16 + 10 + 6) - 3)

Is it possible to find a correspondence (bijection) between natural numbers $\mathbb{N}$ and the result obtained with the inclusion-exclusion principle (with the assumption that the elements in the set can be ordered)?

For the example above the bijection would look something like:

0 -> 1
1 -> 7
2 -> 11
3 -> 13
4 -> 17
5 -> 19
6 -> 23
7 -> 29
...
23 -> 89
24 -> 91
25 -> 97

Does a general technique exist that allows to determine the position in the natural numbers $\mathbb{N}$ of a valid element without having to iterate through all of them and vice-versa? Can the inclusion-exclusion principle be used for purposes other than counting?

Even if not strictly correlated, the bijection of the combinatorial number system comes to mind.

Update: Starting from the actual value, it is easy to find the correspondence to the natural numbers $\mathbb{N}$. In the example above, to find the position of $n$, we just need use the inclusion-exclusion principle with $n-1$ as upper end. For example for $n = 29$, the position in $\mathbb{N}$ is given counting the integers {1,...,28} are not divisible by 2, 3 or 5.

The opposite direction is unclear to me. How is it possible for example starting with 7, getting back 29?

1

There are 1 best solutions below

0
On

Generating functions are one method to attack this problem. You can do complements by simply negating and disjoint unions by simply adding. Divisibility is also straightforward (substituting $x^p$ for $x$). Extracting a function back from a generating function can be a little complex (literally) by using roots of unity. We'll simplify things by using only divisors 2 and 3 and leave the messier 2,3,5 for WolframAlpha.

  • $\frac{1}{1-x}$ is the gf for $\langle 1,1,1,1,1...\rangle$.
  • $\frac{1}{1-x^2}$ is the gf for $\langle 1,0,1,0,1...\rangle$ or the indicator function for even numbers.
  • $\frac{1}{1-x^3}$ is the gf for $\langle 1,0,0,1,0,0,1...\rangle$ or the indicator function for numbers divisible by 3.
  • $\frac{1}{1-x} - \frac{1}{1-x^3} - \frac{1}{1-x^3} + \frac{1}{1-x^6}$ is the gf for $\langle 0,1,0,0,0,1,0,1,0,0,0,1,0...\rangle$ or the indicator function for numbers not divisible by 2 or 3 (by inclusion-exclusion).

Notice this has a cycle of 6

The indexes with 1 are the sought numbers. They also cycle but with a period of 2. Reading off those indices gives $$\langle 1,5,7,11,13,17,19...\rangle$$ made up of two patterns

  • $\langle 1,5,1,5,1,5,1...\rangle$, and
  • $\langle 0,0,6,6,12,12,18...\rangle$

The first has gf $\frac{1+5x}{1-x^2}$ and the second $6 \frac{1}{1-x}\frac{1}{1-x^2}$ or

$$\frac{1+5x}{1-x^2} + 6 x^2 \frac{1}{1-x}\frac{1}{1-x^2}$$

which through a little partial sums and collecting in a readable form is

$$ \frac{3}{(1-x)^2} - \frac{1}{2}\left(\frac{3}{1-x} + \frac{1}{1+x}\right)$$

Extracting the coefficients from each piece, this is

$$f(n) = 3n + \frac{1}{2}(3 - (-1)^n)$$.


Three overlapping IE items is only a little bit more complex IE-wise, but a lot more complex extracting the function from the generating function.

For your sequence $< 1,7,11,13,17,19,23,29,...>$, the cycle length is 8.

$$\frac{1 + 7x + 11x^2 + 13x^3 + 17x^4 + 19x^5 + 23x^6 + 29x^7}{1-x^8} + 30 x^8 \frac{1}{1-x}\frac{1}{1-x^8}$$.

To get $f(n)$ for this you'd need the eighth roots of unity and solve a system of eight equations (a Vandermonde matrix) to get the coefficients, which is a bit unwieldy for humans. And this is where I (very reasonably I think) punt to Wolfram Alpha.

It simplifies the above very nicely to

$$ \frac{30}{8(1-x)^2} - \frac{1}{8(1+x)} - \frac{15}{8(1-x)} - \frac{1+x}{4(1+x^2)} - \frac{1 - 3x - 3x^2 + x^2}{2(1+x^4)}$$

You can almost read off the function from this gf:

$$f(n) = \frac{30}{8} n - \frac{1}{8} (-1)^n - \frac{15}{8} - \frac{1}{8} (1 + i)((-i)^n - i^(n+1)) - \rm{a\ big\ mess\ dealing\ with\ } \frac{1+i}{2}$$


This method is not necessarily generalizable to arbitrary IE situations, but is doable with gfs that are rational functions or otherwise have extractible functions.

Also, this particular solution is very ad hoc - it mixes both IE and divisibility just to get the cyclic pattern which was found purely by inspection. And I left out all the computational details of extracting the roots from the gf to get the function sought after.