1

Given two multisets $A$ and $B$, is it possible to map all of the elements of these two multisets into two integer (for example, integer $A_1$ will represent the elements of multiset $A$, and integer $B_1$ will represent the elements of multiset $B$), in a way that allows for the number of intersections of multiset $A$ and $B$ to be found using only the integers $A_1$ and $B_1$?

For example, if multiset $A = \{1,2,3,4,5\}$ and multiset $B = \{7, 1, 2, 6, 7, 8\}$, then these two multisets should be able to be mapped to two integers that represent the data in these two multisets ($A_1$ and $B_1$), such that the number of intersections of these two multisets should be able to be computed using only the integers $A_1$ and $B_1$ (without using the underlying data). The number of intersections of the multisets $A$ and $B$ in this case is 2.

Asaf Karagila
  • 393,674
  • There are always ways; if nothing else, one can imagine an algorithm that effectively takes the integer $A_1$, maps it back to $A$, and computes the answer the 'hard way'. Since there are plenty of ways to map finite sets of numbers in 1:1 fashion onto numbers, this answers the question directly. Do you have specific computations in mind? – Steven Stadnicki Feb 18 '22 at 21:53

2 Answers2

1

I think a precise phrasing of the question is:

Is there a function $f\colon \scr P(\mathbb Z)\to \mathbb Z$ such that for all $A, A', B, B'\in \scr P(\mathbb Z),$ if $f(A) = f(A')$ and $f(B) = f(B'),$ then $|A \cap B | = |A' \cap B'|?$

The answer to this is "No."

If $f$ were such a function, then it would be injective, because for any $A, A'\in\scr P(\mathbb Z):$

$$ \begin{align} f(A) = f(A') &\implies (\forall x\in\mathbb Z)\,\big(\,|A \cap \{x\} | = |A' \cap \{x\}|\,\big)\\ &\implies A=A', \end{align}$$

where you can see that the first implication is true by taking $B = B' = \{x\}$ in the property that $f$ is required to have.

But there is no injective function from $\mathscr P(\mathbb Z)$ to $\mathbb Z,$ by Cantor's theorem.


Note that if you replace $\mathscr P(\mathbb Z)$ with the set $S$ of all finite subsets of $\mathbb Z,$ then the answer is positive (as @StevenStadnicki pointed out in a comment): $S$ and $\mathbb Z$ have the same cardinality, so you can just let $f$ be any injective function from $S$ to $\mathbb Z.$

Mitchell Spector
  • 9,917
  • 3
  • 16
  • 34
1

If we assume the sets to be finite, this can be done by mapping a set to the product of primes corresponding to the elements, i.e the element $j\in A$ corresponds to the $j$th prime $p_j$. By the fundamental theorem of arithmetic, from the product $\prod_{j\in A} p_j$ we see which primes are present and can recover the set $A$.

Now as you have two (finite) sets, just recover them both and you can recover the intersection.

For infinite sets this doesn't work, of course. And nothing does, as proved in the earlier answer.

BTW: are you talking about multisets because you have $7$ appearing twice in $B$? Well, this method still works because the multiplicities of primes are also accounted for in the prime factorization.

EDIT: To allow integers, leave every other prime for the sign (its presence marks negativity for example. And for zero take the first prime. Or even better zero to two and then onwards 3 to 1, 5 to -1 and so on...

ploosu2
  • 8,707
  • Since the OP referred to integers, you'd really need to take into account $0$ and negative numbers. That's why in my answer I just said to take any injective function from the set of all finite subsets of $\mathbb Z$ to $\mathbb Z$ -- any such function will work; it doesn't matter which one you use. – Mitchell Spector Feb 19 '22 at 07:14
  • 1
    @MitchellSpector Yes, thanks. I edited. Any function works but it is great to have it (easily) computable. – ploosu2 Feb 19 '22 at 07:53
  • Agreed -- there's something to be said for having a specific example. (There's also a benefit to having a general solution.) – Mitchell Spector Feb 19 '22 at 07:55