How to use exponential generating functions to count the number of k-letter permutations from n letters? I was learning about exponential generating functions and stumbled upon the following question and answer :
Sample question

Given the string of letters ABBBBBBBBBBBBBBBBBCDEFGHIJKLMOPQRSTUVWXYZ (that's 17 Bs and the other 25 letters of the alphabet), how many distinct ways are there to pick a string of 12 letters from it? Assume that order (so AB is different from BA) and letter (so the letters A and B are able to be told apart from each other) is the only distinguishing factor (i.e. two Bs are the same as each other).
Source : How many distinct 12-letter "words" are able to be formed from the string of letters "ABBBBBBBBBBBBBBBBBCDEFGHIJKLMOPQRSTUVWXYZ"?

Sample answer

$f(x) = e^x (1+x)^{25}$
Answer =${12!}\times [x^{12}]f(x)$
Source : https://math.stackexchange.com/a/3880665/996485

I tried to use the same technique on another similar question :

Suppose you have the world "BUBBLES" where you are allowed to mix the letters as you want. Each different permutation of letters counts as a distinct word if it cannot be recognized as a previous word already counted. Words do not necessarily have to match up with standard English words either, so "words" like "SULBEBB" or "BSLBEBU" are acceptable. How many four-letter permutations can be formed from the word "BUBBLES"?
Source : How many ways are there to organize the letters in the word BUBBLES into a 4-letter permutation?

My attempt
EGF for B's: $e^x$
EGF for U's : 1+x
EGF for L's : 1+x
EGF for E's : 1+x
EGF for S's : 1+x
$g(x)=(1+x+\frac{x^2}{2}+\frac{x^3}{3!}+...)(1+x)^4$
$7! \times [x^7]g(x)=7! \times 1/6=840$
$[x^7]g(x)$ was found from Wolfram
However, the correct answer seems to be $208.$ Why did my exponential generating function give the wrong answer here?
 A: Instead of $\color{red}{7}![x^{\color{red}7}]$, it should be $\color{blue}{4}![x^{\color{blue}4}]$, since you are enumerating $\color{blue}{\text{four}}$-letter sequences. However, you will find that
$$
4![x^4](1+x)^4e^x=209
$$
which is much closer, but still incorrect, so what went wrong? The problem now is the $e^x$ factor. This factor represents the choice of the number of B's in the word. The full series $e^x=1x^0+1x^1/1!+1x^2/2!+\dots$ would imply that you are counting words with any number of B's, but there are only three B's available in BUBBLE. This makes it apparent that the $209$ number is counting the single extra permutation "BBBB", so subtracting this out gives the correct count. Another way to fix this would be to instead find
$$
4![x^4](1+x)^4\color{blue}{\left(1+x^1+\frac{x^2}{2}+\frac{x^3}{6}\right)}=208
$$
where the egf $1+x^1+\frac{x^2}{2}+\frac{x^3}{6}$ represents that it is valid to select either zero, one, two, or three B's, but no more.
Note that for the first problem you discussed, with 17 B's and one of each other letter, you could have also used
$$
12![x^{12}](1+x)^{25}\left(1+x^1+\frac{x^2}{2!}+\dots+\frac{x^{17}}{17!}\right)
$$
to find the answer. The reason it was valid to use $e^x$ for the B's was that we were counting 12-letter words, so allowing for an unlimited number of B's did not affect the count. But if $12$ were replaced with a number which was greater than $17$, then you would not be able to use the $e^x$ shortcut.
A: We have
EGF of U, L, E, S: $1+x$
EGF of B's: $e^x-\frac{x^4}{4!}$
We get
$G\left ( x \right )=\left ( 1+x \right )^4\left ( e^{x}-\frac{x^4}{4!} \right )$
The desired number is the coefficient of $\frac{x^4}{4!}$ term in expansion of $G(x)$:
$\left [ \frac{x^4}{4!} \right ]G\left ( x \right )=\left [ \frac{x^4}{4!} \right ]\left ( 1+x \right )^4e^x-1=\left [ \frac{x^4}{4!} \right ]\left ( 1+4x+6x^2+4x^3+x^4 \right )e^x-1=1+4\cdot4+6\cdot12+4\cdot4!+4!-1=\boxed {208}$
A: Another way ( Thanks to fungarwai, my admired hero):
We have
$\sum_{{0\le u,e,l,s\le 1\atop 0\le b\le 3 }\atop b+u+e+l+s=4} \binom{4}{b,u,e,l,s}=
4!\sum_ {{0\le u,e,l,s\le 1\atop 0\le b\le 3 }\atop b+u+e+l+s=4}\binom{1}{b,u,e,l,s}
=4!\sum_ {{0\le u,e,l,s\le 1\atop b= 3 }\atop b+u+e+l+s=4}\frac{4}{b!}+4!\sum_ {{0\le u,e,l,s\le 1\atop b=2 }\atop b+u+e+l+s=4}\frac{6}{b!}+4!\sum_ {{0\le u,e,l,s\le 1\atop b=1 }\atop b+u+e+l+s=4}\frac{4}{b!}+4!\sum_ {{0\le u,e,l,s\le 1\atop b=0 }\atop b+u+e+l+s=4}\frac{1}{b!}=4!\frac{4}{3!}+4!\frac{6}{2!}+4!\frac{4}{1!}+4!\frac {1}{0!}=4!\left (\frac{4}{6}+ \frac{6}{2}+4+1 \right )=\boxed {208}$
