Describe the language generated by this context-free grammar









up vote
1
down vote

favorite












I have the following grammar,



  1. S -> Sb

  2. S -> aaSb

  3. S -> b

The typical derivations in this grammar are
S => Sb => [aaSb]b => [aa[b]b]b => aabbb for n = 1
S => Sb => [aaSb]b => [aa[aaSb]b]b => [aa[aabb]b]b => aaaabbbb for n = 2



Edit:
So I claimed that this grammar generates the language
L = a^(2n)b^(n+2) : n >= 1



I am pretty sure that my a goes a^(2n) since there's two a before S, but what about b. There is no lambda here so my n goes from n >= 1?.



Edit:
b^(n+1) and b^(2n+1) are both wrong assumptions because the grammar can derive a string aaaaaabbbbb if n = 3.

I modified my b to be b^(n+2).
so that L becomes L = a^(2n)b^(n+2) : n >= 1










share|improve this question























  • Maybe this is new to me, but is this a software programming question?
    – stealththeninja
    Nov 9 at 2:31










  • Not really, this is more like Computer Science question.
    – Storage Lenovo
    Nov 9 at 2:35










  • The grammar can produce aaaaaabbbbb which doesn't match the form you're proposing. (I'm pretty sure a CFG can't produce a language with an exponential number of symbols, though I can't prove that in this comment.)
    – David Maze
    Nov 9 at 3:04










  • You are right the grammar produces aaaaaabbbbb if n = 3 only if b is b^(n+2). So my assumption that b^(2n) or b^(2n+1) is wrong.
    – Storage Lenovo
    Nov 9 at 3:15











  • Production 1 means that you can add an arbitrary number of bs at the end. That makes an equality relationship pretty unlikely.
    – rici
    Nov 9 at 4:51














up vote
1
down vote

favorite












I have the following grammar,



  1. S -> Sb

  2. S -> aaSb

  3. S -> b

The typical derivations in this grammar are
S => Sb => [aaSb]b => [aa[b]b]b => aabbb for n = 1
S => Sb => [aaSb]b => [aa[aaSb]b]b => [aa[aabb]b]b => aaaabbbb for n = 2



Edit:
So I claimed that this grammar generates the language
L = a^(2n)b^(n+2) : n >= 1



I am pretty sure that my a goes a^(2n) since there's two a before S, but what about b. There is no lambda here so my n goes from n >= 1?.



Edit:
b^(n+1) and b^(2n+1) are both wrong assumptions because the grammar can derive a string aaaaaabbbbb if n = 3.

I modified my b to be b^(n+2).
so that L becomes L = a^(2n)b^(n+2) : n >= 1










share|improve this question























  • Maybe this is new to me, but is this a software programming question?
    – stealththeninja
    Nov 9 at 2:31










  • Not really, this is more like Computer Science question.
    – Storage Lenovo
    Nov 9 at 2:35










  • The grammar can produce aaaaaabbbbb which doesn't match the form you're proposing. (I'm pretty sure a CFG can't produce a language with an exponential number of symbols, though I can't prove that in this comment.)
    – David Maze
    Nov 9 at 3:04










  • You are right the grammar produces aaaaaabbbbb if n = 3 only if b is b^(n+2). So my assumption that b^(2n) or b^(2n+1) is wrong.
    – Storage Lenovo
    Nov 9 at 3:15











  • Production 1 means that you can add an arbitrary number of bs at the end. That makes an equality relationship pretty unlikely.
    – rici
    Nov 9 at 4:51












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have the following grammar,



  1. S -> Sb

  2. S -> aaSb

  3. S -> b

The typical derivations in this grammar are
S => Sb => [aaSb]b => [aa[b]b]b => aabbb for n = 1
S => Sb => [aaSb]b => [aa[aaSb]b]b => [aa[aabb]b]b => aaaabbbb for n = 2



Edit:
So I claimed that this grammar generates the language
L = a^(2n)b^(n+2) : n >= 1



I am pretty sure that my a goes a^(2n) since there's two a before S, but what about b. There is no lambda here so my n goes from n >= 1?.



Edit:
b^(n+1) and b^(2n+1) are both wrong assumptions because the grammar can derive a string aaaaaabbbbb if n = 3.

I modified my b to be b^(n+2).
so that L becomes L = a^(2n)b^(n+2) : n >= 1










share|improve this question















I have the following grammar,



  1. S -> Sb

  2. S -> aaSb

  3. S -> b

The typical derivations in this grammar are
S => Sb => [aaSb]b => [aa[b]b]b => aabbb for n = 1
S => Sb => [aaSb]b => [aa[aaSb]b]b => [aa[aabb]b]b => aaaabbbb for n = 2



Edit:
So I claimed that this grammar generates the language
L = a^(2n)b^(n+2) : n >= 1



I am pretty sure that my a goes a^(2n) since there's two a before S, but what about b. There is no lambda here so my n goes from n >= 1?.



Edit:
b^(n+1) and b^(2n+1) are both wrong assumptions because the grammar can derive a string aaaaaabbbbb if n = 3.

I modified my b to be b^(n+2).
so that L becomes L = a^(2n)b^(n+2) : n >= 1







context-free-grammar regular-language formal-languages context-free-language






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 6:51

























asked Nov 9 at 2:30









Storage Lenovo

153




153











  • Maybe this is new to me, but is this a software programming question?
    – stealththeninja
    Nov 9 at 2:31










  • Not really, this is more like Computer Science question.
    – Storage Lenovo
    Nov 9 at 2:35










  • The grammar can produce aaaaaabbbbb which doesn't match the form you're proposing. (I'm pretty sure a CFG can't produce a language with an exponential number of symbols, though I can't prove that in this comment.)
    – David Maze
    Nov 9 at 3:04










  • You are right the grammar produces aaaaaabbbbb if n = 3 only if b is b^(n+2). So my assumption that b^(2n) or b^(2n+1) is wrong.
    – Storage Lenovo
    Nov 9 at 3:15











  • Production 1 means that you can add an arbitrary number of bs at the end. That makes an equality relationship pretty unlikely.
    – rici
    Nov 9 at 4:51
















  • Maybe this is new to me, but is this a software programming question?
    – stealththeninja
    Nov 9 at 2:31










  • Not really, this is more like Computer Science question.
    – Storage Lenovo
    Nov 9 at 2:35










  • The grammar can produce aaaaaabbbbb which doesn't match the form you're proposing. (I'm pretty sure a CFG can't produce a language with an exponential number of symbols, though I can't prove that in this comment.)
    – David Maze
    Nov 9 at 3:04










  • You are right the grammar produces aaaaaabbbbb if n = 3 only if b is b^(n+2). So my assumption that b^(2n) or b^(2n+1) is wrong.
    – Storage Lenovo
    Nov 9 at 3:15











  • Production 1 means that you can add an arbitrary number of bs at the end. That makes an equality relationship pretty unlikely.
    – rici
    Nov 9 at 4:51















Maybe this is new to me, but is this a software programming question?
– stealththeninja
Nov 9 at 2:31




Maybe this is new to me, but is this a software programming question?
– stealththeninja
Nov 9 at 2:31












Not really, this is more like Computer Science question.
– Storage Lenovo
Nov 9 at 2:35




Not really, this is more like Computer Science question.
– Storage Lenovo
Nov 9 at 2:35












The grammar can produce aaaaaabbbbb which doesn't match the form you're proposing. (I'm pretty sure a CFG can't produce a language with an exponential number of symbols, though I can't prove that in this comment.)
– David Maze
Nov 9 at 3:04




The grammar can produce aaaaaabbbbb which doesn't match the form you're proposing. (I'm pretty sure a CFG can't produce a language with an exponential number of symbols, though I can't prove that in this comment.)
– David Maze
Nov 9 at 3:04












You are right the grammar produces aaaaaabbbbb if n = 3 only if b is b^(n+2). So my assumption that b^(2n) or b^(2n+1) is wrong.
– Storage Lenovo
Nov 9 at 3:15





You are right the grammar produces aaaaaabbbbb if n = 3 only if b is b^(n+2). So my assumption that b^(2n) or b^(2n+1) is wrong.
– Storage Lenovo
Nov 9 at 3:15













Production 1 means that you can add an arbitrary number of bs at the end. That makes an equality relationship pretty unlikely.
– rici
Nov 9 at 4:51




Production 1 means that you can add an arbitrary number of bs at the end. That makes an equality relationship pretty unlikely.
– rici
Nov 9 at 4:51












2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










The language generated by this grammar is a^(2n) b^(n+m+1) where n and m are natural numbers. To show this, (a) we see that any string derived using the grammar's productions matches the above and (b) any string matching the above can be derived using the grammar's productions.



(a) The grammar can and must use rule (3) exactly once. This gives the +1 in the number of bs. Execution of rule (2) can happen some number of times n, putting 2n as on the front and n bs on the back, hence the 2n and n terms. Rule (1) can be executed any number of times m, hence the term.



(b) Given a string a^(2n) b^(n+m+1) for natural numbers n and m: use rule (1) a number of times equal to m; then, use rule (2) a number of times equal to n; then, user rule (3) once. Thus, the grammar generates the string.



Another way to write the same answer is a^2n b^m with m > n.






share|improve this answer



























    up vote
    0
    down vote













    One way to tackle this is to rewrite the grammar. Note that productions 1 and 2 both end in Sb, so we can left-factor them:



    S -> ASb
    S -> b
    A ->
    A -> aa


    From the first two productions, it's fairly easy to see that S generates A^n b^n+1 for n >= 0.



    From the last two productions, A^n generates a^2k for 0 <= k <= n.



    So the language is a^2k b^n+1 for n >= 0, 0 <= k <= n.



    Or equivalently, let m = n - k to obtain a^2k b^k+m+1 for k,m >= 0.






    share|improve this answer




















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53219010%2fdescribe-the-language-generated-by-this-context-free-grammar%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote



      accepted










      The language generated by this grammar is a^(2n) b^(n+m+1) where n and m are natural numbers. To show this, (a) we see that any string derived using the grammar's productions matches the above and (b) any string matching the above can be derived using the grammar's productions.



      (a) The grammar can and must use rule (3) exactly once. This gives the +1 in the number of bs. Execution of rule (2) can happen some number of times n, putting 2n as on the front and n bs on the back, hence the 2n and n terms. Rule (1) can be executed any number of times m, hence the term.



      (b) Given a string a^(2n) b^(n+m+1) for natural numbers n and m: use rule (1) a number of times equal to m; then, use rule (2) a number of times equal to n; then, user rule (3) once. Thus, the grammar generates the string.



      Another way to write the same answer is a^2n b^m with m > n.






      share|improve this answer
























        up vote
        0
        down vote



        accepted










        The language generated by this grammar is a^(2n) b^(n+m+1) where n and m are natural numbers. To show this, (a) we see that any string derived using the grammar's productions matches the above and (b) any string matching the above can be derived using the grammar's productions.



        (a) The grammar can and must use rule (3) exactly once. This gives the +1 in the number of bs. Execution of rule (2) can happen some number of times n, putting 2n as on the front and n bs on the back, hence the 2n and n terms. Rule (1) can be executed any number of times m, hence the term.



        (b) Given a string a^(2n) b^(n+m+1) for natural numbers n and m: use rule (1) a number of times equal to m; then, use rule (2) a number of times equal to n; then, user rule (3) once. Thus, the grammar generates the string.



        Another way to write the same answer is a^2n b^m with m > n.






        share|improve this answer






















          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          The language generated by this grammar is a^(2n) b^(n+m+1) where n and m are natural numbers. To show this, (a) we see that any string derived using the grammar's productions matches the above and (b) any string matching the above can be derived using the grammar's productions.



          (a) The grammar can and must use rule (3) exactly once. This gives the +1 in the number of bs. Execution of rule (2) can happen some number of times n, putting 2n as on the front and n bs on the back, hence the 2n and n terms. Rule (1) can be executed any number of times m, hence the term.



          (b) Given a string a^(2n) b^(n+m+1) for natural numbers n and m: use rule (1) a number of times equal to m; then, use rule (2) a number of times equal to n; then, user rule (3) once. Thus, the grammar generates the string.



          Another way to write the same answer is a^2n b^m with m > n.






          share|improve this answer












          The language generated by this grammar is a^(2n) b^(n+m+1) where n and m are natural numbers. To show this, (a) we see that any string derived using the grammar's productions matches the above and (b) any string matching the above can be derived using the grammar's productions.



          (a) The grammar can and must use rule (3) exactly once. This gives the +1 in the number of bs. Execution of rule (2) can happen some number of times n, putting 2n as on the front and n bs on the back, hence the 2n and n terms. Rule (1) can be executed any number of times m, hence the term.



          (b) Given a string a^(2n) b^(n+m+1) for natural numbers n and m: use rule (1) a number of times equal to m; then, use rule (2) a number of times equal to n; then, user rule (3) once. Thus, the grammar generates the string.



          Another way to write the same answer is a^2n b^m with m > n.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 9 at 18:27









          Patrick87

          17.6k32659




          17.6k32659






















              up vote
              0
              down vote













              One way to tackle this is to rewrite the grammar. Note that productions 1 and 2 both end in Sb, so we can left-factor them:



              S -> ASb
              S -> b
              A ->
              A -> aa


              From the first two productions, it's fairly easy to see that S generates A^n b^n+1 for n >= 0.



              From the last two productions, A^n generates a^2k for 0 <= k <= n.



              So the language is a^2k b^n+1 for n >= 0, 0 <= k <= n.



              Or equivalently, let m = n - k to obtain a^2k b^k+m+1 for k,m >= 0.






              share|improve this answer
























                up vote
                0
                down vote













                One way to tackle this is to rewrite the grammar. Note that productions 1 and 2 both end in Sb, so we can left-factor them:



                S -> ASb
                S -> b
                A ->
                A -> aa


                From the first two productions, it's fairly easy to see that S generates A^n b^n+1 for n >= 0.



                From the last two productions, A^n generates a^2k for 0 <= k <= n.



                So the language is a^2k b^n+1 for n >= 0, 0 <= k <= n.



                Or equivalently, let m = n - k to obtain a^2k b^k+m+1 for k,m >= 0.






                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  One way to tackle this is to rewrite the grammar. Note that productions 1 and 2 both end in Sb, so we can left-factor them:



                  S -> ASb
                  S -> b
                  A ->
                  A -> aa


                  From the first two productions, it's fairly easy to see that S generates A^n b^n+1 for n >= 0.



                  From the last two productions, A^n generates a^2k for 0 <= k <= n.



                  So the language is a^2k b^n+1 for n >= 0, 0 <= k <= n.



                  Or equivalently, let m = n - k to obtain a^2k b^k+m+1 for k,m >= 0.






                  share|improve this answer












                  One way to tackle this is to rewrite the grammar. Note that productions 1 and 2 both end in Sb, so we can left-factor them:



                  S -> ASb
                  S -> b
                  A ->
                  A -> aa


                  From the first two productions, it's fairly easy to see that S generates A^n b^n+1 for n >= 0.



                  From the last two productions, A^n generates a^2k for 0 <= k <= n.



                  So the language is a^2k b^n+1 for n >= 0, 0 <= k <= n.



                  Or equivalently, let m = n - k to obtain a^2k b^k+m+1 for k,m >= 0.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 9 at 18:38









                  Michael Dyck

                  838611




                  838611



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53219010%2fdescribe-the-language-generated-by-this-context-free-grammar%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

                      ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ

                      How do I collapse sections of code in Visual Studio Code for Windows?