2

Like think of the function $f\colon \{ 0,1\}^* \rightarrow \{0,1\}^*$ which maps a binary string string $x$ to say a string of $0$s of length $\vert x \vert ^2$ whre $\vert x \vert$ is the length of the input string.

This to my mind looks like a work that can be done using only a linear amount of space on the work tape. All you really need to do is just have a counter to count the length of the input string in one pass and then you know what $\vert x \vert$ is and then squaring it is a constant time process and then just output those many $0$s.

Is my intutiion correct? How is one supposed to formally prove such a space-bound on the working of a (deterministic Turing Machine) DTM? Can someone kindly show how to write this up formally?

Yuval Filmus
  • 276,994
  • 27
  • 311
  • 503
user6818
  • 1,135
  • 8
  • 13

1 Answers1

1

Perhaps the simplest way to show that a certain task can be done with small space is writing C-like pseudocode for it. If you are only using a constant number of variables, and each variable is exponentially bounded in terms of the input length (i.e. $|x| = O(k^n)$ for fixed $k$), then the resulting computation uses at most linear space. You can use the fact that addition, multiplication and division can be done in linear space ($O(n)$), as well as operations like determining the input length.

As an example, here is pseudocode for your algorithm:

f(x) {
  l = |x|;
  y = l * l;
  for i from 1 to y do:
    output 0;
}

The variables here are $l,y,i$ ($x$ is on the input tape so doesn't count). All operations are in linear space (as long as the inputs are small enough), $l \leq n$ and $y,i \leq n^2$, so the algorithm uses linear space.

If the bounds on the variables are polynomial ($O(n^k)$) rather than exponential ($O(k^n)$), then the resulting program is logspace (uses $O(\log n)$ space); all operations mentioned can be implemented in logspace. Indeed, since the bounds in your case are polynomial, your algorithm is logspace; the fact that the output is larger doesn't matter, since we only count space on the work tape.

Yuval Filmus
  • 276,994
  • 27
  • 311
  • 503
  • I am not getting you. (1) What is $k$ and $n$ for you and what in the DTM corresponds to that? (2) As a pseudocode I can see how the space constraint is counted but I have no clue what is the DTM equivalent for what your pseudocode does! I can't see a way to go back and forth between algorithmic thinking and DTM implementation - and its there that the work-tape constraints have to be implemented (3) I am not familiar with this idea that addition, multiplication and division can be done in linear space. – user6818 Feb 03 '15 at 02:27
  • BTW, I am a complete newcomer to this theory! So kindly excuse my elementary questions. Its great that a renowned expert like you is helping me! – user6818 Feb 03 '15 at 02:28
  • (1) $n$ is the input size (in bits), and $k$ is an arbitrary constant. Any will do. (2) This is usually swept under the rug, though you're right that you can only do that after having been convinced that this conversion could potentially be done. Perhaps you can start with implementing simple algorithms like incrementing a counter. (3) This is not an idea but algorithms that use only linear space (or less) to add, multiply and divide. I think the "high school" algorithms are good enough for this purpose. – Yuval Filmus Feb 03 '15 at 03:32
  • How do you implement a "counter" in DTM? As in how do you count the length of the arbitrary string of 0,1s that is being given as entries on the input tape? [...I guess the write-up here is what explains how to add (and hence multiply and power-raise ?) two integers in log -space - http://jeapostrophe.github.io/2013-10-29-tmadd-post.html - right? ...] – user6818 Feb 03 '15 at 03:52
  • This is getting too specific. There must be some textbook with a "hands-on" approach for Turing machines, though I'm not aware of any. You're right to worry about these matters, but since the details are tedious, one usually just uses one's intuition on what can be done using which resources. – Yuval Filmus Feb 03 '15 at 03:54
  • I have experience with graduate level algorithm writing - recently did that - but I don't know how to specify a Turing Machine procedure to implement anything - and isn't that the kind of thing that is required do kind of stuff as asked here - http://cs.stackexchange.com/questions/11588/proving-language-in-space-complexity - may be you can type in a complete answer to substitute for your comments there...] – user6818 Feb 03 '15 at 03:54
  • Nobody implements Turing machines any more, and for a reason. It's too tedious. If you really care for it, you can write a compiler from C to Turing machines, but that would be extremely tedious. You'll just have to work it out yourself. – Yuval Filmus Feb 03 '15 at 03:55
  • But isn't specifying a Turing Machine procedure is what is required to answer the question that has been asked in the other stackexchange link that I posted? What else constitutes an answer when asked to show if a certain language is or is not a member of a complexity class? – user6818 Feb 03 '15 at 03:57
  • An informal argument. It's the same with all mathematical proofs - you don't give a formal argument in some formal system. You give a convincing argument, convincing according to the conventions of the area. The conventions of theoretical computer science don't involve stating Turing machines, since it's too tedious and unnecessary. Just like we all believe that informal proofs can be formalized in principle, though in practice it's too tedious, just so we believe that pseudocode can be converted to formal computation models, though in practice it's too bothersome to actually work it out. – Yuval Filmus Feb 03 '15 at 04:00
  • Thanks for the insights. I have years of experience with writing mathematics proofs but this TM proofs are a new thing to me. Can you kindly update your answer in this link to make it complete? http://cs.stackexchange.com/questions/11588/proving-language-in-space-complexity (that would be a kind help and can serve as a model as to how to write such proofs) – user6818 Feb 03 '15 at 04:08
  • The accepted answer there shows what constitutes a proof in this case. It would be quite a waste of time for me or anybody else to actually convert this into a Turing machine. You should never be writing Turing machines in full. I encourage you to implement very simple algorithm in full just to get the hang of it. Doing anything more is like compiling a program to assembly code manually, only worse. – Yuval Filmus Feb 03 '15 at 04:12
  • Thanks a LOT for this very insightful discussion! If I succeed in penetrating this subject a lot of the credit shall be yours! (...I started on theoretical CS over the last ~5 months...) – user6818 Feb 03 '15 at 06:24