Show that language is accepted by a pushdown automaton

  • MHB
  • Thread starter evinda
  • Start date
  • Tags
    Language
In summary: Let's see...\begin{array}{}S&\to& axyb \\x &\to& \varnothing \\y &\to& \varnothing \end{array}So $ab$ is accepted. Is that allowed?Btw, perhaps you should use different casing (like $a$ and $X$) to visually distinguish terminals from...
  • #1
evinda
Gold Member
MHB
3,836
0
Hello again! (Wasntme)

I have to show that the language [tex]\left \{ w\epsilon \left \{ a,b \right \}^{*}:w=a^{m}b^{n},m\neq n \right \} [/tex] is accepted by a pushdown automaton.
Can I use the sentence "A string is accepted by a pushdown automaton if,starting with an empty stack,there is a path through the automaton such that the automaton stops in an accepting state after the entire string has been read." to show it?
 
Technology news on Phys.org
  • #2
evinda said:
Hello again! (Wasntme)

I have to show that the language [tex]\left \{ w\epsilon \left \{ a,b \right \}^{*}:w=a^{m}b^{n},m\neq n \right \} [/tex] is accepted by a pushdown automaton.
Can I use the sentence "A string is accepted by a pushdown automaton if,starting with an empty stack,there is a path through the automaton such that the automaton stops in an accepting state after the entire string has been read." to show it?

Hey again! (Smirk)

I have just refreshed my knowledge about pushdown automatons.
Apparently it starts with an initial stack symbol.
So I think the proper sentence should be: "A string is accepted by a pushdown automaton if, starting with the initial stack symbol, there is a path through the automaton such that the automaton stops in an accepting state after the entire string has been read."
 
  • #3
I like Serena said:
Hey again! (Smirk)

I have just refreshed my knowledge about pushdown automatons.
Apparently it starts with an initial stack symbol.
So I think the proper sentence should be: "A string is accepted by a pushdown automaton if, starting with the initial stack symbol, there is a path through the automaton such that the automaton stops in an accepting state after the entire string has been read."

And how can I show it?Do I have to draw the pushdown automaton?
 
  • #4
evinda said:
And how can I show it?Do I have to draw the pushdown automaton?

That would be my preferred way.
 
  • #5
I like Serena said:
That would be my preferred way.

Ok,I will try it! :D Except from that,is there also an other way,how I could show that the language is accepted by a pushdown automaton? :confused:
 
  • #6
evinda said:
Ok,I will try it! :D Except from that,is there also an other way,how I could show that the language is accepted by a pushdown automaton? :confused:

You could also formally specify a pushdown automaton (PDA).

Here's an example from wiki:

The following is the formal description of the PDA which recognizes the language \(\displaystyle \{0^n1^n \mid n \ge 0 \}\) by final state:

\(\displaystyle M=(Q,\ \Sigma,\ \Gamma,\ \delta, \ p,\ Z, \ F)\), where
\(\displaystyle Q = \{ p,q,r \}\)
\(\displaystyle \Sigma = \{0, 1\}\)
\(\displaystyle \Gamma = \{A, Z\}\)
\(\displaystyle q_{0} = p\)
\(\displaystyle F = \{r\}\)

\(\displaystyle \delta\) consists of the following six instructions:

\(\displaystyle (p,0,Z,p,AZ)\),
\(\displaystyle (p,0,A,p,AA)\),
\(\displaystyle (p,\epsilon,Z,q,Z)\),
\(\displaystyle (p,\epsilon,A,q,A)\),
\(\displaystyle (q,1,A,q,\epsilon)\), and
\(\displaystyle (q,\epsilon,Z,r,Z)\).​
Such a specification is much harder to read or to verify. :eek:
Note that the example on wiki also contains a picture that contains everything that is needed.
 
  • #7
evinda said:
Can I use the sentence "A string is accepted by a pushdown automaton if,starting with an empty stack,there is a path through the automaton such that the automaton stops in an accepting state after the entire string has been read." to show it?
There are different definitions of when a word is accepted. For example. some of them require that the stack is empty in the end while others don't. You should check your sources.

A language is accepted by a pushdown automaton iff it is context-free, so you could also construct a grammar to show that your language is accepted by a pushdown automaton. The ultimate determination is made by the one who designed the problem, but I think that if a question refers to a pushdown automaton, then such automaton has to be constructed.
 
  • #8
Evgeny.Makarov said:
There are different definitions of when a word is accepted. For example. some of them require that the stack is empty in the end while others don't. You should check your sources.

A language is accepted by a pushdown automaton iff it is context-free, so you could also construct a grammar to show that your language is accepted by a pushdown automaton. The ultimate determination is made by the one who designed the problem, but I think that if a question refers to a pushdown automaton, then such automaton has to be constructed.
I have tried to construct a grammar,to show that the language is accepted by a pushdown automaton.That's what I got:
[tex]S\rightarrow axyb ,
x\rightarrow ax ,
y\rightarrow by ,
x\rightarrow \varnothing ,
y\rightarrow \varnothing
[/tex]
Is it right?Or am I wrong? :confused: :eek:
 
  • #9
evinda said:
I have tried to construct a grammar,to show that the language is accepted by a pushdown automaton.That's what I got:
[tex]S\rightarrow axyb ,
x\rightarrow ax ,
y\rightarrow by ,
x\rightarrow \varnothing ,
y\rightarrow \varnothing
[/tex]
Is it right?Or am I wrong? :confused: :eek:

Let's see...

\begin{array}{}S&\to& axyb \\
x &\to& \varnothing \\
y &\to& \varnothing
\end{array}

So $ab$ is accepted. Is that allowed?

Btw, perhaps you should use different casing (like $a$ and $X$) to visually distinguish terminals from non-terminals?
 
  • #10
I like Serena said:
Let's see...

\begin{array}{}S&\to& axyb \\
x &\to& \varnothing \\
y &\to& \varnothing
\end{array}

So $ab$ is accepted. Is that allowed?

Oh,you are right :eek: It should't be accepted!

- - - Updated - - -

I like Serena said:
Let's see...

\begin{array}{}S&\to& axyb \\
x &\to& \varnothing \\
y &\to& \varnothing
\end{array}

So $ab$ is accepted. Is that allowed?

Btw, perhaps you should use different casing (like $a$ and $X$) to visually distinguish terminals from non-terminals?

So,should it be like that:
[tex]S\rightarrow aXYb ,
X\rightarrow aaX ,
Y\rightarrow bY ,
X\rightarrow \varnothing ,
Y\rightarrow \varnothing
[/tex]

or like that:
[tex]S\rightarrow aXYb ,
X\rightarrow aX ,
Y\rightarrow bbY ,
X\rightarrow \varnothing ,
Y\rightarrow \varnothing
[/tex]

or something else?
 
  • #11
evinda said:
Oh,you are right :eek: It should't be accepted!

- - - Updated - - -
So,should it be like that:
[tex]S\rightarrow aXYb ,
X\rightarrow aaX ,
Y\rightarrow bY ,
X\rightarrow \varnothing ,
Y\rightarrow \varnothing
[/tex]

or like that:
[tex]S\rightarrow aXYb ,
X\rightarrow aX ,
Y\rightarrow bbY ,
X\rightarrow \varnothing ,
Y\rightarrow \varnothing
[/tex]

or something else?

With both grammars I can still construct $ab$. :eek:
 
  • #12
I like Serena said:
With both grammars I can still construct $ab$. :eek:

And what could I change so that it cannot happen that m=n?
 
  • #13
evinda said:
And what could I change so that it cannot happen that m=n?

Start with something like $S \to a S b$ which will allow a symmetric build-up.
Only allow it to terminate when there is an asymmetry in either $a$ or $b$.
So add for instance $S \to aA\ |\ Bb$.
 
  • #14
I like Serena said:
Start with something like $S \to a S b$ which will allow a symmetric build-up.
Only allow it to terminate when there is an asymmetry in either $a$ or $b$.
So add for instance $S \to aA\ |\ Bb$.

I looked again the exercise and realized that the language is the union of the two languages: $ \displaystyle \left \{ w\epsilon \left \{ a,b \right \}^{*}:w=a^{m}b^{n},m>n\right \}$ and $ \displaystyle \left \{ w\epsilon \left \{ a,b \right \}^{*}:w=a^{m}b^{n},m<n\right \}$ .So is the grammar the following?
$$S \to S_{1}|S_{2} $$
$$S_{1} \to AB $$
$$A\to aAb| \varnothing$$
$$B\to bB|b$$
$$S_{2}\to XY$$
$$X\to aX|a$$
$$Y\to aYb|\varnothing$$
 
  • #15
evinda said:
I looked again the exercise and realized that the language is the union of the two languages: $ \displaystyle \left \{ w\epsilon \left \{ a,b \right \}^{*}:w=a^{m}b^{n},m>n\right \}$ and $ \displaystyle \left \{ w\epsilon \left \{ a,b \right \}^{*}:w=a^{m}b^{n},m<n\right \}$ .So is the grammar the following?
$$S \to S_{1}|S_{2} $$
$$S_{1} \to AB $$
$$A\to aAb| \varnothing$$
$$B\to bB|b$$
$$S_{2}\to XY$$
$$X\to aX|a$$
$$Y\to aYb|\varnothing$$

Looks good! ;)

But... I thought you were going to draw a pushdown automaton. You said so... :rolleyes:

Btw... how do you feel about an avatar picture? :eek:
 
  • #16
Evgeny.Makarov said:
There are different definitions of when a word is accepted. For example. some of them require that the stack is empty in the end while others don't. You should check your sources.

A language is accepted by a pushdown automaton iff it is context-free, so you could also construct a grammar to show that your language is accepted by a pushdown automaton. The ultimate determination is made by the one who designed the problem, but I think that if a question refers to a pushdown automaton, then such automaton has to be constructed.

The exercise is:"Show that the following language(the one that I wrote at the first post) is accepted by a pushdown automaton".So,could I just say that the language is accepted by a pushdown automaton,because of the fact that there is a contextfree grammar that generates it? :confused:

- - - Updated - - -

I like Serena said:
Looks good! ;)

But... I thought you were going to draw a pushdown automaton. You said so... :rolleyes:

I will try to draw the pushdown automaton and I'll tell you later what I have done! :D

- - - Updated - - -

I like Serena said:
Start with something like $S \to a S b$ which will allow a symmetric build-up.
Only allow it to terminate when there is an asymmetry in either $a$ or $b$.
So add for instance $S \to aA\ |\ Bb$.

Is there also an other grammar that generates the language,than the grammar that I wrote at my previous post? :confused:
 
  • #17
evinda said:
The exercise is:"Show that the following language(the one that I wrote at the first post) is accepted by a pushdown automaton".So,could I just say that the language is accepted by a pushdown automaton,because of the fact that there is a contextfree grammar that generates it? :confused:

Yes.

- - - Updated - - -
I will try to draw the pushdown automaton and I'll tell you later what I have done! :D

Can I see the drawing?
I like pictures! :eek:
- - - Updated - - -
Is there also an other grammar that generates the language,than the grammar that I wrote at my previous post? :confused:

Of course.
For instance:
$$S \to aSb\ |\ aA\ |\ bB$$
$$A \to aA\ |\ \varnothing$$
$$B \to bB\ |\ \varnothing$$
 
  • #18
evinda said:
Is there also an other grammar that generates the language,than the grammar that I wrote at my previous post?
Yes.

N. had the habit of simply writing answers to homework assignments on the board (the method of solution being, of course, obvious) when he was asked how to solve problems. One time one of his students tried to get more helpful information by asking if there was another way to solve the problem. N. looked blank for a moment, thought, and then answered, "Yes".
 
  • #19
Evgeny.Makarov said:
Yes.

:D ;) :cool:

- - - Updated - - -

I like Serena said:
Can I see the drawing?
I like pictures! :eek:

I wanted to draw a pushdown automaton,but I haven't found a lot of examples and I haven't really understood,how such automata can be drawn.
Could you explain me? :eek:
[/QUOTE]

I like Serena said:
Of course.
For instance:
$$S \to aSb\ |\ aA\ |\ bB$$
$$A \to aA\ |\ \varnothing$$
$$B \to bB\ |\ \varnothing$$
Great!Thank you! :)
 
  • #20
evinda said:
I wanted to draw a pushdown automaton,but I haven't found a lot of examples and I haven't really understood,how such automata can be drawn.
Could you explain me? :eek:

Here's one for a pushdown automaton that accepts $0^n1^n$.

500px-Pda-example.svg.png


We start in state $\color{brown}p$ where symbol $\color{green}0$ is accepted.
On the stack we track the number of $\color{green}0$s that we accepted as the number of $\color{blue}A$s.

When a symbol $\color{green}0$ comes in while the stack still contains the initial stack symbol $\color{blue}Z$, $\color{blue}A$ is pushed onto the stack ($\color{blue}Z$ is replaced by $\color{blue}{AZ}$).
When another symbol $\color{green}0$ comes in while the top of the stack contains $\color{blue}A$, another $\color{blue}A$ is pushed onto the stack ($\color{blue}A$ is replaced by $\color{blue}{AA}$).

And so on...Aha! You have a mathy avatar now. Good! :D
 
  • #21
I like Serena said:
Here's one for a pushdown automaton that accepts $0^n1^n$.

500px-Pda-example.svg.png


We start in state $\color{brown}p$ where symbol $\color{green}0$ is accepted.
On the stack we track the number of $\color{green}0$s that we accepted as the number of $\color{blue}A$s.

When a symbol $\color{green}0$ comes in while the stack still contains the initial stack symbol $\color{blue}Z$, $\color{blue}A$ is pushed onto the stack ($\color{blue}Z$ is replaced by $\color{blue}{AZ}$).
When another symbol $\color{green}0$ comes in while the top of the stack contains $\color{blue}A$, another $\color{blue}A$ is pushed onto the stack ($\color{blue}A$ is replaced by $\color{blue}{AA}$).
And so on...

I have tried this,but I don't think that it is right..I haven't really understood the stacks :confused:
View attachment 1816
 

Attachments

  • 1543036_589841881071145_636498170_n.jpg
    1543036_589841881071145_636498170_n.jpg
    26 KB · Views: 51
  • #22
evinda said:
I have tried this,but I don't think that it is right..I haven't really understood the stacks :confused:

The problem here is that for instance $ab$ is accepted.
If we take the upper branch in your automaton and accept $a$ once, we can then make a shift to the next state while accepting $b$, and then let the automaton finish.

We need a stack to keep track how many $a$'s were accepted.
So in each transition, we do not only accept an input symbol, we also manipulate the stack.

Going back to the example I just gave (from wiki).
Here is how the stack would develop while reading the string $0011$.

500px-Pda-steps.svg.png


Leftmost you see that the stack begins as
$$\begin{bmatrix}Z\end{bmatrix}$$

After reading the symbol $0$, an $A$ is pushed on top of it.
So we get the stack
$$\begin{bmatrix}A \\ Z \end{bmatrix}$$

After reading another symbol $0$, another $A$ is pushed on top, yielding
$$\begin{bmatrix}A \\ A \\ Z \end{bmatrix}$$
Note that there are as many $A$'s on the stack as we have read $0$'s.

And so on.
 
  • #23
I like Serena said:
The problem here is that for instance $ab$ is accepted.
If we take the upper branch in your automaton and accept $a$ once, we can then make a shift to the next state while accepting $b$, and then let the automaton finish.

We need a stack to keep track how many $a$'s were accepted.
So in each transition, we do not only accept an input symbol, we also manipulate the stack.

Going back to the example I just gave (from wiki).
Here is how the stack would develop while reading the string $0011$.

500px-Pda-steps.svg.png


Leftmost you see that the stack begins as
$$\begin{bmatrix}Z\end{bmatrix}$$

After reading the symbol $0$, an $A$ is pushed on top of it.
So we get the stack
$$\begin{bmatrix}A \\ Z \end{bmatrix}$$

After reading another symbol $0$, another $A$ is pushed on top, yielding
$$\begin{bmatrix}A \\ A \\ Z \end{bmatrix}$$
Note that there are as many $A$'s on the stack as we have read $0$'s.

And so on.

I wish you a happy new year! :) :)

I have tried again to draw the pushdown automaton.That's what I did:
View attachment 1818
 

Attachments

  • 1499790_590095967712403_1493489713_n.jpg
    1499790_590095967712403_1493489713_n.jpg
    31.8 KB · Views: 48
  • #24
I have tried again to draw the pushdown automaton.That's what I did:

Looking good! ;)

One problem (or rather 2): the strings $aa{}^*$ and $bb{}^*$ are not accepted while they should.

evinda said:
I wish you a happy new year! :) :)

HAPPY NEW YEAR! (Angel)
 
  • #25
I like Serena said:
Looking good! ;)

One problem (or rather 2): the strings $aa{}^*$ and $bb{}^*$ are not accepted while they should.

And what could I change,so that the strings $aa{}^*$ and $bb{}^*$ get accepted? :confused:
 
  • #26
evinda said:
And what could I change,so that the strings $aa{}^*$ and $bb{}^*$ get accepted? :confused:

Well, you could for instance replace the first transition $a;Z/AZ$ by $\varepsilon;Z/Z$ and also the first transition $b;Z/BZ$ by $\varepsilon;Z/Z$.
 
  • #27
I like Serena said:
Well, you could for instance replace the first transition $a;Z/AZ$ by $\varepsilon;Z/Z$ and also the first transition $b;Z/BZ$ by $\varepsilon;Z/Z$.

So,should it be like that?
View attachment 1820
 

Attachments

  • 1482244_590538097668190_544439118_n.jpg
    1482244_590538097668190_544439118_n.jpg
    30 KB · Views: 48
  • #28
evinda said:
So,should it be like that?

Yep. All good now. (Priidu)
 
  • #29
I like Serena said:
Yep. All good now. (Priidu)

Nice...Thank you very much! (Happy)
 
  • #30
evinda said:
Nice...Thank you very much! (Happy)

Oh wait! :eek:
The PDA correctly accepts $a^nb^nb^+$ in the upper branch.
However, in the lower branch it accepts $b^na^na^+$... that is not right. :eek:
It should accept $a^+a^nb^n$.
 
  • #31
I like Serena said:
Oh wait!
The PDA correctly accepts $a^nb^nb^+$ in the upper branch.
However, in the lower branch it accepts $b^na^na^+$... that is not right. :eek:
It should accept $a^+a^nb^n$.

I have changed it :) Is it right now?
View attachment 1822
 

Attachments

  • 1558680_590814367640563_1302933525_n (1).jpg
    1558680_590814367640563_1302933525_n (1).jpg
    29.9 KB · Views: 43
  • #32
evinda said:
I have changed it :) Is it right now?

Let me take a more careful look this time. :eek:

In the upper branch we can read $\varepsilon$ and leave the stack as $z$.
Then, in the next state, we can read $a$, but only if there is an $a$ on the top of the stack... but the first time there is a $z$ on top, so we're stuck! :eek:

In the lower branch we can now read $a^+$, leaving a $z$ on top of the stack, which is good.
Then we're stuck again, because we can't move on as long as the $z$ is still on top of the stack.

When we're able to pass that blockage, there is one more hurdle.
We will have a stack full of $a$'s... and we can only move on if there is a $b$ on top of the stack, but they were never pushed onto the stack! :eek:
 
  • #33
Evgeny.Makarov said:
A language is accepted by a pushdown automaton iff it is context-free, so you could also construct a grammar to show that your language is accepted by a pushdown automaton.

I looked again at the exercise and saw that I have to show that the language is accepted by a deterministic pushdown automaton.So,can I just show that the language is context-free,or do I have to do something else?? :confused:
 
  • #34
Not all context-free languages are accepted by deterministic pushdown automata. The easiest is probably to construct such automaton.
 
  • #35
Evgeny.Makarov said:
Not all context-free languages are accepted by deterministic pushdown automata. The easiest is probably to construct such automaton.

And is this the only way?Because I am not really familiar with the construction of pushdown automata! :confused:
 

Similar threads

  • Programming and Computer Science
Replies
11
Views
3K
  • Programming and Computer Science
Replies
13
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Calculus and Beyond Homework Help
Replies
1
Views
1K
  • Programming and Computer Science
Replies
14
Views
3K
  • Math Proof Training and Practice
Replies
25
Views
2K
  • General Math
Replies
0
Views
831
Replies
11
Views
1K
  • Advanced Physics Homework Help
Replies
1
Views
953
Back
Top