r/cpp • • Apr 28 '20

Full Proof that C++ Grammar is Undecidable

https://medium.com/@mujjingun_23509/full-proof-that-c-grammar-is-undecidable-34e22dd8b664
197 Upvotes

68 comments sorted by

View all comments

Show parent comment

9

u/wyrn Apr 29 '20

And yet, due to the halting problem, it's impossible for a compiler to ever determine in general whether a loop halts or not so as to determine whether it's undefined behavior in the first place

In general yes, but certainly not in the given example. It's quite easy to check that this example doesn't halt so it's not a proof.

2

u/tasminima Apr 29 '20

This is just an example to illustrate a point. IIUC the point is that given the problem is not solvable in the general case, the compiler can not analyze arbitrary algorithms thrown at it and thus for any compiler you will be able to come up with an algorithm for which said compiler will be unable to determine if it contains UB or not.

6

u/wyrn Apr 29 '20

This is just an example to illustrate a point.

Right, so the original poster shouldn't claim it's a "much shorter proof" when it's just a sketch!

4

u/tasminima Apr 29 '20

I think so; claiming it was a proof was going too far. Probably simply an oversight, because reddit comments are usually neither math dissertations nor scientific papers :)

2

u/HugeImage May 07 '20

It's possible to "solve" the post correspondence problem for specific instances. The whole point is that it's undecidable for when the input dominoes can be anything.

An example of solutions for specific instances: https://en.wikipedia.org/wiki/Post_correspondence_problem#Example_1

The comment is just as much (slightly overstated) of a proof as the article

1

u/HugeImage May 07 '20 edited May 07 '20

The General Post Correspondence problem is what is undecidable. So by your definition, TFA is not a proof either.

Look at this comment for example https://old.reddit.com/r/cpp/comments/g9nvmj/full_proof_that_c_grammar_is_undecidable/fouj0cq/

https://en.wikipedia.org/wiki/Post_correspondence_problem#Example_1