Presentation is loading. Please wait.

Presentation is loading. Please wait.

Properties of Regular Languages

Similar presentations


Presentation on theme: "Properties of Regular Languages"— Presentation transcript:

1 Properties of Regular Languages
Chapter 8

2 Regular Languages A language is regular iff it is accepted by some DFA. Example: L = {w  {a, b}* : every a is immediately followed by a b}.

3 Languages: Regular or Not?
a*b* is regular. {anbn: n  0} is not. {w  {a, b}* : every a is immediately followed by b} is regular. {w  {a, b}* : every a has a matching b somewhere} is not ● Showing that a language is regular. ● Showing that a language is not regular.

4 How Many Regular Languages?
Theorem: There is a countably infinite number of regular languages. Proof: ● Upper bound on number of regular languages: number of FSMs (or regular expressions). ● Lower bound on number of regular languages: {a},{aa},{aaa},{aaaa},{aaaaa},{aaaaaa},… are all regular. That set is countably infinite.

5 Regular And Nonregular Languages?
There is a countably infinite number of regular languages. There is an uncountably infinite number of languages over any nonempty alphabet . So there are many more nonregular languages than there are regular ones.

6 Showing that a Language is Regular
Theorem: Every finite language is regular. Proof: If L is the empty set, then it is defined by the regular expression  and so is regular. If it is any finite language composed of the strings s1, s2, … sn for some positive integer n, then it is defined by the regular expression: s1  s2  …  sn So it too is regular.

7 Showing that a Language is Regular
Example: Let L = L1  L2, where: L1 = {anbn, n  0}, and L2 = {bnan, n  0} L =

8 More Examples current US president}. 10,000 BP and 0 otherwise}
● L1 = {w  {0 - 9}*: w is the social security number of the current US president}. ● L2 = {1 if Santa Claus exists and 0 otherwise} ● L3 = {1 if God exists and 0 otherwise} ● L4 = {1 if there were people in North America before 10,000 BP and 0 otherwise} ● L5 = {1 if there were people in North America before 15,000 BP and 0 otherwise} ● L6 = {w  {0 - 9}+ : w is the decimal representation, no leading 0’s, of a prime Fermat number}

9 Prime Fermat Numbers  = {0 - 9}
L = {w  {0 - 9}+ : w is the decimal representation, no leading 0’s, of a prime Fermat number} The Fermat numbers are defined by Fn = , n  0 Example elements of L: F0 = 3, F1 = 5, F2 = 17, F3 = 257, F4 = 65,537 Is L regular? Pierre de Fermat (1601 – 1665) thought that all Fermat numbers were prime, but admitted that he had no proof. These first five are prime. But they are the only known Prime Fermat numbers. F5 and many others are known not to be. It is likely that no others are. It is also known that all divisors of Fn are of the form k2n for some k.

10 Finiteness - Theoretical vs. Practical
Any finite language is regular. The size of the language doesn't matter. Parity Soc. Sec. # Checking Checking But, from an implementation point of view, it very well may. When is an FSM a good way to encode the facts about a language? FSM’s are good at looking for repeating patterns. They don't bring much to the table when the language is just a set of unrelated strings.

11 Regular Does Not Always Mean Tractable
Let  = {12, 13, 21, 23, 31, 32}. Let L be the language of strings that correspond to successful move sequences. The shortest string in L has length This is a finite language. There is an FSM that accepts L. How many states are there? Each disk is on one of the three poles. The order of the disks on a given pole is fixed. So there are 364 states.

12 Showing That L is Regular
1. Show that L is finite. 2. Exhibit an FSM for L. 3. Exhibit a regular expression for L. 4. Show that the number of equivalence classes of L is finite. 5. Exhibit a regular grammar for L. 6. Exploit the closure theorems.

13 Closure Properties of Regular Languages
● Union ● Concatenation ● Kleene star ● Complement ● Intersection ● Difference ● Reverse ● Letter substitution

14 Closure of Regular Languages Under Complement

15 The Complement Procedure
Given: an FSM M, Construct a new machine to accept L(M): If necessary, use ndfsmtodfsm to construct M, a deterministic equivalent of M. Make sure that M is described completely. Swap accepting and nonaccepting states.

16 Closure of Regular Languages Under Complement
What about? st: Complete the FSM a b a b b a 2nd: Swap accepting and final states a,b Need to make sure all transitions are explicitly represented. b a a,b On input bbb?

17 Closure of Regular Languages Under Complement
What about: a Only works for DFSMs, but can convert any NDFSM into an equivalent DFSM. On input a?

18 A Complement Example

19 Closure of Regular Languages Under Intersection
L1  L2 = L L2 Write this in terms of operations we have already proved closure for: ● Union ● Concatenation ● Kleene star ● Complementation L(M1)  L(M2) = (L(M1) L(M2)).

20 Closure of Regular Languages Under Intersection
L1  L2 = (L1  L2) L L2 Write this in terms of operations we have already proved closure for: ● Union ● Concatenation ● Kleene star ● Complementation L(M1)  L(M2) = (L(M1) L(M2)).

21 Closure of Regular Languages Under Difference
L1 - L2 = L(M1) – L(M2) = L(M1)  L(M2).

22 Closure of Regular Languages Under Difference
L1 - L2 = L1  L2 L(M1) – L(M2) = L(M1)  L(M2).

23 Letter Substitution Example: Let: 1 = {a, b}, 2 = {0, 1},
● Let 1 and 2 be alphabets. ● Let sub be any function from 1 to 2*. Example: Let: 1 = {a, b}, 2 = {0, 1}, sub(a) = 0, and sub(b) = 11. {0n12n, n  0}

24 Letter Substitution letsub is a letter substitution function iff:
letsub(L1) = {w  2* : y  L1 and w = y except that: every character c of y is replaced by sub(c)}. Example: sub(a) = 0, and sub(b) = 11. Then letsub({anbn, n  0}) = {0n12n, n  0}

25 Divide-and-Conquer Let L = {w  {a, b}* : w contains an even number of a’s and an odd number of b’s and all a’s come in runs of three}. L = L1  L2, where: L1 = {w  {a, b}* : w contains an even number of a’s and an odd number of b’s}, and L2 = {w  {a, b}* : all a’s come in runs of three}

26 L1 is Regular

27 L2 is Regular

28 Don’t Try to Use Closure Backwards
One Closure Theorem: If L1 and L2 are regular, then so is L = L1  L2 But if L is regular, what can we say about L1 and L2?

29 Don’t Try to Use Closure Backwards
One Closure Theorem: If L1 and L2 are regular, then so is L = L1  L2 But if L is regular, what can we say about L1 and L2? ab = ab  (a  b)* (they are regular)

30 Don’t Try to Use Closure Backwards
One Closure Theorem: If L1 and L2 are regular, then so is L = L1  L2 But if L is regular, what can we say about L1 and L2? ab = ab  (a  b)* (they are regular) ab = ab  {anbn, n  0} (they may not be regular)

31 Don’t Try to Use Closure Backwards
Another Closure Theorem: If L1 and L2 are regular, then so is L = L1 L2 But if L2 is not regular, what can we say about L? L = L L2

32 Don’t Try to Use Closure Backwards
Another Closure Theorem: If L1 and L2 are regular, then so is L = L1 L2 But if L2 is not regular, what can we say about L? L = L L2 {abanbn : n  0} = {ab} {anbn : n  0}

33 Don’t Try to Use Closure Backwards
Another Closure Theorem: If L1 and L2 are regular, then so is L = L1 L2 But if L2 is not regular, what can we say about L? L = L L2 {abanbn : n  0} = {ab} {anbn : n  0} L is not. {aaa*} = {a*} {ap: p is prime}

34 Don’t Try to Use Closure Backwards
Another Closure Theorem: If L1 and L2 are regular, then so is L = L1 L2 But if L2 is not regular, what can we say about L? L = L L2 {abanbn : n  0} = {ab} {anbn : n  0} L is not. {aaa*} = {a*} {ap: p is prime} L is.


Download ppt "Properties of Regular Languages"

Similar presentations


Ads by Google