16

This was a homework assignment problem which I know I have incorrectly answered. I gave:

S -> ''

meaning that S yields the empty string. I know that the empty set and empty string are not the same. According to my professor, the answer is:

S -> S

Now, that answer seems strange to me:

  1. It will never terminate.
  2. It isn't so much a language as the absence of one.

I understand from a strictly mathematical standpoint, I'm not going to get anywhere with number two. However, is it required for a language to terminate? Having a language that CAN go on forever sounds okay, but one that never will terminate sounds wrong enough that I thought I'd ask if anyone knows if that's a language requirement or not.

Levi Morrison
  • 19,116
  • 7
  • 65
  • 85
  • 1
    I think this question would be better suited to cstheory.stackexchange.com. – jwodder Sep 26 '11 at 17:17
  • S := S is one correct answer. Clearly infinitely many grammars generate the empty language. What part of the definition of grammar does this grammar violate? None... – Patrick87 Sep 26 '11 at 18:06
  • @Patrick87 the part I am hoping exists that states that it must be able to terminate? That's the whole premise of the question! – Levi Morrison Sep 26 '11 at 18:10
  • 1
    Sorry, I misunderstood. So yeah, there is no such requirement, unfortunately. A necessary and sufficient condition equivalent to "there must be a way to terminate" is "grammars define non-empty languages". – Patrick87 Sep 26 '11 at 18:45
  • 2
    @jwodder cstheory.stackexchange.com doesnt cover this kind of problem (research level only) – jfisk Dec 12 '11 at 03:06

1 Answers1

16

From the Formal Grammar Wikipedia page:

the language of G, denoted as L(G), is defined as all those sentences that can be derived in a finite number of steps from the start symbol S.

Starting with S, applying the production rule once to S gives S. Applying the rule twice gives S. By induction, applying the rule any finite number still gives S. Since no sentences can be derived in a finite number of steps, the language is empty, so your professor is correct.

Alternative ways to define a grammar that accepts the empty set are L(G) = {} (the language is empty) or P = {} (the set of production rules is empty).

Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
  • You aren't required to accept an answer that you don't feel answers the question. If you want better quality answers you could try a bounty. – Mark Byers Sep 27 '11 at 15:04
  • 1
    The only bad thing about this answer is that it flounders a little with irrelevant information. The answer is absolutely right: your professor is unambiguously correct, and his is an unambiguous set of productions for generating the empty language. Your accepting or failing to accept this answer won't change mathematics. – Patrick87 Sep 30 '11 at 13:07
  • @Levi: He gave you a better answer: The empty grammar (i.e. no production rules at all). – Nemo Sep 30 '11 at 15:53
  • The key: "Since no [strings] can be derived in a *finite* number of steps the language is empty[...]" My natural inclination (and that of my peers) was to try to continually re-substitute and try again, meaning we forget the finite aspect of the problem. – Levi Morrison May 04 '18 at 18:41