How many words exist, such that the total number of each letter has a given parity?
Let $N := \{1,\dots,n\}$. I regard the set $N^r$, that is, the set of all words of length $r$ with the "letters" $1$, $\dots$, $n$.
Then I choose a subset of $A \subseteq \{1,\dots,n\}$ and regard the set $T_A$, which is defined as follows:
$T_A$ consists of all words $i = (i_1,\dots,i_r) \in N^r$, such that:
- for all $a \in A$, the letter $a$ occurs an odd number of times (that is, $\# \{k : i_k = a\}$ is odd).
- for all $a \in \{1,\dots,n\}\backslash A$, the letter $a$ occurs an even number of times.
(That is, the subset $A$ specifies which letters in a word occur in total with an odd parity.)
Is there any formula $F$, depending on $r$, $n$, and $\#A$, which gives the cardinality $\# T_A$ ?
I got a recursive formula for $F$ which leads to a difference equation in two variables (which I couldn't solve up to now with the usual methods for solving difference equations).
Since the problem is simple to explain, I hope that it remainds on a related problem which is solved yet. It would be great if someone takes delight in it, or, at most, has an idea :-) Thanks a lot for your time.
A little example:
Let $n = 2$, $r = 3$ and $A = \{1\}$.
Question: In how many $3$-tuples appears the entry $1$ odd times?
Answer: In $4$, since \begin{align*} T_A &= \{i \in N^r : 1 \text{ appears $1$ or $3$ times in $i$}\}\\ &= \{(1,2,2),(2,1,2),(2,2,1),(1,1,1)\}. \end{align*}
Though I haven't figured out a compact solution yet, I do have a thought on how to make the recursive solution more approachable (Dynamic Programming), so I want to share it with you.
First of all, we need a 3-dimension matrix, let's call it M, and the three of its inputs dimensions are: number of even letters #EVEN, number of odd letters #ODD, and total number of letters r. Its output is the number of words that have #EVEN even letters, #ODD odd letters, and r total letters.
let denote it M[#ODD, #EVEN, r]
I will give you the base cases as examples. It is easy to tell that when we have 1 odd letter, 0 even letter, and 1, 3, 5 ... total letter, the number of combinations for words is #A (all we need to do is to select one odd letter out of #A letters). Similarly, when we have 0 odd letter, 1 even letter, and 2, 4, 6 ... total letter, the number of combination for words is n - #A (select one even letter out of n - #A).
Notations are:
M[1, 0, 1] = #A . M[1, 0, 3] = #A .
...
M[0, 1, 2] = n - #A . M[0, 1, 4] = n - #A .
...
Now, we update the matrix in this manner: each time we only increment one odd number or one even number based on the previous results. Say if we want to calculate M[a, b, r], then M[a, b, r] = $$M[a - 1, b, r - 1] \cdot \binom{r}{1} + M[a - 1, b, r - 3] \cdot \binom{r}{3} + ... + M[a, b - 1, r - 2] \cdot \binom{r}{2} + M[a, b - 1, r - 4] \cdot \binom{r}{4} + ...$$
To make a brief explanation, suppose from the previous step, we have r - k letters for the word, and now we want to add a single letter that occur k times, then all we need to do is to find k places (from the target word with a total of r places) to insert the letter.
Also, notice that there are a few infeasible places. For instance, for an arbitrary set of a, b, r, where a + 2b > r or a and r are not both even or odd, then it is impossible to find a word with length r while having a odd letters and b even letters, in this case, fill in the matrix M[a, b, r] = 0.
You can keep updating this matrix until you have all information you need for a word of length r, then you will just sum up the matrix values with third dimension equals to r: $$\#T = \Sigma_{a, b}{M[a, b, r]}$$
I am not good at combinatoric's formulae, so I can't get the exact solution. If you can code this up in a programming language, you can eventually get this problem solved. Hopefully my answer can give you an idea on how to proceed.