4

For stack-oriented programming language, how many top-most items of the stack are needed to be accessible in order to be Turing complete?

Is it enough to be able to access just the top-most item? Two items? Three? Any item?

In the case of Forth, is it necessary to have rot, pick, roll? Why does rot operates with exactly top three items?

Ecir Hana
  • 270
  • 2
  • 7

1 Answers1

2

It depends on what kinds of things you can store on the stack.

If each item on the stack is of unbounded size, you can simulate a two-counter machine, which is Turing-complete. Therefore, in this case, you can achieve Turing-completeness with just the ability to access the top two items on the stack.

If items are bounded-size, restricting to access a bounded number of top-most items of the stack gives something equivalent in power to a PDA. (For instance, suppose all you can do is access the top 5 items of the stack, and use that together with a finite control to transition to a new state of the finite control and either push/pop. Then grouping the items into 5-tuples, we can build an equivalent machine where you only need to access the topmost item. That machine is a PDA.) Therefore, in this case, it's not Turing complete with access to any finite number of items at the top of the stack.

D.W.
  • 167,959
  • 22
  • 232
  • 500