Give a regular expression












1














Let Σ be {0, 1} Give a regular expression generating words over Σ containing an even number of 1’s or with a length which is multiple of 3.



I came up with this solution:



ε ( ((0*(10*10*)) + ((0+1) (0+1) (0+1)) )



and that's from this automata I drew up enter image description here



but I am unsure if it's correct...










share|cite|improve this question
























  • You would be better served posting your question on cs.stackexchange.com . (But - in short - the NFA you constructed is not correct, as it accepts the string "1" which it shouldn't.)
    – Aky
    Apr 29 '16 at 15:00










  • @Aky This question would be immediately closed on http://cs.stackexchange.com.
    – J.-E. Pin
    Apr 29 '16 at 16:57
















1














Let Σ be {0, 1} Give a regular expression generating words over Σ containing an even number of 1’s or with a length which is multiple of 3.



I came up with this solution:



ε ( ((0*(10*10*)) + ((0+1) (0+1) (0+1)) )



and that's from this automata I drew up enter image description here



but I am unsure if it's correct...










share|cite|improve this question
























  • You would be better served posting your question on cs.stackexchange.com . (But - in short - the NFA you constructed is not correct, as it accepts the string "1" which it shouldn't.)
    – Aky
    Apr 29 '16 at 15:00










  • @Aky This question would be immediately closed on http://cs.stackexchange.com.
    – J.-E. Pin
    Apr 29 '16 at 16:57














1












1








1







Let Σ be {0, 1} Give a regular expression generating words over Σ containing an even number of 1’s or with a length which is multiple of 3.



I came up with this solution:



ε ( ((0*(10*10*)) + ((0+1) (0+1) (0+1)) )



and that's from this automata I drew up enter image description here



but I am unsure if it's correct...










share|cite|improve this question















Let Σ be {0, 1} Give a regular expression generating words over Σ containing an even number of 1’s or with a length which is multiple of 3.



I came up with this solution:



ε ( ((0*(10*10*)) + ((0+1) (0+1) (0+1)) )



and that's from this automata I drew up enter image description here



but I am unsure if it's correct...







automata






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Nov 30 at 13:52









Glorfindel

3,41981830




3,41981830










asked Apr 29 '16 at 14:49









Paul

1616




1616












  • You would be better served posting your question on cs.stackexchange.com . (But - in short - the NFA you constructed is not correct, as it accepts the string "1" which it shouldn't.)
    – Aky
    Apr 29 '16 at 15:00










  • @Aky This question would be immediately closed on http://cs.stackexchange.com.
    – J.-E. Pin
    Apr 29 '16 at 16:57


















  • You would be better served posting your question on cs.stackexchange.com . (But - in short - the NFA you constructed is not correct, as it accepts the string "1" which it shouldn't.)
    – Aky
    Apr 29 '16 at 15:00










  • @Aky This question would be immediately closed on http://cs.stackexchange.com.
    – J.-E. Pin
    Apr 29 '16 at 16:57
















You would be better served posting your question on cs.stackexchange.com . (But - in short - the NFA you constructed is not correct, as it accepts the string "1" which it shouldn't.)
– Aky
Apr 29 '16 at 15:00




You would be better served posting your question on cs.stackexchange.com . (But - in short - the NFA you constructed is not correct, as it accepts the string "1" which it shouldn't.)
– Aky
Apr 29 '16 at 15:00












@Aky This question would be immediately closed on http://cs.stackexchange.com.
– J.-E. Pin
Apr 29 '16 at 16:57




@Aky This question would be immediately closed on http://cs.stackexchange.com.
– J.-E. Pin
Apr 29 '16 at 16:57










2 Answers
2






active

oldest

votes


















0














I think in the even number of $1$'s category, your NFA will miss strings of the form $110$ since you do not have an ending $0*$ at the end of your regex.



The other part of your regex only detects strings of length $3$, not multiples of 3. The correct thing would be to allow the second part of your regex to be repeated as many times as you want.



So, doing this step-by-step:




  1. even number of ones: $ (0^*(10^*)(10^*)0^*)^*$ The inner part of the regex allows for any number of zeroes before, after, and in between two $1$s. The outer $*$ allows for the two 1's matching regex to repeat as many times as desired, thereby allowing for an even number of 1's


  2. strings of lengths of multiples of 3: $((0 + 1)(0 + 1)(0 + 1))^*$ By allowing the entire chunk to repeat, we allow strings of length $ 0, 3, ldots, 3n, n in mathbb{N}$.



Full regex: $$R = ((0^*(10^*)(10^*)0^*)^*) + ((0 + 1)(0 + 1)(0 + 1))^*$$






share|cite|improve this answer























  • edited the regex to work for even number of zeroes
    – Siddharth Bhat
    Apr 29 '16 at 15:03










  • Thank you so much! , but do the regex also need to work for even number of zeros for the question? i mean is it right for this question also?
    – Paul
    Apr 29 '16 at 15:05










  • I'm not entirely sure what you mean, but the regex is a solution to your question if that's what you're asking.
    – Siddharth Bhat
    Apr 29 '16 at 15:09










  • @Paul - yes, it is definitely "inefficient" in the sense that there are some states that could be pruned. But, well, I think this is the most intuitive way to go about it. Efficiency is an exercise for the reader :)
    – Siddharth Bhat
    Apr 29 '16 at 15:09



















0














Hint. Your language is the union of two (regular) languages: the langage
$L_1$ of all words containing an even number of $1$'s and the language $L_2$
of the words of length multiple of 3. Now just find a regular expression for $L_1$ and a regular expression for $L_2$ (this is easy in both cases) and just take the union of your two regular expressions.






share|cite|improve this answer





















    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "69"
    };
    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
    },
    noCode: true, onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f1764179%2fgive-a-regular-expression%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









    0














    I think in the even number of $1$'s category, your NFA will miss strings of the form $110$ since you do not have an ending $0*$ at the end of your regex.



    The other part of your regex only detects strings of length $3$, not multiples of 3. The correct thing would be to allow the second part of your regex to be repeated as many times as you want.



    So, doing this step-by-step:




    1. even number of ones: $ (0^*(10^*)(10^*)0^*)^*$ The inner part of the regex allows for any number of zeroes before, after, and in between two $1$s. The outer $*$ allows for the two 1's matching regex to repeat as many times as desired, thereby allowing for an even number of 1's


    2. strings of lengths of multiples of 3: $((0 + 1)(0 + 1)(0 + 1))^*$ By allowing the entire chunk to repeat, we allow strings of length $ 0, 3, ldots, 3n, n in mathbb{N}$.



    Full regex: $$R = ((0^*(10^*)(10^*)0^*)^*) + ((0 + 1)(0 + 1)(0 + 1))^*$$






    share|cite|improve this answer























    • edited the regex to work for even number of zeroes
      – Siddharth Bhat
      Apr 29 '16 at 15:03










    • Thank you so much! , but do the regex also need to work for even number of zeros for the question? i mean is it right for this question also?
      – Paul
      Apr 29 '16 at 15:05










    • I'm not entirely sure what you mean, but the regex is a solution to your question if that's what you're asking.
      – Siddharth Bhat
      Apr 29 '16 at 15:09










    • @Paul - yes, it is definitely "inefficient" in the sense that there are some states that could be pruned. But, well, I think this is the most intuitive way to go about it. Efficiency is an exercise for the reader :)
      – Siddharth Bhat
      Apr 29 '16 at 15:09
















    0














    I think in the even number of $1$'s category, your NFA will miss strings of the form $110$ since you do not have an ending $0*$ at the end of your regex.



    The other part of your regex only detects strings of length $3$, not multiples of 3. The correct thing would be to allow the second part of your regex to be repeated as many times as you want.



    So, doing this step-by-step:




    1. even number of ones: $ (0^*(10^*)(10^*)0^*)^*$ The inner part of the regex allows for any number of zeroes before, after, and in between two $1$s. The outer $*$ allows for the two 1's matching regex to repeat as many times as desired, thereby allowing for an even number of 1's


    2. strings of lengths of multiples of 3: $((0 + 1)(0 + 1)(0 + 1))^*$ By allowing the entire chunk to repeat, we allow strings of length $ 0, 3, ldots, 3n, n in mathbb{N}$.



    Full regex: $$R = ((0^*(10^*)(10^*)0^*)^*) + ((0 + 1)(0 + 1)(0 + 1))^*$$






    share|cite|improve this answer























    • edited the regex to work for even number of zeroes
      – Siddharth Bhat
      Apr 29 '16 at 15:03










    • Thank you so much! , but do the regex also need to work for even number of zeros for the question? i mean is it right for this question also?
      – Paul
      Apr 29 '16 at 15:05










    • I'm not entirely sure what you mean, but the regex is a solution to your question if that's what you're asking.
      – Siddharth Bhat
      Apr 29 '16 at 15:09










    • @Paul - yes, it is definitely "inefficient" in the sense that there are some states that could be pruned. But, well, I think this is the most intuitive way to go about it. Efficiency is an exercise for the reader :)
      – Siddharth Bhat
      Apr 29 '16 at 15:09














    0












    0








    0






    I think in the even number of $1$'s category, your NFA will miss strings of the form $110$ since you do not have an ending $0*$ at the end of your regex.



    The other part of your regex only detects strings of length $3$, not multiples of 3. The correct thing would be to allow the second part of your regex to be repeated as many times as you want.



    So, doing this step-by-step:




    1. even number of ones: $ (0^*(10^*)(10^*)0^*)^*$ The inner part of the regex allows for any number of zeroes before, after, and in between two $1$s. The outer $*$ allows for the two 1's matching regex to repeat as many times as desired, thereby allowing for an even number of 1's


    2. strings of lengths of multiples of 3: $((0 + 1)(0 + 1)(0 + 1))^*$ By allowing the entire chunk to repeat, we allow strings of length $ 0, 3, ldots, 3n, n in mathbb{N}$.



    Full regex: $$R = ((0^*(10^*)(10^*)0^*)^*) + ((0 + 1)(0 + 1)(0 + 1))^*$$






    share|cite|improve this answer














    I think in the even number of $1$'s category, your NFA will miss strings of the form $110$ since you do not have an ending $0*$ at the end of your regex.



    The other part of your regex only detects strings of length $3$, not multiples of 3. The correct thing would be to allow the second part of your regex to be repeated as many times as you want.



    So, doing this step-by-step:




    1. even number of ones: $ (0^*(10^*)(10^*)0^*)^*$ The inner part of the regex allows for any number of zeroes before, after, and in between two $1$s. The outer $*$ allows for the two 1's matching regex to repeat as many times as desired, thereby allowing for an even number of 1's


    2. strings of lengths of multiples of 3: $((0 + 1)(0 + 1)(0 + 1))^*$ By allowing the entire chunk to repeat, we allow strings of length $ 0, 3, ldots, 3n, n in mathbb{N}$.



    Full regex: $$R = ((0^*(10^*)(10^*)0^*)^*) + ((0 + 1)(0 + 1)(0 + 1))^*$$







    share|cite|improve this answer














    share|cite|improve this answer



    share|cite|improve this answer








    edited Apr 29 '16 at 15:03

























    answered Apr 29 '16 at 14:56









    Siddharth Bhat

    2,8361918




    2,8361918












    • edited the regex to work for even number of zeroes
      – Siddharth Bhat
      Apr 29 '16 at 15:03










    • Thank you so much! , but do the regex also need to work for even number of zeros for the question? i mean is it right for this question also?
      – Paul
      Apr 29 '16 at 15:05










    • I'm not entirely sure what you mean, but the regex is a solution to your question if that's what you're asking.
      – Siddharth Bhat
      Apr 29 '16 at 15:09










    • @Paul - yes, it is definitely "inefficient" in the sense that there are some states that could be pruned. But, well, I think this is the most intuitive way to go about it. Efficiency is an exercise for the reader :)
      – Siddharth Bhat
      Apr 29 '16 at 15:09


















    • edited the regex to work for even number of zeroes
      – Siddharth Bhat
      Apr 29 '16 at 15:03










    • Thank you so much! , but do the regex also need to work for even number of zeros for the question? i mean is it right for this question also?
      – Paul
      Apr 29 '16 at 15:05










    • I'm not entirely sure what you mean, but the regex is a solution to your question if that's what you're asking.
      – Siddharth Bhat
      Apr 29 '16 at 15:09










    • @Paul - yes, it is definitely "inefficient" in the sense that there are some states that could be pruned. But, well, I think this is the most intuitive way to go about it. Efficiency is an exercise for the reader :)
      – Siddharth Bhat
      Apr 29 '16 at 15:09
















    edited the regex to work for even number of zeroes
    – Siddharth Bhat
    Apr 29 '16 at 15:03




    edited the regex to work for even number of zeroes
    – Siddharth Bhat
    Apr 29 '16 at 15:03












    Thank you so much! , but do the regex also need to work for even number of zeros for the question? i mean is it right for this question also?
    – Paul
    Apr 29 '16 at 15:05




    Thank you so much! , but do the regex also need to work for even number of zeros for the question? i mean is it right for this question also?
    – Paul
    Apr 29 '16 at 15:05












    I'm not entirely sure what you mean, but the regex is a solution to your question if that's what you're asking.
    – Siddharth Bhat
    Apr 29 '16 at 15:09




    I'm not entirely sure what you mean, but the regex is a solution to your question if that's what you're asking.
    – Siddharth Bhat
    Apr 29 '16 at 15:09












    @Paul - yes, it is definitely "inefficient" in the sense that there are some states that could be pruned. But, well, I think this is the most intuitive way to go about it. Efficiency is an exercise for the reader :)
    – Siddharth Bhat
    Apr 29 '16 at 15:09




    @Paul - yes, it is definitely "inefficient" in the sense that there are some states that could be pruned. But, well, I think this is the most intuitive way to go about it. Efficiency is an exercise for the reader :)
    – Siddharth Bhat
    Apr 29 '16 at 15:09











    0














    Hint. Your language is the union of two (regular) languages: the langage
    $L_1$ of all words containing an even number of $1$'s and the language $L_2$
    of the words of length multiple of 3. Now just find a regular expression for $L_1$ and a regular expression for $L_2$ (this is easy in both cases) and just take the union of your two regular expressions.






    share|cite|improve this answer


























      0














      Hint. Your language is the union of two (regular) languages: the langage
      $L_1$ of all words containing an even number of $1$'s and the language $L_2$
      of the words of length multiple of 3. Now just find a regular expression for $L_1$ and a regular expression for $L_2$ (this is easy in both cases) and just take the union of your two regular expressions.






      share|cite|improve this answer
























        0












        0








        0






        Hint. Your language is the union of two (regular) languages: the langage
        $L_1$ of all words containing an even number of $1$'s and the language $L_2$
        of the words of length multiple of 3. Now just find a regular expression for $L_1$ and a regular expression for $L_2$ (this is easy in both cases) and just take the union of your two regular expressions.






        share|cite|improve this answer












        Hint. Your language is the union of two (regular) languages: the langage
        $L_1$ of all words containing an even number of $1$'s and the language $L_2$
        of the words of length multiple of 3. Now just find a regular expression for $L_1$ and a regular expression for $L_2$ (this is easy in both cases) and just take the union of your two regular expressions.







        share|cite|improve this answer












        share|cite|improve this answer



        share|cite|improve this answer










        answered Apr 29 '16 at 17:07









        J.-E. Pin

        18.3k21754




        18.3k21754






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Mathematics Stack Exchange!


            • 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.


            Use MathJax to format equations. MathJax reference.


            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%2fmath.stackexchange.com%2fquestions%2f1764179%2fgive-a-regular-expression%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

            To store a contact into the json file from server.js file using a class in NodeJS

            Redirect URL with Chrome Remote Debugging Android Devices

            Dieringhausen