S.O.S. Mathematics CyberBoard

Your Resource for mathematics help on the web!
It is currently Sun, 19 May 2013 19:51:14 UTC

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: regular expression
PostPosted: Wed, 1 Feb 2006 12:00:25 UTC 
Offline
Senior Member

Joined: Mon, 21 Jun 2004 15:56:08 UTC
Posts: 69
Let \Sigma = \left\{ a,b \right\} and the set of all string in \Sigma^\ast that start with an even number of a's and no more than two b's.

I only got the first part which is (aa)+(aa)* -> even numbers of a's, however, I don't know how to get the second part for b's.. Can anyone help?


Last edited by simple on Wed, 9 Feb 2011 05:16:42 UTC, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed, 1 Feb 2006 19:28:44 UTC 
Offline
Member of the 'S.O.S. Math' Hall of Fame

Joined: Sat, 14 Jan 2006 22:40:49 UTC
Posts: 694
Location: Yountville, California
I'm interpreting the description as "starting with an even number of a's followed by no more than two b's." So after the optional b's, the next letter if any must be an a. Also zero is an even number.

The result is: (aa)*b?b?(a[ab]*)?

BTW, in (aa)+(aa)*, the (aa)* is redundant since the + means 1 or more.


Last edited by Bilbo on Sat, 26 Feb 2011 22:16:13 UTC, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed, 1 Feb 2006 22:35:25 UTC 
If Bilbos interpretation is correct you could write (haven't tested it)

(aa)*b{,2}


Top
  
 
 Post subject:
PostPosted: Thu, 2 Feb 2006 00:23:06 UTC 
Online
Member of the 'S.O.S. Math' Hall of Fame
User avatar

Joined: Wed, 1 Oct 2003 04:45:43 UTC
Posts: 9631
(aa)^\ast\cup (aa)^\ast ba^\ast\cup (aa)^\ast ba^\ast ba^\ast


Last edited by Matt on Thu, 2 Feb 2006 09:18:42 UTC, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu, 2 Feb 2006 02:15:02 UTC 
Offline
Member of the 'S.O.S. Math' Hall of Fame

Joined: Sat, 14 Jan 2006 22:40:49 UTC
Posts: 694
Location: Yountville, California
This is a tricky problem! Here is a regular expression testing program. Using it, I found all of our solutions do not work. But a combination of the three solutions does with the addition of using the start ^ and end $ metacharacters.

Code:
#!/usr/bin/perl
(print "$ARGV[1] matches $ARGV[0]\n"), exit(0) if $ARGV[1] =~ /$ARGV[0]/;
print "$ARGV[1] does not match $ARGV[0]\n";


Here are some results.

~ % re "(aa)*b{0,2}" aaabb
aaabb matches (aa)*b{0,2}

~ % re "(aa)*|(aa)*ba*|(aa)*ba*ba*" aaabb
aaabb matches (aa)*|(aa)*ba*|(aa)*ba*ba*

After trial and error, I found that excluding the odd beginning a and the 3rd b are the tough parts. Here's what I ended up with. It's pretty ugly, so I'd like to see it simplified.

~ % re "^((aa)*|(aa)*b{1,2}(a[ab]*)?)$" aabb
aabb matches ^((aa)*|(aa)*b{1,2}(a[ab]*)?)$

~ % re "^((aa)*|(aa)*b{1,2}(a[ab]*)?)$" aabbb
aabbb does not match ^((aa)*|(aa)*b{1,2}(a[ab]*)?)$

~ % re "^((aa)*|(aa)*b{1,2}(a[ab]*)?)$" aaab
aaab does not match ^((aa)*|(aa)*b{1,2}(a[ab]*)?)$


Last edited by Bilbo on Sat, 26 Feb 2011 22:16:35 UTC, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu, 2 Feb 2006 05:15:03 UTC 
Offline
Senior Member

Joined: Mon, 21 Jun 2004 15:56:08 UTC
Posts: 69
Sorry about the misinterpretation part. It should be start with an even number of a's, and contain no more than 2 b's. So I believe all strings include

aa,aab,aabb
aabaa,aabaab,aaaa
aaaabb,aaaabaaaab, aaaaaa, etc...


Last edited by simple on Wed, 9 Feb 2011 05:16:56 UTC, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu, 2 Feb 2006 08:11:01 UTC 
Offline
Member of the 'S.O.S. Math' Hall of Fame

Joined: Sat, 14 Jan 2006 22:40:49 UTC
Posts: 694
Location: Yountville, California
That's much better: ^(aa)*(ba*){0,2}$ seems to work.

The strings starting with b and containing at most two b's are included.


Last edited by Bilbo on Sat, 26 Feb 2011 22:17:04 UTC, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu, 2 Feb 2006 09:07:00 UTC 
Offline
Senior Member

Joined: Mon, 21 Jun 2004 15:56:08 UTC
Posts: 69
Hi Bilbo,

The string need to be begin with even number of a's and contains at most 2 b's...


Last edited by simple on Wed, 9 Feb 2011 05:17:04 UTC, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu, 2 Feb 2006 09:46:47 UTC 
Offline
Member of the 'S.O.S. Math' Hall of Fame

Joined: Sat, 14 Jan 2006 22:40:49 UTC
Posts: 694
Location: Yountville, California
Hi Simple,

As I said before, 0 is an even number, so I think even the empty string fits the description (0 = even # of a's and 0 <= 2 b's). But you can change 1 character to get the result you want. I'll leave that to you.

Thanks for the posting the question. I got something out of it.

Bilbo


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Contact Us | S.O.S. Mathematics Homepage
Privacy Statement | Search the "old" CyberBoard

users online during the last hour
Powered by phpBB © 2001, 2005-2011 phpBB Group.
Copyright © 1999-2013 MathMedics, LLC. All rights reserved.
Math Medics, LLC. - P.O. Box 12395 - El Paso TX 79913 - USA