Question: Find a generating function for a binary string where each block of ones must have an odd length and the string cannot contain the substring 0001.
My approach:
First, a general block decomposition for all binary strings is $(0^*(0^*01^*1)^*1^*)$. I modified this to $0^*(0^*01(11)^*)^*(1(11)^*\cup\epsilon)$ to account for the fact that the 1 blocks must be odd.
Now, to not include 0001, I know that you can use the recursive method wherein you define two sets, call them A and B, where A is the set of all strings not containing 0001 and B is the set of all strings ending in 0001.
Then, we have that $A\cup B = \epsilon \cup A(0\cup 1)$ so $A(x) + B(x) = 1 + 2xA(x)$. Similarly, $B = A0001$ so $B(x) = x^4A(x)$ so I get the relation $$A(x) = \frac{1}{1-2x+x^4}$$ but I'm not sure how to factor in the fact that the 1 block must have odd length.
Any help solving this problem would be appreciated. Thanks!
We start with looking for a regular expression and the corresponding generating function of a somewhat simpler problem, namely considering block lengths of $1$ having length one only.
(Simpler) problem: Find a generating function for a binary string where each block of $1$s has length one and the string cannot contain the substring $0001$.
A regular expression generating strings for this problem is \begin{align*} (\varepsilon|1)(01|001)^{\ast}0^{\ast}\tag{1} \end{align*} In (1) we specify the strings which
start with the empty string or a $1$, followed by
zero or more occurrences of $01$ or $001$ this way guaranteeing that no pattern $0001$ can occur and ending with
zero or more occurrences of $0$.
The corresponding generating function of (1) is \begin{align*} (1+z)&(1+(z^2+z^3)+(z^2+z^3)^2+\cdots)(1+z+z^2+\cdots)\\ &=(1+z)\cdot\frac{1}{1-(z^2+z^3)}\cdot\frac{1}{1-z}\tag{2}\\ &=\frac{1}{1-z^2-z^3} \end{align*}
The expansion (4) was done with some help of WolframAlpha. We see the coefficient of $z^6$ is $25$ and the corresponding valid strings of are \begin{align*} 000000\qquad010000\qquad011100\qquad100101\qquad101110\\ 001000\qquad010010\qquad011101\qquad100111\qquad111000\\ 001001\qquad010100\qquad011111\qquad101000\qquad111001\\ 001010\qquad010101\qquad100000\qquad101001\qquad111010\\ 001110\qquad010111\qquad100100\qquad101010\qquad111110\\ \end{align*}