String Factories

How many binary strings of length n exist with k 10's or 01's

{

# A
x
A
t
x
B
x

# B
x
B
t
x
A
x

{\displaystyle
\begin{cases}
 A = xA + txB + x\\
 B = xB + txA + x
 \end{cases}
 }

Let A be binary strings that ends with 0 and B that ends with 1. x is a counter variable for the length of an accepted word, while t will count the transitions. Then:

# A
x
A
t
x
B
x

{\displaystyle A = xA + txB + x}

# B
x
B
t
x
A
x

{\displaystyle B = xB + txA + x}

 and

A
# B

2
x

1
−
x
−
t
x

=
2
x
2

x
2

(
1
t
)
2

x
3

(
1
t

)
2

.
.
.

{\displaystyle A+B = {2x \over 1-x-tx} = 2x + 2x^2(1+t) + 2x^3(1+t)^2 +...}

The required number for length n and k changes is the coefficient of

x
n

t
k

{\displaystyle x^nt^k}

.

For example, if n = 4 and k = 2 we have six good words: 0100, 0110, 0010, 1011, 1001, and 1101.

## 2940875

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

Find a recursive definition of this sequence

{

# A
t
(
1
C
D
)
,

# B
t
B

t
3

(
1
C
D
)
,

# C
t
(
1
A
B
)
,

# D
t
D

t
4

(
1
A
B
)
,

{\displaystyle \begin{cases}
A = t(1 + C + D), \\
B = tB + t^3(1 + C + D),\\
C = t(1 + A + B),\\
D = tD +t^4(1 + A + B),
\end{cases}
}

Here is a rewriting of above work using automaton and generating functions. The associated grammars need to be unambiguous; if not, because of the copies, the numbers obtained will be higher than the right ones.

By the second diagram, one may write

$A = x + xC + xD$ where :

$A = a\_1x + a\_2x^2 + a\_3x^3 + ... $is the generating function (or the string index) for words that ends exactly in $0$. We have similar expressions for B, C and D.

Similarly, the other three equations are:

$B = x^3 + xB + x^3C + x^3D $

$C = x + xA + xB$

$D = x^4 + x^4A + x^4B + xD$

Here $x$ stands for $0$ or $1$, $x^3$ covers the bit string $000$; $x^4$ covers the bit string $1111$;

The above (second) system easily solves to the same solution as the first diagram :

here (for example), $x + {x^3 \over 1-x } $ encodes the set { 0, 000, 0000, 00000, ....}

the two equations are

$ A+B = {x-x^2+x^3 \over 1-x } ( C + D + 1 ) $ and

$ C+D = {x-x^2+x^4 \over 1-x } ( A + B + 1 ) $

that easily solves to $ W=A+B+C+D= {2x - 2x^2 - x^3 + 4x^4 -x^5 -2x^6 + 2x^7 \over 1 - 2x + 2x^3 - 2x^4 + x^6 - x^7} $

$= 2+2x +3x^2 +6x^3 +11x^4 +18x^5+30x^6 +50x^7 +85x^8 +143x^9+ 241x^{10} + ...$

The denominator encodes the required recurrence.

## 2698725

https://math.stackexchange.com/questions/2698725
The number of sequences of length that can be formed with unique digits containing two of each where no two adjacent elements are alike

let A be strings that end in a, B that end in b, until E= strings that end in e.
The Ordinary Generating Function system is then

{

# A
a
a
.
(
B
C
D
E
)
,

# B
b
b
.
(
A
C
D
E
)
,

# C
c
c
.
(
A
B
D
E
)
,

# D
d
d
.
(
A
B
C
E
)
,

# E
e
e
.
(
A
B
C
D
)
,

# S
A
B
C
D
E

{\displaystyle \begin{cases}
A = a + a.(B+C+D+E), \\
B = b + b.(A+C+D+E),\\
C = c + c.(A+B+D+E),\\
D = d + d.(A+B+C+E),\\
E = e + e.(A+B+C+D),\\
S = A+B+C+D+E
\end{cases}
}

Maple solve delivers as generating function :

a
b
c
d
e
2
(
a
b
a
c
.
.
.
)
3
(
a
b
c
a
b
d
.
.
.
)
4
(
a
b
c
d
a
b
c
e
.
.
.
)
5
a
b
c
d
e

1
−
(
a
b
a
c
.
.
.
)
−
2
(
a
b
c
a
b
d
.
.
.
)
−
3
(
a
b
c
d
a
b
c
e
.
.
.
)
−
4
a
b
c
d
e

{\displaystyle \frac {
a+ b + c+ d + e + 2( ab + ac + ...) + 3(abc + abd + ... ) + 4(abcd + abce ... ) + 5abcde}{ 1 -(ab + ac ...) - 2(abc + abd + ... ) - 3(abcd + abce ... ) - 4abcde }}

The required number is the coefficient of

a
2

b
2

c
2

d
2

e
2

{\displaystyle a^2b^2c^2d^2e^2 }

 and it is

39480

{\displaystyle 39480}

## Goddard

Binary strings with even number of 0's

found here https://people.cs.clemson.edu/~goddard/texts/theoryOfComputation/6a.pdf

1, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024,

A011782 OEIS

{

# A
t
(
1
C
D
)
,

# B
t
B

t
3

(
1
C
D
)
,

# C
t
(
1
A
B
)
,

# D
t
D

t
4

(
1
A
B
)
,

{\displaystyle \begin{cases}
A = t(1 + C + D), \\
B = tB + t^3(1 + C + D),\\
C = t(1 + A + B),\\
D = tD +t^4(1 + A + B),
\end{cases}
}

{

S
→
1
S

0
A
0
S

ϵ

A
1
A

ϵ

{\displaystyle \begin{cases}
S \rightarrow 1S \ |\ 0A0S \ |\ \epsilon \\
A 1A \ |\ \epsilon
\end{cases}
}

# S
1
X
⋅
S
Y
⋅
L
i
n
(
X
)
⋅
Y
⋅
S

{\displaystyle S = 1 + X\cdot S + Y\cdot Lin(X)\cdot Y\cdot S }

{

S
→
1
S

0
T

ϵ

T
→
1
T

0
S

{

# S
1
X
⋅
S
Y
⋅
T

# T
X
⋅
T
Y
⋅
S

{\displaystyle \begin{cases}
S \rightarrow 1S \ |\ 0T \ |\ \epsilon \\
T \rightarrow 1T \ |\ 0S
\end{cases} \ \ \ \ \ \ \ \begin{cases}
S = 1 + X \cdot S + Y\cdot T \\
T = X\cdot T + Y\cdot S
\end{cases}
}