0

Find the number of functions $f:\{a_1,a_2...a_n\} \to \{b_1,b_2,...b_m\}$ where $n>m>3$ such that $f(a_i) \neq f(a_{i+1}), \forall i=1,2,3...(n-1)$ and $f(a_n) \neq f(a_1)$.

Attempt:

It is simple to count the number of functions satisfying the first inequality; we can map $a_1$ to any of the $m$ elements in the codomain. Accordingly, since $f(a_2) \neq f(a_1)$, $a_2$ can be mapped to any of the $(m-1)$ remaining elements. Similarly, extending this argument, $a_3,a_4,a_5...a_n$ can all be mapped to $(m-1)$ elements.

Hence, the number of functions is $m(m-1)^{n-1}$.

Now, I will obtain my desired answer if I can count all the cases where $f(a_n)=f(a_1)$ and subtract that from the above quantity. Suppose $a_1$ and $a_n$ are simultaneously mapped to the same $b_k$. This can happen in $m$ ways. Accordingly, $a_2$ can be mapped to any of the $(m-1)$ remaining elements. The above reasoning can be applied again until $a_{n-1}$ which only has $(m-2)$ possible elements to be mapped to since it cannot equal $f(a_{n})$ which has already been chosen. Hence, the number of functions will be $m(m-1)^{n-2}(m-2)$.

Accordingly, the number of functions where $f(a_n) \neq f(a_1)$ is $m(m-1)^{n-1}-m(m-1)^{n-2}(m-2)=m(m-1)^{n-2}$

However, the reported answer is $(m-1)^n+(-1)^n(m-1)$. I think I made a mistake in counting the functions where $f(a_n)=f(a_1)$ but I'm unable to find it. Can anyone point out the error and help me remedy it?

In the brief solution at the back of the book, they use a recursion $\eta(n,m)=m(m-1)^{n-1} -\eta(n-1,m)$ to count the number of functions but there's no explanation for why and I don't understand how to arrive at this recursion.

Cognoscenti
  • 965
  • 4
  • 16

2 Answers2

1

Let condition (A) be $f(a_i)\neq f(a_{i+1})$ without any wrapping, and condition (B) be $f(a_n)\neq f(a_1)$. The functions satisfying condition (A) and (B) can be looped cyclically into a loop of length $n$, but the functions satisfying condition (A) but not condition (B) can be looped cyclically into a loop of length $n-1$ after deleting $a_n$, because necessarily we have $f(a_{n-1})\neq f(a_1)$. On the other hand, if we have something loopable with $n-1$ terms, then there is a unique way to extend it to $n$ terms with $f(a_n)=f(a_1)$. This yields a bijection between the functions satisfying (A) but not (B) and the functions satisfying (A) and (B) but with only $n-1$ terms. So $\eta(n,m)=m(m-1)^{n-1}-\eta(n-1,m)$

For ease of notation, let $f_n=\eta(n,m)$. If we rearrange this recurrence, then $f_n+f_{n-1}=m(m-1)^{n-1}$, and $f_n=(f_n+f_{n-1})-(f_{n-1}+f_{n-2})+(f_{n-2}+f_{n-3})-\ldots \pm (f_2+f_1)\mp f_1.$ This lets us write $f_n$ in terms of a geometric sequence.

Aaron
  • 25,637
  • The intuition behind making loops reminds me of a different problem on counting functions https://math.stackexchange.com/questions/4883061/summing-a-binomial-series-that-arose-while-counting-functions except you do it with inequalities – Cognoscenti Apr 28 '24 at 10:51
0

In your solution, you missed the case when $f(a_{n-2})=f(a_1)$, as in that case $f(a_{n-1})$ has $m-1$ choices. As for the recursion,

Define $\eta(n,m)$ to be the number of such functions. Then, the number of functions satisfying $f(a_i)\neq f(a_{i+1})$ is $m(m-1)^{n-1}$ as you said. Any such function either has

  • $f(a_1)\neq f(a_n)$, and there are $\eta(n,m)$ many such functions.
  • $f(a_1)=f(a_n)$, in which case we can look at $f$ as a map from $\{a_1,\dots,a_{n-1}\}$ instead, satisfying $f(a_i)\neq f(a_{i-1})$ and $f(a_{n-1})\neq f(a_n)=f(a_1)$. There are $\eta(n-1,m)$ such functions.

Therefore, $$\eta(n,m)+\eta(n-1,m)=m(m-1)^{n-1}$$ and then it is straightforward.

Hope this helps. :)