Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 12 Non-Regular Languages

Similar presentations


Presentation on theme: "Lecture 12 Non-Regular Languages"— Presentation transcript:

1 Lecture 12 Non-Regular Languages
CSCE 355 Foundations of Computation Lecture 12 Non-Regular Languages Topics: Strings distinguishing states Equivalence relation October 8, 2008

2 New: Last Time: Readings section 3.1,3.2(skip DFA RE), 3.3
Ruby: Matching in files (file.rb) Review Relations Again Strings distinguishing states Indistinguishable states Indistinguishable is an Equivalence relation Table of inequivalences Partitions New: If L is regular is the Reversal LR regular? Ruby: Matching in files (fileArgv.rb) Unix Shell “regular expressions”

3 Homework 1. Modify fileArgv.rb to substitute “xxx-xxxx” for every occurrence of phone number in every file in a directory 4.4.2

4 Unix Shell “regular expressions” Aren’t really regular expressions
Examples ls *.rb // * is not the closure operator but wildcard ls [a-d]* grep “[a-d]*” *

5 Ruby Matching in Files II, fileARGV.rb
ARGV.each do |arg| p arg f = File.open(p) f.each do |line| puts line if line =~ /Perl|Python/ puts "Scripting language mentioned:#{line}" end f.close

6 Command-Line Options -i [extension]
Edits ARGV files in place. For each file named in ARGV, anything you write to standard output will be saved back as the contents of that file. A backup copy of the file will be made if extension is supplied. Builtin-Variable $< (or ARGF) - An object that provides access to the concatenation of the contents of all the files given as command-line arguments or $stdin (in the case where there are no arguments).

7 Strings distinguishing states
A string x in Σ* distinguishes two states q1 and q2 if one of δ(q1, x) and δ(q2,x) is a final state and one if not. Examples What string distinguishes q1 and q2 in the DFA? What string distinguishes q3 and q2? Graphically

8 Indistinguishable states
Two states are indistinguishable if there is no string that distinguishes them What if we change the DFA to δ (q1,0) = q3 δ (q1,1) = q1 Then q1 and q2 are not distinguished by any string

9 Indistinguishable is an Equivalence relation
A relation is an Equivalence relation if . Prove Indistinguishable is an Equivalence relation Proof: Let

10 Figure 4.8 DFA page 156 Consider the DFA
Now ε distinguishes C from everything else Table of state inequivalences 1 A B C D E F G H . X 1 A B C D 1 1 1 1 1 E F G H 1

11 Table of state inequivalences
1 Table of state inequivalences 1 A B C D 1 1 A B C D E F G H . X 1 1 1 E F G H 1 Consider the string “0” Find pairs of states (p,r) with δ(q, 0)is distinguished from δ(r, 0) since δ(D, 0) = C and δ(X, 0) !=C; D is disting. from X = A, B, E, G, H since δ(F, 0) = C and δ(X, 0) !=C; F is disting. from X = A, B, E, G, H Now consider the string “0”

12 Table of state inequivalences
1 Table of state inequivalences 1 A B C D 1 1 A B C D E F G H . X 1 1 1 E F G H 1 Consider the string “1” Find pairs of states (p,r) with δ(q, 1)is distinguished from δ(r, 1) Is δ(A, 1)=B distinguished from δ(B, 1)=C? Is δ(A, 1)=B distinguished from δ(E, 1)=F? Is δ(A, 1)=B distinguished from δ(F, 1)=G? Is δ(A, 1)=B distinguished from δ(G, 1)=E? Now consider the string “0”

13 Table of state inequivalences
1 Table of state inequivalences 1 A B C D 1 1 A B C D E F G H . X 1 1 1 E F G H 1 Do iterations considering both 0 and 1. If for an iteration there is no change then there never will be. So stop. Now consider the string “0”

14 Partitions Equivalence class of x denoted [x]
Π = {X1, X2, … Xn} is a partition of a set S if . If R is an equivalence relation on a set S then R induces a partition on S which means the equivalence classes form a partition

15 Minimization of DFA First eliminate states not reachable from the start state Partition the states into sets of indistinguishable states (equivalence classes) Figure 4.12 Minimum state DFA equivalent to DFA in figure 4.8 (slide 10)

16

17 Strings distinguishable for a Language
Two strings y and z are distinguished by a language L if there is a string x such that exactly one of yx and zx is in L Example: L

18 Consequences for DFA Suppose a DFA D=(Q, Σ, δ, q0, F) has n states and that Language L has than n distinguished prefixes Then L cannot be the language accepted by D, (L(D). Why?

19

20 Applications

21 Not all Languages are regular

22

23 Pumping Lemma for regular languages


Download ppt "Lecture 12 Non-Regular Languages"

Similar presentations


Ads by Google