If M is a turing machine, we can construct a Context Sensitive Grammar G, and then check if the context sensitive grammar is context free, and finally context free grammar is regular or not in a way as described.
If A Context sensitive grammar G is Context Free, if contains only nonterminals on the left, and if it is regular as well, it contains nonterminals at the end of production rules.

- 23
- 1
- 3
-
Is this a copy paste homework question? – zero298 Feb 05 '19 at 21:27
-
@zero298 no, pardon my english if it seems so, i was reading a book by Harry R. Lewis and. Christos H. Papadimitriou, and i had a doubt. – Puneet Singh Feb 08 '19 at 18:38
2 Answers
There are Turing machines which accept regular languages, and there are Turing machines which accept languages that are not regular. Whether a language is regular or not is a semantic property - having to do with what's in the language, not with the form of the Turing machine - so, by Rice's theorem, it cannot be decided whether L(M) is regular.
Another way to see this is to assume it is decidable and then derive a contradiction. For instance, if this were a decidable problem, you could decide whether an arbitrary TM accepts any strings; that is, whether L(M) is the empty language. To do this, simply construct a new TM by replacing halt_accept with a new TM accepting a known non-regular language. This TM's language will be irregular - so our decider will halt_reject - if and only if the target TM made it to halt_accept on some input (in which case it will accept strings beginning with that prefix, and ending with any string in an irregular language). To make this construction really work, the new TM would probably need to have an extra symbol in the input alphabet to separate the first and second parts; otherwise the distinction between the prefix and the irregular suffix could be muddied.
Example: let M be the input TM over alphabet A and M' be any TM which accepts palindromes over B. Then our new TM will be over alphabet (A union B union {c}), where c is not an element of either A or B. This new TM will have the same initial state as M' and will use the same halt_accept and halt_reject states as M'. Any transition in M which moved into the halt_accept state of M will instead move to the initial state of M' and move the tape head to the symbol to the immediate right of c, whereas any transition in M which moved into the halt_reject state in M will instead move to the halt_reject state in M'. Our tape input to this new TM will look like xcy, where x is a string over A and y is a string over B. Suppose M accepts x. Then M would have moved into the halt_accept state of M. Therefore, our new TM would enter into the initial state of M' and begin looking at y. The new TM would accept on any palindrome y over B, an irregular language; and the language of strings xcy which end with any palindrome over B cannot be a regular language, unless no such strings are accepted. Since we know there are palindromes over alphabet B, the only way the language could be empty is if there were no strings x over A which caused M to enter halt_accept; that is, L(M) would have to be empty. Therefore:
- if our new TM is decided to be regular, we know M is empty
- if our new TM is decided not to be regular, we know M is non-empty
Therefore, we can decide whether M is empty if we can decide whether TMs accept regular languages or not. This assumes you accept that "L(M) is empty" is undecidable in the first place; otherwise, you could think of another construction for a language you do already know is undecidable.

- 27,682
- 3
- 38
- 73
-
I understand that any semantic property is undecidable, but what is wrong with my reasoning. We can construct an unrestrictred grammar from a turing machine, and then if that grammar contains single non-terminal on the left of production rules, its context free and if the right of production rules have a single non terminal at the end, it implies its regular as well ! – Puneet Singh Feb 08 '19 at 18:41
-
1@PuneetSingh That is true, however - you might get an unrestricted grammar that's not context-free or regular, but the language generated could still be context-free ir regular. All CFGs generate CFLs, but plenty of grammars that aren't CFGs do too. We deduce there is no correct computable function which constructs a CFG from an unrestricted grammar or prints "not a CFL". – Patrick87 Feb 08 '19 at 19:16
-
Thank you Patrick, i get the point now. My construction may be possible in certain cases, but not generally! – Puneet Singh Feb 08 '19 at 19:29
It sounds like the question you're asking is,
Is the following a decidable problem: given a Turing machine M, determine whether L(M) is regular.
The answer appears to be no: https://cs.stackexchange.com/a/85237

- 59,154
- 9
- 110
- 123
-
yeah, but what is wrong with the reasoning i made above. If that reasoning is flaw-less, it implies otherwise – Puneet Singh Feb 08 '19 at 18:43