- 71 Views
- Uploaded on
- Presentation posted in: General

Chapter 11 - 4

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Chapter 11 - 4

Regular Language Topics

- Regular languages are also characterized by special grammars called regular grammars whose productions take the following form, where w is a string of terminals.
A â†’ wB or A â†’ w.

- Example. A regular grammar for the language of a*b* is
S â†’Ù¨ | aS | T

T â†’ b | bT.

- Write a regular grammar for {ab, acb, accb, â€¦, acnb, â€¦}.
- Solution: A regular expression for the language is ac*b. A regular grammar is
S â†’ aT

T â†’ b | cT.

- Regular grammars as we have defined them are often called right-regular because there are also left-regular grammars that require productions to have the form
A â†’ Bw or A â†’ w.

- Any language with a right-regular grammar also has a left-regular grammar, andconversely.

- For the regular expression a*bc* we have the following grammars.
- Right regular: S â†’ aS | bT
T â†’Ù¨ | cT.

- Left Regular: S â†’ Sc | Tb
T â†’Ù¨ | Ta.

- Notice in the previous example that right-regular grammars derive strings by examining the leftmost letter first, while left-regular grammars examine the rightmost letter first.
- Example/Quiz. Find a right-regular grammar and a left-regular grammar for the language of the regular expression a(b + c)*de*.
- Right regular: S â†’ aT
T â†’ bT | cT | dU

U â†’Ù¨ | eU.

- Left Regular: S â†’ Se | Td
T â†’ a | Tb | Tc.

1. State names become the nonterminals. So rename them to be uppercase letters.

2. The start state becomes the start symbol of the grammar.

3. For each state transition from I to J labeled with x construct a production I â†’ xJ.

4. For each final state F construct a production F â†’Ù¨.

- Transform the following NFA into a regular grammar.
Solution:

S â†’ aI | F

I â†’ aI | bF

F â†’Ù¨

This grammar can be simplified to

S â†’ aI | Ù¨

I â†’ aI | b

- Transform the regular expression a*(ba)* into a regular grammar.
- Solution: Draw an NFA and then use the algorithm.
An NFA:

The resulting grammar:

S â†’ aS | bI | Ù¨

I â†’ aF

F â†’ bJ | Ù¨

J â†’ aF.

- Simplify the grammar.
- Answer:
S â†’ aS | baF | Ù¨

F â†’ baF | Ù¨

- What happens when a DFA hasan error state, like the following DFA?
- Answer: The resulting grammar:
S â†’ aF | bE

F â†’ aE | bJ | Ù¨

J â†’ aF | bE

E â†’ aE | bE.

But E does not derive a terminal string. So the grammar simplifies to

S â†’ aF

F â†’ bJ | Ù¨

J â†’ aF.

- Simplify the grammar further.
- Answer: S â†’ aF
F â†’ baF | Ù¨.

1. Replace any production with multiple terminals by productions with single terminals.

2. The start state is the grammar start symbol.

3. Transform I â†’ aJ into a transition from I to J labeled with a.

4. Transform I â†’ J into a transition from I to J labeled with Ù¨.

5. Transform each I â†’ a into a transition from I to new single final state F labeled with a.

6. The final states are F together with each state I with a production I â†’Ù¨.

- Transform the following regular grammar into a NFA.
S â†’ abS | T | Ù¨

T â†’ cT | d

- Solution. Transform S â†’ abS into S â†’ aI and I â†’ bS, so the grammar becomes
S â†’ aI | T | Ù¨

I â†’ bS

T â†’ cT | d

Now the NFA can

be drawn:

- What is the regular expression for the language of the grammar?
- Answer: (ab)*(Ù¨ + c*d)

- When we know some properties of regular languages they can help us argue, BWOC, thatcertain languages are not regular.

- If L is an infinite regular language, then it is recognized by a DFA with, say, m states.
- If s in L and | s | â‰¥ m, then an acceptance path for s must pass through some state twice.
- The following graph depicts the situation.
- The dotted arrows represent the path to acceptance for s and the letters x, y, and z representthe concatenation of the letters along the edges of the path. So s = xyz and y â‰ Ù¨. Assumethat the middle state is the first repeated state on the path. So | xy | â‰¤ m. Since the loop canbe traversed any number of times, we have the pumping property: xykz âˆˆ L for all k âˆˆ N

- The language L = {anbn | n âˆˆ N} is not regular.
- Proof: Assume, BWOC, that L is regular. Since L is infinite, the pumping lemma applies.
Choose s = ambm. Then s = xyz, where y â‰ Ù¨, | xy | â‰¤ m, and xykz âˆˆ L for all k âˆˆ N.

Since | xy | â‰¤ m and s = ambm = xyz, it follows that xy is a string of aâ€™s.

Since y â‰ Ù¨, it must be that y = ai for some i > 0.

Weâ€™ll try for a contradiction with k = 2. The pumping property implies xy2z âˆˆ L.

But xy2z = am + ibm, which is not in L because i > 0.

This contradiction implies that L is not regular. QED.

- In the previous proof we exhibited a contradiction when k = 2. Find similarcontradictions for k = 0 and k = 3.
- Answer: (k = 0) The pumping property implies xy0z âˆˆ L. In other words, xz âˆˆ L.
But xz = am-ibm, which is not in L because i > 0. This contradiction implies that L is notregular. QED.

(k = 3) The pumping property implies xy3z âˆˆ L. But xy3z = am + 2ibm, which is not in L

because i > 0. This contradiction implies that L is not regular. QED.

- Prove the language L = {aabnac2n | n âˆˆ N} is not regular.
- Proof: Assume, BWOC, that L is regular. Since L is infinite, the pumping lemma applies.
Choose s = aabmac2m. Then s = xyz, where y â‰ Ù¨, | xy | â‰¤ m and xykz âˆˆ L for all k âˆˆ N.

Since | xy | â‰¤ m, there are three cases for y:

Case 1: y = aabi for some 0 â‰¤ i â‰¤ m-2. (Remember, | xy | â‰¤ m, so x = Ù¨ in this case.)

Case 2: y = abi for some 0 â‰¤ i â‰¤ m-2. (In this case, we have x = a.)

Case 3: y = bi for some 0 < i â‰¤ m-2-j. (In this case, x = aabj for some 0 â‰¤ j â‰¤ m-3)

We can obtain a contradiction in each case by considering k = 0, which implies xz âˆˆ L.

Case 1: xz = bm-iac2m which is not in L because strings of L must begin with aa.

Case 2: xz = abm-iac2m which is not in L because strings of L must begin with aa.

Case 3: xz = aabm-iac2mwhich is not in L because strings in L must have twice as many câ€™s as bâ€™s which canâ€™t be the case since i > 0.

So each of the three cases yields a contradiction. Therefore L is not regular. QED.