3

I have to explain how a 2-PDA works and then write a program (in Delphi) which simulates a 2-PDA step by step for the language $L = \{w\$w\ |\ w ∈ \{0,1\}^n\ with\ n>0\}$. So far, so good.

Now I know that a 2-PDA works with two stacks and is equivalent to a Turing Machine. It reads from an input tape and can save the current digit in either the first or the second stack. How can I decide in which stack the digit is read and/or saved? Especially since it's a computer program that should deal with that step.

Since it's equivalent to a Turing Machine, I get that one stack can deal with the left side and the other with the right side of the input. However, this is not really enough information for me to write a programm that simulates it. So how does the 2-PDA read the word, for instance, 01001$01001 from language $L$. Where does it begin? How does it accept the word?

I know, so many questions, I don't want to have them answered all in much detail but the most important thing is just how it works.

babou
  • 19,445
  • 40
  • 76
Tim Lâm
  • 33
  • 1
  • 5
  • 1
    Your question is unclear. Do you want to understand how the 2-PDA works, in particular for the problem you are given, or do you ask how it simulates a Turing Machine (TM). A 2-PDA in general will simply read input left to right from the input tape and act on two stacks instead of one. for each transition. Acceptance can be by accepting states, though variations are possible as usual. A PDA does not have to save input in a stack. It stores in the stack(s) whatever is needed: Stack(s) and input alphabets can be unrelated (as for standard PDA). – babou Apr 30 '15 at 10:22
  • Duplicate? Or this? Anyway, just follow the definition; it's not too different from implementing PDAs. – Raphael Apr 30 '15 at 12:23
  • @babou I wanted to understand how a 2-PDA works so that I am able to create one because I couldn't really figure it out. Thanks for your comment, it really helped :)

    @ Raphael I think it is not a duplicate because the other question dealt with a PDA that can move its reading head in both directions. I was talking about a PDA with two stacks.

    – Tim Lâm Apr 30 '15 at 13:53
  • Do you still need help. If not, you can try to answer your own question, and describe the way the 2-PDA can accept this language. The idea takes 2 or 3 lines at most. – babou Apr 30 '15 at 14:55

1 Answers1

2

To write a program that simulates a 2-PDA (which will be able to process any transition function $\delta$, not just a particular language) what you need to do is to implement a stack class, with just the operations that it is allowed to have. The simulator is essentially a loop that keeps track of the current state of $\delta$, which has to be stored in a suitable way, and of the current input symbol. You will receive as input the encoding of a function, and the input string.

As for the specific language at hand: the $\$$ in the middle actually makes it quite easy to design a transition function for this language. Without it, you would have a more difficult (and more interesting) problem. Just push symbols into one of the stacks and wait for the $\$$ to come up. You can then start using the other stack for the second half of the input string. Pop them both together. If in the process all symbols match, and in the end both stacks are empty, accept.

As you can see, we won't necessarily use the two stacks as if they stood for the content of the tape at each side of the head of a Turing machine.

André Souza Lemos
  • 3,276
  • 1
  • 14
  • 30
  • Okay I save all the digits from the left of the $$$ and save them to the first stack. When I reach the $$$, I save all the digits on the right to the second stack. Now how do I "pop them both together"? Furthermore, how would the syntax look like? With normal PDAs, I note it as something like this: q1, (input digit) → q1, (stack digit), (new stack digit) How do I tell it to store it in the second stack? – Tim Lâm May 03 '15 at 16:37
  • "Together" in "pop them both together" does not mean simultaneously. It's just that the transition function must make sure that, in the popping out phase, the symbols that are popped from the two stacks (one after the other) are equal. As to your second question, the two stacks have different names. A transition will name the stack it is changing. – André Souza Lemos May 03 '15 at 18:08
  • Could you elaborate more on the popping out phase? As far as I knew, the PDA reads the word and at the end of the word, it stops. If the stack is empty or it is in its final state, the word is accepted. Now how do you pop all of the digits in the stack out? Is this a process designed for the 2-PDA or do you just have another transition at the empty word and pop the stacks out then? And then just check if they're the same? – Tim Lâm May 04 '15 at 21:26
  • The 2-PDA can transition without consuming symbols from the input. I suggest that you look for a good textbook on formal languages, one that covers this topic in a way that suits your style of learning. – André Souza Lemos May 04 '15 at 21:49
  • I got it working almost. Now last step is the popping out phase. For a computer program, could I just check the content of the two stacks and if they are the same, accept the word? Or is there any formal criteria I need to regard? – Tim Lâm May 10 '15 at 13:04
  • If you are simulating the 2-PDA, your program should be like a small virtual machine that behaves exactly like a generic pushdown automaton with 2 stacks, from start to finish. – André Souza Lemos May 10 '15 at 13:28
  • Okay then how does the 2-PDA do it? Unfortunately, I did not find any helpful literature about just that issue. Do you check both stacks at one transition? Then you could do q2, ε, 0, 0 → q2, ε, ε which would mean: When it is in the state q2 and there is no input and both stacks have a zero on top, delete both zeros and read the next symbols and so on. Does this work? – Tim Lâm May 10 '15 at 13:40
  • The key word here is generic. Check this out: http://webber-labs.com/fl.html. There, you will find the source code for a few simulators. Maybe that will help. – André Souza Lemos May 10 '15 at 13:48