News for hackers. Stuff that matters.
Re:What type of Machine is the C Preprocessor? by lisper on Monday January 27, 2014 @04:20PM (#7133308)
"What we are missing is the ability to re-enter old states."

That's deadly. Any machine with a finite number of states that cannot re-enter a state it has previously been in must necessarily halt on all input. That makes it strictly less powerful than even an FSM.

Re:What type of Machine is the C Preprocessor? by caf on Monday January 27, 2014 @06:29PM (#7134148)
It is worth noting that must necessarily halt on all input is quite a desirable property in a macro language evaluated at compile time.
Re:What type of Machine is the C Preprocessor? by gus_massa on Monday January 27, 2014 @06:48PM (#7134231)
On the other hand, in Lisp/Scheme/... language family you have a Turing complete language for macro language, Lisp/Scheme/... respectively. In those languages, macros are powerful and must be used with care. The advantage is that complex macros are easy to write.
Re:What type of Machine is the C Preprocessor? by lisper on Monday January 27, 2014 @07:44PM (#7134445)
That is arguable. All else being equal it might be true, but all else is not equal. The benefit of never having your compiler enter an infinite loop may not be worth the cost in terms of lost expressive power.
Re:What type of Machine is the C Preprocessor? by mtdewcmu on Tuesday January 28, 2014 @10:27AM (#7137575)
Has it been proven that the ability to write undecidable programs confers expressive power such that you can't have one without the other? It seems self-evident that running forever can't be useful, so you should be able to say WLOG that useful programs always halt. So the set of all useful programs is strictly smaller than the set of Turing machines. Is there a formal reason why Turing machines are desirable?
Re:What type of Machine is the C Preprocessor? by lisper on Tuesday January 28, 2014 @12:30PM (#7138375)
> Has it been proven that the ability to write undecidable programs confers expressive power such that you can't have one without the other?

Yes.

> It seems self-evident that running forever can't be useful

Really? Do you not think that it might be useful for, say, an operating system to run forever?

Re:What type of Machine is the C Preprocessor? by mtdewcmu on Tuesday January 28, 2014 @09:45PM (#7141503)
>> Has it been proven that the ability to write undecidable programs confers expressive power such that you can't have one without the other?

Yes.

Can you provide a reference?

>> It seems self-evident that running forever can't be useful

Really? Do you not think that it might be useful for, say, an operating system to run forever?

It's nice when the OS has the option of shutting down deterministically.

Re:What type of Machine is the C Preprocessor? by caf on Wednesday January 29, 2014 @12:06AM (#7142035)
Do you think it is useful to implement an operating system entirely at compile-time, in an implementation which uses separate compile and run phases?
Re:What type of Machine is the C Preprocessor? by mtdewcmu on Wednesday January 29, 2014 @03:50PM (#7146765)
I'm not sure I follow what you're talking about. Operating Systems are tangential to the point, though. When I said all useful programs halt, the kinds of programs I meant are the kind used to prove things about computation. Those programs are simplified abstractions of real programs, and they generally compute one result and then halt (if they halt). Being simple makes those programs easier to use in proofs than real programs. However, the proofs still generalize to real programs; a real-world program with multiple functions is equivalent to several single-function programs glued together together.

So my point in saying that all useful programs halt was really to argue that all useful programs must have the constraint that they their behavior is always predictable, or controllable, in some sense. In a trivial way, computers are always predictable, but Turing proved that there are cases where it's impossible to predict the eventual outcome of a program in advance, i.e., the halting problem. In precise terms, the outcome (halt/not halt) of some programs is said to be undecidable or uncomputable. Undecidability is a hallmark of Turing machines. But since real programs are written by humans, who can't solve undecidable problems, real programs will never be able to gain any advantage from undecidable behavior.

Re:What type of Machine is the C Preprocessor? by caf on Wednesday January 29, 2014 @12:05AM (#7142032)
It's still a desirable property, it's just that it's a property in essential tension with another desirable property.
Re:What type of Machine is the C Preprocessor? by ithinkso on Monday January 27, 2014 @08:00PM (#7134552)
It is not that simple. I have a little problem with finding comprehensive definition of Turing completeness - in order to decide if certain machine is turing complete does one have to prove that it can also simulate infinite, not halting algorithms?

If yes, then not being able to re-enter old states disqualifies C preprocessor as a turing complete machine by considering simple machine that goes left and right till the end of time. However, is it really an algorithm? If there is no output one could simply replace that with just empty machine that halts for sure, therefore it can be simulated in C preprocessor.

On the other hand, if this is not requirement then we know that every algorithm we have to simulate to prove turing completeness halts eventually, there is no ability to re-enter old states but if algorithm halts we could just add enough more states (finitely many) that allows it to finish.

Re:What type of Machine is the C Preprocessor? by throwaway82740 on Monday January 27, 2014 @09:02PM (#7134833)
I would look at it a slightly different way. It's not that the definition of Turing completeness explicitly says that a language must be able to simulate "infinite" algorithms. It's that it must be able simulate what a Turing machine can do. Turing machines are quite capable of running non-halting algorithms, so the language must be able to as well.

Contrived example: One algorithm a Turing machine could perform would be to write the characters "TM" every two cells on its entire tape. The tape is unbounded, so this algorithm is, colloquially speaking, infinite. Clearly, you cannot simulate this with a halting machine like the C preprocessor.

Re:What type of Machine is the C Preprocessor? by ithinkso on Monday January 27, 2014 @09:48PM (#7134994)
This is exactly the problem I was talking about. In every definition I've read there was strict condition that set of all possible states Q is non-empty (and finite). But there is difference in definition of set of final states. In [1] there is a comparison - in columns labeled "Peter Linz" and "Wikipedia" F is defined as subset of Q. This implies that it also could be empty, although in column labeled "Michael Sipser" there is a special state q_accept that explicitly exist in Q, therefore F is not-empty. Unfortunately there is no information if q_accept has to be reachable from start state.

But consider this: How one could say that this machine is actually writing "TM" every two cells? If you investigate tape states while machine is still running it might change (on meta-level you my expect that this is actually true but you might for example make some bug that you're not aware of). The only way to be able to see that "TM" has been written is after the machine halts.

[1] http://www.cis.upenn.edu/~matuszek/cit596-2012/NewPages/turi...

Re:What type of Machine is the C Preprocessor? by lisper on Monday January 27, 2014 @09:29PM (#7134926)
> I have a little problem with finding comprehensive definition of Turing completeness

http://lmgtfy.com/?q=turing+completeness

> in order to decide if certain machine is turing complete does one have to prove that it can also simulate infinite, not halting algorithms?

Yes.

Re:What type of Machine is the C Preprocessor? by ithinkso on Monday January 27, 2014 @09:59PM (#7135033)
> Yes

And you're saying this based on what? Thanks for googling this for me, although the key-word was "comprehensive" not any definition.

Re:What type of Machine is the C Preprocessor? by lisper on Monday January 27, 2014 @10:14PM (#7135087)
Ah, then what you're looking for is a comprehensive description, not a comprehensive definition. (I gather your native language is not English?) For that you will have to read a book on computability theory (at least -- it depends on just how "comprehensive" you want to get).

> And you're saying this based on what?

Based on the definition of Turing-completeness, and the (trivial) fact that there exist Turing machines that do not halt. A Turing-complete system is, by definition, a system that can emulate any Turing machine. Because some Turing machines don't halt, any system that never halts cannot emulate a Turing machine that does not halt, and so by definition is not Turing-complete.

Re:What type of Machine is the C Preprocessor? by ithinkso on Monday January 27, 2014 @10:54PM (#7135212)
You're right, maybe I do not understand because of different meaning of those words in english, which is not, in fact, my native language, but let me try explain you what I think.

From wikipedia we read:

Turing completeness

A computational system that can compute every Turing-computable function is called Turing complete (or Turing powerful). Alternatively, such a system is one that can simulate a universal Turing machine.

From the first part I think compute means that from some input A there is output B. It is later explained in 'computable function' article:

Each computable function f takes a fixed, finite number of natural numbers as arguments. Note that the functions are partial in general, i.e. they may not be defined for every possible choice of input. If a computable function is defined for a certain input, then it returns a single natural number as output (this output can be interpreted as a list of numbers using a pairing function).

So if computable function is returning something that means it halts. We are able to compute every halting algorithm in preprocessor hence it is turing complete.

Second part of this definitions says that one has to simulate turing machine (and uses the word 'alternatively' so basically it has to be the same but I can go anyway). I think that 'simulate' in this context mean 'producing same output' rather than 'doing step by step the same'. Internal tape states at certain point in time should not matter because while running they might change (or if they matter we could just return list of pair {state,time} at the end).

There is no doubt that non-halting turing machines exists but I'm not sure if that apply to this particular problem anyhow since they are not computing anything.

Re:What type of Machine is the C Preprocessor? by chriswarbo on Tuesday January 28, 2014 @06:33AM (#7136496)
> Second part of this definitions says that one has to simulate turing machine (and uses the word 'alternatively' so basically it has to be the same but I can go anyway). I think that 'simulate' in this context mean 'producing same output' rather than 'doing step by step the same'. Internal tape states at certain point in time should not matter because while running they might change (or if they matter we could just return list of pair {state,time} at the end).

> There is no doubt that non-halting turing machines exists but I'm not sure if that apply to this particular problem anyhow since they are not computing anything.

The exact steps of a Turing Machine don't need to be emulated exactly, only the output needs to be the same. However, it's trivial to turn your back-and-forth example into a Turing-computable function:

Let's call your back-and-forth machine "M1" and, without loss of generality, let's say it starts at cell 0, moves to cell 1, then back to cell 0. We can then define a new machine "M2" which outputs a list of M1's head positions at each step, based on a direct simulation of M1. In other words, M2 will output 01010101010101.... forever, never halting.

The C preprocessor cannot simulate M2, precisely because it cannot simulate M1.

Also, note that we don't need to wait for a Turing machine to halt before we read its output. There are many useful programs which should not halt, like servers and operating systems.

Re:What type of Machine is the C Preprocessor? by lisper on Tuesday January 28, 2014 @02:18AM (#7135828)
> I think that 'simulate' in this context mean 'producing same output' rather than 'doing step by step the same'.

That is correct. But "producing the same output" means not halting when a TM does not halt. Otherwise it is not the same output.

But halting is actually a red herring in this case. Because the number of states that a cpp-machine can visit is finite, it is easy to construct a TM (or even an FSM) that halts on all inputs but produces a different output than any given cpp machine for some input. For example, a TM can do bignum arithmetic that halts on all inputs, but for some input it must be the case that such a TM will produce a different output than any given FSM, and hence any given cpp-machine, since cpp-machines are strictly less powerful than FSMs.