13.11.2014 Views

Introduction to Computational Linguistics

Introduction to Computational Linguistics

Introduction to Computational Linguistics

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

12. Finite State Au<strong>to</strong>mata 39<br />

There is a lot of repetition involved in this definition, so it is necessary only <strong>to</strong><br />

look at part of this. First, notice that prior <strong>to</strong> this definition, the program contains<br />

definitions of sets of states, which are simply sets of integers. The type is called<br />

StateSet. Similarly, the type CharSet is defined. Also there is the type of<br />

transition, which has three entries, first, symbol and second. They define the<br />

state prior <strong>to</strong> scanning the symbol, the symbol, and the state after scanning the<br />

symbol, respectively. Then a type of sets of transitions is defined. These are<br />

now used in the definition of the object type au<strong>to</strong>ma<strong>to</strong>n. These things need <strong>to</strong><br />

be formally introduced. The attribute mutable shows that their values can be<br />

changed. After the equation sign is a value that is set by default. You do not have<br />

<strong>to</strong> set the value, but <strong>to</strong> prevent error it is wise <strong>to</strong> do so. You need a method <strong>to</strong> even<br />

get at the value of the objects involved, and a method <strong>to</strong> change or assign a value<br />

<strong>to</strong> them. The idea behind an object type is that the objects can be changed, and<br />

you can change them interactively. For example, after you have loaded the file<br />

fsa.ml typing #use "fsa.ml" you may issue<br />

(110)<br />

# let a = new au<strong>to</strong>ma<strong>to</strong>n;;<br />

Then you have created an object identified by the letter a, which is a finite state<br />

au<strong>to</strong>ma<strong>to</strong>n. The initial state is 0, the state set, the alphabet, the set of accepting<br />

states is empty, and so is the set of transitions. You can change any of the values<br />

using the appropriate method. For example, type<br />

(111)<br />

# a#add_alph ’z’;;<br />

and you have added the letter ‘z’ <strong>to</strong> the alphabet. Similarly with all the other<br />

components. By way of illustration let me show you how <strong>to</strong> add a transition.<br />

(112)<br />

# a#add_transitions {first = 0; second = 2; symbol = ’z’};;<br />

So, effectively you can define and modify the object step by step.<br />

If A is not partial it is called <strong>to</strong>tal. It is an easy matter <strong>to</strong> make an au<strong>to</strong>ma<strong>to</strong>n<br />

<strong>to</strong>tal. Just add a state q ♯ and add a transition 〈q, a, q ♯ 〉 when there was no transition<br />

〈q, a, q ′ 〉 for any q ′ . Finally, add all transitions 〈q ♯ , a, q ♯ 〉, q ♯ is not accepting.<br />

Theorem 5 Let A be a finite state au<strong>to</strong>ma<strong>to</strong>n. Then L(A) is regular.<br />

The idea is <strong>to</strong> convert the au<strong>to</strong>ma<strong>to</strong>n in<strong>to</strong> an equation. To this end, for every state<br />

x<br />

q let T q := {x : i 0 −→ q}. Then if 〈r, a, q〉, we have T q ⊇ a · T r . In fact, if i i 0 we

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!