开发者

linear grammar with unequal number of 0s and 1s

开发者 https://www.devze.com 2023-04-11 17:39 出处:网络
Is it possible to come up with a linear grammar with unequal number of 0s and 1s? Su开发者_StackOverflow中文版ch as 0100, 01100, 111,1,0, 100101001...

Is it possible to come up with a linear grammar with unequal number of 0s and 1s?

Su开发者_StackOverflow中文版ch as 0100, 01100, 111,1,0, 100101001...

I know there is a context-free grammar for this, but is there a linear grammar?

Thanks.


A grammar is regular if and only if it is either left regular or right regular. The left regular grammars are equivalent to the left linear grammars. The right regular grammars are equivalent to the right linear grammars. Therefore, if a regular grammar exists that generates the indicated language, then it is either right or left regular, and hence equivalent to either a left or right linear grammar.

edit1:

Note that there's no regular grammar generating the indicated language LUNEQ. To see this, consider the fact that LEQ = { w : na(w) = nb(w)} is the complement of LUNEQ. Because the regular languages are closed under complementation and LEQ is not a regular language, LUNEQ is not a regular language.

edit2:

I believe the pumping lemma for linear languages can be used to show that the indicated language LUNEQ is not linear. Here is what I've come up with. I'm fairly confident it's correct. My primary concern is that you were asked - presumably - for a linear language generating the indicated language; however, I came to the conclusion that there is no such grammar.

Assume LUNEQ is linear. By the pumping lemma for linear languages, there exists an n > 0 depending on LUNEQ such that for all zLUNEQ, z can be written uvwxy where:

  • |vx| > 0,
  • |uvxy| ≤ n, and
  • uviwxiyLUNEQ for all i ≥ 0.

Let n be the constant guaranteed be the pumping lemma. Consider the string

  • z = anb(n! + 2n)an

Since zLUNEQ, it can be decomposed into substrings uvwxy satisfying the constraints of the pumping lemma such that, for all i ≥ 0, the string

  • uviwxiy = a|u|ai|v|a(n - |u| - |v|)b(n! + 2n)a(n - |x| - |y|)ai|x|a|y|

is a member of LUNEQ. Since 1 ≤ |vx| ≤ n, |vx| divides n!. Hence, (n!|vx|-1 + 1) is a natural number. Setting i to (n!|vx|-1 + 1) gives the string

  • z' = uv(n!|vx|-1 + 1)wx(n!|vx|-1 + 1)y = a|u|a(n!|vx|-1 + 1)|v|a(n - |u| - |v|)b(n! + 2n)a(n - |x| - |y|)a(n!|vx|-1 + 1)|x|a|y|

Simplifying the pumped string gives us an equal number of a's and b's:

  • na(z') = 2n - |vx| + (n!|vx|-1 + 1)|vx| = 2n + n!

Since (2n + n!) is equivalent to the number of b's in the pumped string, z' ∉ LUNEQ. But this contradicts the assumption that LUNEQ is a linear language. Hence, LUNEQ is not a linear language.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号