Homework #3 Solutions #1. True or False a)a a b a matches a* + b* T F b) babab matches b (ab)* T F...

9
Homework #3 Solutions
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    217
  • download

    2

Transcript of Homework #3 Solutions #1. True or False a)a a b a matches a* + b* T F b) babab matches b (ab)* T F...

Page 1: Homework #3 Solutions #1. True or False a)a a b a matches a* + b* T F b) babab matches b (ab)* T F c) If A =  then A B =  for all languages B T F d)

Homework #3 Solutions

Page 2: Homework #3 Solutions #1. True or False a)a a b a matches a* + b* T F b) babab matches b (ab)* T F c) If A =  then A B =  for all languages B T F d)

#1. True or False

a) a a b a matches a* + b* T F

b) babab matches b (ab)* T F

c) If A = then A B = for all languages B T F

d) If A = {} then A B = for all languages B T F

e) If A = a* and = {a,b}, then * - A = b* T F

Page 3: Homework #3 Solutions #1. True or False a)a a b a matches a* + b* T F b) babab matches b (ab)* T F c) If A =  then A B =  for all languages B T F d)

#2. Write regular expressions for the set of strings of 0’s and 1’s with at most one pair of consecutive 1’s

• Exercise says “at most one” occurrence of “11”, so start with

( + 1 + 11)

• Now build around it the combination of 1’s and 0’s that will prevent another occurrence of “11”:

In front: (0 +10)*After: (0 + 01)*

• So altogether: (0 +10)* ( + 1 + 11) (0 +10)*

Page 4: Homework #3 Solutions #1. True or False a)a a b a matches a* + b* T F b) babab matches b (ab)* T F c) If A =  then A B =  for all languages B T F d)

#3. Draw the graph for the following DFA and then convert to regular expression.

This gives you an idea how messy these are, and how you’d really like to plug them into a computer program!

1. Using Sudkamp method: Eliminating “r”:

p s

q

1

1

0 + 10*1

0

0

Page 5: Homework #3 Solutions #1. True or False a)a a b a matches a* + b* T F b) babab matches b (ab)* T F c) If A =  then A B =  for all languages B T F d)

#3 continued

• Then eliminating “s”

• Eliminating “q”

p

q

1

0 0(0 + 10*1)

1(0 + 10*1)

p

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

• Now we * the expression on the loop to get the regular expression:(1 + (0(0 + 10*1))(1(0 + 10*1))*0)*Whew!

Page 6: Homework #3 Solutions #1. True or False a)a a b a matches a* + b* T F b) babab matches b (ab)* T F c) If A =  then A B =  for all languages B T F d)

#3 continued Using Kozen Method removing qpp

pqrs = ppprs + pq

prs (qqprs )*qp

prs

pp

prs = 1*

pqprs = 1*0 (0 +10*1)

qqprs = 01*0 (0 + 10*1) + 1 (0 +10*1)

qpprs = 01*

So pppqrs = 1* + 1*0 (0 +10*1) (01*0 (0 + 10*1) + 1(0+10*1 )* 01*

I’m sure this can be simplified. If anyone wants to send me their simplification, I’ll post it with full credit to the sender!

Page 7: Homework #3 Solutions #1. True or False a)a a b a matches a* + b* T F b) babab matches b (ab)* T F c) If A =  then A B =  for all languages B T F d)

#4. Does (R +S)* S = (R*S)* ? Justify your answer

• No

• Counter-example: if is not in S, then they are not equal.

Page 8: Homework #3 Solutions #1. True or False a)a a b a matches a* + b* T F b) babab matches b (ab)* T F c) If A =  then A B =  for all languages B T F d)

#5. What does the Perl expression: s/(^[A_Z]{1})([az]+)\.sgml/\1\2\.html/g tr/a-z/A-Z/ say to do?

• Converts file names with extension “sgml” to file names with extension “html”,

• and changes all letters to upper-case

Page 9: Homework #3 Solutions #1. True or False a)a a b a matches a* + b* T F b) babab matches b (ab)* T F c) If A =  then A B =  for all languages B T F d)

#6. What do you think the regular expression on

the Module 3 page represents?

• Looks like “social security numbers”