20.07.2013 Views

Notes on computational linguistics.pdf - UCLA Department of ...

Notes on computational linguistics.pdf - UCLA Department of ...

Notes on computational linguistics.pdf - UCLA Department of ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Stabler - Lx 185/209 2003<br />

Each <strong>of</strong> these soluti<strong>on</strong>s represents a different pro<strong>of</strong>, a pro<strong>of</strong> that could be diagrammed like the <strong>on</strong>e discussed<br />

above. 10<br />

Pitfall 2: Infinite terms<br />

Step 3 <strong>of</strong> the unificati<strong>on</strong> algorithm involves checking to see if a variable occurs in a term. This is called the<br />

“occurs check.” It is easy to find examples to show that this check is necessary. C<strong>on</strong>sider the prolog axiom<br />

which says that for any number N, the successor <strong>of</strong> N is greater than N:<br />

greaterthan(s(N),N).<br />

Now suppose we try to prove that some number is greater than itself. In prolog, this would be an attempt to<br />

prove the goal:<br />

| ?- greaterthan(N,N).<br />

To establish this goal, prolog will select the axiom greaterthan(s(N),N) and rename the variables to get<br />

something like E = greaterthan(s(A1), A1). We will then try to unify this with the goal F = greaterthan(N, N),<br />

but these are not unifiable. Let’s see why this is so. Comparing these expressi<strong>on</strong>s, we find that they differ at<br />

the expressi<strong>on</strong>s s(A1) and N, soσ1 ={N↦ s(A1)}. NowwecompareEσ1 = greaterthan(s(A1), s(A1)) with<br />

Fσ1 = greaterthan(s(A1), A1). These differ at the expressi<strong>on</strong>s s(A1) and A1. ButA1 occurs in s(A1) and so<br />

the algorithm stops with failure. We do not attempt to apply the substituti<strong>on</strong> {A1 ↦ s(A1)}.<br />

For the sake <strong>of</strong> efficiency, though, standard implementati<strong>on</strong>s <strong>of</strong> prolog do not apply the occurs check.<br />

This <strong>on</strong>ly causes trouble in certain cases, like the <strong>on</strong>e described above. If you give prolog the axiom above and<br />

the goal ?- greaterthan(N,N)., then prolog will start printing out something horrible like:<br />

N = s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s<br />

(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s<br />

(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s<br />

(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s(s<br />

...<br />

If you ever get something like this, try to stop it by typing c<strong>on</strong>trol-C <strong>on</strong>ce or twice. It should be clear by now<br />

why prolog prints this out.<br />

Like the problem with left recursi<strong>on</strong>, the designers <strong>of</strong> prolog could have eliminated this problem, but instead<br />

they chose to let the users <strong>of</strong> prolog avoid it so that (when the users are appropriately careful to avoid the<br />

pitfalls) the pro<strong>of</strong>s can be computed very quickly.<br />

10 Try diagramming <strong>on</strong>e or two <strong>of</strong> these pro<strong>of</strong>s <strong>on</strong> a dull evening.<br />

21

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

Saved successfully!

Ooh no, something went wrong!