Regular Languages and Non-Regular Languages: A Comprehensive Guide with Examples, Lecture notes of Theory of Computation

This note talks about the definiton of regular languages and also its use

Typology: Lecture notes

2016/2017

Uploaded on 04/21/2017

kudzai-shangwa
kudzai-shangwa 🇿🇼

7 documents

1 / 15

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Prepared by Zanamwe N Monday, March 25, 2013
The Regular Operations
There are 3 operations on languages, called the regular operations, and they are used to study
properties of the regular languages.
Definition: Let L1 and L2 be languages. We define the regular operations union,
concatenation and Kleene star as follows:
1. Union: L1L2 {x | xL1 or xL2}
2. Concatenation: L1L2 {xy | xL1 and y L2}
 Star: L1* { x1x2x3...xk | k>=0 and each xi L1}
Example:
Let the alphabet = {0, 1}, If language L1 = {00, 11} and language L2 = {01, 10}, then:
1. L1L2 {00,11, 01, 10}
2. L1L2 {0001, 0010, 1101, 1110}
3. L1* = {Λ, 00, 11, 0011, 1100...}
Regular languages
Are languages that can be defined by REs
Closure Properties
Theorem: the class of RLs is closed under union, concatenation, Kleene Closure, intersection
and complement.
Proofs
1. The class of RLs is closed under union
This means that when we have RLs L1 and L2 then L1 ∪L2 is also regular.
To prove that L1 ∪L2 is regular, take two FAs say M1 and M2 for L1 and L2
respectively and combine them into one new machine say M that accepts its input if
either M1 or M2 accepts their input.
This can also be proved by taking two REs, say r1 and r2 for L1 and L2 respectively
and combine them into one new RE r
2. The class of RLs is closed under the Concatenation
This means that when we have two RLs L1 and L2 then L1L2 is also regular.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Regular Languages and Non-Regular Languages: A Comprehensive Guide with Examples and more Lecture notes Theory of Computation in PDF only on Docsity!

The Regular Operations  There are 3 operations on languages, called the regular operations, and they are used to study properties of the regular languages.  Definition: Let L 1 and L 2 be languages. We define the regular operations union , concatenation and K leene star as follows:

  1. Union: L 1 L 2 { x | x L 1 or x L 2 }
  2. Concatenation: L 1 L 2 { xy | x L 1 and y L 2 }  Star: L 1 * { x 1 x 2 x 3 ...xk | k>=0 and each xi ∈ L 1 }   Example: Let the alphabet = {0, 1}, If language L 1 = {00, 11} and language L 2 = {01, 10}, then:
  3. L 1 L 2 {00,11, 01, 10}
  4. L 1 L 2 {0001, 0010, 1101, 1110}
  5. L 1 * = {Λ, 00, 11, 0011, 1100...} Regular languages Are languages that can be defined by REs Closure Properties Theorem: the class of RLs is closed under union, concatenation, Kleene Closure, intersection and complement. Proofs
  6. The class of RLs is closed under union  This means that when we have RLs L 1 and L 2 then L 1 ∪ L 2 is also regular.  To prove that L 1 ∪ L 2 is regular, take two FAs say M 1 and M 2 for L 1 and L 2 respectively and combine them into one new machine say M that accepts its input if either M 1 or M 2 accepts their input.  This can also be proved by taking two REs, say r 1 and r 2 for L 1 and L 2 respectively and combine them into one new RE r
  7. The class of RLs is closed under the Concatenation  This means that when we have two RLs L 1 and L 2 then L 1 L 2 is also regular.

 To prove that L 1 L 2 is regular, take two FAs say M 1 and M 2 for L 1 and L 2 respectively and combine them into one new machine say M that accepts strings in L 1 concatenated with strings in L2.  This can also be proved by taking two REs, say r 1 and r 2 for L 1 and L 2 respectively and combine them into one new RE r

  1. The class of RL is closed under the Kleene Closure  This implies that if we have a RL L 1 , then, L 1 * is also regular  To prove that L 1 * is regular, take an FA say M 1 for the language L 1 and modify it to accept L 1 *  This can also be proved by taking a RE say r 1 for L 1 and then finding its Kleene Closure
  2. The class of RLs is closed under Complementation  This means that if we have a regular language L 1 , then ܮ 1 is also regular.  This is proved by taking a finite automaton say M 1 for L 1 and modify it to accept ܮ 1.  The procedure is as follows: o Reverse the status of each state, ie if a state was final make it non-final and if a state was non-final make it final.
  3. The class of RLs is closed under Intersection  This means that if we have two RLs L 1 and L 2 for M 1 and M 2 respectively, then L 1 ∩ L 2 also regular.  To prove that L 1 ∩ L 2 is regular, we use DeMorgan’s Law which states that: o L 1 ∩ L 2 = ቀܮ 1 + ܮ 2 ቁ  Due to the fact the L 1 ݀݊ܽ L 2 are regular, so are ܮ 1 and ܮ 2. Since ܮ 1 and ܮ 2 are regular so is ܮ 1 + ܮ 2. And because ܮ 1 + ܮ 2 is regular so is ቀܮ 1 + ܮ 2 ቁwhich means that L 1 ∩ L 2 is regular. Example : Given two regular languages L 1 and L 2 over {a,b}, prove that L 1 ∩ L 2 is regular.  L 1 – all strings over {a,b} with a double a – r 1 = (a+b)aa(a+b)

z3 = x2 or x4 - final state z4 = x2 or x5 - final state z5 = x3 or x4 - non-final state z6 = x3 or x5 - final state. The machine for M1 + M2 is as follows: The compliment of the above machine L 1 ∩ L 2 is given below

The clever work saving method The machine that accepts the intersection of two languages can be constructed by using the union algorithm but changing the designation of the final states. A state is final in the resulting machine if and only if both the corresponding states of the first machine and the corresponding states of the second machine are final states. For example Find the intersection of L 1 and L 2 given that: L 1 = all words that begin with an a- the RE is a(a+b)* L 2 = all words that end with an a - the RE is (a+b)a L 1 ∩ L 2 = all words that begin and end with letter a – the RE is a(a+b)a + a

  1. The class of RLs is closed under Set Difference  This means that if we have two RLs L 1 and L 2 for M 1 and M 2 respectively, then L 1 - L 2 also regular.  To prove that L 1 - L 2 is regular, take two FAs say M 1 and M 2 for L 1 and L 2 respectively and combine them into one new machine say M that accepts strings in L 1 - strings in L2. L 1 - L 2 = L 1 ∩ ܮ 2. Non Regular Languages We have seen regular languages defined by different formalisms:
    • languages that can be recognized by a DFA.
    • languages that can be recognized by an NFA.
    • languages that can be denoted by a regular expression.
    • languages that can be generated by a right-linear grammar.  You might begin to wonder: are there any languages that are not regular?  In this unit we will see that there are languages that are not regular.  There is a proof tool that is often used to prove languages non-regular.
    • the pumping lemma – which describes an important property that all regular languages have. – If you can show that a given language does not have this property, you can conclude that it is not a regular language.  By Kleen’s theorem, Non regular languages cannot be defined by Res, DFAs, NFAs, TGs, GTG and RGs.  All languages are either regular or non-regular, none are both

 Let language L be {ߣ, ܾܽ , ܾܾܽܽ , ܾܾܾܽܽܽ , ܾܾܾܽܽܽܽ ܾ , ܾܾܾܾܾܽܽܽܽܽ , …}  This language can be defined as {anbn} = {w = {a,b}*^ | each w is of the form n a’s followed by n b’s}  Note the {a n b n } is not a regular expression because it includes symbols {} and n that are not in the alphabet of RE’s.  Is {a n b n } regular?  We have already indicated that regular languages are accepted by finite automata, so lets draw the FA that accept L. Proof that L is not regular  Assume that L is a regular language, then there would be a finite automaton that will accept L.  By definition this finite state automaton must have a finite number of states, say 90 states.  By definition this finite state automaton must accept all words in L and reject all words not in L  Now the string a^100 b^100 is in L  The first 100 letters of the string are a’s  Our finite state automaton cannot visit a new state for each of these letters because it has 9 0 states.  Therefore at some point it must return to a state that it has visited previously.

a

a

a

a

b

b

b

b

b

y is the substring starting at the letter after substring x. So y is substring of w that travels around the circuit coming back to the same state the circuit began with. Since there must be a circuit, y cannot be the null string. The substring y contains the symbols of w for exactly one loop around the circuit. z is the rest of w starting with one symbol after the substring y to the end of the substring w. This z could be null. The path for z could also loop around the y (or any other) circuit.  Intuitively what this says is that we can always a nonempty string y not far from the beginning of the string w ∈ L that can be “pumped": by repeating y any number of times (including zero times, i.e. deleting it) you obtain a string which is still in the language.  The pumping lemma tells us that all regular languages must possess the pumping property.  Thus we can show that a language is not regular by showing that it violates the pumping lemma. However, just because a language satisfies the pumping lemma, this does not mean the language is regular.  In other words there are non-regular languages which obey the pumping lemma.  Thus we should be careful and not use the pumping lemma to prove that a language is regular!  We should only use it to prove that some language is not regular. Later we will give a condition which is both necessary and sufficient for a language to be regular. Suppose you want to prove that an infinite language L is not regular:

  1. Assume the opposite: L is regular
  2. The pumping lemma should hold for L
  3. Use the pumping lemma to obtain a contradiction
  4. Therefore, L is not regular Explanation of Step 3: How to get a contradiction
  5. Let p be the critical length for L
  6. Choose a particular string which satisfies the length condition
  7. Write
  8. Show that for some
  9. This gives a contradiction, since from pumping lemma wL wxyz w ^  xyi^ zL i  1 w  xyi^ zL

Example 1 Prove using the pumping lemma that the language L = {anbn^ where n = 0, 1,2,3..} is not regular. Solution:

  1. Assume that L is regular and there exists some finite state automaton that can recognise it
  2. If L contains any word w of the form xyz then L must also contain all strings of the form xykz for k = 0,1,2,3,4,...
  3. A non-arbitrary word in L may be partitioned into three successive substrings, x, y and z in only three ways: a. x is an unbroken (possibly null) string of a’s, y is a non-null unbroken string of a’s and z is an unbroken string of b’s b. x is an unbroken string of a’s, y is a non-null unbroken string of b’s, z (possibly null) unbroken string of b’s c. x is unbroken string of a’s, y is unbroken string of some a’s followed by some b’s, z (possibly null) unbroken string of b’s  Examining each of the above three cases, we see that pumping y gives words that have: a. too many a’s b. too many b’s c. only strings accepted have one ab  None of these words is in L  Thus our assumption that some finite state automaton could recognise L must be false  Therefore there is no such finite state automaton  Therefore L is not regular

x

y

z

Solution

  1. Assume that L is regular and there exists some finite state automaton that can recognise it
  2. If L contains any word w of the form xyz then L must also contain all strings of the form xy k z for k = 0,1,2,3,4,...
  3. A non-arbitrary word in L may be partitioned into three successive substrings, x, y and z in only five ways: a. x is an unbroken (possibly null) string of a’s, y is a non-null unbroken string of a’s, and z contains the transitions from a’s to b’s and from b’s to c’s b. x is an unbroken (possibly null) string of a’s, y contains the transitions from a’s to b’s and z contains the transitions from b’s to c’s c. x contains transitions from a’s to b’s, y is an unbroken string of b’s, and z contains transitions from b’s to c’s d. x contains transitions from a’s to b’s, y contains transitions from b’s to c’s and z is an unbroken (possibly null) string of c’s e. x contains transitions from a’s to b’s and transitions from b’s to c’s, y is a non-null unbroken string of c’s and z is an unbroken (possibly null) string of c’s We have to show that in each case, by going around the circuit an arbitrary number of times (that is by pumping y), the finite state automaton will accept words of the form xy k z that are demonstrably not in L.  Examining each of the above five cases, we see that pumping y gives words that have: a. Too many a’s (ie p+q > r) b. More than one transition from a to b c. Too many b’s (ie p+q > r) d. More than one transition from b to c e. Too many c’s (ie p+q < r)

 None of these words is in L  Thus our assumption that some finite state automaton could recognise L must be false  Therefore there is no such finite state automaton  Therefore L is not regular Example 4 Prove that the language EQUAL is not regular. EQUAL is the language of all words with the total number of a’s and b’s. Solution Note that: L(a

b

) ∩ EQUAL = {a n b n }. Now if EQAUL were a regular language, then {a n b n } would be the intersection of two regular languages and it would have to be regular itself. Since {anbn} is not regular, EQUAL cannot be. Decidability Decidability refers to a problem with a decision procedure. A decision procedure is an effective solution to a problem that has a yes or no answer. Decidability issues

1. How can we tell if two regular expressions define the same language 2. How can we tell if two finite automata are equivalent 3. How can we tell if the language defined by a finite automaton has finitely many or infinitely many words in it. 1. Deciding whether two regular expressions determine the exact/same language  Given two languages L and M defined either by a finite automaton or regular expressions we can produce finite automata for languages ܮ, ܯ, M ∩ ܮ, L ∩ ܯ,  Therefore we produce a finite automaton that accepts the language (M ∩ ܮ) + (L ∩ ܯ)  This machine accepts the language of all words that are in L but not in M or else in M but not in L  If L and M are the same language, this machine cannot accept any words  If this machine accepts even one word the L is not equal to M, even the one word is the null word.