Creating a diagram for a PDA that recognizes each L - diagram

Trying to understand PDAs, but don't really grasp how to draw them.
first of all, I don't really understand how a PDA would look different if the restrictions say that the #a, or #b, or #c would be "greater than zero" or "greater than or equal to zero." I drew the following PDA diagrams for each of the textbook questions they seem right enough to me. Just want a second hand look.
So the logic for my first PDA is that for every "a" input, there will be a multiple of four "a" moved onto the stack. When a "b" input is entered, every "a" from the stack will result in one empty string, clearing the stack.
For the second PDA I created a non deterministic PDA because there can be zero "a" or zero "b". Therefore for every even input of "bb" there will be no change to the stack since there can be an infinite number of "bb", but the "a" will be preserved on the stack because it will have to be called again after the "bb" if there are "a".

If I understand your diagrams correctly, they are not correct and seem to betray a basic misunderstanding of how PDAs work. Rather than try to work with you to understand your thought process in producing these, I will derive new PDAs and let you reconcile them to what you have attempted. I will not provide drawings but I will describe what the drawings would look like; I'll provide tables as these are easier to render.
1) L = {a^i b^j | i > 0, j = 4i + 2}
When you make any automaton, you are trying to find states and transitions. A good first place to start is to wonder about the initial state, since we know we'll need one. Is it the only one we need, or will we need more? Is it accepting? For this language, we can see that it is not accepting (since, if the initial state were accepting, the PDA would accept the empty string, which can't be in our language since we require i > 0). Since our language does contain strings, we know we need an accepting state so we know we need at least two states; call them q0 for the initial state and q1 for the other state we know we'll need. Now that we have a couple of states, we can turn out attention for a moment to the first transitions.
Now, we know we need to allow for some a's at the beginning of our strings. Indeed, we must require at least one a. Let us think for a moment about what this means. Suppose we add a transition from q0 back to q0 accepting a. If we don't put anything on the stack, we lose information about whether we have seen any a's or not. However, we do have a stack, and so we can remember what we need to know: that we have before seen an a. Therefore, we can add an ability to transition from q0 to q0 upon reading an a and record that fact upon our stack. We will later require the ability to check the stack to see if we have seen some a's. Now we can ask what we shall put on the stack.
We have some options here, and there are no right or wrong answers. What you choose will depend on what automaton formulation you're relying on and what your design goals are for the automaton. Yes, an automaton is designed in the same way as a real machine or a computer program. We want to make a design choice that obeys the rules of our formalism and that is simple and easy to work with. One approach is to add what we later are expecting to see corresponding to the symbol we have consumed; for each a we see now, we need to see four b's later; so we can add bbbb to the stack now, and later pop one b from the stack for each b read from input. This is convenient. Notice that when we read the first a, we can take care of the "+2" requirement by adding bbbbbb instead of bbbb, so long as we know when we are reading the first a - which we know by examining the stack.
Based on all of these considerations, we can produce a partial table for the PDA we have been designing, and then we can assess our progress and see where left we have to go:
q e S q' S'
--- --- --- --- ---
q0 a Z q0 bbbbbbZ
q0 a b q0 bbbbb
We use Z to represent the bottom of the stack. When we see the first a (we know it is the first because the stack is empty, i.e., the topmost symbol is the one representing the bottom of the stack) we add bbbbbb. Each successive a adds bbbb to the top of the stack (by replacing b with bbbbb).
Now we must consider how b's are to be handled. Can we process a b by looping from q0 to q0? A moment's thought should convince you that this is not a good idea. If we loop from q0 to q0 upon seeing a b, then we have no easy facility for preventing the PDA from accepting further a's. But this would result in a string that cannot possibly be in our desired language, since in our language no a's can come after a b. It seems therefore necessary that whatever transition accepts b's, not have as its target the state q0. We therefore choose q1 as the target of the transition under discussion. What shall be the source? So far, only q0 has been reached in our PDA, and we only have q0 and q1 to choose from. We have two choices now: either we provide a mechanism for transitioning from q0 to q1 without seeing a b, or we provide a mechanism for transitioning on a b. The first of these approaches requires indeterminism based on our previous design choices, so we might prefer the latter as being more explicit and easier to reason about. This leads to the following transition (added to our previous table):
q e S q' S'
--- --- --- --- ---
q0 a Z q0 bbbbbbZ
q0 a b q0 bbbbb
q0 b b q1 -
This transition says that when we see a b in q0 and we have seen a's before on the stack, transition to q1 and throw away the topmost stack symbol. Remember, we designed the stack in such a way that we should always throw away one b on the stack for each b we read in the input.
Now that we have arrived at state q1, a natural question to ask is whether this state should be accepting or not. The answer is that it must not be, otherwise we could accept a string without enough b's to clear its stack; that is, we would have j < 4i + 2. So we will need a new state, call it q2, and q1 will not be accepting. What shall we use q1 for? We can easily use it to read the remaining b's and pop from the stack by adding this transition:
q e S q' S'
--- --- --- --- ---
q0 a Z q0 bbbbbbZ
q0 a b q0 bbbbb
q0 b b q1 -
q1 b b q1 -
This fourth transition can be taken as long as we have b's to read and b's on the stack. There are three things that can happen during this process:
We run out of b's on the stack, but still have b's in the input
We run out of b's on the stack at the same time as we finish reading all b's in the input
We still have b's on the stack when the input is exhausted
Only in the second case should we accept, and we can reach the second case by repeated applications of the fourth transition. However, q1 is not accepting. Therefore, we will require a way to transition from q1 to an accepting state - we might as well call q2 this state - when we might be in it. If we are truly in that state, we require an epsilon transition when we see an empty stack in q1:
q e S q' S'
--- --- --- --- ---
q0 a Z q0 bbbbbbZ
q0 a b q0 bbbbb
q0 b b q1 -
q1 b b q1 -
q1 - Z q2 Z
Now, in q2, we might be in either case 1 or 2: the stack is empty, but do we have any more symbols to read? It turns out this is not problematic in the least since further input symbols will cause the PDA to crash immediately in state q2.
Second is left as an exercise.

Related

how to deal with this case in transition-based dependency parsing

I'm reading the "14.4 Transition-Based Dependency Parsing" part of this article, and have some questions about the execution process of the following case.
As described, the parser read the input buffer from the left to right, and leverage a stack structure to apply one operation choosing from left-arc, right-arc and shift. Each reduce operation(i.e. left-arc and right-arc) is applied on the top two elements of the stack, and parser can also choose shift to push the next unprocessed word in the input buffer into the stack.
I'm wondering how will the parser process the following case.
Assume that the input sequence consists of four words: a b c d, and the golden dependency structure is:
ROOT
|
b
|
c
|
d
|
a
, which means that b is the head of c and c is the dependent child of b, and so on.
I draw these dependencies on the paper, and confirm that this dependency tree is projective which satisfy the requirement of the parser model. However, I've failed to figure out the correct process for its dependency tree construction. According to the transition-based parser algorithm, it seems that I could only do the shift operation and finally get to the state with the stack of [ROOT, a, b, c, d]. What would be the next step of the parsing?

why push down automata need a initial stack symbol?

while defining a transition of CFG or type-2 grammer with PDA we need initial stack-symbol mostly denoted by Zo.
my doubt is why we need it because finally we are going to empty the stack at all....??
Pushdown automata need the initial stack symbol because each move is determined by the current input symbol and the one at the top of the stack. This leads to the reality that no move is possible if the stack is empty.
And yes the stack can be reduced to only the stack symbol. Consider...
L={ (a^n)(b^n) : n >= 0 }
I could push down a 0 for each a I read, which - btw - the first of which will be (q0, a, z), and then when I read my first b I pop 0s and push nothing back. I know that I'm done and the language is accepted when there's no input consumed and the stack symbol is atop the stack.
Notice in the transition function above the first move is determined by the first input and the stack symbol. Can you see how without it you'd never be able to start?

Automaton that recognizes a language without 3 consecutive zeros

I would create a finite state automaton that recognizes the language of strings of 0 and 1 that don't contain 3 consecutive zeros.
I tried to do the following automaton but isn't complete as, for example, it doesn't recognize the string: 1001110
How can I change it? For the rest, my reasoning to solve the exercise is that correct?
Thanks so much
i made this in paint so not looking nice but,try below automation.
Your starting state, q0, is a state that is not reached by reading a zero. As you correctly modeled in your automaton, from the state q0 you must allow the automaton to read up to two zeros, hence you need states q1 (reached by reading exactly one consecutive zero) and q2 (reached by reading exactly two consecutive zeros).
Whenever you read a 1 you will be in a state that was not reached by reading a zero.
Now a question is, how many states do you need?
It is permissible to have more than one end state in a finite automaton. In this case you must have more than one end state, because any time you read a 1 you must reach a state that permits two subsequent consecutive zeros to be read, whereas every time you read a zero you much reach a state that does not permit two subsequent consecutive zeros to be read, and your language has strings that end in zero as well as strings that end in 1.

drawing minmal DFA for the given regular expression

What is the direct and easy approach to draw minimal DFA, that accepts the same language as of given Regular Expression(RE).
I know it can be done by:
Regex ---to----► NFA ---to-----► DFA ---to-----► minimized DFA
But is there any shortcut way? like for (a+b)*ab
Regular Expression to DFA
Although there is NO algorithmic shortcut to draw DFA from a Regular Expression(RE) but a shortcut technique is possible by analysis not by derivation, it can save your time to draw a minimized dfa. But off-course the technique you can learn only by practice. I take your example to show my approach:
(a + b)*ab
First, think about the language of the regular expression. If its difficult to sate what is the language description at first attempt, then find what is the smallest possible strings can be generate in language then find second smallest.....
Keep memorized solution of some basic regular expressions. For example, I have written here some basic idea to writing left-linear and right-linear grammars directly from regular expression. Similarly you can write for construing minimized dfa.
In RE (a + b)*ab, the smallest possible string is ab because using (a + b)* one can generate NULL(^) string. Second smallest string can be either aab or bab. Now one thing we can easily notice about language is that any string in language of this RE always ends with ab (suffix), Whereas prefix can be any possible string consist of a and b including ^.
Also, if current symbol is a; then one possible chance is that next symbol would be a b and string end. Thus in dfa we required, a transition such that when ever a b symbol comes after symbol a, then it should be move to some of the final state in dfa.
Next, if a new symbol comes on final state then we should move to some non-final state because any symbol after b is possible only in middle of some string in language as all language string terminates with suffix 'ab'.
So with this knowledge at this stage we can draw an incomplete transition diagram like below:
--►(Q0)---a---►(Q1)---b----►((Qf))
Now at this point you need to understand: every state has some meaning for example
(Q0) means = Start state
(Q1) means = Last symbol was 'a', and with one more 'b' we can shift to a final state
(Qf) means = Last two symbols was 'ab'
Now think what happens if a symbol a comes on final state. Just more to state Q1 because this state means last symbol was a. (updated transition diagram)
--►(Q0)---a---►(Q1)---b----►((Qf))
▲-----a--------|
But suppose instead of symbol a a symbol b comes at final state. Then we should move from final state to some non-final state. In present transition graph in this situation we should make a move to initial state from final state Qf.(as again we need ab in string for acceptation)
--►(Q0)---a---►(Q1)---b----►((Qf))
▲ ▲-----a--------|
|----------------b--------|
This graph is still incomplete! because there is no outgoing edge for symbol a from Q1. And for symbol a on state Q1 a self loop is required because Q1 means last symbol was an a.
a-
||
▼|
--►(Q0)---a---►(Q1)---b----►((Qf))
▲ ▲-----a--------|
|----------------b--------|
Now I believe all possible out-going edges are present from Q1 & Qf in above graph. One missing edge is an out-going edge from Q0 for symbol b. And there must be a self loop at state Q0 because again we need a sequence of ab so that string can be accept. (from Q0 to Qf shift is possible with ab)
b- a-
|| ||
▼| ▼|
--►(Q0)---a---►(Q1)---b----►((Qf))
▲ ▲-----a--------|
|----------------b--------|
Now DFA is complete!
Off-course the method might look difficult at first few tries. But if you learn to draw this way you will observe improvement in your analytically skills. And you will find this method is quick and objective way to draw DFA.
* In the link I given, I described some more regular expressions, I would highly encourage you to learn them and try to make DFA for those regular expressions too.

What type of languages are accepted by a PDA in which stack size is limited?

What type(s) of languages are accepted by a PDA in which stack size is limited to, say 20 items?
In my view it should still be CFL, because there is a temporary memory to store.
A PDA with a stack limited to containing 20 items is equivalent to a DFA. Here's the proof.
Take any PDA-20, and you can make it into an equivalent DFA. Let's say the stack alphabet S where |S| = N. You also have the bottom-of-stack symbol Z. We imagine an additional symbol, -, which we can also have on the stack, which stands for "unused". The stack is now equivalent to a string of the form x = -* S* Z where |x| = 20, in all cases. Pushing onto the stack consists in replacing occurrences of -, whereas popping consists in replacing other symbols with -, in a LIFO manner. There are now (N+2)^20 possible configurations of the stack for any PDA-20. To construct the DFA, simply replicate each state of the DFA by this factor, and have transitions to states of the DFA reflect the new configuration of the stack. This way, the information contained in the configuration of the stack in the PDA-20 is contained in the current state of the DFA.
Take any DFA, and you can make it into an equivalent PDA-20. Simply don't use the stack, and you have a PDA-20 which accepts the same language as the DFA.
Just to illustrate the first part of the proof, consider a PDA-5 with states A, B, C, ..., Z, and a lot of transitions. Let's say the input alphabet is {0, 1}. Then there are 2^5 = 32 different stack configurations, say. The DFA equivalent to this PDA-5 might have states A1, B1, ..., Z1, A2, B2, ..., Z2, ..., A32, B32, ..., Z32, though it will have the same number of transitions as the original. If a transition in the original PDA-5 would have taken the stack from configuration #2 in state R to configuration #17 and the machine to state F, the DFA will go from state R2 to state F17.

Resources