2827898

https://math.stackexchange.com/questions/2827898/recurrence-for-number-of-words-of-length-r-over-n-with-no-three-consecutiv/

$$S(X) = X + tX^3 \cdot Lin(tX + tX^2)$$

$$ Lin ( \ (S(X_1) + S(X_2) + \dots + S(X_n) \ ) $$

Using the Soup and Croutons diagram - an explanation of the GJ theory

This automaton produces strings with multiplicities. However, the multiplicities will be recorded in the generating function. For example, the cluster 11111 is generated with multiplicity 8 but will be exactly recorded as $$1 + 3t +3t^2 + t^3$$ in the "at least" generating function.

1. 1 1 1 1 1 has no t

2. 111 1 1 - at least one bad 111 (in first position)

3. 1 111 1 - at least one bad 111 (in the second position)

4. 1 1 111 - at least one bad 111 (in the third position)

5. 111 1 1 - at least two bad 111's (in first and second positions)

6. 111 11 - at least two bad 111's (in first and third positions)

7. 1 111 1 - at least two bad 111's (in second and third positions)

8. 111 1 1 - all three bad 111's

$$C_k = k^3t + (k + k^2)tC_k$$ hence each $$C_k$$ has the generating function

$$ \frac {s^3t} {1 - st - s^2t}$$

By diagram we have $$S = 1 + nsS + nCS$$ so the generating function for S is

$$ \frac 1 { 1 - ns - n \frac {s^3t} {1 - st - s^2t} }$$

By Goulden-Jackson PIE, we have $$Exact(t) = AtLeast(t-1)$$ and we are interested in $$Exact(0)$$ so we take $$t = -1$$ in previous and we obtain the expected - previously presented - result.