Processing math: 100%
Close
Close Window

OpenDSA Stand-alone Modules

Chapter 0 modules

Show Source |    | About   «  0.268. Regular Grammars   ::   Contents   ::   0.270. Identifying Non-regular Languages  »

Closure Properties of Regular Grammars

1. Closure Properties of Regular Grammars

1.1. Closure Concept

Definition: A set is closed over a (binary) operation if, whenever the operation is applied to two members of the set, the result is a member of the set.

Example 1

L={x|xis a positive even integer}

Is L is closed under the following?

  • addition? Yes. [How do you know? Need a proof.]
  • multiplication? Yes. [How do you know? Need a proof.]
  • subtraction? No. 610=4. [Now you know!]
  • division? No. 4/4=1. [Now you know!]

1.2. Closure of Regular Languages

Consider regular languages L1 and L2. In other words, regular expressions r1 and r2 such that L1=L(r1) and L2=L(r2).

These we already know: [Ask yourself: Why do we know this?]

  • r1+r2 is a regular expression denoting L1L2 So, regular languages are closed under union.
  • r1r2 is a regular expression denoting L1L2. So, regular languages are closed under concatenation.
  • r1 is a regular expression denoting L1. So, regular languages are closed under star-closure.

Proof: Regular languages are closed under complementation.

L1 is a regular language a DFA M such that L1=L(M).
Construct DFA M such that:
final states in M are nonfinal states in M.
nonfinal states in M are final states in M.
wL(M)wˉL closed under complementation.

Note

Why a DFA, will an NFA work? With difficulty: It must be a complete NFA with trap states added.

Proof: Regular languages are closed under intersection.

One simple way to prove this is using DeMorgan's Law:

L1L2=¯¯L1¯L2

Here is another approach by construction.

L1 and L2 are regular languages DFAs M1 and M2 such that L1=L(M1) and L2=L(M2).
L1=L(M1) and L2=L(M2)
M1=(Q,Σ,δ1,q0,F1)
M2=(Q,Σ,δ2,p0,F2)

Note

The idea is to construct a DFA so that it accepts only if both M1 and M2 accept

Now, construct M=(Q,Σ,δ,(q0,p0),F)
Q=(Q×P)
δ:
δ((qi,pj),a)=(qk,pl) if
δ1((qi,a)=qk)M1 and δ2((pj,a)=pl)M1.
F={(qi,pj)Q|qiF1 and pjF2}
wL(M)wL1L2 is closed under intersection

Example 2

Create the DFA for the intersection of two DFAs:

L1=ab and L2=aa{a|b}

stnfaints

1.3. Regular languages are closed under these operations

Reversal: LR

Difference: L1L2

Right quotient:

Definition: L1L2={x|xyL1 for some yL2}

In other words, it is prefixs of appropriate strings in L1.

Example 3

L1={abba}
L2={bn|n is even, n>0}
L1/L2={ab}

Theorem: If L1 and L2 are regular, then L1L2 is regular.

Proof: (sketch)

DFA M=(Q,Σ,δ,q0,F) such that L1=L(M).

Construct DFA M=(Q,Σ,δ,q0,F) (equivalent to M except for final states).

For each state i do
Make i the start state (representing Li)
if LiL2 then
put qi in F in M

Note

Not empty means there's a path between start and a final state.

QED.

Homomorphism:

Definition: Let Σ,Γ be alphabets. A homomorphism is a function h:ΣΓ

Homomorphism means to substitute a single letter with a string.

Example 4

Σ={a,b,c},Γ={0,1}
h(a)=11
h(b)=00
h(c)=0

h(bc)=h(b)h(c)=000
h(ab)=h(a)h(b)=11(h(b))=11(00)

1.4. Questions about regular languages

L is a regular language.

  • Given L,Σ,wΣ, is wL?

    Answer: Construct a FA and test if it accepts w.

  • Is L empty?

    Example: L={anbm|n>0,m>0}{bnam|n>1,m>1} is empty.

    Construct a FA. If there is a path from start state to a final state, then L is not empty.

    Note

    Perform depth first search.

    This was easy! But we will see that in other contexts that complement is not so simple to decide.

  • Is L infinite?

    Construct a FA. Determine if any of the vertices on a path from the start state to a final state are the base of some cycle. If so, then L is infinite.

  • Does L1=L2?

    Construct L3=(L1¯L2)(¯L1L2). If L3=, then L1=L2.

    Again, in other contexts, this is impossible. For example, we will prove that its not possible to decide, in general, if two programs do the same thing.

1.5. Summary: How do we prove that a language is regular?

We have a number of approaches in our toolbox.

  • Write a DFA that accepts the language.
  • Write a NFA that accepts the language.
  • Write a regular expression that accepts the language.
  • Write a regular grammar tha accepts the language.
  • Define the language in terms of one or more known regular languages that are manipulated by operators known to be closed under for regular languages.

   «  0.268. Regular Grammars   ::   Contents   ::   0.270. Identifying Non-regular Languages  »

nsf
Close Window