Soup and Croutons

## 2827898

https://math.stackexchange.com/questions/2827898

Recurrence for Number of Words of Length over with no three consecutive letters the same

S
(
X
# )
X
t

X

3

⋅
L
i
n
(
t
X
t

X

2

)

{\displaystyle S(X)=X+tX^{3}\cdot Lin(tX+tX^{2})}

L
i
n
(

(
S
(

X

1

)
S
(

X

2

)
⋯
S
(

X

n

)

)

{\displaystyle 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
3
t
3

t

2

t

3

{\displaystyle 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

3

t
(
k

k

2

)
t

C

k

{\displaystyle C\_{k}=k^{3}t+(k+k^{2})tC\_{k}}

 hence each

C

k

{\displaystyle C\_{k}}

 has the generating function

s

3

t

1
−
s
t
−

s

2

t

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

By diagram we have

# S
1
n
s
S
n
C
S

{\displaystyle S=1+nsS+nCS}

 so the generating function for S is

1

1
−
n
s
−
n

s

3

t

1
−
s
t
−

s

2

t

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

By Goulden-Jackson PIE, we have

E
x
a
c
t
(
t
# )
A
t
L
e
a
s
t
(
t
−
1
)

{\displaystyle Exact(t)=AtLeast(t-1)}

 and we are interested in

E
x
a
c
t
(
0
)

{\displaystyle Exact(0)}

 so we take

# t
−
1

{\displaystyle t=-1}

 in previous and we obtain the expected - previously presented - result.

## 295695

https://math.stackexchange.com/questions/295695

Counting strings containing specified appearances of words

L
i
n
(
X
Y
C
(
X
,
Y
)
)

{\displaystyle Lin(X+Y+C(X,Y))}

# C
t
Y
X
Y
⋅
L
i
n
(
t
X
Y
)
)

{\displaystyle C=tYXY\cdot Lin(tXY))}

I have studied for a while the Goulden-Jackson method and I find it kind of bully.

Imagine there is a soup S and here comes a guy throwing a potato 101 in the soup. "Fellows, there is \*at least\* one potato in the soup !" says, then he throws another potato in the soup. "Fellows, there are \*at least\* two potatoes in the soup" ! Then he applies the inclusion-exclusion principle

N
(
t
# )
E
(
t
1
)

{\displaystyle N(t)=E(t+1)}

 and he gets the \*exact\* potatoes amount there were in the soup.

The generating functions for the language of the above automaton is given by solving.

Here, the power of

x

{\displaystyle x}

 counts the length of a word and the power of

t

{\displaystyle t}

 the number of added 101's

The "at least" generating function is

N
(
x
,
t
# )
S
(
x
,
t
# )

1
−
t

x

2

1
−
2
x
−

x

2

t

x

3

t

{\displaystyle N(x,t)=S(x,t)={1-tx^{2} \over 1-2x-x^{2}t+x^{3}t}}

The "exact" generating function is

E
(
x
,
t
# )
N
(
x
,
t
−
1
# )

1

x

2

−
t

x

2

1
−
2
x

x

2

−

x

3

−

x

2

t
−

x

3

t

{\displaystyle E(x,t)=N(x,t-1)={1+x^{2}-tx^{2} \over 1-2x+x^{2}-x^{3}-x^{2}t-x^{3}t}}

1

1
−
2
x
−

x

3

(
y
−
1
)

1
−

x

2

(
y
−
1
)

{\displaystyle {\frac {1}{1-2x-{\frac {x^{3}(y-1)}{1-x^{2}(y-1)}}}}}

## 2818572

https://math.stackexchange.com/questions/2818572

For example, given a bit string of length 6, how many are there that contain 110 as a substring, and how many that contain 101 ?

L
i
n
(
X
Y
−
Y
Y
X
)

{\displaystyle Lin(X+Y-YYX)}

Check the article here : https://oeis.org/A005251 in OEIS.
The mentioned recurrence formula is : a(n) = a(n-1) + a(n-2) + a(n-4) and it may be obtained by taking into account four kind of sequences:

A
n

{\displaystyle A\_n}

 : good sequences of length n that finish in 00

B
n

{\displaystyle B\_n}

 : good sequences of length n that finish in 01

C
n

{\displaystyle C\_n}

 : good sequences of length n that finish in 10

D
n

{\displaystyle D\_n }

 : good sequences of length n that finish in 11

and see what happens if we add one digit.

their sum

E

n
1

{\displaystyle E\_{n+1}}

 would be expressed  :

E

n
1

=

A

n
1

B

n
1

C

n
1

D

n
1

=
(

A

n

B

n

C

n

D

n

)

A

n
−
1

B

n
−
1

D

n
−
1

=
.
.
.
.
.
.
# .

E

n

E

n
−
1

E

n
−
3

{\displaystyle E\_{n+1}=A\_{n+1}+B\_{n+1}+C\_{n+1}+D\_{n+1}=(A\_{n}+B\_{n}+C\_{n}+D\_{n})+A\_{n-1}+B\_{n-1}+D\_{n-1}=.......=E\_{n}+E\_{n-1}+E\_{n-3}}

where the first four E's are 4, 7, 12, 21 for n = 2, 3, 4, 5 and they have to be obtained by hand.

Again, given the work around strings in the last days, there is a simple method to obtain a GF for the strings avoiding 110.

Suppose that we generate strings in the language

# L
(
1
0
110

)

∗

{\displaystyle L=(1+0+110)^{\*}}

. There are two ways of obtaining the bad 110 in the process of building strings.

$\alpha = \ $ the hard way, by adding 0's and 1' to some previous string

$\beta = \ $ the short way, by adding directly a 110 to some previous string

for example, a string that contains two occurrences of 110 (there are no overlappings)

$w = ....110...110...$ may be obtained in four ways, depending on what method was used to derive each 110.

We have a multiplicity of 4 for $w$.

If we use a $-$ sign in the expression $(x+y-xxy)$ , the coefficient of the algebraic sum that describes the multiplicity of w changes from $4$ to $0$, because $1-1-1+1=0$. The four cases are $\alpha\alpha,\alpha\beta, \beta\alpha,\beta\beta $ where $\alpha\alpha$ means that the two $110's$ of $w$ were obtained the hard way.

So happens for other strings with multiplicities of 8, 16, 32...

It remains to write the GF

1
(
x
y
−
x
x
y
)
(
x
y
−
x
x
y

)

2

.
.
# .

1

1
−
x
−
y
x
x
y

{\displaystyle 1+(x+y-xxy)+(x+y-xxy)^{2}+...={\frac {1}{1-x-y+xxy}}}

We have obtained https://oeis.org/A000071, the Fibonacci numbers - 1 in OEIS.

## 3297032

https://math.stackexchange.com/questions/3297032

Probability of drawing a sequence of balls with at least consecutive red balls

{

# S
1
S
X
S
Y
X

# T
S
Y

{\displaystyle {\begin{cases}S=1+SX+SYX\\T=SY\end{cases}}}

The generating function for binary (red-blue or 0-1) n-sequences that do not contain k-substrings of 1' is

$$ 1-y^k \over 1-x-y-xy^k $$

[![two factories][1]][1]

```
 [1]: https://i.stack.imgur.com/7mVk2.jpg

```

By using "factory diagrams" to generate sequences that do not contain k-strings of 1's, we get for $k=2$ (left diagram)

```
 $ S= 1 + Sx + Syx $ for sequences that do not contain 11's and end in 0, then $T = Sy$ for sequences that end in $1$. Hence the $S+T$ generating function.

```

Generaly (right diagram), $ S= 1 + Sx + Syx + Sy^2x +...+ Sy^{k-1}x $ and
$T= S(y + y^2 +...+ y^{k-1})$