Return a cross product of two sets A and B such that only one entry is returned based on a condition

30 Views Asked by At

Lets say I have a set $A={\text{'Akshat'},\text{'John'},\text{'Mike'}}$ and a set $B={\text{'Modi'},\text{'Kerry'}}$. Set $A$ represents a set of voters while $B$ represents a set of candidates for an election. I want to return a set $A\text XB$ such that the matching is done only for the element in $B$ for which an element in $A$ votes for. For example, if $\text{'Akshat'}$ votes for $\text{'Modi'}$, $\text{'John'}$ votes for $\text{'Kerry'}$ and $\text{'Mike'}$ for $\text{'Kerry'}$, my $A\text XB$ should be $\{(\text{'Akshat'},\text{'Modi'}),(\text{'John'},\text{'Kerry'}),(\text{'Mike'},\text{'Kerry'})\}$.That is, all elements of $A$ are matched to $B$ but not all elements of $B$ are associated with $A$. How will I write a mathematical representation of such a set $A\text XB$? Also, if I want to find out the number of people who voted for $\text{'Kerry'}$, how would I write that in a mathematical representation?

1

There are 1 best solutions below

0
On BEST ANSWER

The correct mathematical name for what you have is a function $f:A \to B$ such that $f(\text{'Akshat'}) = \text{'Modi'}$, and so on. In other words, the function $f$ assigns, to each voter, the person they voted for.

Set theoretically, such a function is usually represented as the set $\{(\text{'Akshat'},\text{'Modi'}),(\text{'John'},\text{'Kerry'}),(\text{'Mike'},\text{'Kerry'})\}$ of ordered pairs, just as you've described, but unless you're going to do some really low-level reasoning, that's not too important.

The set of people voting for $\text{'Kerry'}$ is usually written using the notation $f^{-1}$ (called "$f$ inverse", which is not really a function from $B$ to $A$, but a function that takes a subset of $B$ and returns a subset of $A$), like so: $f^{-1}(\{\text{'Kerry'}\}) = \{\text{'John'}, \text{'Mike'}\}$. If you want the number of people voting for $\text{'Kerry'}$, then you just find the size of that set: $|f^{-1}(\{\text{'Kerry'}\})| = 2$.