1 / 33

LING 388: Language and Computers

LING 388: Language and Computers. Sandiway Fong 9/27 Lecture 10. Adminstrivia. Reminder Homework 4 due Wednesday. Today’s Topic. Finite State Automata (FSA) equivalent to the regular expressions we’ve been studying. Regular Expressions: Example. .... from lecture 8

zarek
Download Presentation

LING 388: Language and Computers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Adminstrivia • Reminder • Homework 4 due Wednesday

  3. Today’s Topic • Finite State Automata (FSA) • equivalent to the regular expressions we’ve been studying

  4. Regular Expressions: Example .... from lecture 8 • example (sheeptalk) • baa! • baaa! • baaaa! • … • regular expression • baaa*! • baa+!

  5. Regular Expressions: Example .... from lecture 8 • example (sheeptalk) • baa! • baaa! • baaaa! • … • regular expression • baaa*! • baa+! a s b w a x a y > ! z

  6. Regular Expressions: Example • step-by-step • regular expression • baaa*! s > Start state: s

  7. Regular Expressions: Example • step-by-step • regular expression • baaa*! • b • from s, • see ‘b’, • move tow s b w >

  8. Regular Expressions: Example • step-by-step • regular expression • baaa*! • ba • From w, • see an ‘a’, • move tox s b w a x >

  9. Regular Expressions: Example • step-by-step • regular expression • baaa*! • baa • From x, • see an ‘a’, • move toy s b w a x a y >

  10. Regular Expressions: Example • step-by-step • regular expression • baaa*! • baaa* • baa • baaa • baaaa • baaaaa... • from y, • see an ‘a’, • move to ? s b w a x a y > a y’ but machine must have a finite number of states! a y” a ...

  11. Regular Expressions: Example • step-by-step • regular expression • baaa*! • baaa* • baa • Baaa • baaaa • baaaaa... • from y, • see an ‘a’, • “loop” aka return to state y a s b w a x a y >

  12. Regular Expressions: Example • step-by-step • regular expression • baaa*! • baaa*! • from y, • see an ‘!’, • move to final state z (indicated in red) a s b w a x a y > ! z Note: machine cannot finish (i.e. reach the end of the input string) in states s, x or y

  13. Finite State Automata (FSA) • construction • the step-by-step FSA construction method we just used • works for any regular expression • conclusion • anything we can encode with a regular expression, we can build a FSA for it • an important step in showing that FSA and REs are equivalent

  14. a b c d x y e ... ... z etc. a etc. one loop for each character y Microsoft Word Wildcards • basic wildcards • ? and * • ? any single character • e.g. p?t put, pit, pat, pet • * zero or more characters

  15. a x y a a e i o x y u Microsoft Word Wildcards • basic wildcards • @ • one or more of the preceding character • e.g. a@ • [ ] • range of characters • e.g. [aeiou]

  16. see anything but ‘<‘ see anything but ‘>‘ x x y y < > Microsoft Word Wildcards • basic wildcards • < > • < • beginning of a word • can think of there being a special symbol/invisible character marking the beginning of each word • > • end of a word • suppose there is an invisible character marking the end of each word

  17. see anything but ‘>‘ x y > see anything but ‘m‘ x m y z > Microsoft Word Wildcards • basic wildcards • < > • > • end of a word • Note • the see-anything-but loop is implicit • m> • “word that ends in m” • example: • mom is...

  18. Finite State Automata (FSA) • more formally • (Q,s,f,Σ,) • set of states (Q): {s,w,x,y,z} 5 states must be a finite set • start state (s): s • end state(s) (f): z • alphabet (Σ): {a, b, !} • transition function : signature: character × state → state • (b,s)=w • (a,w)=x • (a,x)=y • (a,y)=y • (!,y)=z a s b w a x a y > ! z

  19. Finite State Automata (FSA) • in Prolog • define one predicate for each state • taking one argument (the input list L) • consume input character (take the head of the list) • call next state with the tail of the list • rule • fsa(L) :- s(L). i.e. call start state s

  20. Finite State Automata (FSA) • state s: (start state) • s([b|L]) :-w(L). match input string beginning with b and call statewwith remainder of input • state w: • w([a|L]) :- x(L). • state x: • x([a|L]) :- y(L). • state y: • y([a|L]) :- y(L). • y([!|L]) :- z(L). • state z: (end state) • z([]). a s b w a x a y > ! z

  21. Finite State Automata (FSA) • query • ?-s([b,a,a,a,!]). a s b w a x a y > [a,a,a,!] [a,a,!] [a,!] [b,a,a,a,!] ! [!] Database s([b|L]) :-w(L). w([a|L]) :- x(L). x([a|L]) :- y(L). y([a|L]) :- y(L). y([!|L]) :- z(L). z([]). z []

  22. Finite State Automata (FSA) • In which state does query • ?-s([b,a,b,a,!]). fail? a s b w a x a y > [a,b,a,!] [b,a,b,a,!] [b,a,!] ! Database s([b|L]) :-w(L). w([a|L]) :- x(L). x([a|L]) :- y(L). y([a|L]) :- y(L). y([!|L]) :- z(L). z([]). z

  23. FSA • Finite State Automata (FSA) have a limited amount of expressive power • Let’s look at a modification to FSA and its effect on its power

  24. b a b b abb 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? • Answer: No • because we can always convert a machine with string-transitions into one without

  25. Finite State Automata (FSA) • equivalent a a s b w a x a y > s baa y > ! ! z machine with 5 states z

  26. Finite State Automata (FSA) • equivalent a a s b w a x a y > s baa y > ! ! Database s([b|L]) :-w(L). w([a|L]) :-x(L). x([a|L]) :- y(L). y([a|L]) :- y(L). y(['!'|L]) :- z(L). z([]). Database s([b,a,a|L]) :- y(L). y([a|L]) :- y(L). y(['!'|L]) :- z(L). z([]). z z

  27. b ε x y Empty Transitions • so far... • how about allowing the empty character? • i.e. go from x to y without seeing a input character • does this endow the FSA with any more power? • Answer: No • because we can always convert a machine with empty transitions into one without

  28. a b b Empty Transitions • example • (ab)|b a b > > ε

  29. a b a b > ε Empty Transitions • example • (ab)|(empty string) = final state

  30. s x a a b y a b b 1 2 3 ε 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 > >

  31. a b 1 2 3 a NDFSA • more generally • non-determinism can be had not just withε-transitionsbut with any symbol • example: • given a, we can proceed to either state 2 or 3 >

  32. a b a b 1 2 3 2,3 2,3 2 1 3 a NDFSA • 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) > >

  33. > > > > a a {1} {1} {1} {1} {2,3} {2,3} b {3} a b a b > 1 2 3 2,3 2,3 2 1 3 a b {2,3} {3} a > NDFSA • example • (set of states) • construct new machine with states = set of possible states of the old machine • Essential trick: • i.e. simulate the old (non-deterministic) machine with the new machine

More Related