Presentation is loading. Please wait.

Presentation is loading. Please wait.

LING 388: Language and Computers Sandiway Fong Lecture 6: 9/13.

Similar presentations


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

1 LING 388: Language and Computers Sandiway Fong Lecture 6: 9/13

2 Administrivia Next Monday –September 20th –Laboratory Class –Homework #2 will be handed out –Instructional Computing Lab (ICL) –meet in SBS 224 (not here) Homework #1 –has been graded

3 Review Rules: 1.app([],L2,L2). 2.app([X|L1],L2,[X|L3]) :- app(L1,L2,L3). Computation tree: ?- app([1,2],[3,4],L). renames variables internally, cf. priming, L = _G297 Call: (7) app([1, 2], [3, 4], _G297) ? _G297 = [1|_G360] Call: (8) app([2], [3, 4], _G360) ? _G360 = [2|_G363] Call: (9) app([], [3, 4], _G363) ? _G363 = [3,4] Exit: (9) app([], [3, 4], [3, 4]) ? Exit: (8) app([2], [3, 4], [2, 3, 4]) ? _G360 = [2| [3,4]] Exit: (7) app([1, 2], [3, 4], [1, 2, 3, 4]) ? _G297 = [1|[2,3,4]] L = [1, 2, 3, 4] L = _G297

4 Last Time … Regular Expressions Finite State Automata (FSA) in Prolog sx y a a b b a+b+a+b+ 

5 Today’s Topic Equivalence between regular expressions and FSA More on FSA …

6 Regular Expressions (RE)  FSA How to show equivalence? Example (RE  FSA) –show methodically how each regular expression operator can be converted into a piece of a FSA [standard grep-style (not microsoft word) notation] –asingle symbol a –a n n occurrences of a –a * zero or more occurrences of a –a + one or more occurrences of a –a|ba or b –a?a is optional

7 Regular Expressions (RE)  FSA Operators –asingle symbol a –a n n occurrences of a –a –a n a 3  a a aa

8 Regular Expressions (RE)  FSA Operators –a * zero or more occurrences of a –a + one or more occurrences of a –a * –a + a + = aa * a a a

9 Regular Expressions (RE)  FSA Operators –a|ba or b –a?a is optional –a|b –a? a? = a| a b a

10 Regular Expressions (RE)  FSA -Transitions –do they endow the FSA with any more power? –Answer: No –We can always convert a machine with -transitions into one without Example: –(ab)|b a b a b b

11 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 choice point  need to keep track of where we could be –Example: Initially, states 1 or 2 sx y a a b b 12 a 3 b

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

13 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

14 Equivalence Regular Grammars FSA Regular Expressions NDFSA FSA with -transitions

15 NDFSA and Prolog We have already seen how to encode a regular FSA in Prolog –First method: (one predicate per state) s([a|L]) :- x(L). x([a|L]) :- x(L). x([b|L]) :- y(L). y([]). y([b|L]) :- y(L). s([a|L]) :- x(L). x([a|L]) :- x(L). x([b|L]) :- y(L). y([]). y([b|L]) :- y(L). sx y a a b b

16 NDFSA and Prolog We can do the same for NDFSA –direct encoding –without conversion to FSA –let Prolog ’ s computation rule keep track of the possible states and choice points for us sx a a y b 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([]).

17 NDFSA and Prolog Computation tree –?- s([a]).L=[] rule 1 ?- x([]). –No ?- y([]).L=[] rule 2 –Yes rule 4 sx a a y b 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([]).

18 -Transitions and Prolog Earlier example: sx a y b 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([]).

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

20 Next time Another neat feature of Prolog –Definite clause grammars (DCG) –Regular grammars


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

Similar presentations


Ads by Google