ICS 171 Homework #14

1. (30) What is the internal horn clause representation of the following 5 grammar rules.

```( (s) --> (np)(verb)(prep_phrase))
( (prep_phrase) --> (prep) (np))
((prep) --> (:word to))
((proper_name) --> (:word UCI))
((verb) --> (:word went))```

If you can't figure it out, you can do something like this 5 times;

`(convert-rule '( (s) --> (np)(verb)(prep_phrase))).`

2. (40) Modify the simple grammar *dcg-rules* so that the following goals succeeds.

```(prove-and-ask '((s (I went to UCI) ())))
(prove-and-ask '((s (I ate an apple at UCI) ())))```

Hint 1. Use the above 5 grammar rules

Hint 2. "I" is a pronoun. Pronouns are noun phrases (np).

Hint 3. Some other rules are also needed.

You will type something like this

```(load "unify")
(store-clauses (convert-rules *dcg-rules*))
(prove-and-ask '((s (I went to UCLA) ())))```

`3. (10) Find all the solutions to (prove-and-ask '((s (?A ?B ?C ?D ?E) ())))`

Hint ((adresss) --> (:word ?name) (:word @) (:word ?domain)) will recognize anything of the form "NAME @ DOMAIN" We will assume that a space is inserted before and after the @ to make this easier.

EXTRA CREDIT Write a DCG grammar to parse infix arithmetic expressions and construct a lisp representation of the expressions. This will be somewhat similar to

*dcg-rules-building-structure*.

For example, given (x ^ 3 + 5 * x ^ 2 + 3 * x + -7) the following structure should be built:

`(+  (^ x 3) (+  (* 5 (^ x 2))  (+ (* 3 x) -7)))`
Watch out for precedence and left recursion. In addition, to include parentheses in your input, you can use |(| and |)| to treat parentheses as a symbol rather than the start or end of a list. Interface this to the derivative horn clauses, so you can take the derivative of something in infix. Also, you should be able to use the grammar rules to convert a lisp representation of a derivative back into an infix list.
Back to http://www.ics.uci.edu/~pazzani/171-p.html (text only) or http://www.ics.uci.edu/~pazzani/171.html .

Michael Pazzani
Department of Information and Computer Science,
University of California, Irvine
Irvine, CA 92717-3425
pazzani@ics.uci.edu