Let $L_{n} = {x in Sigma^* | x = ywz, w^R = w, |w| geq n, |y| = |z| }$ Generate a cfg of $L_n$
up vote
1
down vote
favorite
Let $L_{n} = {x in Sigma^* | x = ywz, w^R = w, |w| geq n, |y| = |z| }$
Generate a cfg of $L_n$
For n = 1, 2, 3
Informally, x is in $L_n$ means
some palindrome of at least length n is a substring of x that occurs
exactly at the midpoint of x.
for $n = 1$
$S to 0S0 | 1S1 | 0S1 | 1S0|0 | 1 | 00 | 11$
for $n = 2$
$S to 0S0 | 1S1 | 0S1 | 1S0 | 0A0 | 1A1$
$A to 0 | 1 | epsilon$
for $n = 3$
$S to 0S0 | 1S1 | 0S1 | 1S0 | 0A0 | 1A1$
$A to 0 | 1 | 00 | 11 | epsilon$
would this be right?
Say I changed it to $|y| > |z|$ or $|y| < |z|$ how would this differ?
formal-languages context-free-grammar
add a comment |
up vote
1
down vote
favorite
Let $L_{n} = {x in Sigma^* | x = ywz, w^R = w, |w| geq n, |y| = |z| }$
Generate a cfg of $L_n$
For n = 1, 2, 3
Informally, x is in $L_n$ means
some palindrome of at least length n is a substring of x that occurs
exactly at the midpoint of x.
for $n = 1$
$S to 0S0 | 1S1 | 0S1 | 1S0|0 | 1 | 00 | 11$
for $n = 2$
$S to 0S0 | 1S1 | 0S1 | 1S0 | 0A0 | 1A1$
$A to 0 | 1 | epsilon$
for $n = 3$
$S to 0S0 | 1S1 | 0S1 | 1S0 | 0A0 | 1A1$
$A to 0 | 1 | 00 | 11 | epsilon$
would this be right?
Say I changed it to $|y| > |z|$ or $|y| < |z|$ how would this differ?
formal-languages context-free-grammar
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Let $L_{n} = {x in Sigma^* | x = ywz, w^R = w, |w| geq n, |y| = |z| }$
Generate a cfg of $L_n$
For n = 1, 2, 3
Informally, x is in $L_n$ means
some palindrome of at least length n is a substring of x that occurs
exactly at the midpoint of x.
for $n = 1$
$S to 0S0 | 1S1 | 0S1 | 1S0|0 | 1 | 00 | 11$
for $n = 2$
$S to 0S0 | 1S1 | 0S1 | 1S0 | 0A0 | 1A1$
$A to 0 | 1 | epsilon$
for $n = 3$
$S to 0S0 | 1S1 | 0S1 | 1S0 | 0A0 | 1A1$
$A to 0 | 1 | 00 | 11 | epsilon$
would this be right?
Say I changed it to $|y| > |z|$ or $|y| < |z|$ how would this differ?
formal-languages context-free-grammar
Let $L_{n} = {x in Sigma^* | x = ywz, w^R = w, |w| geq n, |y| = |z| }$
Generate a cfg of $L_n$
For n = 1, 2, 3
Informally, x is in $L_n$ means
some palindrome of at least length n is a substring of x that occurs
exactly at the midpoint of x.
for $n = 1$
$S to 0S0 | 1S1 | 0S1 | 1S0|0 | 1 | 00 | 11$
for $n = 2$
$S to 0S0 | 1S1 | 0S1 | 1S0 | 0A0 | 1A1$
$A to 0 | 1 | epsilon$
for $n = 3$
$S to 0S0 | 1S1 | 0S1 | 1S0 | 0A0 | 1A1$
$A to 0 | 1 | 00 | 11 | epsilon$
would this be right?
Say I changed it to $|y| > |z|$ or $|y| < |z|$ how would this differ?
formal-languages context-free-grammar
formal-languages context-free-grammar
edited Nov 16 at 1:27
Joey Kilpatrick
1,163121
1,163121
asked Nov 12 at 22:00
Tree Garen
35019
35019
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Everything here is assuming $Sigma={0,1}$.
Your solution for $n=1$ and $n=2$ are correct, but $n=3$ is not quite right because it allows $11$ and $00$ which are not in $L_3$. To fix this, simply remove $epsilon$ from the rule for $A$. The following solution, while verbose, scales well for any $n$.
The rule $A_i$ will be the rule that produces every palindrome of length $i$ or $i-1$. For $ige3$, $$
A_ilongrightarrow 0A_{i-2}0text{ }|text{ }1A_{i-2}1text{ }|text{ }0A_{i-3}0text{ }|text{ }1A_{i-3}1
$$
Let
$$
A_2longrightarrow 0text{ }|text{ }1text{ }|text{ }00text{ }|text{ }11 \
A_1longrightarrow epsilontext{ }|text{ }0text{ }|text{ }1 \
A_0longrightarrow epsilon
$$
Then any $L_n$ can be produced by the rules for $A_0, A_1, ..., A_n, A_{n+1}$ and starting symbol $S$ with rule$$
Slongrightarrow 0S0text{ }|text{ } 0S1text{ }|text{ }1S0text{ }|text{ }1S1text{ }|text{ }A_{n+1}
$$
For $n=1$, we can write,
$$
Slongrightarrow 0S0text{ }|text{ } 0S1text{ }|text{ }1S0text{ }|text{ }1S1text{ }|text{ }A_2 \
A_2longrightarrow 0text{ }|text{ }1text{ }|text{ }00text{ }|text{ }11 \
A_1longrightarrow epsilontext{ }|text{ }0text{ }|text{ }1 \
A_0longrightarrow epsilon
$$
For $n=2$, we can write,
$$
Slongrightarrow 0S0text{ }|text{ } 0S1text{ }|text{ }1S0text{ }|text{ }1S1text{ }|text{ }A_3 \
A_3longrightarrow 0A_{1}0text{ }|text{ }1A_{1}1text{ }|text{ }0A_{0}0text{ }|text{ }1A_{0}1 \
A_2longrightarrow 0text{ }|text{ }1text{ }|text{ }00text{ }|text{ }11 \
A_1longrightarrow epsilontext{ }|text{ }0text{ }|text{ }1 \
A_0longrightarrow epsilon
$$
For $n=3$, we can write,
$$
Slongrightarrow 0S0text{ }|text{ } 0S1text{ }|text{ }1S0text{ }|text{ }1S1text{ }|text{ }A_4 \
A_4longrightarrow 0A_{2}0text{ }|text{ }1A_{2}1text{ }|text{ }0A_{1}0text{ }|text{ }1A_{1}1 \
A_3longrightarrow 0A_{1}0text{ }|text{ }1A_{1}1text{ }|text{ }0A_{0}0text{ }|text{ }1A_{0}1 \
A_2longrightarrow 0text{ }|text{ }1text{ }|text{ }00text{ }|text{ }11 \
A_1longrightarrow epsilontext{ }|text{ }0text{ }|text{ }1 \
A_0longrightarrow epsilon
$$
And so on.
If $|y|>|z|$, then we just add the rule $$
R longrightarrow 0Rtext{ }|text{ }1Rtext{ }|text{ }0Stext{ }|text{ }1S
$$
and let $R$ be the starting symbol.
If $|y|<|z|$, then we just add the rule $$
R longrightarrow R0text{ }|text{ }R1text{ }|text{ }S0text{ }|text{ }S1
$$
and let $R$ be the starting symbol.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Everything here is assuming $Sigma={0,1}$.
Your solution for $n=1$ and $n=2$ are correct, but $n=3$ is not quite right because it allows $11$ and $00$ which are not in $L_3$. To fix this, simply remove $epsilon$ from the rule for $A$. The following solution, while verbose, scales well for any $n$.
The rule $A_i$ will be the rule that produces every palindrome of length $i$ or $i-1$. For $ige3$, $$
A_ilongrightarrow 0A_{i-2}0text{ }|text{ }1A_{i-2}1text{ }|text{ }0A_{i-3}0text{ }|text{ }1A_{i-3}1
$$
Let
$$
A_2longrightarrow 0text{ }|text{ }1text{ }|text{ }00text{ }|text{ }11 \
A_1longrightarrow epsilontext{ }|text{ }0text{ }|text{ }1 \
A_0longrightarrow epsilon
$$
Then any $L_n$ can be produced by the rules for $A_0, A_1, ..., A_n, A_{n+1}$ and starting symbol $S$ with rule$$
Slongrightarrow 0S0text{ }|text{ } 0S1text{ }|text{ }1S0text{ }|text{ }1S1text{ }|text{ }A_{n+1}
$$
For $n=1$, we can write,
$$
Slongrightarrow 0S0text{ }|text{ } 0S1text{ }|text{ }1S0text{ }|text{ }1S1text{ }|text{ }A_2 \
A_2longrightarrow 0text{ }|text{ }1text{ }|text{ }00text{ }|text{ }11 \
A_1longrightarrow epsilontext{ }|text{ }0text{ }|text{ }1 \
A_0longrightarrow epsilon
$$
For $n=2$, we can write,
$$
Slongrightarrow 0S0text{ }|text{ } 0S1text{ }|text{ }1S0text{ }|text{ }1S1text{ }|text{ }A_3 \
A_3longrightarrow 0A_{1}0text{ }|text{ }1A_{1}1text{ }|text{ }0A_{0}0text{ }|text{ }1A_{0}1 \
A_2longrightarrow 0text{ }|text{ }1text{ }|text{ }00text{ }|text{ }11 \
A_1longrightarrow epsilontext{ }|text{ }0text{ }|text{ }1 \
A_0longrightarrow epsilon
$$
For $n=3$, we can write,
$$
Slongrightarrow 0S0text{ }|text{ } 0S1text{ }|text{ }1S0text{ }|text{ }1S1text{ }|text{ }A_4 \
A_4longrightarrow 0A_{2}0text{ }|text{ }1A_{2}1text{ }|text{ }0A_{1}0text{ }|text{ }1A_{1}1 \
A_3longrightarrow 0A_{1}0text{ }|text{ }1A_{1}1text{ }|text{ }0A_{0}0text{ }|text{ }1A_{0}1 \
A_2longrightarrow 0text{ }|text{ }1text{ }|text{ }00text{ }|text{ }11 \
A_1longrightarrow epsilontext{ }|text{ }0text{ }|text{ }1 \
A_0longrightarrow epsilon
$$
And so on.
If $|y|>|z|$, then we just add the rule $$
R longrightarrow 0Rtext{ }|text{ }1Rtext{ }|text{ }0Stext{ }|text{ }1S
$$
and let $R$ be the starting symbol.
If $|y|<|z|$, then we just add the rule $$
R longrightarrow R0text{ }|text{ }R1text{ }|text{ }S0text{ }|text{ }S1
$$
and let $R$ be the starting symbol.
add a comment |
up vote
0
down vote
accepted
Everything here is assuming $Sigma={0,1}$.
Your solution for $n=1$ and $n=2$ are correct, but $n=3$ is not quite right because it allows $11$ and $00$ which are not in $L_3$. To fix this, simply remove $epsilon$ from the rule for $A$. The following solution, while verbose, scales well for any $n$.
The rule $A_i$ will be the rule that produces every palindrome of length $i$ or $i-1$. For $ige3$, $$
A_ilongrightarrow 0A_{i-2}0text{ }|text{ }1A_{i-2}1text{ }|text{ }0A_{i-3}0text{ }|text{ }1A_{i-3}1
$$
Let
$$
A_2longrightarrow 0text{ }|text{ }1text{ }|text{ }00text{ }|text{ }11 \
A_1longrightarrow epsilontext{ }|text{ }0text{ }|text{ }1 \
A_0longrightarrow epsilon
$$
Then any $L_n$ can be produced by the rules for $A_0, A_1, ..., A_n, A_{n+1}$ and starting symbol $S$ with rule$$
Slongrightarrow 0S0text{ }|text{ } 0S1text{ }|text{ }1S0text{ }|text{ }1S1text{ }|text{ }A_{n+1}
$$
For $n=1$, we can write,
$$
Slongrightarrow 0S0text{ }|text{ } 0S1text{ }|text{ }1S0text{ }|text{ }1S1text{ }|text{ }A_2 \
A_2longrightarrow 0text{ }|text{ }1text{ }|text{ }00text{ }|text{ }11 \
A_1longrightarrow epsilontext{ }|text{ }0text{ }|text{ }1 \
A_0longrightarrow epsilon
$$
For $n=2$, we can write,
$$
Slongrightarrow 0S0text{ }|text{ } 0S1text{ }|text{ }1S0text{ }|text{ }1S1text{ }|text{ }A_3 \
A_3longrightarrow 0A_{1}0text{ }|text{ }1A_{1}1text{ }|text{ }0A_{0}0text{ }|text{ }1A_{0}1 \
A_2longrightarrow 0text{ }|text{ }1text{ }|text{ }00text{ }|text{ }11 \
A_1longrightarrow epsilontext{ }|text{ }0text{ }|text{ }1 \
A_0longrightarrow epsilon
$$
For $n=3$, we can write,
$$
Slongrightarrow 0S0text{ }|text{ } 0S1text{ }|text{ }1S0text{ }|text{ }1S1text{ }|text{ }A_4 \
A_4longrightarrow 0A_{2}0text{ }|text{ }1A_{2}1text{ }|text{ }0A_{1}0text{ }|text{ }1A_{1}1 \
A_3longrightarrow 0A_{1}0text{ }|text{ }1A_{1}1text{ }|text{ }0A_{0}0text{ }|text{ }1A_{0}1 \
A_2longrightarrow 0text{ }|text{ }1text{ }|text{ }00text{ }|text{ }11 \
A_1longrightarrow epsilontext{ }|text{ }0text{ }|text{ }1 \
A_0longrightarrow epsilon
$$
And so on.
If $|y|>|z|$, then we just add the rule $$
R longrightarrow 0Rtext{ }|text{ }1Rtext{ }|text{ }0Stext{ }|text{ }1S
$$
and let $R$ be the starting symbol.
If $|y|<|z|$, then we just add the rule $$
R longrightarrow R0text{ }|text{ }R1text{ }|text{ }S0text{ }|text{ }S1
$$
and let $R$ be the starting symbol.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Everything here is assuming $Sigma={0,1}$.
Your solution for $n=1$ and $n=2$ are correct, but $n=3$ is not quite right because it allows $11$ and $00$ which are not in $L_3$. To fix this, simply remove $epsilon$ from the rule for $A$. The following solution, while verbose, scales well for any $n$.
The rule $A_i$ will be the rule that produces every palindrome of length $i$ or $i-1$. For $ige3$, $$
A_ilongrightarrow 0A_{i-2}0text{ }|text{ }1A_{i-2}1text{ }|text{ }0A_{i-3}0text{ }|text{ }1A_{i-3}1
$$
Let
$$
A_2longrightarrow 0text{ }|text{ }1text{ }|text{ }00text{ }|text{ }11 \
A_1longrightarrow epsilontext{ }|text{ }0text{ }|text{ }1 \
A_0longrightarrow epsilon
$$
Then any $L_n$ can be produced by the rules for $A_0, A_1, ..., A_n, A_{n+1}$ and starting symbol $S$ with rule$$
Slongrightarrow 0S0text{ }|text{ } 0S1text{ }|text{ }1S0text{ }|text{ }1S1text{ }|text{ }A_{n+1}
$$
For $n=1$, we can write,
$$
Slongrightarrow 0S0text{ }|text{ } 0S1text{ }|text{ }1S0text{ }|text{ }1S1text{ }|text{ }A_2 \
A_2longrightarrow 0text{ }|text{ }1text{ }|text{ }00text{ }|text{ }11 \
A_1longrightarrow epsilontext{ }|text{ }0text{ }|text{ }1 \
A_0longrightarrow epsilon
$$
For $n=2$, we can write,
$$
Slongrightarrow 0S0text{ }|text{ } 0S1text{ }|text{ }1S0text{ }|text{ }1S1text{ }|text{ }A_3 \
A_3longrightarrow 0A_{1}0text{ }|text{ }1A_{1}1text{ }|text{ }0A_{0}0text{ }|text{ }1A_{0}1 \
A_2longrightarrow 0text{ }|text{ }1text{ }|text{ }00text{ }|text{ }11 \
A_1longrightarrow epsilontext{ }|text{ }0text{ }|text{ }1 \
A_0longrightarrow epsilon
$$
For $n=3$, we can write,
$$
Slongrightarrow 0S0text{ }|text{ } 0S1text{ }|text{ }1S0text{ }|text{ }1S1text{ }|text{ }A_4 \
A_4longrightarrow 0A_{2}0text{ }|text{ }1A_{2}1text{ }|text{ }0A_{1}0text{ }|text{ }1A_{1}1 \
A_3longrightarrow 0A_{1}0text{ }|text{ }1A_{1}1text{ }|text{ }0A_{0}0text{ }|text{ }1A_{0}1 \
A_2longrightarrow 0text{ }|text{ }1text{ }|text{ }00text{ }|text{ }11 \
A_1longrightarrow epsilontext{ }|text{ }0text{ }|text{ }1 \
A_0longrightarrow epsilon
$$
And so on.
If $|y|>|z|$, then we just add the rule $$
R longrightarrow 0Rtext{ }|text{ }1Rtext{ }|text{ }0Stext{ }|text{ }1S
$$
and let $R$ be the starting symbol.
If $|y|<|z|$, then we just add the rule $$
R longrightarrow R0text{ }|text{ }R1text{ }|text{ }S0text{ }|text{ }S1
$$
and let $R$ be the starting symbol.
Everything here is assuming $Sigma={0,1}$.
Your solution for $n=1$ and $n=2$ are correct, but $n=3$ is not quite right because it allows $11$ and $00$ which are not in $L_3$. To fix this, simply remove $epsilon$ from the rule for $A$. The following solution, while verbose, scales well for any $n$.
The rule $A_i$ will be the rule that produces every palindrome of length $i$ or $i-1$. For $ige3$, $$
A_ilongrightarrow 0A_{i-2}0text{ }|text{ }1A_{i-2}1text{ }|text{ }0A_{i-3}0text{ }|text{ }1A_{i-3}1
$$
Let
$$
A_2longrightarrow 0text{ }|text{ }1text{ }|text{ }00text{ }|text{ }11 \
A_1longrightarrow epsilontext{ }|text{ }0text{ }|text{ }1 \
A_0longrightarrow epsilon
$$
Then any $L_n$ can be produced by the rules for $A_0, A_1, ..., A_n, A_{n+1}$ and starting symbol $S$ with rule$$
Slongrightarrow 0S0text{ }|text{ } 0S1text{ }|text{ }1S0text{ }|text{ }1S1text{ }|text{ }A_{n+1}
$$
For $n=1$, we can write,
$$
Slongrightarrow 0S0text{ }|text{ } 0S1text{ }|text{ }1S0text{ }|text{ }1S1text{ }|text{ }A_2 \
A_2longrightarrow 0text{ }|text{ }1text{ }|text{ }00text{ }|text{ }11 \
A_1longrightarrow epsilontext{ }|text{ }0text{ }|text{ }1 \
A_0longrightarrow epsilon
$$
For $n=2$, we can write,
$$
Slongrightarrow 0S0text{ }|text{ } 0S1text{ }|text{ }1S0text{ }|text{ }1S1text{ }|text{ }A_3 \
A_3longrightarrow 0A_{1}0text{ }|text{ }1A_{1}1text{ }|text{ }0A_{0}0text{ }|text{ }1A_{0}1 \
A_2longrightarrow 0text{ }|text{ }1text{ }|text{ }00text{ }|text{ }11 \
A_1longrightarrow epsilontext{ }|text{ }0text{ }|text{ }1 \
A_0longrightarrow epsilon
$$
For $n=3$, we can write,
$$
Slongrightarrow 0S0text{ }|text{ } 0S1text{ }|text{ }1S0text{ }|text{ }1S1text{ }|text{ }A_4 \
A_4longrightarrow 0A_{2}0text{ }|text{ }1A_{2}1text{ }|text{ }0A_{1}0text{ }|text{ }1A_{1}1 \
A_3longrightarrow 0A_{1}0text{ }|text{ }1A_{1}1text{ }|text{ }0A_{0}0text{ }|text{ }1A_{0}1 \
A_2longrightarrow 0text{ }|text{ }1text{ }|text{ }00text{ }|text{ }11 \
A_1longrightarrow epsilontext{ }|text{ }0text{ }|text{ }1 \
A_0longrightarrow epsilon
$$
And so on.
If $|y|>|z|$, then we just add the rule $$
R longrightarrow 0Rtext{ }|text{ }1Rtext{ }|text{ }0Stext{ }|text{ }1S
$$
and let $R$ be the starting symbol.
If $|y|<|z|$, then we just add the rule $$
R longrightarrow R0text{ }|text{ }R1text{ }|text{ }S0text{ }|text{ }S1
$$
and let $R$ be the starting symbol.
answered Nov 16 at 1:00
Joey Kilpatrick
1,163121
1,163121
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2995951%2flet-l-n-x-in-sigma-x-ywz-wr-w-w-geq-n-y-z-gene%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown