Is the language L={words without the substring 'bb' } regular? - regex

L = {words such that the substring 'bb' is not present in in it
Given that the alphabet is A = {a,b}, is this language regular? If so, is there a regular expression that represents it?

Yes, this language is regular. Since this looks like homework, here's a hint: if the string bb isn't present, then the string consists of lots of blocks of strings of the form a* or a*b. Try seeing how to assemble the solution from this starting point.
EDIT: If this isn't a homework problem, here's one possible solution:
(a*(ba+)*b?)?
The idea is to decompose the string into a lot of long sequences of as with some b's interspersed in-between them. The first block of a's is at the front. Then, we repeatedly place down a b, at least one a, and then any number of additional as. Finally, we may optionally have one b at the end. As an alternative, we could have the empty string, so the entire thing is guarded by a ?.
Hope this helps!

Related

I need help finding all strings not included in (a*b)*

I'm doing this for homework. I need to write a regular expression for a language over (a, b) that includes all strings not included in a language (a*b)*
for example 'aaaaaaabaaaaaaaabaaaaaaabaaaabaaaaaaaaab' would work. So I'm looking for a regular expression for allll the strings which are not included in that.
Can you help me at least get on the right step to figure it out?
I know that a*b means as many a's as we want followed by one b. Then that whole sort as many times as we want.
It seems that your (a*b)* regular expression matches anything that ends in a b or is empty.
so a regular expression that matches anything that end in a seems to be the solution..
a$ or /a$/
[^ab]*
This probably should do the trick.
This says the string should not have any a or b. ^ is the symbol for negation.
You could iterate over the String and check for characters besides 'a' and 'b'. It seems chains of 'b's are allowed and the empty string are a part of the language, since the Kleene star allows for zero instances of the character.

regex - At most two pair of consecutives

I'm taking a computation course which also teaches about regular expressions. There is a difficult question that I cannot answer.
Find a regular expression for the language that accepts words that contains at most two pair of consecutive 0's. The alphabet consists of 0 and 1.
First, I made an NFA of the language but cannot convert it to a GNFA (that later be converted to regex). How can I find this regular expressin? With or without converting it to a GNFA?
(Since this is a homework problem, I'm assuming that you just want enough help to get started, and not a full worked solution?)
Your mileage may vary, but I don't really recommend trying to convert an NFA into a regular expression. The two are theoretically equivalent, and either can be converted into the other algorithmically, but in my opinion, it's not the most intuitive way to construct either one.
Instead, one approach is to start by enumerating various possibilities:
No pairs of consecutive zeroes at all; that is, every zero, except at the end of the string, must be followed by a one. So, the string consists of a mixed sequence of 1 and 01, optionally followed by 0:
(1|01)*(0|ε)
Exactly one pair of consecutive zeroes, at the end of the string. This is very similar to the previous:
(1|01)*00
Exactly one pair of consecutive zeroes, not at the end of the string — and, therefore, necessarily followed by a one. This is also very similar to the first one:
(1|01)*001(1|01)*(0|ε)
To continue that approach, you would then extend the above to support two pair of consecutive zeroes; and lastly, you would merge all of these into a single regular expression.
(0+1)*00(0+1)*00(0+1)* + (0+1)*000(0+1)*
contains at most two pair of consecutive 0's
(1|01)*(00|ε)(1|10)*(00|ε)(1|10)*

Does this regular expression generate a regular language?

I was told that the language generated by the regular expression:
(a*b*)*
is regular.
However, my thinking goes against this, as follows. Can anyone please provide an explanation whether I'm thinking right or wrong?
My Thoughts
(a*b*) refers to a single sequence of any amount of a, followed by any amount of b (can be empty). And this single sequence (which can't be changed) can be repeated 0 or more time. For example:
a* = a
b* = bbbb
-> (a*b*) = abbbb
-> (a*b*)* = abbbbabbbbabbbb, ...
On the other hand, since aba is not an exact repetition of the sequence ab, it is not included in the language.
aaabaaabaaab => is included in the language
aba => is not included in the language
Thus, the language consists of sequences that are an arbitrary-time repetition of a subsequence that is any amount of a followed by any amount of b. Therefore, the language is not regular since it requires a stack.
It's a zero or more times, followed by b zero or more times, repeated zero or more times.
""
"a"
"b"
"ab"
"ba"
"aab"
"bbabb"
"aba"
all pass.
* is not +.
aba is in that language; it's just an overly-complicated way to say "the set of all strings consisting of as and bs".
EDIT: The repeating group doesn't mean that the contents of the group must be repeated exactly; that would require a backreference. ((a*b*)?\1*)
Rather, it means that the group itself should be repeated, matching any string that it can match.
Technically /(a*b*)*/ will match everything and nothing.
Because all the operators are *'s it means zero or more. So since zero is an option, it will pretty much match anything.
It's wrong, you don't need a stack. Your DFA just thinks "can I add just another a (or not)?" or "can I add just another b (or not)?" in an endless loop until the word is consumed.
It is a regular expression, yes.
The * say something like "can repeat 0 or more times". The + is basically similar, different only that it need one repeatition on minimal (or be 1 or more times).
This regular expressions says, somethink like:
Repeat "below group" zero or more times;
Repeat a zero or more times;
Repeat b zero or more times;
Can works fine with all of your examples.
Edit/Note: the aba is validated too.
I hope to help :p
Basically, it'll match any string thats empty or made by a bunch of a and b. It reads:
(('a' zero or + times)('b' zero or + times) zero of plus times
That's why it matches aba:
(('a' one time)('b' one time)) one time ((a one time)(b zero time)) one time
You're wrong. :)
0 is also an amount, so aba is in this language. It wouldn't be if the regex was (a+b+)+, because + would mean '1 or more' where * means '0 or more'.

Describing RE's in English Language

I have the following question from a past exam paper:
I am struggling to formalise their definitions within the necessary 15 word limit. So far I have:
i) The empty string or set of strings that contain zero or many a's OR b's OR both
ii) The set of strings that start with one or many a's, unless preceded by b's, followed by one or many a's with zero or many possible preceding b's.
My definitions seem rather cumbersome...I just don;t want to lose any info by oversimplifying the definition.
Try to simplify the regular expressions before describing them.
i is equivalent to (a | b)* which means any number of a's and b's in any order.
ii is equivalent to (a|b)*a(a|b)*a which is hard to describe in only 15 words, my best attempt is a's and b's in any order, at least two a's, the final letter is a
I have written a tool that attempts to do this for arbitrary regular expressions. You can find it here. Enter your regular expression and change the mode to "Explain."

what is regular expression not generated over {a,b}?

I am really stuck with these 2 questions for over 2 days now. I'm trying to figure out what the question means. My tutor is out of town too.
Question 1: Write a regular expression for the only strings that are not generated over {a,b} by the expression: (a+b)****a(a+b)****. Explain your reasoning.
And I tried the second question. Do you think is there any better answer than this one?
What is a regular expression of a set of strings that contain an odd number of as or exactly two bs (a((a|b)(a|b))****|bb) I know to represent any odd length of a's, the RE is a((a|b)(a|b))****
Here's a start for the first question. First consider the strings that this regular expression generates:
(a+b)*a(a+b)*
It must begin with a AND
Every b must have at least one an a immediately before it AND
There must either be an aab or else the string must end in a.
The inverse of this is:
It must not begin with a OR
There is at least one b not after an a OR
The string consists only of repetitions of ab.
For the second question you should check that you have understood the question correctly. Your interpretation seems to be:
What is the regular expression for the set of strings that contain either (an odd number of a's and any number of b's) or (exactly two b's and no a's).
But another interpretation is this:
What is the regular expression for the set of strings that contain either (an odd number of a's and any number of b's) or (exactly two b's and any number of a's).
To match two a's you would use something like aa right?
Now we know that the + is a quantifier for 1 or more and the * is a quantifier for 0 or more. So if we want to repeat that entire pattern, we can put it in a group and repeat the entire pattern like so: (aa)+.
That would match:
aa
aaaa
But not:
a (because aa requires at least 2 items)`
aaa (because aa will match the first two, but you'll have an extra a)
And if we want to make that odd an even, we can simply add one extra a outside of the group like so: a(aa)+. However, since we wanted an odd amount without a specific minimum we shouldn't use + since that will require atleast 3 a's.
So the entire answer would be: (bb|a(aa)*)
It sounds like the first question is asking you to write a regular expression for the set of strings that do not match the provided regular expression.
For instance, suppose the question was asking for a regular expression for the set of strings not matched by aa+ over {a}. Well, here are a few strings that do match:
'aa'
'aaaa'
'aaaaa'
What are some strings that do not match? Here are the only two:
''
'a'
A regex for the latter set is a?.
Regarding the second question, I would suggest drumming up some positive and negative test cases. Run some strings like this through your regex and see what happens:
'a' (should pass)
'aaa' (should pass)
'bb' (should pass)
'' (should fail)
'aa' (should fail)
'aba' (should fail)
Good luck!
The expression (a+b)*a(a+b)* just means: there has to be an a inside the string. The only strings that cant be generated by this expression are those: b*
This expression means that RE must contain Atleast 1 'A' in the expression.
this expression doest not accept
'b'
'b'*
or
Empty set