MHB Show that language is accepted by a pushdown automaton

  • Thread starter Thread starter evinda
  • Start date Start date
  • Tags Tags
    Language
Click For Summary
The discussion revolves around demonstrating that the language { w ∈ {a,b}*: w = a^m b^n, m ≠ n } is accepted by a pushdown automaton (PDA). Participants clarify that a string is accepted by a PDA if it starts with an initial stack symbol and ends in an accepting state after reading the entire string. They explore constructing a grammar to represent the language, considering both the conditions for acceptance and the need for asymmetry in the counts of 'a's and 'b's. Suggestions include drawing a PDA and providing formal specifications, with a focus on ensuring the grammar correctly reflects the language's requirements. Ultimately, the conversation emphasizes the necessity of constructing a PDA or a context-free grammar to validate the acceptance of the language.
evinda
Gold Member
MHB
Messages
3,741
Reaction score
0
Hello again! (Wasntme)

I have to show that the language \left \{ w\epsilon \left \{ a,b \right \}^{*}:w=a^{m}b^{n},m\neq n \right \} 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
evinda said:
Hello again! (Wasntme)

I have to show that the language \left \{ w\epsilon \left \{ a,b \right \}^{*}:w=a^{m}b^{n},m\neq n \right \} 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."
 
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?
 
evinda said:
And how can I show it?Do I have to draw the pushdown automaton?

That would be my preferred way.
 
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:
 
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 $$\{0^n1^n \mid n \ge 0 \}$$ by final state:

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

$$\delta$$ consists of the following six instructions:

$$(p,0,Z,p,AZ)$$,
$$(p,0,A,p,AA)$$,
$$(p,\epsilon,Z,q,Z)$$,
$$(p,\epsilon,A,q,A)$$,
$$(q,1,A,q,\epsilon)$$, and
$$(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.
 
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.
 
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:
S\rightarrow axyb ,<br /> x\rightarrow ax ,<br /> y\rightarrow by ,<br /> x\rightarrow \varnothing ,<br /> y\rightarrow \varnothing<br />
Is it right?Or am I wrong? :confused: :o
 
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:
S\rightarrow axyb ,<br /> x\rightarrow ax ,<br /> y\rightarrow by ,<br /> x\rightarrow \varnothing ,<br /> y\rightarrow \varnothing<br />
Is it right?Or am I wrong? :confused: :o

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 :o 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:
S\rightarrow aXYb ,<br /> X\rightarrow aaX ,<br /> Y\rightarrow bY ,<br /> X\rightarrow \varnothing ,<br /> Y\rightarrow \varnothing<br />

or like that:
S\rightarrow aXYb ,<br /> X\rightarrow aX ,<br /> Y\rightarrow bbY ,<br /> X\rightarrow \varnothing ,<br /> Y\rightarrow \varnothing<br />

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

- - - Updated - - -
So,should it be like that:
S\rightarrow aXYb ,<br /> X\rightarrow aaX ,<br /> Y\rightarrow bY ,<br /> X\rightarrow \varnothing ,<br /> Y\rightarrow \varnothing<br />

or like that:
S\rightarrow aXYb ,<br /> X\rightarrow aX ,<br /> Y\rightarrow bbY ,<br /> X\rightarrow \varnothing ,<br /> Y\rightarrow \varnothing<br />

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? :o
 
  • #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! :o
- - - 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! :o

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? :o
[/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? :o

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: 104
  • #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: 93
  • #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![/color] (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: 102
  • #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! :o
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$.
 

Similar threads

Replies
11
Views
3K
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 9 ·
Replies
9
Views
8K