Give a regular expression
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
but I am unsure if it's correct...
automata
add a comment |
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
but I am unsure if it's correct...
automata
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
add a comment |
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
but I am unsure if it's correct...
automata
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
but I am unsure if it's correct...
automata
automata
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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:
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
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))^*$$
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
add a comment |
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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:
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
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))^*$$
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
add a comment |
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:
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
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))^*$$
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
add a comment |
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:
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
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))^*$$
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:
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
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))^*$$
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Apr 29 '16 at 17:07
J.-E. Pin
18.3k21754
18.3k21754
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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