REGEX L(r) = {a^n b^m : n + m is even}, r =?












0














So I did a problem earlier that said:



L(r) = {w in {a,b}* : w contains at least 2 a's}


For that one I said {a^2n , b} because that guarantees a string like aab or aabaab etc. Not sure how to approach the one I posted about in the title. Possibly a solution might be a^2n, b^2m so its always even, but also 2 odd numbers like a^n b^3m is also always even. Am i allowed to set boundaries like n>=m?



Thank you!










share|improve this question




















  • 1




    Consider the automaton which accepts a^n when n is even. The "failure" case would be that n is odd. In that "failure" case, you want a following automaton b^m which accepts when m is odd. Otherwise, you want a following automaton b^m which accepts when m is even.
    – Corion
    Nov 13 '18 at 10:02






  • 1




    what about ^(?=(?:..)*$)[ab]*$ (regex101.com/r/1aldWm/1)
    – Nahuel Fouilleul
    Nov 13 '18 at 10:31












  • @Corion how would I write that in terms of r? I understand the logic just not the syntax.
    – solnay
    Nov 13 '18 at 10:39






  • 2




    I think this question better suits Mathematics StackExchange site and it's regular-expressions tag. Also, are you sure there is a possibility to use a regular expression for this? Seems more like a grammar is to be used here, since irregularities you mention oppose the "regular" part in "regex" :)
    – Asunez
    Nov 13 '18 at 10:45






  • 1




    @Asunez As I showed, the language is regular, as it can be accepted by a DFA.
    – Corion
    Nov 13 '18 at 10:48
















0














So I did a problem earlier that said:



L(r) = {w in {a,b}* : w contains at least 2 a's}


For that one I said {a^2n , b} because that guarantees a string like aab or aabaab etc. Not sure how to approach the one I posted about in the title. Possibly a solution might be a^2n, b^2m so its always even, but also 2 odd numbers like a^n b^3m is also always even. Am i allowed to set boundaries like n>=m?



Thank you!










share|improve this question




















  • 1




    Consider the automaton which accepts a^n when n is even. The "failure" case would be that n is odd. In that "failure" case, you want a following automaton b^m which accepts when m is odd. Otherwise, you want a following automaton b^m which accepts when m is even.
    – Corion
    Nov 13 '18 at 10:02






  • 1




    what about ^(?=(?:..)*$)[ab]*$ (regex101.com/r/1aldWm/1)
    – Nahuel Fouilleul
    Nov 13 '18 at 10:31












  • @Corion how would I write that in terms of r? I understand the logic just not the syntax.
    – solnay
    Nov 13 '18 at 10:39






  • 2




    I think this question better suits Mathematics StackExchange site and it's regular-expressions tag. Also, are you sure there is a possibility to use a regular expression for this? Seems more like a grammar is to be used here, since irregularities you mention oppose the "regular" part in "regex" :)
    – Asunez
    Nov 13 '18 at 10:45






  • 1




    @Asunez As I showed, the language is regular, as it can be accepted by a DFA.
    – Corion
    Nov 13 '18 at 10:48














0












0








0







So I did a problem earlier that said:



L(r) = {w in {a,b}* : w contains at least 2 a's}


For that one I said {a^2n , b} because that guarantees a string like aab or aabaab etc. Not sure how to approach the one I posted about in the title. Possibly a solution might be a^2n, b^2m so its always even, but also 2 odd numbers like a^n b^3m is also always even. Am i allowed to set boundaries like n>=m?



Thank you!










share|improve this question















So I did a problem earlier that said:



L(r) = {w in {a,b}* : w contains at least 2 a's}


For that one I said {a^2n , b} because that guarantees a string like aab or aabaab etc. Not sure how to approach the one I posted about in the title. Possibly a solution might be a^2n, b^2m so its always even, but also 2 odd numbers like a^n b^3m is also always even. Am i allowed to set boundaries like n>=m?



Thank you!







regex math automata formal-languages computability






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 10:27









mrzasa

8,973103878




8,973103878










asked Nov 13 '18 at 9:37









solnaysolnay

134




134








  • 1




    Consider the automaton which accepts a^n when n is even. The "failure" case would be that n is odd. In that "failure" case, you want a following automaton b^m which accepts when m is odd. Otherwise, you want a following automaton b^m which accepts when m is even.
    – Corion
    Nov 13 '18 at 10:02






  • 1




    what about ^(?=(?:..)*$)[ab]*$ (regex101.com/r/1aldWm/1)
    – Nahuel Fouilleul
    Nov 13 '18 at 10:31












  • @Corion how would I write that in terms of r? I understand the logic just not the syntax.
    – solnay
    Nov 13 '18 at 10:39






  • 2




    I think this question better suits Mathematics StackExchange site and it's regular-expressions tag. Also, are you sure there is a possibility to use a regular expression for this? Seems more like a grammar is to be used here, since irregularities you mention oppose the "regular" part in "regex" :)
    – Asunez
    Nov 13 '18 at 10:45






  • 1




    @Asunez As I showed, the language is regular, as it can be accepted by a DFA.
    – Corion
    Nov 13 '18 at 10:48














  • 1




    Consider the automaton which accepts a^n when n is even. The "failure" case would be that n is odd. In that "failure" case, you want a following automaton b^m which accepts when m is odd. Otherwise, you want a following automaton b^m which accepts when m is even.
    – Corion
    Nov 13 '18 at 10:02






  • 1




    what about ^(?=(?:..)*$)[ab]*$ (regex101.com/r/1aldWm/1)
    – Nahuel Fouilleul
    Nov 13 '18 at 10:31












  • @Corion how would I write that in terms of r? I understand the logic just not the syntax.
    – solnay
    Nov 13 '18 at 10:39






  • 2




    I think this question better suits Mathematics StackExchange site and it's regular-expressions tag. Also, are you sure there is a possibility to use a regular expression for this? Seems more like a grammar is to be used here, since irregularities you mention oppose the "regular" part in "regex" :)
    – Asunez
    Nov 13 '18 at 10:45






  • 1




    @Asunez As I showed, the language is regular, as it can be accepted by a DFA.
    – Corion
    Nov 13 '18 at 10:48








1




1




Consider the automaton which accepts a^n when n is even. The "failure" case would be that n is odd. In that "failure" case, you want a following automaton b^m which accepts when m is odd. Otherwise, you want a following automaton b^m which accepts when m is even.
– Corion
Nov 13 '18 at 10:02




Consider the automaton which accepts a^n when n is even. The "failure" case would be that n is odd. In that "failure" case, you want a following automaton b^m which accepts when m is odd. Otherwise, you want a following automaton b^m which accepts when m is even.
– Corion
Nov 13 '18 at 10:02




1




1




what about ^(?=(?:..)*$)[ab]*$ (regex101.com/r/1aldWm/1)
– Nahuel Fouilleul
Nov 13 '18 at 10:31






what about ^(?=(?:..)*$)[ab]*$ (regex101.com/r/1aldWm/1)
– Nahuel Fouilleul
Nov 13 '18 at 10:31














@Corion how would I write that in terms of r? I understand the logic just not the syntax.
– solnay
Nov 13 '18 at 10:39




@Corion how would I write that in terms of r? I understand the logic just not the syntax.
– solnay
Nov 13 '18 at 10:39




2




2




I think this question better suits Mathematics StackExchange site and it's regular-expressions tag. Also, are you sure there is a possibility to use a regular expression for this? Seems more like a grammar is to be used here, since irregularities you mention oppose the "regular" part in "regex" :)
– Asunez
Nov 13 '18 at 10:45




I think this question better suits Mathematics StackExchange site and it's regular-expressions tag. Also, are you sure there is a possibility to use a regular expression for this? Seems more like a grammar is to be used here, since irregularities you mention oppose the "regular" part in "regex" :)
– Asunez
Nov 13 '18 at 10:45




1




1




@Asunez As I showed, the language is regular, as it can be accepted by a DFA.
– Corion
Nov 13 '18 at 10:48




@Asunez As I showed, the language is regular, as it can be accepted by a DFA.
– Corion
Nov 13 '18 at 10:48












1 Answer
1






active

oldest

votes


















1














You correctly observe that n and m must either be both even or both odd. It only needs to be added that an odd number is one more than an even number.



A simple regular expression for "an even number of as" ( {a2n : n ≥ 0}) is (aa)*, while "an odd number of as" is (aa)*a.



Building on that, we can two cases for the original question: (aa)*(bb)* and (aa)*a(bb)*b, which can be combined into (aa)*(ab+ε)(bb)*. (Assuming you are using + for alternation and ε for the empty string.)






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',
    autoActivateHeartbeat: false,
    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%2f53277926%2fregex-lr-an-bm-n-m-is-even-r%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You correctly observe that n and m must either be both even or both odd. It only needs to be added that an odd number is one more than an even number.



    A simple regular expression for "an even number of as" ( {a2n : n ≥ 0}) is (aa)*, while "an odd number of as" is (aa)*a.



    Building on that, we can two cases for the original question: (aa)*(bb)* and (aa)*a(bb)*b, which can be combined into (aa)*(ab+ε)(bb)*. (Assuming you are using + for alternation and ε for the empty string.)






    share|improve this answer




























      1














      You correctly observe that n and m must either be both even or both odd. It only needs to be added that an odd number is one more than an even number.



      A simple regular expression for "an even number of as" ( {a2n : n ≥ 0}) is (aa)*, while "an odd number of as" is (aa)*a.



      Building on that, we can two cases for the original question: (aa)*(bb)* and (aa)*a(bb)*b, which can be combined into (aa)*(ab+ε)(bb)*. (Assuming you are using + for alternation and ε for the empty string.)






      share|improve this answer


























        1












        1








        1






        You correctly observe that n and m must either be both even or both odd. It only needs to be added that an odd number is one more than an even number.



        A simple regular expression for "an even number of as" ( {a2n : n ≥ 0}) is (aa)*, while "an odd number of as" is (aa)*a.



        Building on that, we can two cases for the original question: (aa)*(bb)* and (aa)*a(bb)*b, which can be combined into (aa)*(ab+ε)(bb)*. (Assuming you are using + for alternation and ε for the empty string.)






        share|improve this answer














        You correctly observe that n and m must either be both even or both odd. It only needs to be added that an odd number is one more than an even number.



        A simple regular expression for "an even number of as" ( {a2n : n ≥ 0}) is (aa)*, while "an odd number of as" is (aa)*a.



        Building on that, we can two cases for the original question: (aa)*(bb)* and (aa)*a(bb)*b, which can be combined into (aa)*(ab+ε)(bb)*. (Assuming you are using + for alternation and ε for the empty string.)







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 13 '18 at 17:12

























        answered Nov 13 '18 at 17:06









        ricirici

        152k19132197




        152k19132197






























            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%2f53277926%2fregex-lr-an-bm-n-m-is-even-r%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

            List item for chat from Array inside array React Native

            Thiostrepton

            Caerphilly