Properties of Regular Languages

Slides:



Advertisements
Similar presentations
Context-Free and Noncontext-Free Languages
Advertisements

1 Languages. 2 A language is a set of strings String: A sequence of letters Examples: “cat”, “dog”, “house”, … Defined over an alphabet: Languages.
1 More Properties of Regular Languages. 2 We have proven Regular languages are closed under: Union Concatenation Star operation Reverse.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 School of Innovation, Design and Engineering Mälardalen University 2012.
Finite State Machines Chapter 5. Languages and Machines.
CMPS 3223 Theory of Computation
Deterministic Finite State Machines Chapter 5. Languages and Machines 2.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
Automata, Computability, & Complexity by Elaine Rich ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Slides provided by author Slides edited for.
Regular and Nonregular Languages Chapter 8. Languages: Regular or Not? a * b * is regular. { a n b n : n  0} is not. {w  { a, b }* : every a is immediately.
1 Undecidability Reading: Chapter 8 & 9. 2 Decidability vs. Undecidability There are two types of TMs (based on halting): (Recursive) TMs that always.
1 State SymbolRead- Q E(Q) a b a b a b Convert to a DFA: Start state: Final States:
Regular and Nonregular Languages Chapter 8. Languages: Regular or Not? a * b * is regular. { a n b n : n  0} is not. {w  { a, b }* : every a is immediately.
MA/CSSE 474 Theory of Computation Decision Problems DFSMs.
Context-Free and Noncontext-Free Languages Chapter 13 1.
MA/CSSE 474 Theory of Computation Regular Expressions Intro.
Regular Expressions Chapter 6 1. Regular Languages Regular Language Regular Expression Finite State Machine L Accepts 2.
Strings and Languages CS 130: Theory of Computation HMU textbook, Chapter 1 (Sec 1.5)
CS 3240 – Chapter 4.  Closure Properties  Algorithms for Elementary Questions:  Is a given word, w, in L?  Is L empty, finite or infinite?  Are L.
Context-Free and Noncontext-Free Languages Chapter 13 1.
Properties of Regular Languages
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
Regular and Nonregular Languages Chapter 8 1. Languages: Regular or Not? a * b * is regular. { a n b n : n  0} is not. {w  { a, b }* : every a is immediately.
CS 203: Introduction to Formal Languages and Automata
Context-Free and Noncontext-Free Languages Chapter 13.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Finite State Machines Chapter 5. Languages and Machines.
Set, Alphabets, Strings, and Languages. The regular languages. Clouser properties of regular sets. Finite State Automata. Types of Finite State Automata.
P Symbol Q E(Q) a b a b a b Convert to a DFA: Start state: Final States:
1 Closure E.g., we understand number systems partly by understanding closure properties: Naturals are closed under +, , but not -, . Integers are closed.
MA/CSSE 474 Theory of Computation Closure properties of Regular Languages Pumping Theorem.
MA/CSSE 474 Theory of Computation How many regular/non-regular languages are there? Closure properties of Regular Languages (if there is time) Pumping.
MA/CSSE 474 Theory of Computation Decision Problems, Continued DFSMs.
MA/CSSE 474 Theory of Computation Regular Expressions Intro.
MA/CSSE 474 Theory of Computation Closure properties of Regular Languages Pumping Theorem.
Context-Free and Noncontext-Free Languages Chapter 13.
Decidability and Undecidability Proofs
Languages.
CSE 105 theory of computation
Properties of Regular Languages
PROPERTIES OF REGULAR LANGUAGES
Nondeterministic Finite Automata (NFA)
CSE 105 theory of computation
Nonregular Languages Section 2.4 Wed, Oct 5, 2005.
CSE 105 theory of computation
CSE 105 theory of computation
Properties of Regular Languages
Properties of Regular Languages
CSE322 CONSTRUCTION OF FINITE AUTOMATA EQUIVALENT TO REGULAR EXPRESSION Lecture #9.
Properties of Regular Languages
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Closure Properties of Regular Languages
Chapter 4 Properties of Regular Languages
Instructor: Aaron Roth
Convert to a DFA: Start state: Final States: P Symbol Q E(Q) a b.
CSE 105 theory of computation
Chapter 1 Regular Language
Instructor: Aaron Roth
Instructor: Aaron Roth
CSE 105 theory of computation
CSC312 Automata Theory Kleene’s Theorem Lecture # 12
CSE 105 theory of computation
NFAs accept the Regular Languages
MA/CSSE 474 Theory of Computation
Languages Fall 2018.
CSE 105 theory of computation
CSE 105 theory of computation
Presentation transcript:

Properties of Regular Languages Chapter 8

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}.

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.

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.

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.

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.

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

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}

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 = + 1, 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+2 + 1 for some k.

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.

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 264 -1. 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.

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.

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

Closure of Regular Languages Under Complement

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.

Closure of Regular Languages Under Complement What about? 1st: 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?

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?

A Complement Example

Closure of Regular Languages Under Intersection L1  L2 = L1 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)).

Closure of Regular Languages Under Intersection L1  L2 = (L1  L2) L1 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)).

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

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

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}

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}

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}

L1 is Regular

L2 is Regular

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?

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)

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)

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 = L1 L2

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 = L1 L2 {abanbn : n  0} = {ab} {anbn : n  0}

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 = L1 L2 {abanbn : n  0} = {ab} {anbn : n  0} L is not. {aaa*} = {a*} {ap: p is prime}

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 = L1 L2 {abanbn : n  0} = {ab} {anbn : n  0} L is not. {aaa*} = {a*} {ap: p is prime} L is.