a) Show that the generating function by length for binary strings where every block of 0s has length at least 2, each block of ones has length at least 3 is:
$$\frac{(1-x+x^3)(1-x+x^2)}{1-2x+x^2-x^5}$$
b) Give a recurrence relation and enough initial conditions to determine coefficients of power series.
So for a), I came up with the block decomposition $((0^*00)^*(1^*111)^*)^*$ and found the generating function, using the fact that $0\leadsto x$, $1\leadsto x$, and $a^*\leadsto\frac{1}{1-a}$ where a is some binary string:
$$\frac{(1-x)^2}{(1-x-x^2)(1-x-x^3)}$$
which, clearly, does not equal the expected result. Could someone clear up for me where I went wrong?
Also, for b), how would you find a recurrence relation, since the degree of the numerator and denominator are the same, so there would be no general $a_n$ term.
Thanks in advance for any help!
Generating Function
We can piece together the generating function as follows $$ \overbrace{\vphantom{\left(\frac{x^2}1\right)}\ \ \frac1{1-x}\ \ }^{\substack{\text{any number}\\\text{of ones}}}\overbrace{\vphantom{\left(\frac{x^2}1\right)}\frac1{1-\underbrace{\quad\frac{x^2}{1-x}\quad}_{\substack{\text{two or more}\\\text{zeros}}}\underbrace{\quad\frac{x}{1-x}\quad}_{\substack{\text{one or more}\\\text{ones}}}}}^{\substack{\text{any number of blocks of zeros}\\\text{and ones}}}\overbrace{\left(1+\frac{x^2}{1-x}\right)}^{\substack{\text{zero or two or}\\\text{more zeros}}} $$ The block decomposition is $1^\ast\left(000^\ast11^\ast\right)^\ast\left(()+000^\ast\right)$
Thus, the generating function is $$ \bbox[5px,border:2px solid #C0A000]{\frac{1-x+x^2}{1-2x+x^2-x^3}} $$
Recurrence Relation
Note that $$ \begin{align} &1-x+x^2\\ &=\left(1-2x+x^2-x^3\right)\sum_{k=0}^\infty a_kx^k\\ &=\overbrace{\vphantom{()}\quad\ a_0\quad\ }^1+\overbrace{(a_1-2a_0)}^{-1}\,x+\overbrace{(a_2-2a_1+a_0)}^1\,x^2+\sum_{k=3}^\infty\overbrace{(a_k-2a_{k-1}+a_{k-2}-a_{k-3})}^0\,x^k \end{align} $$ Therefore, the recurrence relation is determined by the denominator: $a_0=1$, $a_1=1$, and $a_2=2$, then for $n\ge3$, use $$ \bbox[5px,border:2px solid #C0A000]{a_n=2a_{n-1}-a_{n-2}+a_{n-3}} $$