# LING 388: Language and Computers Sandiway Fong Lecture 9: 9/27.

## Presentation on theme: "LING 388: Language and Computers Sandiway Fong Lecture 9: 9/27."— Presentation transcript:

LING 388: Language and Computers Sandiway Fong Lecture 9: 9/27

Adminstrivia Reminder –Homework 2 due tonight –Need Help?

Administrivia some lectures are now available on the course hompage in audio format –as MP3 files –courtesy of Josh Harrison

Last Time Expressing regular expressions as FSA

Last Time Expressing regular expressions as FSA Microsoft Word Wildcards –@ one or more of the preceding character e.g. a@ –[ ] range of characters e.g. [aeiou] xy a a xy o a e i u

Last Time Prolog FSA implementation –regular expression: ba + ! –query ?- s([b,a,a,’!’]). –code one predicate per state (but each predicate may have more than one rule) –s([b|L]) :- x(L). sx z b ! y a a > –y([a|L]) :- y(L). –y([‘!’|L]) :- z(L). –z([]). –x([a|L]) :- y(L).

Today’s Topic More on the power of FSA …

FSA Finite State Automata (FSA) have a limited amount of expressive power Let’s look at some modifications to FSA and their effects on its power

String Transitions –so far... all machines have had just a single character label on the arc so if we allow strings to label arcs –do they endow the FSA with any more power? b Answer: No –because we can always convert a machine with string-transitions into one without abb abb

Empty Transitions –so far... all machines have had just a single character label on the arc how about allowing the empty string? –i.e. go from x to y without seeing a input character –does this endow the FSA with any more power? b Answer: No –because we can always convert a machine with empty transitions into one without xy

Empty Transitions example –(ab)|b a b a b b

NDFSA Basic FSA –deterministic it’s clear which state we’re always in, or deterministic = no choice point NDFSA –ND = non-deterministic i.e. we could be in more than one state non-deterministic  choice point –example: initially, either in state 1 or 2 sx y a a b b 12 a 3 b > >

NDFSA more generally –non-determinism can be had not just with -transitions but with any symbol example: –given a, we can proceed to either state 2 or 3 12 a a 3 b >

NDFSA –are they more powerful than FSA? –similar question asked earlier for -transitions –Answer: No –We can always convert a NDFSA into a FSA example –(set of states) 12 a a 3 b 1 2,3 a 3 b 2 > >

NDFSA example –(set of states) trick: –construct new machine with states = set of possible states of the old machine 12 a a 3 b > {1} > a > {2,3} {3}{3} ba {1} > {2,3} {3} ba {1} > {2,3} 1 2,3 a 3 b 2 >

Equivalence FSANDFSA FSA with -transitions same expressive power

NDFSA and Prolog we have already seen how to encode a regular FSA in Prolog –(using one predicate per state) s([b|L]) :- x(L). x([a|L]) :- y(L). y([a|L]) :- y(L). y([‘!’|L]) :- z(L). z([]). s([b|L]) :- x(L). x([a|L]) :- y(L). y([a|L]) :- y(L). y([‘!’|L]) :- z(L). z([]). sx z b ! y a a >

NDFSA and Prolog we can do the same for NDFSA –without the set-of-states conversion to FSA –let Prolog ’ s computation rule keep track of the possible states and choice points for us s([a|L]) :- x(L). s([a|L]) :- y(L). x([b|L]) :- y(L). y([]). s([a|L]) :- x(L). s([a|L]) :- y(L). x([b|L]) :- y(L). y([]). sx a a y b >

NDFSA and Prolog computation tree –?- s([a]).L=[] rule 1 ?- x([]). –No ?- y([]).L=[] rule 2 –Yes rule 4 1.s([a|L]) :- x(L). 2.s([a|L]) :- y(L). 3.x([b|L]) :- y(L). 4.y([]). 1.s([a|L]) :- x(L). 2.s([a|L]) :- y(L). 3.x([b|L]) :- y(L). 4.y([]). sx a a y b >

-Transitions and Prolog earlier example s([a|L]):- x(L). s(L):- x(L). x([b|L]):- y(L). y([]). s([a|L]):- x(L). s(L):- x(L). x([b|L]):- y(L). y([]). sx a y b >

-Transitions and Prolog Computation tree: –?- s([b]). rule 2 ?- x([b]).L=[] rule 3 –?- y([]). rule 4 »Yes 1.s([a|L]):- x(L). 2.s(L):- x(L). 3.x([b|L]):- y(L). 4.y([]). 1.s([a|L]):- x(L). 2.s(L):- x(L). 3.x([b|L]):- y(L). 4.y([]). sx a y b >

Download ppt "LING 388: Language and Computers Sandiway Fong Lecture 9: 9/27."

Similar presentations